Advertisement Jump to content

OpenGL how to systematicaly draw objects with different programs/VAOs/set of uniforms

Recommended Posts


i'm struggling with that question for a long time now. assume you have 2 programs (shader) and 2 vertex arrays to draw 2 different kind of things:

1. VAO: attributes are vec3 position, vec4 color

2. VAO: atributes are vec3 position, vec2 texturecoordinates, vec3 normals

both programs use different uniforms:

1. PROGRAM: mat4 transform

2. PROGRAM: mat4 transform, several material parameters, textures, lights, ...

drawcalls are the same for both ... how would you simplify that?

/// general draw call
struct DrawRangeElementsBaseVertex
	GLenum Mode = GL_POINTS;
	GLuint Start = 0;
	GLuint End = 0;
	GLsizei Count = 0;
	const GLvoid* Indices = nullptr;
	GLint BaseVertex = 0;

/// general draw method
void Draw(const DrawElementsBaseVertex & cmd)
	glDrawElementsBaseVertex(cmd.Mode, cmd.Count, cmd.Type, cmd.Indices, cmd.BaseVertex);

/// (using PROGRAM 1 and VAO 1)
struct CDrawableNode
	/// world space transform
	glm::mat4 Transformation = glm::mat4(1);
	CMaterial Material;
	DrawRangeElementsBaseVertex MeshDrawCall;

/// (using PROGRAM 2 and VAO 2)
struct CDrawableGeometry
	/// world space transform
	glm::mat4 Transformation = glm::mat4(1);

	/// drawcall references
	std::vector<DrawRangeElementsBaseVertex> DrawCalls;

now i have 2 different for-loops for processing all the "CDrawableGeometry" and "CDrawableNode" in my scene. i'd like to do it with 1 big loop using "struct CRenderstates" somehow. has anybody some infos / links to useful sites / advices where to start with that ? somehow like:

for each renderstate ... set state

--> for each program/VAO ... use shader, bind program, set uniforms

----> for each object ... set program-specific uniforms, issue drawcalls

Share this post

Link to post
Share on other sites

Not sure what you're really asking, you pasted some source that doesn't really tell much - like what's your DrawableGeometry vs DrawableNode? What's the problem of doing it in one loop? Have you read about render queues, render items, sorting, state caching etc? 

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!