Jump to content
  • Advertisement
Sign in to follow this  
D_J_P

glGetUniform problem

This topic is 2356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having trouble using glGetUniformfv(). I'd like to be able to perform a calculation within my Vertex shader, and set the value of a uniform to that result, and then retrieve that uniform's value after I swap buffers. But it seems that I can only ever retrieve the values which I've sent to the shader via glUniform1fv() or glUniform1f(), and not values I assign within the Vertex shader.

My Vertex shader is looking up a texture (sampler) value according to gl_Vertex.xyz. It also performs certain calculations on it. And I would like to get the resultant values back from OGL. I have confirmed that the uniform I'm trying to use a) is setup and working properly, b) can receive values via glUniform1f, c) can be changed within the Vertex shader. But when I use glGetUniformfv after I swap buffers, the value it returns is always the last value I passed with glUniform1f, and NOT the value that I know it has been changed to within the Vertex shader. I have also separated out the setting of the uniform's value from the display loop, so I know it's not being reset before I can query its value.

So how can I accomplish this? Alternately, what other approach can I employ to extract the results I calculated in the Vertex shader?


Just in case it helps, here's a bit more detail:

I have a rather large dataset, comprised of a set (up to N=76) of 4-byte values which vary over time. I need to be able to plot these onscreen as horizontal lines, and scroll through them. Think of 76 audio waveforms plotted at once and you have the basic idea. Each "channel" may have 200,000 samples or more, over the course of the "recording". I've got the display working fine, using VertexBufferObjects and VertexIndexObjects. I've also saved the data itself to a 3D texture (sampler), and the Vertex shader uses gl_Vertex to lookup the data value in the sampler.

All this means that I can read the data from disk, decompress it and push it to the graphics card, then discard the data because everything I need is now on the card. Except that I need the data values to be able to display onscreen - not all of them, just one value per trace at a given time point, as designated by a user-manipulable "cursor". I can't get the values from the CPU side because the data's been discarded there. And even if I were to keep it, I'm doing my signal processing in the Vertex shader, and I need the resultant values even more than I need the original values. I've already tried to do all the calculations on the CPU, and just push to OGL the resultant values... except the CPU is too slow to do the signal processing on 75 channels (up to 30 seconds onscreen, sampled at 500 samples per second, scrolling in realtime), and also recalc a whole new set of vertices at the same time. My current build works very well, very fast, but I just need those darned values.

Share this post


Link to post
Share on other sites
Advertisement
I didn't read the entirety of your words, but you cant read values from a shader. It would stall the gpu shader system so bad. You can store things into a texture and read the texture back to the cpu.

Share this post


Link to post
Share on other sites
You can either write to a render buffer, or texture or use Transform Feedback.

Share this post


Link to post
Share on other sites

I'm having trouble using glGetUniformfv(). I'd like to be able to perform a calculation within my Vertex shader, and set the value of a uniform to that result, and then retrieve that uniform's value after I swap buffers. But it seems that I can only ever retrieve the values which I've sent to the shader via glUniform1fv() or glUniform1f(), and not values I assign within the Vertex shader.

My Vertex shader is looking up a texture (sampler) value according to gl_Vertex.xyz. It also performs certain calculations on it. And I would like to get the resultant values back from OGL. I have confirmed that the uniform I'm trying to use a) is setup and working properly, b) can receive values via glUniform1f, c) can be changed within the Vertex shader. But when I use glGetUniformfv after I swap buffers, the value it returns is always the last value I passed with glUniform1f, and NOT the value that I know it has been changed to within the Vertex shader.


As pointed out above, this is unfortunately not how the GPU pipeline works. For one, since the vertex shader is executed for each vertex you render, you would have as output as many variables than you had transformed vertices, instead of just a single constant.

But anyways, all data that the GPU pipeline takes in at various stages: vertex data, shader constant registers, textures, are always static (constant) during rendering. They cannot be written to. The only parts that get modified are the attached color, depth and stencil render targets. If you need to output some values from the render, you will need to output the data to one of those buffers. In newer APIs (D3D11, OGL4(?)), you can also render out to unstructured buffers (i.e. render to vertex data, or data you interpret in some custom manner), or use compute shaders to perform more generic write patterns (but often at some performance caveats).

Share this post


Link to post
Share on other sites
Thanks to all. I'll be trying to tackle it with FBO for the time being, as I have some implementation of that which I can modify

Thx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!