0

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

ammar26
  • 1,584
  • 4
  • 21
  • 41

1 Answers1

2

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.

BDL
  • 21,052
  • 22
  • 49
  • 55
  • So glDrawArraysInstanced will not take more then 4 vertices even if define the primitive count to be twice? – ammar26 Dec 16 '14 at 09:09
  • No. Thats not what glDrawArraysInstanced is for. It draws the SAME data primitive_count times. Have a look to the [reference](https://www.opengl.org/sdk/docs/man/html/glDrawArraysInstanced.xhtml), there is a code sample explaining that. – BDL Dec 16 '14 at 09:14