Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: texelFetchBuffer()

  1. #11
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    205
    Quote Originally Posted by thokra View Post
    Please post both your vertex and fragment shader and you buffer setup code, both for geometry and colors.
    My code:
    vertex shader:
    Code :
    in vec3 a_position;
    uniform float offset_x;
    uniform isamplerBuffer out_offset;
    out vec4 offset;
    void main()
    { 
          offset=texelFetch(out_offset,int(a_position.z));
    	  gl_Position = vec4(a_position.x + offset_x, a_position.y, 1.0, 1.0);
     
    }
    Fragment shader:
    Code :
    out vec4 Color;
    in vec4 offset;
    void main() 
    {
     
    	 Color = offset;
    }

    buffer setup code:
    Code :
    	GLfloat pixels[]={0.0f,1.0f,0.0f,1.0f, 0.0f,0.0f,1.0f,1.0f,  1.0f,1.0f,1.0f,1.0f, 1.0f,0.0f,1.0f,1.0f};
    	   GLfloat vertices[] = 
    		{
    			-0.9f,  -0.6f, 0.0f,
    			-0.9f,  -0.9f, 1.0f,
    			-0.6f,  -0.9f, 2.0f,
    			-0.6f, -0.6f,  3.0f	
     
    	 };
    				glGenBuffers(1,&bufferid);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGenBuffers(1,&bufferid)"));
    				glBindBuffer(GL_TEXTURE_BUFFER,bufferid);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glBindBuffer(GL_TEXTURE_BUFFER,bufferid);")); 
     
    				glBufferData(GL_TEXTURE_BUFFER,sizeof(pixels),pixels,GL_STATIC_DRAW);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glBufferData(GL_TEXTURE_BUFFER,sizeof(vert),vert,*value);"));
     
     
    				glGenTextures(1, &buffer_texture);	
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGenTextures(1, &buffer_texture);")); 
     
     
    				glActiveTexture(GL_TEXTURE0);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glActiveTexture(GL_TEXTURE0);")); 
     
    				glBindTexture(GL_TEXTURE_BUFFER, buffer_texture);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glBindTexture(GL_TEXTURE_BUFFER, buffer_texture);")); 
     
    				glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, bufferid);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, bufferid);")); 
     
     
    				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);")); 
     
       				glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);")); 
     
     
    				attr_vertex = glGetAttribLocation(shader_data.psId, "a_position");
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGetAttribLocation(shader_data.psId, \"a_position\");"));
    				glVertexAttribPointer(attr_vertex, 3 , GL_FLOAT, GL_FALSE ,0, vertices);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glVertexAttribPointer(attr_vertex, 3 , GL_FLOAT, GL_FALSE ,0, 0);"));
    				glEnableVertexAttribArray(attr_vertex);
    				nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glEnableVertexAttribArray(attr_vertex);"));
     
     
    				glDrawArrays(GL_TRIANGLE_FAN,0,4);

  2. #12
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Before going further, could you please clarify which of the buffer setup stuff is done in which function? The draw call appears to be right next to the setup functions. Can you please post complete functions, including headers? Or simply your whole program?

    One thing I can definitely say is that you don't need filtering setup:

    Code :
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    "Why not?" you might ask. Well, first of all, you modify state for the target GL_TEXTURE_2D but your buffer texture has its own state and target: GL_TEXTURE_BUFFER. Therefore, you do absolutely nothing for your buffer texture with the above calls. Furthermore, buffer textures aren't filtered anyway so setting up filters is useless.

    Other than that, the setup of the buffer looks ok.

  3. #13
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    205
    Quote Originally Posted by thokra View Post
    Before going further, could you please clarify which of the buffer setup stuff is done in which function? The draw call appears to be right next to the setup functions. Can you please post complete functions, including headers? Or simply your whole program?
    glBufferData(GL_TEXTURE_BUFFER,sizeof(pixels),pixe ls,GL_STATIC_DRAW);
    this function is storing the bufferdata i.e. pixels[] in this case. After that glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, bufferid); attaches the buffer to texture "bufferid".

    One thing I can definitely say is that you don't need filtering setup:

    Code :
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    "Why not?" you might ask. Well, first of all, you modify state for the target GL_TEXTURE_2D but your buffer texture has its own state and target: GL_TEXTURE_BUFFER. Therefore, you do absolutely nothing for your buffer texture with the above calls. Furthermore, buffer textures aren't filtered anyway so setting up filters is useless.

    Other than that, the setup of the buffer looks ok.
    Also, i removed filtering modes. i was unaware that they are useless in texbuffer.
    Just ignore all GL_ERROR_CHECK() calls as they are just for error checking purpose.

  4. #14
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    glBufferData(GL_TEXTURE_BUFFER,sizeof(pixels),pixe ls,GL_STATIC_DRAW);
    this function is storing the bufferdata i.e. pixels[] in this case. After that glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, bufferid); attaches the buffer to texture "bufferid".
    I'd be in the wrong place helping you if I wasn't aware of that.

    What I need is your actual program code, the complete functions including the headers (argument list, return type, function name etc.) so I can see what's going on in your program. Best to simply post the complete code if it fits here.

Posting Permissions

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