Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL, interface block

Tags:

opengl

glsl

The Problem:

I'm learning OpenGL from http://www.arcsynthesis.org/gltut/index.html tutorial, and I had really hard time getting Tutorial 13: Geometry Impostors working (6+ hours), and it is now working after a really minor change in the code that should actually be no-op, and I need your help to find out why does it change anything.

Explanation - edited:

The problem was that with the unchanged code the fragment shader didn't get correct input from the geometry shader, but with either replacing geometry shader's out interface block to separate variables or giving the block an instance name makes the program work fine. But these changes should be no-op.

The problem is probably a name collision.

Like this it doesn't work:

in VertexData
{
    vec3 cameraSpherePos;
    float sphereRadius;
} vert[];

out FragData
{
    flat vec3 cameraSpherePos;
    flat float sphereRadius;
    smooth vec2 mapping;
};

void main()
{
     mapping = 
     cameraSpherePos = 
     sphereRadius = 
     EmitVertex();
     /* mapping's value doesn't get to the fragment shader correctly */
}

But either giving FragData an instance name like frag, and using frag.mappaing instad of mapping, or using 3 separate variables solves the problem.

Why doesn't it work without an instance name?

Edit: It seems to be a driver issue.

like image 210
IceCool Avatar asked May 19 '13 21:05

IceCool


3 Answers

Create instance names for all interface blocks like:

FragData { /* ... */ } gs2fs; 

And then:

gs2fs.cameraCornerPos = vec4(vert[0].cameraSpherePos, 1.0);
like image 87
dinony Avatar answered Oct 21 '22 16:10

dinony


Working with GLSL samples often gets tedious due to nasty version problems.

Some general debugging advice:

  • verify that you included the proper version tags in your shader source
  • verify that your OpenGL Driver actually supports that version by calling glGetString(GL_SHADING_LANGUAGE_VERSION)
  • create means of runtime shader-recompilation (e.g. by assigning that to a key event)
  • and FOREMOST: use glGetShaderInfoLog() and glGetProgramInfoLog()!
like image 29
Solkar Avatar answered Oct 21 '22 15:10

Solkar


The problem actually was with not using the latest driver.

I was running this on linux, and got the latest driver from Ubuntu's package manager: the Nvidia 310-experimental. But even though its experimental, it's rather old. With manually installing the 319 from nvidia's site the code worked fine without any change.

Moral of the story:

Always use the latest drivers.

like image 26
IceCool Avatar answered Oct 21 '22 16:10

IceCool