Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

OpenGL(GLSL) Gradient with gsamplerBuffer:Reading buffer data in different formats

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
No replies to this topic

#1 emt   Members   

134
Like
0Likes
Like

Posted 11 January 2014 - 05:25 AM

I am trying to use same buffer and reading it in two different formats.

The intention is to obtain a gradient at output, but not getting the desired output.

Using  texelFetch(...),glTexBuffer(...)  and  gsamplerBuffer .

Kindly suggest the corrections/changes that may be required. Below are the relevant code snippets,

    // Relevant C code snippet
    // Fill the texture buffer data for gradient
    #define BUFFER_SIZE 256
    char* buffer = (char*)malloc(BUFFER_SIZE);
    for (i = 0; i < 32; i++)
    {
        buffer[2 * i]= (float)((float)i * 0.5 / 31.0);// left to right gradient 0....0.5
        buffer[(2 * i + 1) * 4 + 0] = (char)(128.0 / 31.0 * (float)(31 - i));//inverted gradient 0.5...0
        buffer[2 * (i + 1) * 4 + 1] = (char)(128.0 / 31.0 * (float)(31 - i));//inverted gradient 0.5...0
        buffer[2 * (i + 1) * 4 + 2] = (char)(128.0 / 31.0 * (float)(31 - i));//inverted gradient 0.5...0
        buffer[(2 * i + 1) * 4 + 3] = (char)255;        
    }
------------------------------------------------------------------------------------------------------------
    // Generate the two texture buffer
    glGenBuffers( 2,texBuffObj);
    glGenTextures(2, textureID);
    // Fill the data into buffer as GL_RGBA8
    glBindBuffer( GL_TEXTURE_BUFFER,texBuffObj[0]);
    glBufferData( GL_TEXTURE_BUFFER,BUFFER_SIZE,buffer,GL_DYNAMIC_DRAW);
    glBindTexture(GL_TEXTURE_BUFFER, textureID[0]);
    glTexBuffer(GL_TEXTURE_BUFFER,GL_RGBA8,texBuffObj[0]);
    // Fill the data into buffer as GL_RGBA32F
    glBindBuffer( GL_TEXTURE_BUFFER,texBuffObj[1]);
    glBufferData( GL_TEXTURE_BUFFER,BUFFER_SIZE,buffer,GL_DYNAMIC_DRAW);
    glBindTexture(GL_TEXTURE_BUFFER, textureID[1]);
    glTexBuffer(GL_TEXTURE_BUFFER,GL_RGBA32F,texBuffObj[1]);
------------------------------------------------------------------------------------------------------------
    #define BUFFER_OFFSET(offset) ((void *)(offset))
    // Use the GL_RGBA8 buffer in the draw call
    glBindTexture(GL_TEXTURE_BUFFER, textureID[0]);
    glDrawElements(GL_TRIANGLES, 3 , GL_UNSIGNED_SHORT, 0);
    // Use the GL_RGBA32F buffer in the draw call
    glBindTexture(GL_TEXTURE_BUFFER, textureID[1]);
    glDrawElements(GL_TRIANGLES, 3 , GL_UNSIGNED_SHORT, BUFFER_OFFSET(3,GLushort));    
------------------------------------------------------------------------------------------------------------
    //Fragment shader code
    #version 330 core
    uniform usamplerBuffer samplerRGBA8;
    uniform usamplerBuffer samplerRGBA32F;
    // Ouput data
    out vec4 color;
    in vec2 vs_posCoord;//not the texture coordinates
    void main()
    {
        vec4 colBuffRGBA8;
        vec4 colBuffRGBA32F;
        int offset = int(vs_posCoord.x + vs_posCoord.y) % 32;
        colBuffRGBA32F = texelFetch(samplerRGBA32F,int(offset)) ;
        colBuffRGBA8 = texelFetch(samplerRGBA8,int(offset) + 1);
        color = vec4(colBuffRGBA32F) + colBuffRGBA8;
    }





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.