diff mbox

[Branch,~glmark2-dev/glmark2/trunk] Rev 45: When loading a texture that is not RGBA or RGB, convert it to one of these two formats.

Message ID 20110721123633.17019.35345.launchpad@loganberry.canonical.com
State Accepted
Headers show

Commit Message

Alexandros Frantzis July 21, 2011, 12:36 p.m. UTC
------------------------------------------------------------
revno: 45
committer: Alexandros Frantzis <alf82@freemail.gr>
timestamp: Mon 2010-07-12 18:34:44 +0300
message:
  When loading a texture that is not RGBA or RGB, convert it to one of these two formats.
modified:
  src/texture.cpp


--
lp:glmark2
https://code.launchpad.net/~glmark2-dev/glmark2/trunk

You are subscribed to branch lp:glmark2.
To unsubscribe from this branch go to https://code.launchpad.net/~glmark2-dev/glmark2/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'src/texture.cpp'
--- src/texture.cpp	2010-07-12 10:06:29 +0000
+++ src/texture.cpp	2010-07-12 15:34:44 +0000
@@ -15,25 +15,45 @@ 
 
         nOfColors = surface->format->BytesPerPixel;
         if (nOfColors == 4) {
-            if (surface->format->Rmask == 0x000000ff)
-                texture_format = GL_RGBA;
-            else {
-                fprintf(stderr, "Error: %s: Unsupported pixel format BGRA\n", pFilename);
-                return 1;
+            texture_format = GL_RGBA;
+            // If the picture is not RGBA convert it
+            if (surface->format->Rmask != 0x000000ff) {
+                SDL_PixelFormat format = {
+                    surface->format->palette,
+                    surface->format->BitsPerPixel,
+                    surface->format->BytesPerPixel,
+                    surface->format->Rloss, surface->format->Gloss,
+                    surface->format->Bloss, surface->format->Aloss,
+                    0,  8, 16, 24,
+                    0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000,
+                    surface->format->colorkey, surface->format->alpha
+                };
+                SDL_Surface *tmp = SDL_ConvertSurface(surface, &format, 0);
+                SDL_FreeSurface(surface);
+                surface = tmp;
+            }
+        }
+        else if (nOfColors == 3) {
+            texture_format = GL_RGB;
+            // If the picture is not RGB convert it
+            if (surface->format->Rmask != 0x000000ff) {
+                SDL_PixelFormat format = {
+                    surface->format->palette,
+                    surface->format->BitsPerPixel,
+                    surface->format->BytesPerPixel,
+                    surface->format->Rloss, surface->format->Gloss,
+                    surface->format->Bloss, surface->format->Aloss,
+                    0,  8, 16, 24,
+                    0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000,
+                    surface->format->colorkey, surface->format->alpha
+                };
+                SDL_Surface *tmp = SDL_ConvertSurface(surface, &format, 0);
+                SDL_FreeSurface(surface);
+                surface = tmp;
             }
         }
         else {
-            if (nOfColors == 3) {
-                if (surface->format->Rmask == 0x000000ff)
-                    texture_format = GL_RGB;
-                else {
-                    fprintf(stderr, "Error: %s: Unsupported pixel format BGR\n", pFilename);
-                    return 1;
-                }
-            }
-            else {
-                printf("warning: the image is not truecolor..  this will probably break\n");
-            }
+            printf("warning: the image is not truecolor..  this will probably break\n");
         }
 
         glGenTextures(3, pTexture);