2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "SDL_config.h"
24 /* Atari OSMesa.ldg implementation of SDL OpenGL support */
29 #include <GL/osmesa.h>
32 #include <mint/osbind.h>
34 #include "SDL_endian.h"
35 #include "SDL_video.h"
36 #include "SDL_atarigl_c.h"
37 #if SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
38 #include "SDL_loadso.h"
43 #define PATH_OSMESA_LDG "osmesa.ldg"
44 #define PATH_MESAGL_LDG "mesa_gl.ldg"
45 #define PATH_TINYGL_LDG "tiny_gl.ldg"
49 /*--- Functions prototypes ---*/
51 static void SDL_AtariGL_UnloadLibrary(_THIS);
54 static void CopyShadowNull(_THIS, SDL_Surface *surface);
55 static void CopyShadowDirect(_THIS, SDL_Surface *surface);
56 static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface);
57 static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface);
58 static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface);
59 static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface);
60 static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface);
61 static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface);
62 static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface);
63 static void CopyShadow8888To555(_THIS, SDL_Surface *surface);
64 static void CopyShadow8888To565(_THIS, SDL_Surface *surface);
66 static void ConvertNull(_THIS, SDL_Surface *surface);
67 static void Convert565To555be(_THIS, SDL_Surface *surface);
68 static void Convert565To555le(_THIS, SDL_Surface *surface);
69 static void Convert565le(_THIS, SDL_Surface *surface);
70 static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface);
72 static int InitNew(_THIS, SDL_Surface *current);
73 static int InitOld(_THIS, SDL_Surface *current);
76 /*--- Public functions ---*/
78 int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
82 gl_active = InitOld(this, current);
84 gl_active = InitNew(this, current);
91 void SDL_AtariGL_Quit(_THIS, SDL_bool unload)
95 /* Old mesa implementations */
96 if (this->gl_data->OSMesaDestroyLDG) {
97 this->gl_data->OSMesaDestroyLDG();
104 /* New mesa implementation */
106 if (this->gl_data->OSMesaDestroyContext) {
107 this->gl_data->OSMesaDestroyContext(gl_ctx);
114 SDL_AtariGL_UnloadLibrary(this);
117 #endif /* SDL_VIDEO_OPENGL */
121 int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
125 #if SDL_VIDEO_OPENGL_OSMESA_DYNAMIC
127 SDL_bool cancel_load;
130 SDL_SetError("OpenGL context already created");
134 /* Unload previous driver */
135 SDL_AtariGL_UnloadLibrary(this);
137 /* Load library given by path */
138 handle = SDL_LoadObject(path);
139 if (handle == NULL) {
140 /* Try to load another one */
141 path = SDL_getenv("SDL_VIDEO_GL_DRIVER");
142 if ( path != NULL ) {
143 handle = SDL_LoadObject(path);
146 /* If it does not work, try some other */
147 if (handle == NULL) {
148 path = PATH_OSMESA_LDG;
149 handle = SDL_LoadObject(path);
152 if (handle == NULL) {
153 path = PATH_MESAGL_LDG;
154 handle = SDL_LoadObject(path);
157 if (handle == NULL) {
158 path = PATH_TINYGL_LDG;
159 handle = SDL_LoadObject(path);
163 if (handle == NULL) {
164 SDL_SetError("Could not load OpenGL library");
168 this->gl_data->glGetIntegerv = SDL_LoadFunction(handle, "glGetIntegerv");
169 this->gl_data->glFinish = SDL_LoadFunction(handle, "glFinish");
170 this->gl_data->glFlush = SDL_LoadFunction(handle, "glFlush");
172 cancel_load = SDL_FALSE;
173 if (this->gl_data->glGetIntegerv == NULL) {
174 cancel_load = SDL_TRUE;
176 /* We need either glFinish (OSMesa) or glFlush (TinyGL) */
177 if ((this->gl_data->glFinish == NULL) &&
178 (this->gl_data->glFlush == NULL)) {
179 cancel_load = SDL_TRUE;
183 SDL_SetError("Could not retrieve OpenGL functions");
184 SDL_UnloadObject(handle);
185 /* Restore pointers to static library */
186 SDL_AtariGL_InitPointers(this);
190 /* Load functions pointers (osmesa.ldg) */
191 this->gl_data->OSMesaCreateContextExt = SDL_LoadFunction(handle, "OSMesaCreateContextExt");
192 this->gl_data->OSMesaDestroyContext = SDL_LoadFunction(handle, "OSMesaDestroyContext");
193 this->gl_data->OSMesaMakeCurrent = SDL_LoadFunction(handle, "OSMesaMakeCurrent");
194 this->gl_data->OSMesaPixelStore = SDL_LoadFunction(handle, "OSMesaPixelStore");
195 this->gl_data->OSMesaGetProcAddress = SDL_LoadFunction(handle, "OSMesaGetProcAddress");
197 /* Load old functions pointers (mesa_gl.ldg, tiny_gl.ldg) */
198 this->gl_data->OSMesaCreateLDG = SDL_LoadFunction(handle, "OSMesaCreateLDG");
199 this->gl_data->OSMesaDestroyLDG = SDL_LoadFunction(handle, "OSMesaDestroyLDG");
203 if ( (this->gl_data->OSMesaCreateContextExt == NULL) ||
204 (this->gl_data->OSMesaDestroyContext == NULL) ||
205 (this->gl_data->OSMesaMakeCurrent == NULL) ||
206 (this->gl_data->OSMesaPixelStore == NULL) ||
207 (this->gl_data->OSMesaGetProcAddress == NULL)) {
208 /* Hum, maybe old library ? */
209 if ( (this->gl_data->OSMesaCreateLDG == NULL) ||
210 (this->gl_data->OSMesaDestroyLDG == NULL)) {
211 SDL_SetError("Could not retrieve OSMesa functions");
212 SDL_UnloadObject(handle);
213 /* Restore pointers to static library */
214 SDL_AtariGL_InitPointers(this);
221 this->gl_config.dll_handle = handle;
223 SDL_strlcpy(this->gl_config.driver_path, path,
224 SDL_arraysize(this->gl_config.driver_path));
226 *this->gl_config.driver_path = '\0';
230 this->gl_config.driver_loaded = 1;
238 void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
243 if (this->gl_config.dll_handle) {
244 func = SDL_LoadFunction(this->gl_config.dll_handle, (void *)proc);
245 } else if (this->gl_data->OSMesaGetProcAddress) {
246 func = this->gl_data->OSMesaGetProcAddress(proc);
253 int SDL_AtariGL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
257 SDL_Surface *surface;
264 case SDL_GL_RED_SIZE:
265 mesa_attrib = GL_RED_BITS;
267 case SDL_GL_GREEN_SIZE:
268 mesa_attrib = GL_GREEN_BITS;
270 case SDL_GL_BLUE_SIZE:
271 mesa_attrib = GL_BLUE_BITS;
273 case SDL_GL_ALPHA_SIZE:
274 mesa_attrib = GL_ALPHA_BITS;
276 case SDL_GL_DOUBLEBUFFER:
277 surface = this->screen;
278 *value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF);
280 case SDL_GL_DEPTH_SIZE:
281 mesa_attrib = GL_DEPTH_BITS;
283 case SDL_GL_STENCIL_SIZE:
284 mesa_attrib = GL_STENCIL_BITS;
286 case SDL_GL_ACCUM_RED_SIZE:
287 mesa_attrib = GL_ACCUM_RED_BITS;
289 case SDL_GL_ACCUM_GREEN_SIZE:
290 mesa_attrib = GL_ACCUM_GREEN_BITS;
292 case SDL_GL_ACCUM_BLUE_SIZE:
293 mesa_attrib = GL_ACCUM_BLUE_BITS;
295 case SDL_GL_ACCUM_ALPHA_SIZE:
296 mesa_attrib = GL_ACCUM_ALPHA_BITS;
302 this->gl_data->glGetIntegerv(mesa_attrib, value);
309 int SDL_AtariGL_MakeCurrent(_THIS)
312 SDL_Surface *surface;
315 if (gl_oldmesa && gl_active) {
319 if (this->gl_config.dll_handle) {
320 if ((this->gl_data->OSMesaMakeCurrent == NULL) ||
321 (this->gl_data->OSMesaPixelStore == NULL)) {
327 SDL_SetError("Invalid OpenGL context");
331 surface = this->screen;
333 if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
334 type = GL_UNSIGNED_SHORT_5_6_5;
336 type = GL_UNSIGNED_BYTE;
339 if (!(this->gl_data->OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h))) {
340 SDL_SetError("Can not make OpenGL context current");
344 /* OSMesa draws upside down */
345 this->gl_data->OSMesaPixelStore(OSMESA_Y_UP, 0);
353 void SDL_AtariGL_SwapBuffers(_THIS)
357 if (this->gl_config.dll_handle) {
358 if (this->gl_data->glFinish) {
359 this->gl_data->glFinish();
360 } else if (this->gl_data->glFlush) {
361 this->gl_data->glFlush();
364 this->gl_data->glFinish();
366 gl_copyshadow(this, this->screen);
367 gl_convert(this, this->screen);
372 void SDL_AtariGL_InitPointers(_THIS)
375 this->gl_data->OSMesaCreateContextExt = OSMesaCreateContextExt;
376 this->gl_data->OSMesaDestroyContext = OSMesaDestroyContext;
377 this->gl_data->OSMesaMakeCurrent = OSMesaMakeCurrent;
378 this->gl_data->OSMesaPixelStore = OSMesaPixelStore;
379 this->gl_data->OSMesaGetProcAddress = OSMesaGetProcAddress;
381 this->gl_data->glGetIntegerv = glGetIntegerv;
382 this->gl_data->glFinish = glFinish;
383 this->gl_data->glFlush = glFlush;
385 this->gl_data->OSMesaCreateLDG = NULL;
386 this->gl_data->OSMesaDestroyLDG = NULL;
390 /*--- Private functions ---*/
392 static void SDL_AtariGL_UnloadLibrary(_THIS)
395 if (this->gl_config.dll_handle) {
396 SDL_UnloadObject(this->gl_config.dll_handle);
397 this->gl_config.dll_handle = NULL;
399 /* Restore pointers to static library */
400 SDL_AtariGL_InitPointers(this);
405 /*--- Creation of an OpenGL context using new/old functions ---*/
408 static int InitNew(_THIS, SDL_Surface *current)
410 GLenum osmesa_format;
411 SDL_PixelFormat *pixel_format;
416 if (this->gl_config.dll_handle) {
417 if (this->gl_data->OSMesaCreateContextExt == NULL) {
422 /* Init OpenGL context using OSMesa */
423 gl_convert = ConvertNull;
424 gl_copyshadow = CopyShadowNull;
425 gl_upsidedown = SDL_FALSE;
427 pixel_format = current->format;
428 redmask = pixel_format->Rmask;
429 switch (pixel_format->BitsPerPixel) {
431 /* 1555, big and little endian, unsupported */
433 osmesa_format = OSMESA_RGB_565;
434 if (redmask == 31<<10) {
435 gl_convert = Convert565To555be;
437 gl_convert = Convert565To555le;
442 if (redmask == 31<<11) {
443 osmesa_format = OSMESA_RGB_565;
445 /* 565, little endian, unsupported */
446 osmesa_format = OSMESA_RGB_565;
447 gl_convert = Convert565le;
452 if (redmask == 255<<16) {
453 osmesa_format = OSMESA_RGB;
455 osmesa_format = OSMESA_BGR;
460 if (redmask == 255<<16) {
461 osmesa_format = OSMESA_ARGB;
462 } else if (redmask == 255<<8) {
463 osmesa_format = OSMESA_BGRA;
464 } else if (redmask == 255<<24) {
465 osmesa_format = OSMESA_RGBA;
467 /* ABGR format unsupported */
468 osmesa_format = OSMESA_BGRA;
469 gl_convert = ConvertBGRAToABGR;
474 osmesa_format = OSMESA_COLOR_INDEX;
478 /* Try to keep current context if possible */
480 this->gl_config.accum_red_size +
481 this->gl_config.accum_green_size +
482 this->gl_config.accum_blue_size +
483 this->gl_config.accum_alpha_size;
486 (gl_curformat == osmesa_format) &&
487 (gl_curdepth == this->gl_config.depth_size) &&
488 (gl_curstencil == this->gl_config.stencil_size) &&
489 (gl_curaccum == newaccumsize)) {
492 if (recreatecontext) {
493 SDL_AtariGL_Quit(this, SDL_FALSE);
495 gl_ctx = this->gl_data->OSMesaCreateContextExt(
496 osmesa_format, this->gl_config.depth_size,
497 this->gl_config.stencil_size, newaccumsize, NULL );
500 gl_curformat = osmesa_format;
501 gl_curdepth = this->gl_config.depth_size;
502 gl_curstencil = this->gl_config.stencil_size;
503 gl_curaccum = newaccumsize;
512 return (gl_ctx != NULL);
516 static int InitOld(_THIS, SDL_Surface *current)
518 GLenum osmesa_format;
519 SDL_PixelFormat *pixel_format;
521 int recreatecontext, tinygl_present;
523 if (this->gl_config.dll_handle) {
524 if (this->gl_data->OSMesaCreateLDG == NULL) {
529 /* TinyGL only supports VDI_RGB (OSMESA_RGB) */
531 if (this->gl_config.dll_handle) {
532 if (this->gl_data->glFinish == NULL) {
537 /* Init OpenGL context using OSMesa */
538 gl_convert = ConvertNull;
539 gl_copyshadow = CopyShadowNull;
540 gl_upsidedown = SDL_FALSE;
542 pixel_format = current->format;
543 redmask = pixel_format->Rmask;
544 switch (pixel_format->BitsPerPixel) {
546 /* 15 bits unsupported */
547 if (tinygl_present) {
549 osmesa_format = VDI_RGB;
550 if (redmask == 31<<10) {
551 gl_copyshadow = CopyShadowRGBTo555;
553 gl_copyshadow = CopyShadowRGBTo565;
554 gl_convert = Convert565To555le;
558 gl_upsidedown = SDL_TRUE;
559 osmesa_format = OSMESA_ARGB;
560 if (redmask == 31<<10) {
561 gl_copyshadow = CopyShadow8888To555;
563 gl_copyshadow = CopyShadow8888To565;
564 gl_convert = Convert565To555le;
569 /* 16 bits unsupported */
570 if (tinygl_present) {
572 osmesa_format = VDI_RGB;
573 gl_copyshadow = CopyShadowRGBTo565;
574 if (redmask != 31<<11) {
575 /* 565, little endian, unsupported */
576 gl_convert = Convert565le;
580 gl_upsidedown = SDL_TRUE;
581 osmesa_format = OSMESA_ARGB;
582 gl_copyshadow = CopyShadow8888To565;
583 if (redmask != 31<<11) {
584 /* 565, little endian, unsupported */
585 gl_convert = Convert565le;
591 if (tinygl_present) {
592 osmesa_format = VDI_RGB;
593 gl_copyshadow = CopyShadowDirect;
594 if (redmask != 255<<16) {
595 gl_copyshadow = CopyShadowRGBSwap;
598 gl_copyshadow = CopyShadowDirect;
599 gl_upsidedown = SDL_TRUE;
600 if (redmask == 255<<16) {
601 osmesa_format = OSMESA_RGB;
603 osmesa_format = OSMESA_BGR;
608 if (tinygl_present) {
610 osmesa_format = VDI_RGB;
611 gl_copyshadow = CopyShadowRGBToARGB;
612 if (redmask == 255) {
613 gl_convert = CopyShadowRGBToABGR;
614 } else if (redmask == 255<<8) {
615 gl_convert = CopyShadowRGBToBGRA;
616 } else if (redmask == 255<<24) {
617 gl_convert = CopyShadowRGBToRGBA;
621 gl_upsidedown = SDL_TRUE;
622 gl_copyshadow = CopyShadowDirect;
623 if (redmask == 255<<16) {
624 osmesa_format = OSMESA_ARGB;
625 } else if (redmask == 255<<8) {
626 osmesa_format = OSMESA_BGRA;
627 } else if (redmask == 255<<24) {
628 osmesa_format = OSMESA_RGBA;
630 /* ABGR format unsupported */
631 osmesa_format = OSMESA_BGRA;
632 gl_convert = ConvertBGRAToABGR;
637 if (tinygl_present) {
638 SDL_AtariGL_Quit(this, SDL_FALSE);
642 gl_copyshadow = CopyShadowDirect;
643 osmesa_format = OSMESA_COLOR_INDEX;
647 /* Try to keep current context if possible */
650 (gl_curformat == osmesa_format) &&
651 (gl_curwidth == current->w) &&
652 (gl_curheight == current->h)) {
655 if (recreatecontext) {
656 SDL_AtariGL_Quit(this, SDL_FALSE);
658 gl_shadow = this->gl_data->OSMesaCreateLDG(
659 osmesa_format, GL_UNSIGNED_BYTE, current->w, current->h
663 gl_curformat = osmesa_format;
664 gl_curwidth = current->w;
665 gl_curheight = current->h;
673 return (gl_shadow != NULL);
676 /*--- Conversions routines from shadow buffer to the screen ---*/
678 static void CopyShadowNull(_THIS, SDL_Surface *surface)
682 static void CopyShadowDirect(_THIS, SDL_Surface *surface)
684 int y, srcpitch, dstpitch;
685 Uint8 *srcline, *dstline;
688 srcpitch = surface->w * gl_pixelsize;
689 dstline = surface->pixels;
690 dstpitch = surface->pitch;
692 srcline += (surface->h-1)*srcpitch;
693 srcpitch = -srcpitch;
696 for (y=0; y<surface->h; y++) {
697 SDL_memcpy(dstline, srcline, srcpitch);
704 static void CopyShadowRGBTo555(_THIS, SDL_Surface *surface)
706 int x,y, srcpitch, dstpitch;
707 Uint16 *dstline, *dstcol;
708 Uint8 *srcline, *srccol;
710 srcline = (Uint8 *)gl_shadow;
711 srcpitch = surface->w * gl_pixelsize;
712 dstline = surface->pixels;
713 dstpitch = surface->pitch >>1;
715 srcline += (surface->h-1)*srcpitch;
716 srcpitch = -srcpitch;
719 for (y=0; y<surface->h; y++) {
722 for (x=0; x<surface->w; x++) {
725 dstcolor = ((*srccol++)<<7) & (31<<10);
726 dstcolor |= ((*srccol++)<<2) & (31<<5);
727 dstcolor |= ((*srccol++)>>3) & 31;
728 *dstcol++ = dstcolor;
736 static void CopyShadowRGBTo565(_THIS, SDL_Surface *surface)
738 int x,y, srcpitch, dstpitch;
739 Uint16 *dstline, *dstcol;
740 Uint8 *srcline, *srccol;
742 srcline = (Uint8 *)gl_shadow;
743 srcpitch = surface->w * gl_pixelsize;
744 dstline = surface->pixels;
745 dstpitch = surface->pitch >>1;
747 srcline += (surface->h-1)*srcpitch;
748 srcpitch = -srcpitch;
751 for (y=0; y<surface->h; y++) {
755 for (x=0; x<surface->w; x++) {
758 dstcolor = ((*srccol++)<<8) & (31<<11);
759 dstcolor |= ((*srccol++)<<3) & (63<<5);
760 dstcolor |= ((*srccol++)>>3) & 31;
761 *dstcol++ = dstcolor;
769 static void CopyShadowRGBSwap(_THIS, SDL_Surface *surface)
771 int x,y, srcpitch, dstpitch;
772 Uint8 *dstline, *dstcol;
773 Uint8 *srcline, *srccol;
775 srcline = (Uint8 *)gl_shadow;
776 srcpitch = surface->w * gl_pixelsize;
777 dstline = surface->pixels;
778 dstpitch = surface->pitch;
780 srcline += (surface->h-1)*srcpitch;
781 srcpitch = -srcpitch;
784 for (y=0; y<surface->h; y++) {
788 for (x=0; x<surface->w; x++) {
789 *dstcol++ = srccol[2];
790 *dstcol++ = srccol[1];
791 *dstcol++ = srccol[0];
800 static void CopyShadowRGBToARGB(_THIS, SDL_Surface *surface)
802 int x,y, srcpitch, dstpitch;
803 Uint32 *dstline, *dstcol;
804 Uint8 *srcline, *srccol;
806 srcline = (Uint8 *)gl_shadow;
807 srcpitch = surface->w * gl_pixelsize;
808 dstline = surface->pixels;
809 dstpitch = surface->pitch >>2;
811 srcline += (surface->h-1)*srcpitch;
812 srcpitch = -srcpitch;
815 for (y=0; y<surface->h; y++) {
819 for (x=0; x<surface->w; x++) {
822 dstcolor = (*srccol++)<<16;
823 dstcolor |= (*srccol++)<<8;
824 dstcolor |= *srccol++;
826 *dstcol++ = dstcolor;
834 static void CopyShadowRGBToABGR(_THIS, SDL_Surface *surface)
836 int x,y, srcpitch, dstpitch;
837 Uint32 *dstline, *dstcol;
838 Uint8 *srcline, *srccol;
840 srcline = (Uint8 *)gl_shadow;
841 srcpitch = surface->w * gl_pixelsize;
842 dstline = surface->pixels;
843 dstpitch = surface->pitch >>2;
845 srcline += (surface->h-1)*srcpitch;
846 srcpitch = -srcpitch;
849 for (y=0; y<surface->h; y++) {
853 for (x=0; x<surface->w; x++) {
856 dstcolor = *srccol++;
857 dstcolor |= (*srccol++)<<8;
858 dstcolor |= (*srccol++)<<16;
860 *dstcol++ = dstcolor;
868 static void CopyShadowRGBToBGRA(_THIS, SDL_Surface *surface)
870 int x,y, srcpitch, dstpitch;
871 Uint32 *dstline, *dstcol;
872 Uint8 *srcline, *srccol;
874 srcline = (Uint8 *)gl_shadow;
875 srcpitch = surface->w * gl_pixelsize;
876 dstline = surface->pixels;
877 dstpitch = surface->pitch >>2;
879 srcline += (surface->h-1)*srcpitch;
880 srcpitch = -srcpitch;
883 for (y=0; y<surface->h; y++) {
887 for (x=0; x<surface->w; x++) {
890 dstcolor = (*srccol++)<<8;
891 dstcolor |= (*srccol++)<<16;
892 dstcolor |= (*srccol++)<<24;
894 *dstcol++ = dstcolor;
902 static void CopyShadowRGBToRGBA(_THIS, SDL_Surface *surface)
904 int x,y, srcpitch, dstpitch;
905 Uint32 *dstline, *dstcol;
906 Uint8 *srcline, *srccol;
908 srcline = (Uint8 *)gl_shadow;
909 srcpitch = surface->w * gl_pixelsize;
910 dstline = surface->pixels;
911 dstpitch = surface->pitch >>2;
913 srcline += (surface->h-1)*srcpitch;
914 srcpitch = -srcpitch;
917 for (y=0; y<surface->h; y++) {
921 for (x=0; x<surface->w; x++) {
924 dstcolor = (*srccol++)<<24;
925 dstcolor |= (*srccol++)<<16;
926 dstcolor |= (*srccol++)<<8;
928 *dstcol++ = dstcolor;
936 static void CopyShadow8888To555(_THIS, SDL_Surface *surface)
938 int x,y, srcpitch, dstpitch;
939 Uint16 *dstline, *dstcol;
940 Uint32 *srcline, *srccol;
942 srcline = (Uint32 *)gl_shadow;
943 srcpitch = (surface->w * gl_pixelsize) >>2;
944 dstline = surface->pixels;
945 dstpitch = surface->pitch >>1;
947 srcline += (surface->h-1)*srcpitch;
948 srcpitch = -srcpitch;
951 for (y=0; y<surface->h; y++) {
954 for (x=0; x<surface->w; x++) {
958 srccolor = *srccol++;
959 dstcolor = (srccolor>>9) & (31<<10);
960 dstcolor |= (srccolor>>6) & (31<<5);
961 dstcolor |= (srccolor>>3) & 31;
962 *dstcol++ = dstcolor;
970 static void CopyShadow8888To565(_THIS, SDL_Surface *surface)
972 int x,y, srcpitch, dstpitch;
973 Uint16 *dstline, *dstcol;
974 Uint32 *srcline, *srccol;
976 srcline = (Uint32 *)gl_shadow;
977 srcpitch = (surface->w * gl_pixelsize) >> 2;
978 dstline = surface->pixels;
979 dstpitch = surface->pitch >>1;
981 srcline += (surface->h-1)*srcpitch;
982 srcpitch = -srcpitch;
985 for (y=0; y<surface->h; y++) {
989 for (x=0; x<surface->w; x++) {
993 srccolor = *srccol++;
994 dstcolor = (srccolor>>8) & (31<<11);
995 dstcolor |= (srccolor>>5) & (63<<5);
996 dstcolor |= (srccolor>>3) & 31;
997 *dstcol++ = dstcolor;
1000 srcline += srcpitch;
1001 dstline += dstpitch;
1005 /*--- Conversions routines in the screen ---*/
1007 static void ConvertNull(_THIS, SDL_Surface *surface)
1011 static void Convert565To555be(_THIS, SDL_Surface *surface)
1014 unsigned short *line, *pixel;
1016 line = surface->pixels;
1017 pitch = surface->pitch >> 1;
1018 for (y=0; y<surface->h; y++) {
1020 for (x=0; x<surface->w; x++) {
1021 unsigned short color = *pixel;
1023 *pixel++ = (color & 0x1f)|((color>>1) & 0xffe0);
1030 static void Convert565To555le(_THIS, SDL_Surface *surface)
1033 unsigned short *line, *pixel;
1035 line = surface->pixels;
1036 pitch = surface->pitch >>1;
1037 for (y=0; y<surface->h; y++) {
1039 for (x=0; x<surface->w; x++) {
1040 unsigned short color = *pixel;
1042 color = (color & 0x1f)|((color>>1) & 0xffe0);
1043 *pixel++ = SDL_Swap16(color);
1050 static void Convert565le(_THIS, SDL_Surface *surface)
1053 unsigned short *line, *pixel;
1055 line = surface->pixels;
1056 pitch = surface->pitch >>1;
1057 for (y=0; y<surface->h; y++) {
1059 for (x=0; x<surface->w; x++) {
1060 unsigned short color = *pixel;
1062 *pixel++ = SDL_Swap16(color);
1069 static void ConvertBGRAToABGR(_THIS, SDL_Surface *surface)
1072 unsigned long *line, *pixel;
1074 line = surface->pixels;
1075 pitch = surface->pitch >>2;
1076 for (y=0; y<surface->h; y++) {
1078 for (x=0; x<surface->w; x++) {
1079 unsigned long color = *pixel;
1081 *pixel++ = (color<<24)|(color>>8);
1088 #endif /* SDL_VIDEO_OPENGL */