# glDrawArrays (layered rendering using geometry shader) only draws one point

I have been debugging this for a while but I can't seem to find the issue.

I created a framebuffer for layered rendering like this

GLuint buffer;
glGenFramebuffers(1,&buffer);
glBindFramebuffer(GL_FRAMEBUFFER,buffer);

glFramebufferTexture(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,textures[0],0);

GLenum blub[] = {GL_COLOR_ATTACHMENT0};

glDrawBuffers(1,blub);


where textures[0] is a 3D texture for layered rendering. The texture is texture complete, using nearest for min and mag filtering, no mip mapping, clamp to edge for s,t and r. I can sample from it fine (I initialize the texture to a color based on the z coordinate inside the 3d texture, it's initialized fine as well). The size of the 3D texture right now is 32x32x32 texels.

The framebuffer is framebuffer complete (checked it using glCheckFramebufferStatus).

Then I create and fill a buffer with vertex data for the points like this:

vector<vec2> points;
points.push_back(vec2(0.0f,0.0f)); //should draw in the middle
points.push_back(vec2(0.5f,0.5f)); //3/4th in each direction
points.push_back(vec2(-0.5f,-0.5f)); //opposite of second point
points.push_back(vec2(-0.95f,-0.95f)); //first texel on the bottom left

glGenBuffers(1,&result);

glBindBuffer(GL_ARRAY_BUFFER,result);
glBufferData(GL_ARRAY_BUFFER,points.size()*2*sizeof(float),&points[0],GL_STATIC_DRAW);


where vec2 is the vec2 floating point vector class provided by GLM.

Then I render it by doing this:

glViewport(0,0,textureSizeX,textureSizeY);
glBindFramebuffer(buffer);
glBindBuffer(GL_ARRAY_BUFFER,_pointbuffer);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0,2,GL_FLOAT,GL_FALSE,0,0);
glDrawArrays(GL_POINTS,0,4);


where shader is a shader constructed from vertex, geometry and fragment shaders. It compiles fine without warnings. Depth and stencil testing are disabled. textureSizeX and textureSizeY are the width and height of the 3D texture.

#version 430

layout(location =0) in vec2 pos;

void main()
{
gl_Position = vec4(pos.xy,0,1);
}


#version 430

layout(points) in;
layout(points, max_vertices = 1) out;

void main()
{
gl_Layer = 0;
gl_Position = vec4(gl_in[0].gl_Position.xy,1,1);
gl_PointSize = 1.0f;

EmitVertex();
EndPrimitive();
}


#version 430

out vec4 outcolor;

void main()
{
outcolor = vec4(0,1,0,0);
}


However, only the first point is drawn, as expected in the middle of layer 0 of the 3D texture. I can move around the coordinates of the first point and get the expected results. The points after the first point are always ignored, however. What am I doing wrong?

Hardware is GTX 770 with driver version 331.82 (latest version). Tested it on GT 555M (Notebook GPU), same results. The OpenGL device context is version 4.3.

edit: Tried so far: When I extend the attribute input of the vertex data to a vec4, and change the argument in glVertexAttribPointer accordingly, as expected the z and w components of the vec4 contain the coordinates of the second point, so the positions seem to be in memory as expected.

Similarly, if I change the offset using glVertexAttribPointer (e.g. putting (void*)(sizeof(vec2)*3) as the last parameter), the respective point is drawn.

Just to test if something may be wrong with the rasterization in general, I tried emitting triangles instead of points in the geometry shader. This works as expected.

• Question:Are layout(location=5) + the two glEnableVertexAttribArray(5) and glVertexAttribPointer(5,...) correct OpenGL? No errors are detected via glGetError(), but changing everything from 5 to 0 makes it work. Nov 24, 2013 at 19:58