🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

I don't understand render queues

Started by
0 comments, last by orange1 2 years, 8 months ago

So render queues sort objects in a way as to minimize the amount of state changes. Say each object has a shader, texture and vbo associated with it. And say we sort the objects to draw based on these three parameters.

struct Object {
    //
    Shader* shader;
    Texture* texture;
    Vbo* vbo;
};

void SetStates(Object* object) {
    SetShader(object->shader);
    SetTexture(object->texture);
    SetVbo(object->vbo);
    Draw(object);
}

Now if we sort the objects based on shader, texture and vbo in that order. And call SetStates och each object. Won't we now have state call redundancies when two objects have the same state? If two objects objectA and objectB use the same shader and we run the below code, we have one redundant SetShader call. And in OpenGL at least redundant calls are not guaranteed to be optimized away.

SetStates(objectA);
SetStates(objectB);

Am I misunderstanding how render queues actually work?

Isn't it better to structure the rendering like below instead? That way we avoid redundant calls.

   for shader in shaders
      set shader
      for texture in textures
          set texture
          for vbo in vbos
             set vbo
             for object in objects:
                  draw object

This topic is closed to new replies.

Advertisement