To make a long story short, I wrote a very long message yesterday … and forgot to post it.
So, it will be shorter today.
English is not my native language.
Plus it’s very late. I will make even more mistakes.
I have several “objects”. I don’t mean by this term “open gl set of attributes” or anything like that. I mean : a ship, a rock etc.
All of this objects have several parts.
Each part has a material.
However, there is few materials : they are reused over and over again between objects.
(you can look at kenney’s resources if you want an example).
And I can even reduce this number as many materials are only a single color. I can end up with very few render passes.
So, the idea is: have one mesh per material, and store objects as subparts of the mesh.
I can “acquire” and “release” triangles, and I use a virtual addressing so I can relocate the triangles to keep a mesh without holes.
I already have all of this.
However, I need now to give a transformation matrix to each of my objects.
The idea I have is : store an integer on every vertex (or “on every triangle” if possible, but I think there is still no “triangle shaders”, so it will be “on every vertex”).
This integer references a column in a texture.
The texture has a dimension of n*12 (width = n, height = 12)
n is a power of 2, greater than (or equals to) the number of objects I have.
Why “12” ? Well, it’s a 4x4 matrix, but the last line is always “0 0 0 1”. So, there is 4x3 “meaningfull” values = 12
This way, when I want to update the position/rotation of an object, I can just update one column in the texture.
Technically, 6 float would be enough : euler angles + position. Or 7 : quaternion + position. But whatever, it’s not the question.
My questions are:
is this the “good” way of doing it ?
is there a gl function called “glFloatToBytes”, which would convert my IEEE754 float on my cpu to the representation of the float gpu side ? I don’t know how to store floats in a texture. As it is graphic-card dependent, it has to be a gl function.
is it possible to associate an integer to each vertex ? I know I can associate texture coordinates, normals, colors … but a single integer ? I will need this integer in the vertex shader to lookup for the matrix values in the texture.
do you know a library (in C) that already does that ?
(is this forum the good one ? I am not sure it’s a basic or advanced question)
I am not aiming for a particular version of OpenGL. However, my graphic card is pretty old (amd radeon 6570).
And, if possible, it would be better to run on mobile (in theory, as I don’t have any kind of android anyway).
So, OpenGL ES 2 or 3 would be nice.
I am pretty sure I don’t do “opengl >3.1” stuff. However, as I use (basic) shaders and vbo’s the transition should not bo that hard.
I don’t have internet during the day, only during the evening (after midnight and before 4 am). And then I don’t have an environment to program (and I have other things to do anyway).
thanks for reading.