Unpack in a SSB

狂风中的少年 提交于 2019-12-13 07:57:19

问题


I use part of a SSB as a matrix 3D of linked lists. Each voxel of the matric is a uint that gives the location of the first element of the list.

Before each rendering, I need to re-init this matrix, but not the whole SSB. So I associated the part corresponding to the matrix with a texture 1D to be able to unpack a buffer inside it.

//Storage Shader buffer
glGenBuffers(1, &m_buffer);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_buffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, 
    headerMatrixSizeInByte + linkedListSizeInByte, 
    NULL, 
    GL_DYNAMIC_DRAW);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, 0);

//Texture
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_1D, m_texture);
glTexBufferRange(
    GL_TEXTURE_BUFFER, 
    GL_R32UI, 
    m_buffer, 
    0, 
    headerMatrixSizeInByte);
glBindTexture(GL_TEXTURE_1D, 0);

//Unpack buffer
GLuint* clearData = new uchar[m_headerMatrixSizeInByte];
memset(clearData, 0xff, headerMatrixSizeInByte);
glGenBuffers(1, &m_clearBuffer);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_clearBuffer);
glBufferData(
    GL_PIXEL_UNPACK_BUFFER, 
    headerMatrixSizeInByte, 
    clearData, 
    GL_STATIC_COPY);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
delete[] clearData;

So this is the initialization, now here is the clear attempt :

GLuint err;
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_clearBuffer);
glBindTexture(GL_TEXTURE_1D, m_texture);
err = m_pFunctions->glGetError(); //no error
glTexSubImage1D(
    GL_TEXTURE_1D,
    0, 
    0,  
    m_textureSize, 
    GL_RED_INTEGER, 
    GL_UNSIGNED_INT, 
    NULL);
err = m_pFunctions->glGetError(); //err GL_INVALID_VALUE
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glBindTexture(GL_TEXTURE_1D, 0);

My questions are :

  1. Is it possible to do what I'm attempting to ?
  2. If yes, where did I screw up ?

回答1:


Thanks to Andon again who got half the answer. There is two problem in the code above :

  1. m_textureSize = 32770 which exceeds the limit in one dimension for many hardware. The easy workaround is to use a texture 2D. Since I don't care about the content after the linked list in the buffer, I can write whatever I want in it. In the next rendering call, it will be overwritten in the shaders.
  2. When creating the texture, one function call was missing : glTexStorage2D(GL_TEXTURE_2D, 1, width, height);


来源:https://stackoverflow.com/questions/23747731/unpack-in-a-ssb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!