Mercurial > sdl-ios-xcode
comparison src/video/xbios/SDL_xbios.c @ 989:475166d13b44
Factorize OSMesa OpenGL code for Atari drivers
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Thu, 25 Nov 2004 15:47:49 +0000 |
parents | 7d6f8804a293 |
children | 12b13601a544 |
comparison
equal
deleted
inserted
replaced
988:24b5c3ad4852 | 989:475166d13b44 |
---|---|
34 #include <stdio.h> | 34 #include <stdio.h> |
35 #include <stdlib.h> | 35 #include <stdlib.h> |
36 #include <string.h> | 36 #include <string.h> |
37 #include <sys/stat.h> | 37 #include <sys/stat.h> |
38 #include <unistd.h> | 38 #include <unistd.h> |
39 | |
40 #ifdef HAVE_OPENGL | |
41 #include <GL/osmesa.h> | |
42 #endif | |
43 | 39 |
44 /* Mint includes */ | 40 /* Mint includes */ |
45 #include <mint/cookie.h> | 41 #include <mint/cookie.h> |
46 #include <mint/osbind.h> | 42 #include <mint/osbind.h> |
47 #include <mint/falcon.h> | 43 #include <mint/falcon.h> |
55 #include "SDL_events_c.h" | 51 #include "SDL_events_c.h" |
56 | 52 |
57 #include "SDL_ataric2p_s.h" | 53 #include "SDL_ataric2p_s.h" |
58 #include "SDL_atarievents_c.h" | 54 #include "SDL_atarievents_c.h" |
59 #include "SDL_atarimxalloc_c.h" | 55 #include "SDL_atarimxalloc_c.h" |
56 #include "SDL_atarigl_c.h" | |
60 #include "SDL_xbios.h" | 57 #include "SDL_xbios.h" |
61 | 58 |
62 #define XBIOS_VID_DRIVER_NAME "xbios" | 59 #define XBIOS_VID_DRIVER_NAME "xbios" |
63 | 60 |
64 /*#define DEBUG_VIDEO_XBIOS 1*/ | 61 /*#define DEBUG_VIDEO_XBIOS 1*/ |
78 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface); | 75 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface); |
79 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | 76 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); |
80 | 77 |
81 #ifdef HAVE_OPENGL | 78 #ifdef HAVE_OPENGL |
82 /* OpenGL functions */ | 79 /* OpenGL functions */ |
83 static int XBIOS_GL_LoadLibrary(_THIS, const char *path); | |
84 static void *XBIOS_GL_GetProcAddress(_THIS, const char *proc); | |
85 static int XBIOS_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value); | |
86 static int XBIOS_GL_MakeCurrent(_THIS); | |
87 static void XBIOS_GL_SwapBuffers(_THIS); | 80 static void XBIOS_GL_SwapBuffers(_THIS); |
88 #endif | 81 #endif |
89 | 82 |
90 /* List of video modes */ | 83 /* List of video modes */ |
91 | 84 |
194 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | 187 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); |
195 if ( device ) { | 188 if ( device ) { |
196 memset(device, 0, (sizeof *device)); | 189 memset(device, 0, (sizeof *device)); |
197 device->hidden = (struct SDL_PrivateVideoData *) | 190 device->hidden = (struct SDL_PrivateVideoData *) |
198 malloc((sizeof *device->hidden)); | 191 malloc((sizeof *device->hidden)); |
192 device->gl_data = (struct SDL_PrivateGLData *) | |
193 malloc((sizeof *device->gl_data)); | |
199 } | 194 } |
200 if ( (device == NULL) || (device->hidden == NULL) ) { | 195 if ( (device == NULL) || (device->hidden == NULL) ) { |
201 SDL_OutOfMemory(); | 196 SDL_OutOfMemory(); |
202 if ( device ) { | 197 if ( device ) { |
203 free(device); | 198 free(device); |
204 } | 199 } |
205 return(0); | 200 return(0); |
206 } | 201 } |
207 memset(device->hidden, 0, (sizeof *device->hidden)); | 202 memset(device->hidden, 0, (sizeof *device->hidden)); |
203 memset(device->gl_data, 0, sizeof(*device->gl_data)); | |
208 | 204 |
209 /* Video functions */ | 205 /* Video functions */ |
210 device->VideoInit = XBIOS_VideoInit; | 206 device->VideoInit = XBIOS_VideoInit; |
211 device->ListModes = XBIOS_ListModes; | 207 device->ListModes = XBIOS_ListModes; |
212 device->SetVideoMode = XBIOS_SetVideoMode; | 208 device->SetVideoMode = XBIOS_SetVideoMode; |
219 device->FlipHWSurface = XBIOS_FlipHWSurface; | 215 device->FlipHWSurface = XBIOS_FlipHWSurface; |
220 device->FreeHWSurface = XBIOS_FreeHWSurface; | 216 device->FreeHWSurface = XBIOS_FreeHWSurface; |
221 | 217 |
222 #ifdef HAVE_OPENGL | 218 #ifdef HAVE_OPENGL |
223 /* OpenGL functions */ | 219 /* OpenGL functions */ |
224 device->GL_LoadLibrary = XBIOS_GL_LoadLibrary; | 220 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary; |
225 device->GL_GetProcAddress = XBIOS_GL_GetProcAddress; | 221 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress; |
226 device->GL_GetAttribute = XBIOS_GL_GetAttribute; | 222 device->GL_GetAttribute = SDL_AtariGL_GetAttribute; |
227 device->GL_MakeCurrent = XBIOS_GL_MakeCurrent; | 223 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent; |
228 device->GL_SwapBuffers = XBIOS_GL_SwapBuffers; | 224 device->GL_SwapBuffers = XBIOS_GL_SwapBuffers; |
229 #endif | 225 #endif |
230 | 226 |
231 /* Events */ | 227 /* Events */ |
232 device->InitOSKeymap = Atari_InitOSKeymap; | 228 device->InitOSKeymap = Atari_InitOSKeymap; |
413 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM); | 409 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM); |
414 | 410 |
415 /* Init chunky to planar routine */ | 411 /* Init chunky to planar routine */ |
416 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; | 412 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; |
417 | 413 |
418 #ifdef HAVE_OPENGL | |
419 this->gl_config.driver_loaded = 1; | |
420 #endif | |
421 | |
422 /* We're done! */ | 414 /* We're done! */ |
423 return(0); | 415 return(0); |
424 } | 416 } |
425 | 417 |
426 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | 418 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) |
437 static void XBIOS_FreeBuffers(_THIS) | 429 static void XBIOS_FreeBuffers(_THIS) |
438 { | 430 { |
439 int i; | 431 int i; |
440 | 432 |
441 #ifdef HAVE_OPENGL | 433 #ifdef HAVE_OPENGL |
442 /* Shutdown OpenGL context */ | 434 SDL_AtariGL_Quit(this); |
443 if (XBIOS_ctx) { | |
444 OSMesaDestroyContext(XBIOS_ctx); | |
445 XBIOS_ctx = NULL; | |
446 } | |
447 #endif | 435 #endif |
448 | 436 |
449 for (i=0;i<2;i++) { | 437 for (i=0;i<2;i++) { |
450 if (XBIOS_screensmem[i]!=NULL) { | 438 if (XBIOS_screensmem[i]!=NULL) { |
451 Mfree(XBIOS_screensmem[i]); | 439 Mfree(XBIOS_screensmem[i]); |
581 | 569 |
582 XBIOS_fbnum = 0; | 570 XBIOS_fbnum = 0; |
583 | 571 |
584 #ifdef HAVE_OPENGL | 572 #ifdef HAVE_OPENGL |
585 if (flags & SDL_OPENGL) { | 573 if (flags & SDL_OPENGL) { |
586 GLenum format; | 574 if (!SDL_AtariGL_Init(this, current)) { |
587 | |
588 /* Init OpenGL context using OSMesa */ | |
589 if (new_depth == 8) { | |
590 format = OSMESA_COLOR_INDEX; | |
591 } else { | |
592 format = OSMESA_RGB_565; | |
593 } | |
594 | |
595 XBIOS_ctx = OSMesaCreateContextExt( format, this->gl_config.depth_size, | |
596 this->gl_config.stencil_size, this->gl_config.accum_red_size + | |
597 this->gl_config.accum_green_size + this->gl_config.accum_blue_size + | |
598 this->gl_config.accum_alpha_size, NULL ); | |
599 if (!XBIOS_ctx) { | |
600 XBIOS_FreeBuffers(this); | 575 XBIOS_FreeBuffers(this); |
601 SDL_SetError("OSMesaCreateContext failed"); | 576 SDL_SetError("Can not create OpenGL context"); |
602 return(NULL); | 577 return NULL; |
603 } | 578 } |
604 | 579 |
605 modeflags |= SDL_OPENGL; | 580 modeflags |= SDL_OPENGL; |
606 } | 581 } |
607 #endif | 582 #endif |
897 this->screen->pixels = NULL; | 872 this->screen->pixels = NULL; |
898 } | 873 } |
899 | 874 |
900 #ifdef HAVE_OPENGL | 875 #ifdef HAVE_OPENGL |
901 | 876 |
902 /* OpenGL functions */ | |
903 static int XBIOS_GL_LoadLibrary(_THIS, const char *path) | |
904 { | |
905 /* Library is always opened */ | |
906 this->gl_config.driver_loaded = 1; | |
907 | |
908 return 0; | |
909 } | |
910 | |
911 static void *XBIOS_GL_GetProcAddress(_THIS, const char *proc) | |
912 { | |
913 void *func = NULL; | |
914 | |
915 if (XBIOS_ctx != NULL) { | |
916 func = OSMesaGetProcAddress(proc); | |
917 } | |
918 | |
919 return func; | |
920 } | |
921 | |
922 static int XBIOS_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | |
923 { | |
924 GLenum mesa_attrib; | |
925 SDL_Surface *surface; | |
926 | |
927 if (XBIOS_ctx == NULL) { | |
928 return -1; | |
929 } | |
930 | |
931 switch(attrib) { | |
932 case SDL_GL_RED_SIZE: | |
933 mesa_attrib = GL_RED_BITS; | |
934 break; | |
935 case SDL_GL_GREEN_SIZE: | |
936 mesa_attrib = GL_GREEN_BITS; | |
937 break; | |
938 case SDL_GL_BLUE_SIZE: | |
939 mesa_attrib = GL_BLUE_BITS; | |
940 break; | |
941 case SDL_GL_ALPHA_SIZE: | |
942 mesa_attrib = GL_ALPHA_BITS; | |
943 break; | |
944 case SDL_GL_DOUBLEBUFFER: | |
945 surface = this->screen; | |
946 *value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF); | |
947 return 0; | |
948 case SDL_GL_DEPTH_SIZE: | |
949 mesa_attrib = GL_DEPTH_BITS; | |
950 break; | |
951 case SDL_GL_STENCIL_SIZE: | |
952 mesa_attrib = GL_STENCIL_BITS; | |
953 break; | |
954 case SDL_GL_ACCUM_RED_SIZE: | |
955 mesa_attrib = GL_ACCUM_RED_BITS; | |
956 break; | |
957 case SDL_GL_ACCUM_GREEN_SIZE: | |
958 mesa_attrib = GL_ACCUM_GREEN_BITS; | |
959 break; | |
960 case SDL_GL_ACCUM_BLUE_SIZE: | |
961 mesa_attrib = GL_ACCUM_BLUE_BITS; | |
962 break; | |
963 case SDL_GL_ACCUM_ALPHA_SIZE: | |
964 mesa_attrib = GL_ACCUM_ALPHA_BITS; | |
965 break; | |
966 default : | |
967 return -1; | |
968 } | |
969 | |
970 glGetIntegerv(mesa_attrib, value); | |
971 return 0; | |
972 } | |
973 | |
974 static int XBIOS_GL_MakeCurrent(_THIS) | |
975 { | |
976 SDL_Surface *surface; | |
977 GLenum type; | |
978 | |
979 if (XBIOS_ctx == NULL) { | |
980 return -1; | |
981 } | |
982 | |
983 surface = this->screen; | |
984 if ((surface->format->BitsPerPixel) == 8) { | |
985 type = GL_UNSIGNED_BYTE; | |
986 } else { | |
987 type = GL_UNSIGNED_SHORT_5_6_5; | |
988 } | |
989 | |
990 if (!OSMesaMakeCurrent(XBIOS_ctx, surface->pixels, type, surface->w, surface->h)) { | |
991 SDL_SetError("Can not make OpenGL context current"); | |
992 return -1; | |
993 } | |
994 | |
995 /* OSMesa draws upside down */ | |
996 OSMesaPixelStore(OSMESA_Y_UP, 0); | |
997 | |
998 return 0; | |
999 } | |
1000 | |
1001 static void XBIOS_GL_SwapBuffers(_THIS) | 877 static void XBIOS_GL_SwapBuffers(_THIS) |
1002 { | 878 { |
1003 if (XBIOS_ctx == NULL) { | 879 if (gl_ctx == NULL) { |
1004 return; | 880 return; |
1005 } | 881 } |
1006 | 882 |
1007 XBIOS_FlipHWSurface(this, this->screen); | 883 XBIOS_FlipHWSurface(this, this->screen); |
1008 XBIOS_GL_MakeCurrent(this); | 884 SDL_AtariGL_MakeCurrent(this); |
1009 } | 885 } |
1010 | 886 |
1011 #endif | 887 #endif |