1
\$\begingroup\$

Looks like I have a problem with basic understanding of how OpenGL works. Lets say I have a mesh made out of three cylinders that is shown on the picture: branching example

So are there any major difference in performance/memory if I make three different cylinder objects or one object made out of three cylinders? Well, if I make them separately with OpenGL, there would obviously be memory overhead because I repeat vertices for each of these cylinders in the middle (section area). That I can see. But, what about difference between having one big vertex shader vs having more smaller ones? Lets say we have 20 objects in the scene. Are their vertex shaders all sent separately to the GPU or are they all collected and sent together? If they are sent separately should that be slower than making one big vertex shader that will have to be sent to the GPU at once?

Second part is question about UV-s. Lets say all three cylinders have same texture, or one cylinder has half of the texture and second braching parts have second half of the texture. If I make an object containing all cylinders then obviously I would have to define UV array only for each of my vertices. Taking this into consideration are there any memory/performance issues if I use values for U and V greater than 1. For instance "lower" vertices of cylinder down would have V = 0, "upper" would have V = 1, and "upper" vertices of cylinder up would have V = 2. Does usage of UVs coordinates greater than 1 have any influence on performance or does the OpenGL only do basic rescaling? However, if I use same texture on each cylinder that are made separately then I would have to make UV array only once and just reuse it for each cylinder. Again I'm not sure what is the better option

Basically, lets say branching in this picture is repeated, like in a tree structure. What are the pros and cons of making a whole tree as one object and making it as a collection of a lot of small branches, besides simplicity of second option?

\$\endgroup\$
  • 1
    \$\begingroup\$ Hi Nemanja Stojanovic, and welcome to GameDev.StackExchange. Since answers below have already spoken to both points, I won't make edits to change your question, but in future please ask just one question per question post. It's OK if you have two different questions, just ask them in two different posts. This lets us get more focused Q&A that's easier for users to search, and usually gets better-quality answers faster. Also, when you want to know if way A or B is faster/slower/heavier, the best way to find out is to build a test case and profile it on your target hardware. \$\endgroup\$ – DMGregory Sep 25 '18 at 11:58
1
\$\begingroup\$

For the first part, it depends on rendering pipeline and/or the game engine. If you choose to make them separate, engine could load them as a different subsets/objects and perform frustum culling, so only visible parts are rendered. In terms of memory, not a big difference, and neither in terms of speed, for modern hardware. (But again, it depends - could be a great deal if you're doing it for an ancient console or hardware.)

For the second part, I'd suggest you to stick with UV in [0; 1] range, because OpenGL sampler would require repeat to be enabled, otherwise your model would look weird on parts where your UV's are out of the range. But if you're sure about what you're doing (meaning that you're under control of texture sampling mode), tiled textures are usually achieved through UV's being scaled, meaning they are out of [0; 1] range, obviously. Regarding performance, again, I don't think there's that big of a difference. In theory, there could be made some optimisations if tiling is disabled on a sampler, but I have no idea if some OpenGL implementations actually do them, very low-level stuff here, and implementation dependent.

\$\endgroup\$
0
\$\begingroup\$

The real question is, why would you want to create separate simple objects? If there is no reason, creating one complex one sounds like the best solution, so you have one object to worry about, which makes it more maintainable.

If for any reason you want to have separate objects (to animate them manually, or for any other reason) then you should have them separate, but they'd be harder to maintain, as now you have more objects in your scene.

Performance-wise you won't notice any difference, sure using 10 extra vertices costs some memory, but considering modern games have millions of vertices, this shouldn't be noticeable. CPU-wise you don't really get any penalty, you draw the same amount of triangles (assuming the two separate objects connect perfectly), so the same amount of pixels on the screen are being drawn. You may get an overhead if you execute more drawing calls, but that really depends on the game engine / graphics library.

For the UV part, I'm not sure if I understand it correctly, but when you have UVs greater than 1 there isn't any important penalty in performance, and the behaviour depends on the engine / library that you use. For instance, OpenGL has the GL_REPEAT flag, so if you have UVs greater than 1, the texture simply repeats itself like tiles. So U = 2; and V = 2; would mean that the texture would be drawn 2 times horizontally and 2 times vertically.

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.