pokemoen's picture

Basic geometry shader example

This is a very basic geometry shader example.

It draws two vertical lines using immediate mode, where the geometry shader:

  1. Emits vertices/primitives without change.
  2. 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.

AttachmentSize
GeometryShader.cs7.21 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

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.

the Fiddler's picture

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.ProgramParameter calls are failing. Will test on Nvidia next.

AttachmentSize
GeometryShader.cs18.99 KB
Kiena's picture

Is it fine to use Begin/End with 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.

the Fiddler's picture

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.

kvark's picture

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

zahirtezcan's picture
the Fiddler wrote:

but It seems that Ati drivers do not expose OpenGL 3.2 features yet, so the GL.ProgramParameter calls 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.

layout(points) in;
layout(triangle_strip) out;

edit note: neither my mobile nor quadro NV drivers infer the layout from geom shader (gl and glsl version strings are checked)

zahirtezcan's picture

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

zahirtezcan's picture

Ok, for GLSL version 1.5 and GL version 3.2 there are 3 points to check:

  1. The geometry shader should contain version information i.e "#version 150" as first line
  2. The geometry shader should contain the input layout specification eg. layout(points) in;
  3. The geometry shader should contain the output layout with maximum output vertex count specified eg. 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.