0
votes

I'm trying to draw a two patches of rectangle (for tessellation) and I want to draw them from 0,0 to 1,1 and other from 1,0 to 2,1

I'm using GL_PATCHES to send a quad to my graphics pipeline

My vertex data in homogeneous coordinates is

float vertices[32] = {
0.0, 0.0, 0.0, 1.0, //1st rec
1.0, 0.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
0.0, 1.0, 0.0, 1.0,
  1.0, 0.0, 0.0, 1.0, //2nd rec
  2.0, 0.0, 0.0, 1.0,
  2.0, 1.0, 0.0, 1.0,
  1.0, 1.0, 0.0, 1.0
   };

And in C++ code

glPatchParameteri(GL_PATCH_VERTICES, 4);
glDrawArraysInstanced(GL_PATCHES, 0, 4, 2);

But I'm only getting one rectangle patch from 0,0 to 1,1 on my screen. I don't understand why it it doesn't draw the second rectangle

My tessellation evaluation shader is

vec4 vert= vec4(0.0, 0.0, 0.0, 1.0);
vert.x = gl_in[0].gl_Position.x + gl_TessCoord.x;
vert.y = gl_in[0].gl_Position.y + gl_TessCoord.y;

I convert this vert to vec4 and pass it to gl_Position

1

1 Answers

2
votes

glDrawArraysInstanced draws several instances of the data specified. In your case, it draws two times the vertices 0 to 4, which gives you two quads lying on the same position.

I would suggest you simply use glDrawArrays(GL_PATCHES, 0, 8) instead, but you could also keep your draw call and translate in the vertex shader according to the gl_InstanceID.