PDA

View Full Version : Geometry Shaders in ClanLib 2.2



rombust
03-04-2010, 07:42 PM
I am trying to introduce geometry shaders in ClanLib 2.2 SVN

I have added the extra clFunction’s to opengl.h , for example:


functions->ProgramParameteri = (CL_GLFunctions::ptr_glProgramParameteri) CL_OpenGL::get_proc_address("glProgramParameteriEXT");

And I have added cl_shadertype_geometry to CL_ShaderObject

I created "Examples/GeometryShader" to test it.

See "Sources/shader_color_geometry.cpp". This does all the geometry shader work.

If the line: "program_object.attach(geometry_shader);" is commented out, then the teapot is shown in solid white.

If that line is included, then nothing is shown. I expected the teapot to be shown (the geometry shader just emits a single triangle in the same position).

I would be very grateful if someone is up to the challenge in finding out what is wrong. It should be something very simple!

Note: I had to update my NVidia driver to enable the geometry extension (although it’s core in OpenGL 3.2)

sphair
03-04-2010, 10:50 PM
i tried this on my ati, and the teapot was white with the shader enabled...

rombust
03-05-2010, 10:30 AM
Heh, thanks :)

So it was either my NVidia driver or my graphics card that's at fault

Which is good :D I'll try again on the next driver update

Magnus Norddahl
03-06-2010, 12:41 AM
I tried your geometry shader on my nv-275 card and it doesn't display any teapot on my computer.

I looked quickly at the extension you are using, and it uses these output variables as well: gl_PointSize, gl_ClipVertex, gl_Layer and gl_PrimitiveID.

The extension mentions that if you do not set these variables to specific values, the results are undefined. In particular I could imagine the gl_ClipVertex variable could have an impact on whether the GPU clips your new triangles or not. Supposedly its the position of the vertex in eye coordinates.

I tried adding the following code to your example "gl_PointSize = 1.0; gl_ClipVertex = vec4(0.5,0.5,0.5,1.0); gl_Layer = 0; gl_PrimitiveID = 0;", but it did not cause it to display any teapot.

I noticed that the shader compiler mentioned a 150 version of GLSL, but the shader extension you are using is seemingly only supported by version 120. If I change it to use version 150 it complains about gl_ClipVertex being deprecated, so I'm not really sure you are using the extension that OpenGL 3.2 officially supports?

Another thing worth mentioning is that ClanLib attempts to create an OpenGL 3.0 context and not 3.2 (see "helper.create_opengl3_context(share_context, 3, 0);" in opengl_window_provider_wgl.cpp). I don't know if that could have any impact on whether the extensions you are using work properly or not.

rombust
03-06-2010, 11:27 AM
I didn't read the spec in detail, so yes it is possible that ClanLib sets incorrectly or does not set something the extension requires.

I should try coding a geometry shader without clanlib to see if that works first :)

I used the following links as reference:

http://www.opengl.org/wiki/Geometry_Shaders

http://www.opengl.org/registry/specs/ARB/geometry_shader4.txt

There are various examples online, but haven't tried compiling these (I just looked at the code)

For example:
http://cirl.missouri.edu/gpu/glsl_lessons/glsl_geometry_shader/index.html

rombust
03-08-2010, 02:23 PM
Fixed, I made a silly mistake but incorrectly entering the opengl geometry shader defines.