
Basic geometry shader example
Posted Thursday, 20 August, 2009 - 21:03 by pokemoen inThis is a very basic geometry shader example.
It draws two vertical lines using immediate mode, where the geometry shader:
- Emits vertices/primitives without change.
- Emits an extra copy translated 0.2 over the x axis.
This will cause four vertical lines to be visible.
I admit it's not very spectacular, but see it as an 'Hello World' type of minimal example.
some observations regarding to the need for casting:
GL.Ext.ProgramParameter 2nd parameter is an int: I cast All.Lines and All.Linestrip here, these are equivalent to the BeginMode ones. These tokens do not exist on ExtGeometryShader4. Only the adjecency ones that are added with this extension are available on the ExtGeometryShader4 enum. Other valid values here are GL_POINTS, GL_LINES and GL_TRIANGLES and their strip variants.
I have to cast (GetPName)ExtGeometryShader4.MaxGeometryOutputVerticesExt for use with GL.GetInteger. I am unsure what the policy here is with EXT tokens.
| Attachment | Size |
|---|---|
| GeometryShader.cs | 7.21 KB |


Comments
Re: Basic geometry shader example
Thank you. It works fine on my HD4850 and the code is very clean and concise - nice!
So far, the policy has been to avoid mixing core and EXT tokens as much as possible. The reason is that the OpenGL registry contains more than 300 extensions (372 at the time of writing) and it is simply impossible to check all of those for new tokens. Not to mention that the result would be an unusable mess.
However, now that OpenTK trunk supports side-by-side OpenGL profiles, it might be a good idea to revisit this policy. One idea is to have "core" profiles that are completely clean of extension tokens (e.g. pure, forward-compatible OpenGL 3.2) and add a few common extension tokens to the full profile (OpenTK.Graphics.OpenGL).
I don't consider this a high priority right now, but please open a feature request if you think this will be useful.
See also issue #1120: [OpenGL] Add tokens for OpenGL 3.2 specs.
Re: Basic geometry shader example
Attached is an OpenGL 3.2 version of this sample.
but It seems that Ati drivers do not expose OpenGL 3.2 features yet, so the
GL.ProgramParametercalls are failing. Will test on Nvidia next.Re: Basic geometry shader example
Is it fine to use
Begin/Endwith a 3.2 context without compatibility profile explicitly enabled? I didn't try and used VBOs only since 3.0, so I'm curious. I would expect an error.Re: Basic geometry shader example
The compatibility profile is used by default, unless otherwise specified. See the WGL_ARB_create_context_profile extension.
OpenTK does not support the creation of 'core' 3.2 profiles at this time.
Re: Basic geometry shader example
Has anybody used geometry shaders in a more complex scenario?
When I enable GS in one part of the program, my functionality in the other part (Transform Feedback in particular) starts producing weirdest results (that can be explained as a driver memory corruption)...
Using Catalyst 9.9, WinXP SP3, Radeon HD 2400
Re: Basic geometry shader example
but It seems that Ati drivers do not expose OpenGL 3.2 features yet, so the
GL.ProgramParametercalls are failing.If I understand the 3.2 specs correct, then ProgramParameter function should not be called at all. Input and output types of the geometry shader will be inferred from layout specifiers defined in GLSL 1.5 specs
ie.
edit note: neither my mobile nor quadro NV drivers infer the layout from geom shader (gl and glsl version strings are checked)
Re: Basic geometry shader example
I have solved the problem with Arb.ProgramParameter:( I guess my drivers cannot determine the output primitive or vertex count, since after setting GeometryVerticesOut parameter it inferred input and output types from shader. Is this a bug for the driver or the lack of specs? any ideas?
note: With version 3.2 forward compatible context there is no core entry point for ProgramParameter
Re: Basic geometry shader example
Ok, for GLSL version 1.5 and GL version 3.2 there are 3 points to check:
"#version 150"as first linelayout(points) in;layout(triangle_strip, max_vertices=6) out;This is how I used the geometry shader without using ProgramParameter function, which is not declared in specs.