Advertisement Jump to content
Sign in to follow this  

OpenGL Geometry shader can't output more than 2 components

This topic is 2589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using a geometry shader to create vertex data. This shader should read one point primitive and output 1-10 point primitives.

I did this with glsl 1.20 to make it compatible with mac osx. I used some extensions, and hoorah, as long as the output data consists of no more than 2 varyings, everything works fine. When I go to 3 varyings, it still works perfectly on the mac, but it no longer works on windows.

It can't be a limit of my video adapter, it's a geforce 580. The adapter on my mac is lower level. And to prove things, I did some queries on the adapter:

=> temp = 1024
=> temp = 1024
=> temp = 127

As long as my geometry shader outputs 2 varyings into my vertex buffer:
static const char *varying_names[] = { "gl_Position", "gl_FrontColor" };
glE(glTransformFeedbackVaryingsEXT(id, 2, varying_names, GL_INTERLEAVED_ATTRIBS));

everything works fine.

When I go to three components:
static const char *varying_names[] = { "gl_Position", "gl_FrontColor", "gl_BackColor" };
glE(glTransformFeedbackVaryingsEXT(id, 3, varying_names, GL_INTERLEAVED_ATTRIBS));

it works fine on the mac, it no longer works on windows.

The shaders compile/link without warnings or errors. But the geometry shader doesn't seem to emit data anymore: the query GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN returns 0.

I then have been rewriting things and used some more modern glsl-coding: using in and out varyings (they don't work on mac but they do work on windows, or do I just need to enable another extension?) where I can use my own naming instead of the predefined opengl variables.

Now I also got it to work perfectly up to two components (I'm talking windows only from now on), but when I use three, the geometry shader still seems to emit primitives, but now the values seem to be corrupt.

Does anyone have any experience with this? Is it just some simple shader parameter that needs to be set or something?

So here is the test-code I created on windows to retry from scratch.

Vertex shader:
#version 120
attribute vec3 aVertexPosition;
attribute vec3 aVertexDirection;
varying out vec3 vInPosition;
varying out vec3 vInDirection;
void main(void) {
gl_Position = vec4(aVertexPosition, 1); // not sure if this is necessary
vInPosition = aVertexPosition;
vInDirection = aVertexDirection;

Geometry shader:

#version 120
#extension GL_EXT_geometry_shader4 : enable
#ifdef GL_ES
precision highp float;
varying in vec3 vInPosition[1];
varying in vec3 vInDirection[1];
varying out vec3 vOutPosition;
varying out vec3 vOutDirection;
void main(void) {
vOutPosition = vInPosition[0] + vec3(0.0001, 0, 0);
vOutDirection = vInDirection[0];
gl_Position = vec4(vOutPosition, 1); // not sure if this is necessary

So if I just add:
vs: attribute vec3 aVertexColor;
vs: varying out vec3 vInColor;
vs: vInColor = aVertexColor;
gs: varying in vec3 vInColor[1];
gs: varying out vec3 vOutColor;
gs: vOutColor = vInColor[0];

and adapt the c++ code accordingly: using 3 attributes instead of 2, setting 3 attrib-pointers, increasing the vertex-size in every attrib-pointer, etc... and settings the feedback varyings right... it no longer works. It seems to emit data, but it seems to emit incorrect data.

By the way, I have tried to change every attribute and in/out varying to vec4 (and of course changed my vertex-buffer attrib-pointers accordingly, didn't help.

What am I forgetting???

The only thing I can imagine is that the output varyings of the vertex shader are not put into the input varyings of the geometry shader in the same order. Do I need to specify that? Or is using the same name enough?


Share this post

Link to post
Share on other sites
I'd love to post my solution on this problem, but I was still unable to make it work.
Sorry for the bump, but is there really no one who can help me with this?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!