0

I have two buffers:

(1) Vertices - Holds interleaved positions, colors, etc. Many of these make up a single mesh.

(2) Transforms - Holds 4x4 transform matrices. One of these corresponds to a single mesh.

Since there are many vertices per transform, how do I draw the vertices such that the transform buffer only advances after x vertices have been processed?

I am using glDrawArrays() once to draw everything since each mesh should only be drawn once and they all use the same shader. Right now, I think the vertex shader pulls the next mat4 transform for each vertex, which is too often. Instead of pulling for each vertex, it should only pull for each mesh, which is made up of x vertices.

EDIT

I used glMultiDrawArraysIndirect() as my solution. The following guide on Reddit describes my exact problem and how to solve it:

https://www.reddit.com/r/opengl/comments/3m9u36/how_to_render_using_glmultidrawarraysindirect/

Klayton
  • 1
  • 4
  • Sounds like [`glMultiDrawIndirect` is what you need](https://stackoverflow.com/a/55544058/277176), perhaps with one instance per draw command if all meshes are different. – Yakov Galka Jun 10 '23 at 02:30
  • @YakovGalka Thank you for that suggestion, I used it as my solution. – Klayton Jun 15 '23 at 19:26

1 Answers1

0

You could pass the index of the transform per-vertex (similar to the position, color, etc information) to the vertex shader. This index can then be used in the vertex shader to access the correct transform in the array.

I don't think this can be done with a combination of stride and size as you would have to consume x vertices by loading the same transform. If you want to change the way you draw the shapes you could issue a different draw call for each shape and use a uniform for the transform.

Kevin Spaghetti
  • 620
  • 4
  • 16