S.Seba
S.Seba

Reputation: 121

Which way of rendering objects in OpenGL is more efficient?

Which way of rendering two graphic elements with the same shape but different coordinates is more efficient using OpenGL (for eg. one object is upside down)?

  1. Generate two different sets of points using CPU and then use only one shader in while loop
  2. Generate only one set of points using CPU, create two different shaders and then switch between them in the while loop?

Additional question: Is there a possibility to create a set of points inside a shader? (This points will be calculated using sin() and cos() functions)

Upvotes: 0

Views: 203

Answers (1)

ixf
ixf

Reputation: 26

If in the first case you're switching buffers between OpenGL function calls then probably both solutions are equally bad. If you're holding two shapes in a single buffer and drawing everything in a single call then it's going to be faster than solution 2, but it requires twice the memory, which is also bad. ( You should have a single buffer for the shape and another one for transformations )
In general, you should use as few OpenGL calls as possible.

Regarding the second question: yes. For example, you could use a hard-coded array or derive the point coordinates from gl_VertexID.

Upvotes: 1

Related Questions