Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Shared storage buffer object question

  1. #1
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76

    Shared storage buffer object question

    Greeting:
    I set up a shared storage buffer object in the fragment shader (basically, followed the red book) because my program needed to exchange data with the shader.

    Here's the code in the shader:
    Code :
    layout(std430, binding = 0) buffer BufferObject 
    {
       ivec2 coords; 
       uint objName; 
       float depth;
    };

    Here's the code to access the object in the program:
    Code :
       GLuint buf;
       glGenBuffers(1, &buf);
       glBindBuffer(GL_SHADER_STORAGE_BUFFER, buf);
       glBufferData(GL_SHADER_STORAGE_BUFFER, 8192, NULL, GL_DYNAMIC_COPY);
       glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buf);
     
       bufferData = (int*)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_WRITE);

    Now, to set the buffer variables I do:
    Code :
       bufferData[0] = set coords.x;
       bufferData[1] = set coords.y;
       bufferData[2] = set objName;
       bufferData[3] = set depth;

    All seems ok except I don't think the last variable, depth, is being set properly. I suspect that's because bufferData is cast as int* while depth is float.

    What should I do in this case?

    Thanks in advance,
    Sam
    Last edited by sam_thedancer; 09-17-2013 at 09:31 AM.

  2. #2
    Intern Contributor
    Join Date
    Jun 2013
    Posts
    69
    what are you using the depth for? if its for trying to place the primitive further away from the screen that wont work. changing the depth like this wont result in a decrease or increase in the size of the primitive being drawn. to get depth perception you must use a perspective projection like frustum projection. or you could set w in your homogrnous coordinates so that all the components are divided by it resulting in a smaller primitive, best to use a frustum though
    Last edited by sandbucket; 09-18-2013 at 09:30 AM. Reason: fixed something

  3. #3
    Intern Contributor
    Join Date
    Sep 2012
    Posts
    76
    Quote Originally Posted by sandbucket View Post
    what are you using the depth for? if its for trying to place the primitive further away from the screen that wont work. changing the depth like this wont result in a decrease or increase in the size of the primitive being drawn. to get depth perception you must use a perspective projection like frustum projection. or you could set w in your homogrnous coordinates so that all the components are divided by it resulting in a smaller primitive, best to use a frustum though
    I understand that. What I am trying to do is detect the object clicked by the mouse. So, the ivec2 are click coords input from the app program. And as the frags are processed I check is (gl_FragCoord.x gl_FragCoord.y) match the mouse click coords. So far so good it's working.

    Now, the reason I need to read depth is when one object is aligned with another so I need to know which is closer, which, of course means which has lower depth. However, before I begin the "depth competition" I need to set depth to 1, the farthest value.

    So, that's the story. So I need to know how to access the depth value from the program.

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2013
    Posts
    3
    Have you tried something like these?
    Code :
    ((float*)bufferData)[3] = depth;
    Code :
     bufferData[3] = (int)depth;
    You could use always use glMapBufferRange.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •