diff src/video/SDL_renderer_gl.c @ 2839:f89700cc9272

Progress, maybe. :)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 06 Dec 2008 17:41:01 +0000
parents b128b94ed31e
children 53ca0d758b0a
line wrap: on
line diff
--- a/src/video/SDL_renderer_gl.c	Sat Dec 06 05:49:53 2008 +0000
+++ b/src/video/SDL_renderer_gl.c	Sat Dec 06 17:41:01 2008 +0000
@@ -45,14 +45,21 @@
 static __inline__ int
 bytes_per_pixel(const Uint32 format)
 {
+    if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
+        return SDL_BYTESPERPIXEL(format);
+    }
+
+    /* FOURCC format */
     switch (format) {
+        case SDL_PIXELFORMAT_YV12:
+        case SDL_PIXELFORMAT_IYUV:
+        case SDL_PIXELFORMAT_YUY2:
         case SDL_PIXELFORMAT_UYVY:
-        /* !!! FIXME: other YUV formats here... */
+        case SDL_PIXELFORMAT_YVYU:
             return 2;
         default:
-            return SDL_BYTESPERPIXEL(format);
+            return 1;  /* shouldn't ever hit this. */
     }
-    return -1;  /* shouldn't ever hit this. */
 }
 
 
@@ -723,6 +730,11 @@
         data->texh = (GLfloat) texture->h / texture_h;
     }
 
+    /* YUV formats use RGBA but are really two bytes per pixel */
+    if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
+        texture_w = (texture_w * bytes_per_pixel(texture->format)) / 4;
+    }
+
     data->format = format;
     data->formattype = type;
     renderdata->glBindTexture(data->type, data->texture);