Example for geometry shader + transform feedback ?

Does anyone have an example how to do all of this at the same time:

  1. use vertex, geometry, and fragment shader
  2. output custom varyings to a transform feedback buffer
  3. rendering
  4. retrieve the transform feedback buffer into main memory (of the CPU).

I did a bit of googling, but couldn’t find anything.

Ideally, the sample source code would use the “old-style” shader syntax (with pre-defined attributes).
Oh, and OpenGL / GLSL, please.

Thanks a lot in advance for any kinds of tips, pointers, and suggestions.

Best regards,
Gabriel.

You didn’t do enough Googling. This might be enough for Transform Feedback. You would have to modify the suggested tutorial to use the code that I provided in the thread. The post also points to a geometry shader tutorial, although I haven’t used it. If you have a card that supports geometry shaders, you really should move away from ‘old-style’ shader syntax. G-Truc.net has an opengl sample pack which includes code for doing various things in opengl, including the use of geometry shaders.

I did know about the tutorial code by Shiben Bhattacharjee.
But I couldn’t get it to compile because of the glTransformFeedbackAttribs() in the original source.

Thanks to you, it compiles now – however, I don’t see the green points (i.e., the ones from the transform feedback buffer).
I do see the two red points moving, but not the green ones.
Any ideas, what might be wrong?
Is there any way I can read the transform feedback buffer back into main memory? (so that I can look at the values it contains?)

BTW: I didn’t know you can use glTransformFeedbackVaryingsEXT() on pre-defined vertex attributes …

(Oh, and I had to change the z-coord of the points to -0.3, because with -0.2 they were exactly on the near clipping plane, and thus apparently clipped away.)

Yes, I know about these samples, too – but they use new-style shader syntax, i.e., no pre-defined attributes; and I am developing on Mac OS X 10.6, so I believe I can’t use that, can I?

Regards,
Gabriel.

It might be because Snow Leopard doesn’t support GLSL 1.30 (I don’t know). Use the following shaders instead:


const char* vs1[]={	
	"void main(){"
	"gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
	"gl_FrontColor = gl_Color;"
	"}"
};
const char* fs1[]={	
	"void main(){"
	"gl_FragColor = gl_Color;"
	"}"
};

If that doesn’t make a difference, it maybe a bug. Given that you were getting colors at all with the first shaders would imply that Mac supports newer-styled shaders (GLSL 1.30+). You may have to fiddle with the points’ x and y coordinates until they show up, just like you fiddled with the z.

Is there any way I can read the transform feedback buffer back into main memory? (so that I can look at the values it contains?)

Since a transform feedback buffer is a buffer object, I think you would have to familiarize yourself with MapBuffer.

Yes, I know about these samples, too – but they use new-style shader syntax, i.e., no pre-defined attributes; and I am developing on Mac OS X 10.6, so I believe I can’t use that, can I?

You could understand what it’s doing and write a version that works for you. Copy-and-paste coding is bad; understanding is good.

Thanks for your response.
Experimenting a bit further showed that it was just the line

#version 130

.
Changing that to

#version 120

(no other change needed) does the trick.

G.

The in and out keywords were introduced in GLSL 1.30, so if you are going to use GLSL 1.20 exclusively, you should make the necessary modifications (or use the code provided) to make the shaders GLSL 1.20 compliant.

I have managed to make the example work, at least with a pass-through geometry shader.

There is one funny thing now: when I resize the window, everything is gone!

Does anyone have an idea?

Here is the source code: http://zach.in.tu-clausthal.de/tmp/main.cpp
It is self-contained and uses only GLUT.
(I can also put the Makefile or an XCode project online, if you want.)

All kinds of hints, suggestions, and pointers will be appreciated!

Best,
G.