Results 1 to 4 of 4

Thread: Shared storage buffer object question

  1. #1
    Member Contributor
    Join Date
    Sep 2012
    Posts
    85

    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

  2. #2
    Member Contributor
    Join Date
    Jun 2013
    Posts
    71
    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

  3. #3
    Member Contributor
    Join Date
    Sep 2012
    Posts
    85
    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.

Similar Threads

  1. Get Shader Storage Buffer Object to work
    By FonzTech in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-09-2016, 02:35 PM
  2. Replies: 0
    Last Post: 09-11-2012, 02:48 PM
  3. Texture Buffer Object shared with Vertex Buffer Ob
    By marshats in forum OpenGL: GLSL
    Replies: 3
    Last Post: 09-06-2010, 09:01 AM
  4. Some question about PBO(Pixel Buffer Object)
    By pango in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 11-12-2009, 09:08 PM
  5. Dynamic Object Storage Question
    By GoatNat in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-19-2001, 05:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean