Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using textures with 16 bits unsigned integers images with QOpenGLTexture

Using textures with 16 bits unsigned integers images with QOpenGLTexture

Scheduled Pinned Locked Moved Unsolved General and Desktop
textureintegersunsignedqopengltexture
3 Posts 1 Posters 2.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CamelFrog
    wrote on last edited by
    #1

    Hi,

    For a while I've been using RGB images in 32 bits floating point precision in textures with QOpenGLTexture. I had no trouble with it.
    Originally those images have an unsigned short data type, and I'd liketo keep this data type for sending the data to openGL (BTW, does it actually save some memory at all to do that?). After many attempts, I can't get QOpenGLTexture to display the image. All I end up with is a black image.
    Below is how I setup QOpenGLTexture. The parts that used floating points, and that worked so far, is commented out. The part that assumes images in 16 bits unsigned integers, is right below the latter, uncommented. I'm using OpenGL 3.3, GLSL 330, core profile, on a macbook pro retina with Iris graphics.

    QOpenGLTexture *oglt = new QOpenGLTexture(QOpenGLTexture::Target2D);
            oglt->setMinificationFilter(QOpenGLTexture::NearestMipMapNearest);
            oglt->setMagnificationFilter(QOpenGLTexture::NearestMipMapNearest);
            //oglt->setFormat(QOpenGLTexture::RGB32F); // works
            oglt->setFormat(QOpenGLTexture::RGB16U);  
            oglt->setSize(naxis1, naxis2);
            oglt->setMipLevels(10);
    
            //oglt->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::Float32); // works
            //oglt->setData(QOpenGLTexture::RGB, QOpenGLTexture::Float32, tempImageRGB.data); // works
            oglt->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::UInt16);
            oglt->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt16, tempImageRGB.data);
    

    So, in just these lines above, is there something wrong?
    My data in tempImageRGB.data are between [0-65535] when I used UInt16. When I use QOpenGLTexture::Float32, the data are normalized so they would be within [0-1].

    Then, here is my fragment shader:

    #version 330 core
    
    in mediump vec2 TexCoord;
    out vec4 color;
    
    //uniform mediump sampler2D ourTexture; // Worked
    uniform usampler2D ourTexture; 
    
    void main()
    {
        //mediump vec3 textureColor = texture(ourTexture, TexCoord).rgb; // Worked
        uvec3 textureColor = texture(ourTexture, TexCoord).rgb;
    
        color = vec4(textureColor, 1.0);
    }
    

    In the fragment shader, all I changed is the type from the 32-bits float to the 16 bit unsigned integers case is sampler2D to usampler2D and vec3 to uvec3, but maybe I'm not supposed to do that, am I?

    Thanks for the help.

    C 2 Replies Last reply
    0
    • C CamelFrog

      Hi,

      For a while I've been using RGB images in 32 bits floating point precision in textures with QOpenGLTexture. I had no trouble with it.
      Originally those images have an unsigned short data type, and I'd liketo keep this data type for sending the data to openGL (BTW, does it actually save some memory at all to do that?). After many attempts, I can't get QOpenGLTexture to display the image. All I end up with is a black image.
      Below is how I setup QOpenGLTexture. The parts that used floating points, and that worked so far, is commented out. The part that assumes images in 16 bits unsigned integers, is right below the latter, uncommented. I'm using OpenGL 3.3, GLSL 330, core profile, on a macbook pro retina with Iris graphics.

      QOpenGLTexture *oglt = new QOpenGLTexture(QOpenGLTexture::Target2D);
              oglt->setMinificationFilter(QOpenGLTexture::NearestMipMapNearest);
              oglt->setMagnificationFilter(QOpenGLTexture::NearestMipMapNearest);
              //oglt->setFormat(QOpenGLTexture::RGB32F); // works
              oglt->setFormat(QOpenGLTexture::RGB16U);  
              oglt->setSize(naxis1, naxis2);
              oglt->setMipLevels(10);
      
              //oglt->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::Float32); // works
              //oglt->setData(QOpenGLTexture::RGB, QOpenGLTexture::Float32, tempImageRGB.data); // works
              oglt->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::UInt16);
              oglt->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt16, tempImageRGB.data);
      

      So, in just these lines above, is there something wrong?
      My data in tempImageRGB.data are between [0-65535] when I used UInt16. When I use QOpenGLTexture::Float32, the data are normalized so they would be within [0-1].

      Then, here is my fragment shader:

      #version 330 core
      
      in mediump vec2 TexCoord;
      out vec4 color;
      
      //uniform mediump sampler2D ourTexture; // Worked
      uniform usampler2D ourTexture; 
      
      void main()
      {
          //mediump vec3 textureColor = texture(ourTexture, TexCoord).rgb; // Worked
          uvec3 textureColor = texture(ourTexture, TexCoord).rgb;
      
          color = vec4(textureColor, 1.0);
      }
      

      In the fragment shader, all I changed is the type from the 32-bits float to the 16 bit unsigned integers case is sampler2D to usampler2D and vec3 to uvec3, but maybe I'm not supposed to do that, am I?

      Thanks for the help.

      C Offline
      C Offline
      CamelFrog
      wrote on last edited by
      #2

      Maybe I'm meant to use QOPenGLTexture::RGB_Integer instead of QOpenGLTexture::RGB, but even then, I still have a black image.

      1 Reply Last reply
      0
      • C CamelFrog

        Hi,

        For a while I've been using RGB images in 32 bits floating point precision in textures with QOpenGLTexture. I had no trouble with it.
        Originally those images have an unsigned short data type, and I'd liketo keep this data type for sending the data to openGL (BTW, does it actually save some memory at all to do that?). After many attempts, I can't get QOpenGLTexture to display the image. All I end up with is a black image.
        Below is how I setup QOpenGLTexture. The parts that used floating points, and that worked so far, is commented out. The part that assumes images in 16 bits unsigned integers, is right below the latter, uncommented. I'm using OpenGL 3.3, GLSL 330, core profile, on a macbook pro retina with Iris graphics.

        QOpenGLTexture *oglt = new QOpenGLTexture(QOpenGLTexture::Target2D);
                oglt->setMinificationFilter(QOpenGLTexture::NearestMipMapNearest);
                oglt->setMagnificationFilter(QOpenGLTexture::NearestMipMapNearest);
                //oglt->setFormat(QOpenGLTexture::RGB32F); // works
                oglt->setFormat(QOpenGLTexture::RGB16U);  
                oglt->setSize(naxis1, naxis2);
                oglt->setMipLevels(10);
        
                //oglt->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::Float32); // works
                //oglt->setData(QOpenGLTexture::RGB, QOpenGLTexture::Float32, tempImageRGB.data); // works
                oglt->allocateStorage(QOpenGLTexture::RGB, QOpenGLTexture::UInt16);
                oglt->setData(QOpenGLTexture::RGB, QOpenGLTexture::UInt16, tempImageRGB.data);
        

        So, in just these lines above, is there something wrong?
        My data in tempImageRGB.data are between [0-65535] when I used UInt16. When I use QOpenGLTexture::Float32, the data are normalized so they would be within [0-1].

        Then, here is my fragment shader:

        #version 330 core
        
        in mediump vec2 TexCoord;
        out vec4 color;
        
        //uniform mediump sampler2D ourTexture; // Worked
        uniform usampler2D ourTexture; 
        
        void main()
        {
            //mediump vec3 textureColor = texture(ourTexture, TexCoord).rgb; // Worked
            uvec3 textureColor = texture(ourTexture, TexCoord).rgb;
        
            color = vec4(textureColor, 1.0);
        }
        

        In the fragment shader, all I changed is the type from the 32-bits float to the 16 bit unsigned integers case is sampler2D to usampler2D and vec3 to uvec3, but maybe I'm not supposed to do that, am I?

        Thanks for the help.

        C Offline
        C Offline
        CamelFrog
        wrote on last edited by
        #3

        After some experimenting, the culprit was the MagnificationFilter. Although there were no problem setting the Magnification with QOpenGLTexture::NearestMipMapNearest with float images, with integer images, I had to set to QOpenGLTexture::Nearest.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved