Problem
Sometimes EndPrimitive function in OpenGL's geometry shaders does not work as I expected- few output primitives are joined together.
Details
Program
I want to draw a shape that consists of lines on each multiplication of given angle and distant from given center (given minimum radius and maximum radius). I am trying to write a geometry shader that takes information about a star:
Star.hpp
struct Star{
QVector3D center;
QVector3D color;
GLfloat thickness;
GLfloat repAngle__deg;
GLfloat radiusMin;
GLfloat radiusMax;
};
I am passing the data as Point in VBO. The geometry shader looks like this:
star.geom
#version 330
layout(points) in;
layout(line_strip, max_vertices = 360) out;
in VS_OUT{
vec3 color;
float thickness;
float repAngleDegrees;
float radiusMin;
float radiusMax;
} gs_in[];
out vec3 fColor;
uniform mat4 matrix;
const float PI = 3.1415926;
void main()
{
if(gs_in[0].thickness > 0){
for(float angle = 0; angle < 360; angle += gs_in[0].repAngleDegrees){
float angleRad = PI*angle/180;
float cosVal = cos(angleRad);
float sinVal = sin(angleRad);
float minR = gs_in[0].radiusMin;
float maxR = gs_in[0].radiusMax;
vec4 minOffset = vec4(cosVal * minR, -sinVal * minR, 0.0, 0.0);
gl_Position = matrix * (gl_in[0].gl_Position + minOffset);
fColor = gs_in[0].color;
EmitVertex();
vec4 maxOffset = vec4(cosVal * maxR, -sinVal * maxR, 0.0, 0.0);
gl_Position = matrix * (gl_in[0].gl_Position + maxOffset);
fColor = gs_in[0].color;
EmitVertex();
EndPrimitive();
}
}
}
If I pass more than one "Points" (structures that describes a star I want to draw) there are some unwanted connections between returned primitives as shown in .
The screenshot was taken while rendering data:
Star s;
s.center = {0,0,0};
s.color = {0,0.7,0.1};
s.thickness = 1;
s.repAngle__deg = 15;
QVector<Star> vec;
s.repAngle__deg = 15; s.radiusMin = 25; s.radiusMax = 125;
vec.append(s);
s.repAngle__deg = 30; s.radiusMin = 20; s.radiusMax = 125;
vec.append(s);
s.repAngle__deg = 90; s.radiusMin = 15; s.radiusMax = 125;
vec.append(s);
_vboStars.allocate(vec.constData(), vec.count() * sizeof(Star));
where _vboStars is a QOpenGLBuffer.
from data:
s.repAngle__deg = 10; s.radiusMin = 5; s.radiusMax = 10; vec.append(s);
s.repAngle__deg = 15; s.radiusMin = 15; s.radiusMax = 20; vec.append(s);
s.repAngle__deg = 30; s.radiusMin = 25; s.radiusMax = 30; vec.append(s);
s.repAngle__deg = 60; s.radiusMin = 35; s.radiusMax = 40; vec.append(s);
s.repAngle__deg = 90; s.radiusMin = 45; s.radiusMax = 50; vec.append(s);
I think there is a problem in geometryShader, but I can't find the problem. I've tried also with returning triangle strips (line as 2 triangles) - got same the results.
Observations
- sometimes it works just fine
- it is stable (does not change between frames)
- usually, there are unwanted connections only between few primitives (not all from one input point)
- unwanted connections were not spotted for first input point (usually, they occur for second input point)
My ideas
- Maybe there is a problem with output limitations?
- Driver issue?
- Probably it's my misuse
Environment
- Qt 5.5
- OpenGL
- OpenGL vendor string: Intel Open Source Technology Center
- OpenGL renderer string: Mesa DRI Intel(R) Haswell Desktop
- OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.6.5