0

I have been trying to batch render two different pictures. I have 2 different QOpenGLTexture objects I want to draw in a single draw call with batch rendering but am struggling. Both texture objects have id's but only the last texture objects image is drawn. I believe my problem is with setting up the or frag shader.


//..............Setting up uniform...............//
const GLuint vals[] = {m_texture1->textureId(), m_texture2->textureId()};
m_program->setUniformValueArray("u_TextureID", vals, 2);

//..............frag Shader.....................//
#version 330 core
out vec4 color;
in vec2 v_textCoord;               // Texture coordinate
in float v_index;                  // (0, 1) Vertex for which image to draw.  
                                   // 0 would draw the image of the first texture object
uniform sampler2D u_Texture[2];

void main()
{
    int index = int(v_index);
    color = texture(u_Texture[index], v_textCoord);
};

I've tried experimenting with the index value in the frag shader but it only draws the last texture image or blacks out. I tried implementing it how you would with openGL but have had no luck.

symanoz
  • 51
  • 4
  • 1
    Apart from anything else, the values in uniform `u_Texture` should be the texture units currently associated with the two bound textures -- *not* the texture ids themselves. – G.M. Dec 29 '22 at 10:58
  • ...and why `in float v_index;`? Surely making `v_index` an integer type would make more sense? – G.M. Dec 29 '22 at 11:28
  • The v_index comes from a GLfloat array holding the data about both squares to draw on – symanoz Dec 29 '22 at 20:41

0 Answers0