comparison src/video/gem/SDL_gemvideo.c @ 984:44fd54a0ae5f

Add OSMesa OpenGL support to the Atari GEM video driver
author Patrice Mandin <patmandin@gmail.com>
date Sun, 21 Nov 2004 21:59:47 +0000
parents d9209754ebee
children 952ec1ddcb58
comparison
equal deleted inserted replaced
983:7f08bd66f1ca 984:44fd54a0ae5f
34 */ 34 */
35 35
36 #include <stdio.h> 36 #include <stdio.h>
37 #include <stdlib.h> 37 #include <stdlib.h>
38 #include <string.h> 38 #include <string.h>
39
40 #ifdef HAVE_OPENGL
41 #include <GL/osmesa.h>
42 #endif
39 43
40 /* Mint includes */ 44 /* Mint includes */
41 #include <gem.h> 45 #include <gem.h>
42 #include <gemx.h> 46 #include <gemx.h>
43 #include <mint/osbind.h> 47 #include <mint/osbind.h>
61 #include "SDL_gemwm_c.h" 65 #include "SDL_gemwm_c.h"
62 #include "SDL_xbiosevents_c.h" 66 #include "SDL_xbiosevents_c.h"
63 67
64 /* Defines */ 68 /* Defines */
65 69
66 /* #define DEBUG_VIDEO_GEM 1 */ 70 /*#define DEBUG_VIDEO_GEM 1*/
67 71
68 #define GEM_VID_DRIVER_NAME "gem" 72 #define GEM_VID_DRIVER_NAME "gem"
69 73
70 #undef MIN 74 #undef MIN
71 #define MIN(a,b) (((a)<(b)) ? (a) : (b)) 75 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
104 static void GEM_ClearScreen(_THIS); 108 static void GEM_ClearScreen(_THIS);
105 static void GEM_ClearRect(_THIS, short *rect); 109 static void GEM_ClearRect(_THIS, short *rect);
106 static void GEM_LockScreen(_THIS); 110 static void GEM_LockScreen(_THIS);
107 static void GEM_UnlockScreen(_THIS); 111 static void GEM_UnlockScreen(_THIS);
108 static void refresh_window(_THIS, int winhandle, short *rect); 112 static void refresh_window(_THIS, int winhandle, short *rect);
113
114 #ifdef HAVE_OPENGL
115 /* OpenGL functions */
116 static int GEM_GL_LoadLibrary(_THIS, const char *path);
117 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_MakeCurrent(_THIS);
120 static void GEM_GL_SwapBuffers(_THIS);
121 #endif
109 122
110 /* GEM driver bootstrap functions */ 123 /* GEM driver bootstrap functions */
111 124
112 static int GEM_Available(void) 125 static int GEM_Available(void)
113 { 126 {
173 device->FreeWMCursor = GEM_FreeWMCursor; 186 device->FreeWMCursor = GEM_FreeWMCursor;
174 device->CreateWMCursor = GEM_CreateWMCursor; 187 device->CreateWMCursor = GEM_CreateWMCursor;
175 device->ShowWMCursor = GEM_ShowWMCursor; 188 device->ShowWMCursor = GEM_ShowWMCursor;
176 device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/; 189 device->WarpWMCursor = NULL /*GEM_WarpWMCursor*/;
177 device->CheckMouseMode = GEM_CheckMouseMode; 190 device->CheckMouseMode = GEM_CheckMouseMode;
191
192 #ifdef HAVE_OPENGL
193 /* OpenGL functions */
194 device->GL_LoadLibrary = GEM_GL_LoadLibrary;
195 device->GL_GetProcAddress = GEM_GL_GetProcAddress;
196 device->GL_GetAttribute = GEM_GL_GetAttribute;
197 device->GL_MakeCurrent = GEM_GL_MakeCurrent;
198 device->GL_SwapBuffers = GEM_GL_SwapBuffers;
199 #endif
178 200
179 /* Joystick + Mouse relative motion */ 201 /* Joystick + Mouse relative motion */
180 SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS); 202 SDL_AtariXbios_InstallVectors(ATARI_XBIOS_MOUSEEVENTS|ATARI_XBIOS_JOYSTICKEVENTS);
181 203
182 device->free = GEM_DeleteDevice; 204 device->free = GEM_DeleteDevice;
450 472
451 #ifdef DEBUG_VIDEO_GEM 473 #ifdef DEBUG_VIDEO_GEM
452 printf("sdl:video:gem: VideoInit(): done\n"); 474 printf("sdl:video:gem: VideoInit(): done\n");
453 #endif 475 #endif
454 476
477 #ifdef HAVE_OPENGL
478 this->gl_config.driver_loaded = 1;
479 #endif
480
455 /* We're done! */ 481 /* We're done! */
456 return(0); 482 return(0);
457 } 483 }
458 484
459 SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 485 SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
469 return((SDL_Rect **)-1); 495 return((SDL_Rect **)-1);
470 } 496 }
471 497
472 static void GEM_FreeBuffers(_THIS) 498 static void GEM_FreeBuffers(_THIS)
473 { 499 {
500 #ifdef HAVE_OPENGL
501 /* Shutdown OpenGL context */
502 if (GEM_ctx) {
503 OSMesaDestroyContext(GEM_ctx);
504 GEM_ctx = NULL;
505 }
506 #endif
507
474 /* Release buffer */ 508 /* Release buffer */
475 if ( GEM_buffer2 ) { 509 if ( GEM_buffer2 ) {
476 free( GEM_buffer2 ); 510 free( GEM_buffer2 );
477 GEM_buffer2=NULL; 511 GEM_buffer2=NULL;
478 } 512 }
701 735
702 GEM_fullscreen = SDL_FALSE; 736 GEM_fullscreen = SDL_FALSE;
703 } 737 }
704 738
705 /* Set up the new mode framebuffer */ 739 /* Set up the new mode framebuffer */
706 current->flags = modeflags;
707 current->w = width; 740 current->w = width;
708 current->h = height; 741 current->h = height;
709 if (use_shadow1) { 742 if (use_shadow1) {
710 current->pixels = GEM_buffer1; 743 current->pixels = GEM_buffer1;
711 current->pitch = width * VDI_pixelsize; 744 current->pitch = width * VDI_pixelsize;
713 current->pixels = VDI_screen; 746 current->pixels = VDI_screen;
714 current->pixels += VDI_pitch * ((VDI_h - height) >> 1); 747 current->pixels += VDI_pitch * ((VDI_h - height) >> 1);
715 current->pixels += VDI_pixelsize * ((VDI_w - width) >> 1); 748 current->pixels += VDI_pixelsize * ((VDI_w - width) >> 1);
716 current->pitch = VDI_pitch; 749 current->pitch = VDI_pitch;
717 } 750 }
751
752 #ifdef HAVE_OPENGL
753 if (flags & SDL_OPENGL) {
754 GLenum format = OSMESA_COLOR_INDEX;
755
756 /* Init OpenGL context using OSMesa */
757 switch (VDI_bpp) {
758 case 15:
759 /* 1555, big and little endian unsupported */
760 format = OSMESA_RGB_565;
761 break;
762 case 16:
763 format = OSMESA_RGB_565;
764 /* 565, little endian unsupported */
765 break;
766 case 24:
767 if (VDI_redmask == 255<<16) {
768 format = OSMESA_RGB;
769 } else {
770 format = OSMESA_BGR;
771 }
772 break;
773 case 32:
774 if (VDI_redmask == 255<<16) {
775 format = OSMESA_ARGB;
776 } else if (VDI_redmask == 255<<8) {
777 format = OSMESA_BGRA;
778 } else if (VDI_redmask == 255<<24) {
779 format = OSMESA_RGBA;
780 } else {
781 /* ABGR format unsupported */
782 format = OSMESA_BGRA;
783 }
784 break;
785 }
786
787 GEM_ctx = OSMesaCreateContextExt( format, this->gl_config.depth_size,
788 this->gl_config.stencil_size, this->gl_config.accum_red_size +
789 this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
790 this->gl_config.accum_alpha_size, NULL );
791 if (!GEM_ctx) {
792 GEM_FreeBuffers(this);
793 SDL_SetError("OSMesaCreateContext failed");
794 return(NULL);
795 }
796
797 modeflags |= SDL_OPENGL;
798 }
799 #endif
800
801 current->flags = modeflags;
718 802
719 #ifdef DEBUG_VIDEO_GEM 803 #ifdef DEBUG_VIDEO_GEM
720 printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h); 804 printf("sdl:video:gem: surface: %dx%d\n", current->w, current->h);
721 #endif 805 #endif
722 806
1246 ); 1330 );
1247 #endif 1331 #endif
1248 1332
1249 vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb); 1333 vro_cpyfm( VDI_handle, S_ONLY, pxy, &mfdb_src, &VDI_dst_mfdb);
1250 } 1334 }
1335
1336 #ifdef HAVE_OPENGL
1337
1338 static int GEM_GL_LoadLibrary(_THIS, const char *path)
1339 {
1340 /* Library is always opened */
1341 this->gl_config.driver_loaded = 1;
1342
1343 return 0;
1344 }
1345
1346 static void *GEM_GL_GetProcAddress(_THIS, const char *proc)
1347 {
1348 void *func = NULL;
1349
1350 if (GEM_ctx != NULL) {
1351 func = OSMesaGetProcAddress(proc);
1352 }
1353
1354 return func;
1355 }
1356
1357 static int GEM_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
1358 {
1359 GLenum mesa_attrib;
1360
1361 if (GEM_ctx == NULL) {
1362 return -1;
1363 }
1364
1365 switch(attrib) {
1366 case SDL_GL_RED_SIZE:
1367 mesa_attrib = GL_RED_BITS;
1368 break;
1369 case SDL_GL_GREEN_SIZE:
1370 mesa_attrib = GL_GREEN_BITS;
1371 break;
1372 case SDL_GL_BLUE_SIZE:
1373 mesa_attrib = GL_BLUE_BITS;
1374 break;
1375 case SDL_GL_ALPHA_SIZE:
1376 mesa_attrib = GL_ALPHA_BITS;
1377 break;
1378 case SDL_GL_DOUBLEBUFFER:
1379 mesa_attrib = GL_DOUBLEBUFFER;
1380 break;
1381 case SDL_GL_DEPTH_SIZE:
1382 mesa_attrib = GL_DEPTH_BITS;
1383 break;
1384 case SDL_GL_STENCIL_SIZE:
1385 mesa_attrib = GL_STENCIL_BITS;
1386 break;
1387 case SDL_GL_ACCUM_RED_SIZE:
1388 mesa_attrib = GL_ACCUM_RED_BITS;
1389 break;
1390 case SDL_GL_ACCUM_GREEN_SIZE:
1391 mesa_attrib = GL_ACCUM_GREEN_BITS;
1392 break;
1393 case SDL_GL_ACCUM_BLUE_SIZE:
1394 mesa_attrib = GL_ACCUM_BLUE_BITS;
1395 break;
1396 case SDL_GL_ACCUM_ALPHA_SIZE:
1397 mesa_attrib = GL_ACCUM_ALPHA_BITS;
1398 break;
1399 default :
1400 return -1;
1401 }
1402
1403 glGetIntegerv(mesa_attrib, value);
1404 return 0;
1405 }
1406
1407 static int GEM_GL_MakeCurrent(_THIS)
1408 {
1409 SDL_Surface *surface;
1410 GLenum type;
1411
1412 if (GEM_ctx == NULL) {
1413 return -1;
1414 }
1415
1416 surface = this->screen;
1417
1418 if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
1419 type = GL_UNSIGNED_SHORT_5_6_5;
1420 } else {
1421 type = GL_UNSIGNED_BYTE;
1422 }
1423
1424 if (!OSMesaMakeCurrent(GEM_ctx, surface->pixels, type, surface->w, surface->h)) {
1425 SDL_SetError("Can not make OpenGL context current");
1426 return -1;
1427 }
1428
1429 /* OSMesa draws upside down */
1430 OSMesaPixelStore(OSMESA_Y_UP, 0);
1431
1432 return 0;
1433 }
1434
1435 static void GEM_GL_SwapBuffers(_THIS)
1436 {
1437 GEM_FlipHWSurface(this, this->screen);
1438 }
1439
1440 #endif