Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently trying to use the geometry shader.

My input is a set of points, for which multiple triangle should be created

This is the geometry shader

#version 330
layout(points) in;
layout(triangle_strip, max_vertices = 3) out;

in vec3[] vPos;
out vec3 oPos;

void main() {
    for(int i = -1; i <= 1; i++)
        for(int j = -1; j <= 1; j++)
        {
            for(int k = -1; k <= 1; k++)
            {
                oPos = vPos[0] + vec3(i,j,k);
                EmitVertex();
            }
        EndPrimitive();
        }

}

And this the corresponding C++ code

mMeshGenerator->use();

GLuint query;
glGenQueries(1, &query);
glEnable(GL_RASTERIZER_DISCARD);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mMeshVBO->buffer());
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);
    glBeginTransformFeedback(GL_TRIANGLES);
        mPointsVAO->draw();
    glEndTransformFeedback();
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glFlush();
GLuint primitives;
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &primitives);

std::cout << "-----" << primitives << "-----" << std::endl;
GLfloat feedback[primitives*3*3];
glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(feedback), feedback);

for (int i = 0; i < primitives*3*3; i++) {
    printf("%f\n", feedback[i]);
}
glDisable(GL_RASTERIZER_DISCARD);

According to the query only one primitive is written.

Output for input point (10,20,30):

-----1-----
9.000000
19.000000
29.000000
9.000000
19.000000
30.000000
9.000000
19.000000
31.000000

Whats wrong with my code that there is only 1 triangle instead of 27?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Your code looks like it wants to output 9 triangles each consisting of a discreet three vertex triangle strip, not 27 triangles.

However you have set max_vertices to 3 in the layout statement at the top of the shader so it only emits one triangle before it hits that limit. (The limit is for the whole shader, not per-primitive, otherwise 3 would have been fine).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.