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 3 FirstFirst 123 LastLast
Results 11 to 20 of 22

Thread: RGB or BGR for textures?

  1. #11
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: RGB or BGR for textures?

    ran a few tests on my gffx5900 intf == internal format, NOTE when it saiz RGBA12 or someit i most likely get given RGBA8 etc, also the slight descrepences ~0.1% in timing are due to the timer

    now BGRA is faster than RGBA BUT
    something must be wrong, RGB with packed pixels is giving faster results than BGR.
    So, is my code flawed? (i cant see how)

    glTexSubImage2D Mpix/sec( 624.2) size( 128) intf(GL_RGBA8 ) format(GL_BGRA ) type(GL_UNSIGNED_INT_8_8_8_8_REV)
    glTexSubImage2D Mpix/sec( 623.5) size( 128) intf(GL_RGBA12 ) format(GL_BGRA ) type(GL_UNSIGNED_INT_8_8_8_8_REV)
    glTexSubImage2D Mpix/sec( 623.5) size( 128) intf(GL_RGBA16 ) format(GL_BGRA ) type(GL_UNSIGNED_INT_8_8_8_8_REV)
    glTexSubImage2D Mpix/sec( 622.8) size( 128) intf(GL_RGBA ) format(GL_BGRA ) type(GL_UNSIGNED_INT_8_8_8_8_REV)
    glTexSubImage2D Mpix/sec( 622.8) size( 128) intf(GL_RGBA8 ) format(GL_BGRA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 622.8) size( 128) intf(GL_RGB10_A2 ) format(GL_BGRA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 622.8) size( 128) intf(GL_RGB10_A2 ) format(GL_BGRA ) type(GL_UNSIGNED_INT_8_8_8_8_REV)
    glTexSubImage2D Mpix/sec( 622.1) size( 128) intf(GL_RGBA16 ) format(GL_BGRA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 619.9) size( 128) intf(GL_RGBA ) format(GL_BGRA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 619.9) size( 128) intf(GL_RGBA12 ) format(GL_BGRA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 246.2) size( 128) intf(GL_RGBA12 ) format(GL_BGRA ) type(GL_UNSIGNED_INT_8_8_8_8)
    ..

    glTexSubImage2D Mpix/sec( 390.1) size( 128) intf(GL_RGBA16 ) format(GL_RGBA ) type(GL_UNSIGNED_INT_8_8_8_8)
    glTexSubImage2D Mpix/sec( 388.5) size( 128) intf(GL_RGBA ) format(GL_RGBA ) type(GL_UNSIGNED_INT_8_8_8_8)
    glTexSubImage2D Mpix/sec( 387.3) size( 128) intf(GL_RGB10_A2 ) format(GL_RGBA ) type(GL_UNSIGNED_INT_8_8_8_8)
    glTexSubImage2D Mpix/sec( 386.8) size( 128) intf(GL_RGBA12 ) format(GL_RGBA ) type(GL_UNSIGNED_INT_8_8_8_8)
    glTexSubImage2D Mpix/sec( 385.1) size( 128) intf(GL_RGBA8 ) format(GL_RGBA ) type(GL_UNSIGNED_INT_8_8_8_8)
    glTexSubImage2D Mpix/sec( 272.0) size( 128) intf(GL_RGBA16 ) format(GL_RGBA ) type(GL_UNSIGNED_INT_8_8_8_8_REV)
    glTexSubImage2D Mpix/sec( 271.7) size( 128) intf(GL_RGBA16 ) format(GL_RGBA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 271.7) size( 128) intf(GL_RGBA12 ) format(GL_RGBA ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 271.1) size( 128) intf(GL_RGB10_A2 ) format(GL_RGBA ) type(GL_UNSIGNED_BYTE)
    ..

    glTexSubImage2D Mpix/sec( 384.6) size( 128) intf(GL_RGB10 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 384.6) size( 128) intf(GL_RGB ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 382.9) size( 128) intf(GL_RGB8 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 381.8) size( 128) intf(GL_RGB12 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 380.2) size( 128) intf(GL_RGB16 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 219.3) size( 128) intf(GL_RGB5 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 217.9) size( 128) intf(GL_R3_G3_B2 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 215.4) size( 128) intf(GL_RGB4 ) format(GL_BGR ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 41.2) size( 128) intf(GL_RGB4 ) format(GL_BGR ) type(GL_UNSIGNED_INT )
    ..

    glTexSubImage2D Mpix/sec(1819.9) size( 128) intf(GL_RGB ) format(GL_RGB ) type(GL_UNSIGNED_SHORT_5_6_5)
    glTexSubImage2D Mpix/sec(1819.9) size( 128) intf(GL_RGB4 ) format(GL_RGB ) type(GL_UNSIGNED_SHORT_5_6_5)
    glTexSubImage2D Mpix/sec(1819.9) size( 128) intf(GL_R3_G3_B2 ) format(GL_RGB ) type(GL_UNSIGNED_SHORT_5_6_5)
    glTexSubImage2D Mpix/sec(1813.7) size( 128) intf(GL_RGB5 ) format(GL_RGB ) type(GL_UNSIGNED_SHORT_5_6_5)
    glTexSubImage2D Mpix/sec( 411.1) size( 128) intf(GL_RGB8 ) format(GL_RGB ) type(GL_UNSIGNED_BYTE)
    glTexSubImage2D Mpix/sec( 411.1) size( 128) intf(GL_RGB ) format(GL_RGB ) type(GL_UNSIGNED_BYTE)
    ..

  2. #12
    Member Regular Contributor
    Join Date
    Aug 2003
    Location
    France
    Posts
    299

    Re: RGB or BGR for textures?

    Ahem ... Zed ... do you mean uploading using BGR is twice faster compared to RGB ? Can this be possibly true ?

    SeskaPeel.

  3. #13
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: RGB or BGR for textures?

    i changed this demo as well
    http://www.adrian.lark.btinternet.co.uk/GLBench.htm

    it backs up my results RGB is faster than BGR but according to everyone here this shouldnt be true. so whats going on?

  4. #14
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,979

    Re: RGB or BGR for textures?

    Video cards tend to implement BGR textures in hardware(as windows machines are most populat one). It looks like they implement RGB but that's only fake. Actually, all OpenGL drivers are full of hacks

  5. #15
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: RGB or BGR for textures?

    To answer the original question:

    The only formats that are value for "internal format" are 1,2,3,4 (for compatibility), GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, and the various depth, bump, compression etc extensions, plus their component-signed (GL_RGB8 and friends) versions.

    GL_BGR/GL_BGRA are not valid as internal formats -- you should specify GL_RGB/GL_RGBA.

    However, this doesn't matter, because the component ordering of the internal format (what's stored on the card) is not visible to you through the API. All "GL_RGB" means for internal format is that the card, internally, uses one of each of the R, G and B channels.

    Meanwhile, for external formats, as everyone has said, GL_BGRA/GL_UNSIGNED_BYTE, or GL_BGRA/GL_UNSIGNED_INT_8_8_8_8_REV, is usually the format that hardware optimizes the most for. This is because most image file formats typically store pixels in BGRA format in memory (so that, on a little-endian machine, you can write them as 0xaarrggbb as an integer).
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  6. #16
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: RGB or BGR for textures?

    GL_BGR/GL_BGRA are not valid as internal formats -- you should specify GL_RGB/GL_RGBA.
    sorry about the confusion in my first post, somehow the word 'internal' slipped in there. i meant base format.
    though the question still remains why is RGB (base format) faster than BGR, change the above demo (takes 2 minutes)

  7. #17
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: RGB or BGR for textures?

    IV. Texturing
    25. How can I maximize texture downloading performance?
    Best RGB/RGBA texture image formats/types in order of performance:

    Image Format Image Type Texture Internal Format
    GL_RGB GL_UNSIGNED_SHORT_5_6_5 GL_RGB
    GL_BGRA GL_UNSIGNED_SHORT_1_5_5_5_REV GL_RGBA
    GL_BGRA GL_UNSIGNED_SHORT_4_4_4_4_REV GL_RGBA
    GL_BGRA GL_UNSIGNED_INT_8_8_8_8_REV GL_RGBA
    GL_RGBA GL_UNSIGNED_INT_8_8_8_8 GL_RGBA

    Bear in mind that the NVIDIA GPUs store all 24-bit texels in 32-bit entries, so try using the
    spare alpha channel for something worthwhile, or it will just be wasted space. Moreover, 32-bit
    texels can be downloaded at twice the speed of 24-bit texels. Single or dual component texture
    formats such as GL_LUMINANCE, GL_ALPHA and GL_LUMINANCE_ALPHA are also very
    effective, as well as space efficient, particularly when they are blended with a constant color (e.g.
    grass, sky, etc.). Most importantly, always use glTexSubImage2D instead of glTexImage2D
    (and glCopyTexSubImage2D instead of glCopyTexImage2D) when updating texture images.
    The former call avoids any memory freeing or allocation, while the latter call may be required to
    reallocate its texture buffer for the newly defined texture.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  8. #18
    Junior Member Regular Contributor
    Join Date
    Dec 2000
    Location
    Madrid, Spain
    Posts
    149

    Re: RGB or BGR for textures?

    In http://developer.nvidia.com/object/n...e_formats.html

    there is an interesting list of texture formats supported by NVIDIA hw.
    I'm suprised that except for GF6200, the RGB8 format is stored as RGBA8...

  9. #19
    Advanced Member Frequent Contributor
    Join Date
    Aug 2001
    Location
    Italy
    Posts
    628

    Re: RGB or BGR for textures?

    I'm quite surprised there's still a difference between RGB and BGR.
    Well, since I'm used to RGB I won't change my mind now but someone measured upload performance for real? Having RGB uploaded at half speed than BGR is definetly beyond my expectations. It's just a swap after all.

  10. #20
    Senior Member OpenGL Pro
    Join Date
    Feb 2002
    Location
    Bonn, Germany
    Posts
    1,652

    Re: RGB or BGR for textures?

    Originally posted by zed:
    though the question still remains why is RGB (base format) faster than BGR, change the above demo (takes 2 minutes)
    AFAICS that's only the case with "R5G6B5" internal format. This doesn't exist as an enumerant, but RGB5 (which the plain GL_RGB internal format may be promoted to if you don't request anything else) is a close enough match.

    To make sure what you're measuring, you should query the internal component resolution of the texture (after loading image data).
    Code :
    void
    print_texture_2d_components()
    {
      int red_bits=0;
      int green_bits=0;
      int blue_bits=0;
      int alpha_bits=0;
      int luma_bits=0;
      int intensity_bits=0;
      int depth_bits=0;
     
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_RED_SIZE,&red_bits);
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_GREEN_SIZE,&green_bits);
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_BLUE_SIZE,&blue_bits);
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_ALPHA_SIZE,&alpha_bits);
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_LUMINANCE_SIZE,&luma_bits);
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_INTENSITY_SIZE,&intensity_bits);
     
      //requires ARB_depth_texture
      glGetTexLevelParameteriv(GL_TEXTURE_2D,0,GL_TEXTURE_DEPTH_SIZE,&depth_bits);
     
      if (red_bits)        printf("R%u",red_bits);
      if (geen_bits)       printf("G%u",green_bits);
      if (blue_bits)       printf("B%u",blue_bits);
      if (alpha_bits)      printf("A%u",alpha_bits);
      if (luma_bits)       printf("L%u",luma_bits);
      if (intensity_bits)  printf("I%u",intensity_bits);
      if (depth_bits)      printf("D%u",depth_bits);
     
      printf("\n");
    }

Posting Permissions

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