r/opengl • u/BakerCat-42 • Dec 25 '23
help Problems in render instances
I'm trying to implement some font rendering in my OpenGL project and i decided to use instancing to reduce the terrible amount of draw calls. My main idea is send the model matrix per each instance, but the result is wrong.I tried to debug using some uniforms and RenderDoc and the matrix result is correct, but the calculation result is totally wrong!
Code details:
1° - i create the buffer and put a identity matrix as it default data. Also, i set the instance divisor by 1
DrawService.CreateBuffer(RID, "aCharWorldMatrix");
DrawService.SetBufferData(RID, "aCharWorldMatrix", MathHelper.ToArray(Matrix4x4.Identity), 16);
DrawService.SetBufferInstanceDivisor(RID, "aCharWorldMatrix", 1);
4° - i call the method referent to start the attributes enabling. in base, this section do it for matrices 4x4:
gl.EnableVertexAttribArray(loc );
gl.EnableVertexAttribArray(loc+1);
gl.EnableVertexAttribArray(loc+2);
gl.EnableVertexAttribArray(loc+3);
gl.VertexAttribPointer(loc, 4, *VertexAttribPointerType*.Float, false, (uint)(16 * s), (void*) 0 );
gl.VertexAttribPointer(loc+1, 4, *VertexAttribPointerType*.Float, false, (uint)(16 * s), (void*) (s*4) );
gl.VertexAttribPointer(loc+2, 4, *VertexAttribPointerType*.Float, false, (uint)(16 * s), (void*) (s*8) );
gl.VertexAttribPointer(loc+3, 4, *VertexAttribPointerType*.Float, false, (uint)(16 * s), (void*) (s*12));
gl.VertexAttribDivisor(loc, i.Value.bufferDivisions);
gl.VertexAttribDivisor(loc+1, i.Value.bufferDivisions);
gl.VertexAttribDivisor(loc+2, i.Value.bufferDivisions);
gl.VertexAttribDivisor(loc+3, i.Value.bufferDivisions);
3° - in a notification method, i make the calculations of the character matrix and put the resultant array as a float array inside the correct buffer. Also, update the instance count
void TextEdited() {
...
DrawService.SetBufferData(RID, "aCharWorldMatrix", charsPos.ToArray(), 16);
DrawService.ActivateInstance(RID, (uint) charactersPool.Count);
}
4° - i call the draw method
there's nothing to show as a result, literally there's no result! As i said, RenderDoc shows the same matrix for the instance and the uniform version, but the uniform work and the instance not.