Thirsty4K
Thirsty4K

Reputation: 78

Data from shader to main program

I'm working on a small program in OpenGL and realized I needed to retrieve some data from the geometry shader to the main program so I could handle mouse events. Not much, just some specific square coordinates that are calculated in the geometry shader.

How should I do this? Should I use a small FBO or should I make all the calculations in the main program and then send them to the geometry shader?

Upvotes: 1

Views: 288

Answers (2)

OutOfBound
OutOfBound

Reputation: 2004

The easiest way to do this, is to colorcode you values, you need to send to host and use glGetPixels method. You need to render to a seperate framebuffer, to hide the calculation from the screen. If you want to implement Hittesting on objects of your scene and are not GPU bound this is the way to go.

Upvotes: 0

geometrian
geometrian

Reputation: 15387

Generally speaking, you should do as much computation as possible in the host program.

If you want to read back data from a shader, Google is your friend. Outputting to an FBO is possible, although you'll also need a nontrivial fragment shader. The best option is often to use an SSBO, although image load-store or transform feedback may be more appropriate depending on what you're trying to do.

Upvotes: 3

Related Questions