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 1 of 3 123 LastLast
Results 1 to 10 of 22

Thread: RGB or BGR for textures?

Hybrid View

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

    RGB or BGR for textures?

    ive been using BGR(A) as the base internal format for my textures since the dawn of time, now checking the spec it doesnt seem to mention this as a valid base internal format (though it works), though it does mention its used for draw/readpixels, now quite why i switched over to BGR from RGB im not exactly sure, are there any benifits of using BGR, i seem to recall this is the native format for windows so there might be performance benifits, is this correct.

    cheers zed

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Posts
    124

    Re: RGB or BGR for textures?

    Most images are stored in BGR-format, so it is more simple to load an image and use it as a texture. For RGB you would have to swap the R and the B bytes. The BGR(A) format is a quite old extension if I'm right. It's so old that even the Microsoft OGL implementation supports it.

    Marc

  3. #3
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: RGB or BGR for textures?

    BGR is not an internal format, it's a format enum to tell the driver what your source image data is in, not how the driver should store it in the texture. It is the native format for win32 bitmaps, so if you're uploading win32 image data then you should use the BGR enum.
    Knackered

  4. #4
    Intern Newbie
    Join Date
    Dec 2003
    Location
    china
    Posts
    37

    Re: RGB or BGR for textures?

    use BGR let texture load more quickly on win32
    platform.but only about load speed

  5. #5
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    3,768

    Re: RGB or BGR for textures?

    It's not just Win32 machines. Any little endian system (non-Macs) will benifit from it. It has more to do with hardware than software.

  6. #6
    Senior Member OpenGL Guru knackered's Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    3,032

    Re: RGB or BGR for textures?

    It's nothing to do with the endian of the hardware.
    Knackered

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

    Re: RGB or BGR for textures?

    Originally posted by knackered:
    It's nothing to do with the endian of the hardware.
    I think so. On windows, the decision to swap red and blue stems from some compatibility issue.
    They wanted to make DIBs "device independent".

    At least that's what a very old MSDN document said.

    Somehow, a few images formats chose the swapped red and blue approach.

    Note that a DIB memory layout is 0xXXRRGGBB, while RGBA format means 0xXXBBGGRR. Nothing to do with endianess.

    Upload your textures as GL_BGRA, which tends to be faster. I think textures are commonly stored this way.

    Also, some processors are switchable between little and big endian. PowerPC was one of them.
    ------------------------------
    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. #8
    Junior Member Regular Contributor
    Join Date
    Jun 2003
    Location
    Virginia
    Posts
    215

    Re: RGB or BGR for textures?

    Does uploading from a BGR format really speed things up?

  9. #9
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    676

    Re: RGB or BGR for textures?

    GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV is the fastest upload format on Macintosh.

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    591

    Re: RGB or BGR for textures?

    Originally posted by CatAtWork:
    Does uploading from a BGR format really speed things up?
    On NVIDIA GPUs, yes.

Posting Permissions

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