comparison src/video/gem/SDL_gemvideo.c @ 986:952ec1ddcb58

Add conversion routines for unsupported screen formats
author Patrice Mandin <patmandin@gmail.com>
date Mon, 22 Nov 2004 10:18:04 +0000
parents 44fd54a0ae5f
children 24b5c3ad4852
comparison
equal deleted inserted replaced
985:cec525374267 986:952ec1ddcb58
49 49
50 #include "SDL.h" 50 #include "SDL.h"
51 #include "SDL_error.h" 51 #include "SDL_error.h"
52 #include "SDL_video.h" 52 #include "SDL_video.h"
53 #include "SDL_mouse.h" 53 #include "SDL_mouse.h"
54 #include "SDL_endian.h"
54 #include "SDL_sysvideo.h" 55 #include "SDL_sysvideo.h"
55 #include "SDL_pixels_c.h" 56 #include "SDL_pixels_c.h"
56 #include "SDL_events_c.h" 57 #include "SDL_events_c.h"
57 #include "SDL_cursor_c.h" 58 #include "SDL_cursor_c.h"
58 59
116 static int GEM_GL_LoadLibrary(_THIS, const char *path); 117 static int GEM_GL_LoadLibrary(_THIS, const char *path);
117 static void *GEM_GL_GetProcAddress(_THIS, const char *proc); 118 static void *GEM_GL_GetProcAddress(_THIS, const char *proc);
118 static int GEM_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); 119 static int GEM_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
119 static int GEM_GL_MakeCurrent(_THIS); 120 static int GEM_GL_MakeCurrent(_THIS);
120 static void GEM_GL_SwapBuffers(_THIS); 121 static void GEM_GL_SwapBuffers(_THIS);
122
123 static void GEM_GL_ConvertNull(SDL_Surface *surface);
124 static void GEM_GL_Convert565To555be(SDL_Surface *surface);
125 static void GEM_GL_Convert565To555le(SDL_Surface *surface);
126 static void GEM_GL_Convert565le(SDL_Surface *surface);
127 static void GEM_GL_ConvertBGRAToABGR(SDL_Surface *surface);
128
129 static void (*GEM_GL_Convert)(SDL_Surface *surface);
121 #endif 130 #endif
122 131
123 /* GEM driver bootstrap functions */ 132 /* GEM driver bootstrap functions */
124 133
125 static int GEM_Available(void) 134 static int GEM_Available(void)
749 current->pitch = VDI_pitch; 758 current->pitch = VDI_pitch;
750 } 759 }
751 760
752 #ifdef HAVE_OPENGL 761 #ifdef HAVE_OPENGL
753 if (flags & SDL_OPENGL) { 762 if (flags & SDL_OPENGL) {
754 GLenum format = OSMESA_COLOR_INDEX; 763 int conversion_needed = 0;
764 GLenum format = OSMESA_COLOR_INDEX; /* 8 bits */
755 765
756 /* Init OpenGL context using OSMesa */ 766 /* Init OpenGL context using OSMesa */
767 GEM_GL_Convert = GEM_GL_ConvertNull;
757 switch (VDI_bpp) { 768 switch (VDI_bpp) {
758 case 15: 769 case 15:
759 /* 1555, big and little endian unsupported */ 770 /* 1555, big and little endian, unsupported */
760 format = OSMESA_RGB_565; 771 format = OSMESA_RGB_565;
772 if (VDI_redmask == 31<<10) {
773 GEM_GL_Convert = GEM_GL_Convert565To555be;
774 } else {
775 GEM_GL_Convert = GEM_GL_Convert565To555le;
776 }
761 break; 777 break;
762 case 16: 778 case 16:
763 format = OSMESA_RGB_565; 779 if (VDI_redmask == 31<<11) {
764 /* 565, little endian unsupported */ 780 format = OSMESA_RGB_565;
781 } else {
782 /* 565, little endian, unsupported */
783 format = OSMESA_RGB_565;
784 GEM_GL_Convert = GEM_GL_Convert565le;
785 }
765 break; 786 break;
766 case 24: 787 case 24:
767 if (VDI_redmask == 255<<16) { 788 if (VDI_redmask == 255<<16) {
768 format = OSMESA_RGB; 789 format = OSMESA_RGB;
769 } else { 790 } else {
778 } else if (VDI_redmask == 255<<24) { 799 } else if (VDI_redmask == 255<<24) {
779 format = OSMESA_RGBA; 800 format = OSMESA_RGBA;
780 } else { 801 } else {
781 /* ABGR format unsupported */ 802 /* ABGR format unsupported */
782 format = OSMESA_BGRA; 803 format = OSMESA_BGRA;
804 GEM_GL_Convert = GEM_GL_ConvertBGRAToABGR;
783 } 805 }
784 break; 806 break;
785 } 807 }
786 808
787 GEM_ctx = OSMesaCreateContextExt( format, this->gl_config.depth_size, 809 GEM_ctx = OSMesaCreateContextExt( format, this->gl_config.depth_size,
1432 return 0; 1454 return 0;
1433 } 1455 }
1434 1456
1435 static void GEM_GL_SwapBuffers(_THIS) 1457 static void GEM_GL_SwapBuffers(_THIS)
1436 { 1458 {
1459 GEM_GL_Convert(this->screen);
1437 GEM_FlipHWSurface(this, this->screen); 1460 GEM_FlipHWSurface(this, this->screen);
1438 } 1461 }
1439 1462
1440 #endif 1463 static void GEM_GL_ConvertNull(SDL_Surface *surface)
1464 {
1465 }
1466
1467 static void GEM_GL_Convert565To555be(SDL_Surface *surface)
1468 {
1469 int x,y, pitch;
1470 unsigned short *line, *pixel;
1471
1472 line = surface->pixels;
1473 pitch = surface->pitch >> 1;
1474 for (y=0; y<surface->h; y++) {
1475 pixel = line;
1476 for (x=0; x<surface->w; x++) {
1477 unsigned short color = *pixel;
1478
1479 *pixel++ = (color & 0x1f)|((color>>1) & 0xffe0);
1480 }
1481
1482 line += pitch;
1483 }
1484 }
1485
1486 static void GEM_GL_Convert565To555le(SDL_Surface *surface)
1487 {
1488 int x,y, pitch;
1489 unsigned short *line, *pixel;
1490
1491 line = surface->pixels;
1492 pitch = surface->pitch >>1;
1493 for (y=0; y<surface->h; y++) {
1494 pixel = line;
1495 for (x=0; x<surface->w; x++) {
1496 unsigned short color = *pixel;
1497
1498 color = (color & 0x1f)|((color>>1) & 0xffe0);
1499 *pixel++ = SDL_Swap16(color);
1500 }
1501
1502 line += pitch;
1503 }
1504 }
1505
1506 static void GEM_GL_Convert565le(SDL_Surface *surface)
1507 {
1508 int x,y, pitch;
1509 unsigned short *line, *pixel;
1510
1511 line = surface->pixels;
1512 pitch = surface->pitch >>1;
1513 for (y=0; y<surface->h; y++) {
1514 pixel = line;
1515 for (x=0; x<surface->w; x++) {
1516 *pixel++ = SDL_Swap16(*pixel);
1517 }
1518
1519 line += pitch;
1520 }
1521 }
1522
1523 static void GEM_GL_ConvertBGRAToABGR(SDL_Surface *surface)
1524 {
1525 int x,y, pitch;
1526 unsigned long *line, *pixel;
1527
1528 line = surface->pixels;
1529 pitch = surface->pitch >>2;
1530 for (y=0; y<surface->h; y++) {
1531 pixel = line;
1532 for (x=0; x<surface->w; x++) {
1533 unsigned long color = *pixel;
1534
1535 *pixel++ = (color<<24)|(color>>8);
1536 }
1537
1538 line += pitch;
1539 }
1540 }
1541
1542 #endif