C++ OpenSceneGraph/OpenGL图像格式

C++ OpenSceneGraph/OpenGL图像格式,c++,opengl,glsl,openscenegraph,C++,Opengl,Glsl,Openscenegraph,我需要将2D纹理数组传递给片段着色器,该着色器对uchar元素执行texelFetch和逐位操作 出于这个原因,我需要创建一个具有非常特定的内部格式的纹理,以确保我的纹理是无符号字节整数,并且不会执行不强制转换为浮点的缩放操作 我已经在通用uint8\u t*数组中设置了图像缓冲区 因此,我正在这样做: osg::Texture2DArray texture = new osg::Texture2DArray; for (int i = 0; i < ntextures; i++) {

我需要将2D纹理数组传递给片段着色器,该着色器对
uchar
元素执行
texelFetch
和逐位操作

出于这个原因,我需要创建一个具有非常特定的内部格式的纹理,以确保我的纹理是无符号字节整数,并且不会执行不强制转换为浮点的缩放操作

我已经在通用
uint8\u t*
数组中设置了图像缓冲区

因此,我正在这样做:

osg::Texture2DArray texture = new osg::Texture2DArray;
for (int i = 0; i < ntextures; i++) {
  osg::Image* image = new osg::Image( 
    textureWidth, 
    256, 
    1,
    GL_R8UI, // Texture Internal Format
    GL_RED_INTEGER, // Pixel Format
    GL_UNSIGNED_BYTE, // Pixel Type
    imageBufferPtr[i]);

  texture->setImage(i, image);
}
不会产生任何错误,但我的纹理会以某种方式损坏(可能会执行某些强制转换操作)

我怎样才能解决这个问题

我保证不会将纹理大小调整为2的幂

额外的

这是我的片段着色器

        #version 130 
        #extension GL_EXT_texture_array : enable

        in vec4 texcoord;

        uniform uint            width;
        uniform uint            height;
        uniform usampler2DArray textureA;

        void main() {
            uint x = uint(texcoord.x * float(width));
            uint y = uint(texcoord.y * float(height));
            uint shift = x % 8u;
            uint mask =  1u << shift;
            uint octet = texelFetch(textureA, ivec3(x / 8u, y % 256u,y / 256u), 0).r;
            uint value = (octet & mask) >> shift;
            if (value > 0u)
              gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
            else
              gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
        }
#版本130
#扩展GL\U EXT\U纹理\U数组:启用
在vec4 texcoord;
单位宽度均匀;
统一的单元高度;
均匀使用样品2 Darray纹理;
void main(){
uint x=uint(texcoord.x*浮动(宽度));
uint y=uint(texcoord.y*浮动(高度));
uint位移=x%8u;
uint掩码=1u>移位;
如果(值>0u)
gl_FragColor=vec4(1.0,1.0,1.0,1.0);
其他的
gl_FragColor=vec4(1.0,0.0,0.0,1.0);
}

根据
GL\u亮度判断
没有给出错误,您使用的OpenGL上下文不正确
GL\u亮度
已经很久了。@hidefromkgb那么我应该使用什么格式?@hidefromkgb
GL\u R8UI
也会导致错误通过
GL\u亮度
进行计算,如果没有错误,您使用的OpenGL上下文不正确
GL_亮度
已经很久了。@hidefromkgb那么我应该使用什么格式?@hidefromkgb
GL_R8UI
也会导致错误
        #version 130 
        #extension GL_EXT_texture_array : enable

        in vec4 texcoord;

        uniform uint            width;
        uniform uint            height;
        uniform usampler2DArray textureA;

        void main() {
            uint x = uint(texcoord.x * float(width));
            uint y = uint(texcoord.y * float(height));
            uint shift = x % 8u;
            uint mask =  1u << shift;
            uint octet = texelFetch(textureA, ivec3(x / 8u, y % 256u,y / 256u), 0).r;
            uint value = (octet & mask) >> shift;
            if (value > 0u)
              gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
            else
              gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
        }