cooky451
10-07-2011, 09:45 AM
Hi,
since I have a very high performance lack when I'm rendering many objects, I want to use instancing. (The "bad" functions are glUseProgram/glUniform**/glDrawElements. With instancing I could draw much more objects.)
I'm using the function glDrawElementsInstanced. My question is now, how to get my object matrices into the vertex shader. I tried it with arrays, but even my GeForce GTX 460 can only take a mat4[255]. I can only imagine how low this limit would be on older cards.
Somewhere I read that one could use textures to pass the matrices. Is that really a good idea? (It seems more like a bad hack to me, but if this is the only possibility..)
So if there is no alternative, how can I access the parts of a sampler2D, so that I can read the matrices?
(I'm creating the texture like this:)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, object_status_texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 512, 512, 0, GL_RGBA, GL_FLOAT, &mats[0]);
glUniform1i(shader_object_status_, object_status_texture_id);
since I have a very high performance lack when I'm rendering many objects, I want to use instancing. (The "bad" functions are glUseProgram/glUniform**/glDrawElements. With instancing I could draw much more objects.)
I'm using the function glDrawElementsInstanced. My question is now, how to get my object matrices into the vertex shader. I tried it with arrays, but even my GeForce GTX 460 can only take a mat4[255]. I can only imagine how low this limit would be on older cards.
Somewhere I read that one could use textures to pass the matrices. Is that really a good idea? (It seems more like a bad hack to me, but if this is the only possibility..)
So if there is no alternative, how can I access the parts of a sampler2D, so that I can read the matrices?
(I'm creating the texture like this:)
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, object_status_texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 512, 512, 0, GL_RGBA, GL_FLOAT, &mats[0]);
glUniform1i(shader_object_status_, object_status_texture_id);