Commit e9c344a4 authored by Patrice Mandin's avatar Patrice Mandin

Add support for OpenGL on Atari using OSMesa, the offscreen rendering driver from Mesa

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40979
parent 74f38010
...@@ -53,13 +53,14 @@ Audio (Hardware, XBIOS, GSXB, MCSN, STFA, /dev/audio if threads enabled) ...@@ -53,13 +53,14 @@ Audio (Hardware, XBIOS, GSXB, MCSN, STFA, /dev/audio if threads enabled)
Threads (Multitasking OS only via GNU pth library) Threads (Multitasking OS only via GNU pth library)
Shared object loader (using LDG library from http://ldg.atari.org/) Shared object loader (using LDG library from http://ldg.atari.org/)
Audio CD (MetaDOS) Audio CD (MetaDOS)
OpenGL (using Mesa offscreen rendering driver)
- Driver combinations: - Driver combinations:
Video Kbd Mouse Timer Joysticks Joypads Video Kbd Mouse Timer Joysticks Joypads OpenGL
xbios ikbd ikbd vbl(2) ikbd hardware xbios ikbd ikbd vbl(2) ikbd hardware OSMesa
xbios gemdos xbios vbl(2) xbios hardware xbios gemdos xbios vbl(2) xbios hardware OSMesa
xbios bios xbios vbl(2) xbios hardware xbios bios xbios vbl(2) xbios hardware OSMesa
gem gem gem(1) vbl(2) xbios hardware gem gem gem(1) vbl(2) xbios hardware no
(1) GEM does not report relative mouse motion, so xbios mouse driver is used (1) GEM does not report relative mouse motion, so xbios mouse driver is used
to report this type event. to report this type event.
......
...@@ -1129,6 +1129,19 @@ CheckMacGL() ...@@ -1129,6 +1129,19 @@ CheckMacGL()
fi fi
} }
dnl Check for Mesa offscreen rendering
CheckOSMesa()
{
if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then
AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes)
AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm)
if test x$have_osmesa_hdr = xyes -a x$have_osmesa_lib = xyes; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
SYSTEM_LIBS="$SYSTEM_LIBS -lOSMesa"
fi
fi
}
dnl See if we can use the new unified event interface in Linux 2.4 dnl See if we can use the new unified event interface in Linux 2.4
CheckInputEvents() CheckInputEvents()
{ {
...@@ -2572,6 +2585,7 @@ case "$target" in ...@@ -2572,6 +2585,7 @@ case "$target" in
CheckAtariAudio CheckAtariAudio
CheckAtariLdg CheckAtariLdg
CheckPTH CheckPTH
CheckOSMesa
# Set up files for the audio library # Set up files for the audio library
if test x$enable_threads = xyes -a x$enable_pth = xyes; then if test x$enable_threads = xyes -a x$enable_pth = xyes; then
if test x$enable_audio = xyes; then if test x$enable_audio = xyes; then
......
...@@ -37,6 +37,10 @@ static char rcsid = ...@@ -37,6 +37,10 @@ static char rcsid =
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
/* Mint includes */ /* Mint includes */
#include <mint/cookie.h> #include <mint/cookie.h>
#include <mint/osbind.h> #include <mint/osbind.h>
...@@ -74,6 +78,15 @@ static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface); ...@@ -74,6 +78,15 @@ static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface); static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
#ifdef HAVE_OPENGL
/* OpenGL functions */
static int XBIOS_GL_LoadLibrary(_THIS, const char *path);
static void *XBIOS_GL_GetProcAddress(_THIS, const char *proc);
static int XBIOS_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
static int XBIOS_GL_MakeCurrent(_THIS);
static void XBIOS_GL_SwapBuffers(_THIS);
#endif
/* List of video modes */ /* List of video modes */
/* ST modes */ /* ST modes */
...@@ -93,21 +106,21 @@ static xbiosmode_t xbiosmodelist_tt[]={ ...@@ -93,21 +106,21 @@ static xbiosmode_t xbiosmodelist_tt[]={
static int xbiosnummodes_f30rvb=16; static int xbiosnummodes_f30rvb=16;
static xbiosmode_t xbiosmodelist_f30rvb[]={ static xbiosmode_t xbiosmodelist_f30rvb[]={
{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE}, {BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE},
{BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
{BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
{BPS16|COL80,640,200,16,SDL_FALSE},
{BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE}, {BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE},
{BPS16|OVERSCAN,384,240,16,SDL_FALSE}, {BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE},
{BPS16|VERTFLAG,320,400,16,SDL_FALSE}, {BPS16|VERTFLAG,320,400,16,SDL_FALSE},
{BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE},
{BPS16|OVERSCAN,384,240,16,SDL_FALSE},
{BPS16|COL80,640,200,16,SDL_FALSE},
{BPS16,320,200,16,SDL_FALSE}, {BPS16,320,200,16,SDL_FALSE},
{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE}, {BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE},
{BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
{BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
{BPS8|COL80,640,200,8,SDL_FALSE},
{BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE}, {BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE},
{BPS8|OVERSCAN,384,240,8,SDL_FALSE}, {BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE},
{BPS8|VERTFLAG,320,400,8,SDL_FALSE}, {BPS8|VERTFLAG,320,400,8,SDL_FALSE},
{BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE},
{BPS8|OVERSCAN,384,240,8,SDL_FALSE},
{BPS8|COL80,640,200,8,SDL_FALSE},
{BPS8,320,200,8,SDL_FALSE} {BPS8,320,200,8,SDL_FALSE}
}; };
...@@ -118,8 +131,8 @@ static xbiosmode_t xbiosmodelist_f30vga[]={ ...@@ -118,8 +131,8 @@ static xbiosmode_t xbiosmodelist_f30vga[]={
{BPS16|VERTFLAG,320,240,16,SDL_FALSE}, {BPS16|VERTFLAG,320,240,16,SDL_FALSE},
{BPS8|COL80,640,480,8,SDL_FALSE}, {BPS8|COL80,640,480,8,SDL_FALSE},
{BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
{BPS8,320,480,8,SDL_FALSE}, {BPS8,320,480,8,SDL_FALSE},
{BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE},
{BPS8|VERTFLAG,320,240,8,SDL_FALSE} {BPS8|VERTFLAG,320,240,8,SDL_FALSE}
}; };
...@@ -206,6 +219,15 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) ...@@ -206,6 +219,15 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
device->FlipHWSurface = XBIOS_FlipHWSurface; device->FlipHWSurface = XBIOS_FlipHWSurface;
device->FreeHWSurface = XBIOS_FreeHWSurface; device->FreeHWSurface = XBIOS_FreeHWSurface;
#ifdef HAVE_OPENGL
/* OpenGL functions */
device->GL_LoadLibrary = XBIOS_GL_LoadLibrary;
device->GL_GetProcAddress = XBIOS_GL_GetProcAddress;
device->GL_GetAttribute = XBIOS_GL_GetAttribute;
device->GL_MakeCurrent = XBIOS_GL_MakeCurrent;
device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
#endif
/* Events */ /* Events */
device->InitOSKeymap = Atari_InitOSKeymap; device->InitOSKeymap = Atari_InitOSKeymap;
device->PumpEvents = Atari_PumpEvents; device->PumpEvents = Atari_PumpEvents;
...@@ -393,6 +415,10 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -393,6 +415,10 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* Init chunky to planar routine */ /* Init chunky to planar routine */
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
#ifdef HAVE_OPENGL
this->gl_config.driver_loaded = 1;
#endif
/* We're done! */ /* We're done! */
return(0); return(0);
} }
...@@ -412,6 +438,14 @@ static void XBIOS_FreeBuffers(_THIS) ...@@ -412,6 +438,14 @@ static void XBIOS_FreeBuffers(_THIS)
{ {
int i; int i;
#ifdef HAVE_OPENGL
/* Shutdown OpenGL context */
if (XBIOS_ctx) {
OSMesaDestroyContext(XBIOS_ctx);
XBIOS_ctx = NULL;
}
#endif
for (i=0;i<2;i++) { for (i=0;i<2;i++) {
if (XBIOS_screensmem[i]!=NULL) { if (XBIOS_screensmem[i]!=NULL) {
Mfree(XBIOS_screensmem[i]); Mfree(XBIOS_screensmem[i]);
...@@ -503,6 +537,14 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -503,6 +537,14 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL); XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL);
#ifdef HAVE_OPENGL
if (flags & SDL_OPENGL) {
if (this->gl_config.double_buffer) {
flags |= SDL_DOUBLEBUF;
}
}
#endif
/* Double buffer ? */ /* Double buffer ? */
if (flags & SDL_DOUBLEBUF) { if (flags & SDL_DOUBLEBUF) {
XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM); XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM);
...@@ -525,7 +567,6 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -525,7 +567,6 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
return(NULL); return(NULL);
} }
current->flags = modeflags;
current->w = XBIOS_width = width; current->w = XBIOS_width = width;
current->h = XBIOS_height = height; current->h = XBIOS_height = height;
current->pitch = (width * new_depth)>>3; current->pitch = (width * new_depth)>>3;
...@@ -540,6 +581,33 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -540,6 +581,33 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
XBIOS_fbnum = 0; XBIOS_fbnum = 0;
#ifdef HAVE_OPENGL
if (flags & SDL_OPENGL) {
GLenum format;
/* Init OpenGL context using OSMesa */
if (new_depth == 8) {
format = OSMESA_COLOR_INDEX;
} else {
format = OSMESA_RGB_565;
}
XBIOS_ctx = OSMesaCreateContextExt( format, this->gl_config.depth_size,
this->gl_config.stencil_size, this->gl_config.accum_red_size +
this->gl_config.accum_green_size + this->gl_config.accum_blue_size +
this->gl_config.accum_alpha_size, NULL );
if (!XBIOS_ctx) {
XBIOS_FreeBuffers(this);
SDL_SetError("OSMesaCreateContext failed");
return(NULL);
}
modeflags |= SDL_OPENGL;
}
#endif
current->flags = modeflags;
/* Now set the video mode */ /* Now set the video mode */
#ifndef DEBUG_VIDEO_XBIOS #ifndef DEBUG_VIDEO_XBIOS
Setscreen(-1,XBIOS_screens[0],-1); Setscreen(-1,XBIOS_screens[0],-1);
...@@ -698,13 +766,6 @@ static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface) ...@@ -698,13 +766,6 @@ static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
destscr += destx; destscr += destx;
/* Convert chunky to planar screen */ /* Convert chunky to planar screen */
#ifdef DEBUG_VIDEO_XBIOS
printf("C2p:\n");
printf(" Source: Adr=0x%08x, Pitch=%d\n", surface->pixels, surface->pitch);
printf(" Dest: Adr=0x%08x, Pitch=%d\n", destscr, XBIOS_pitch);
printf(" Size: %dx%d, dblline=%d\n", surface->w, surface->h, XBIOS_doubleline);
fflush(stdout);
#endif
SDL_Atari_C2pConvert( SDL_Atari_C2pConvert(
surface->pixels, surface->pixels,
destscr, destscr,
...@@ -835,3 +896,113 @@ static void XBIOS_VideoQuit(_THIS) ...@@ -835,3 +896,113 @@ static void XBIOS_VideoQuit(_THIS)
this->screen->pixels = NULL; this->screen->pixels = NULL;
} }
#ifdef HAVE_OPENGL
/* OpenGL functions */
static int XBIOS_GL_LoadLibrary(_THIS, const char *path)
{
/* Library is always opened */
this->gl_config.driver_loaded = 1;
return 0;
}
static void *XBIOS_GL_GetProcAddress(_THIS, const char *proc)
{
void *func = NULL;
if (XBIOS_ctx != NULL) {
func = OSMesaGetProcAddress(proc);
}
return func;
}
static int XBIOS_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
{
GLenum mesa_attrib;
SDL_Surface *surface;
if (XBIOS_ctx == NULL) {
return -1;
}
switch(attrib) {
case SDL_GL_RED_SIZE:
mesa_attrib = GL_RED_BITS;
break;
case SDL_GL_GREEN_SIZE:
mesa_attrib = GL_GREEN_BITS;
break;
case SDL_GL_BLUE_SIZE:
mesa_attrib = GL_BLUE_BITS;
break;
case SDL_GL_ALPHA_SIZE:
mesa_attrib = GL_ALPHA_BITS;
break;
case SDL_GL_DOUBLEBUFFER:
surface = this->screen;
*value = ((surface->flags & SDL_DOUBLEBUF)==SDL_DOUBLEBUF);
return 0;
case SDL_GL_DEPTH_SIZE:
mesa_attrib = GL_DEPTH_BITS;
break;
case SDL_GL_STENCIL_SIZE:
mesa_attrib = GL_STENCIL_BITS;
break;
case SDL_GL_ACCUM_RED_SIZE:
mesa_attrib = GL_ACCUM_RED_BITS;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
mesa_attrib = GL_ACCUM_GREEN_BITS;
break;
case SDL_GL_ACCUM_BLUE_SIZE:
mesa_attrib = GL_ACCUM_BLUE_BITS;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
mesa_attrib = GL_ACCUM_ALPHA_BITS;
break;
default :
return -1;
}
glGetIntegerv(mesa_attrib, value);
return 0;
}
static int XBIOS_GL_MakeCurrent(_THIS)
{
SDL_Surface *surface;
GLenum type;
if (XBIOS_ctx == NULL) {
return -1;
}
surface = this->screen;
if ((surface->format->BitsPerPixel) == 8) {
type = GL_UNSIGNED_BYTE;
} else {
type = GL_UNSIGNED_SHORT_5_6_5;
}
if (!OSMesaMakeCurrent(XBIOS_ctx, surface->pixels, type, surface->w, surface->h)) {
SDL_SetError("Can not make OpenGL context current");
return -1;
}
return 0;
}
static void XBIOS_GL_SwapBuffers(_THIS)
{
if (XBIOS_ctx == NULL) {
return;
}
XBIOS_FlipHWSurface(this, this->screen);
XBIOS_GL_MakeCurrent(this);
}
#endif
...@@ -28,6 +28,10 @@ static char rcsid = ...@@ -28,6 +28,10 @@ static char rcsid =
#ifndef _SDL_xbios_h #ifndef _SDL_xbios_h
#define _SDL_xbios_h #define _SDL_xbios_h
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
#include "SDL_types.h" #include "SDL_types.h"
#include "SDL_sysvideo.h" #include "SDL_sysvideo.h"
...@@ -69,6 +73,9 @@ struct SDL_PrivateVideoData { ...@@ -69,6 +73,9 @@ struct SDL_PrivateVideoData {
int frame_number; /* Number of frame for double buffer */ int frame_number; /* Number of frame for double buffer */
int pitch; /* Destination line width for C2P */ int pitch; /* Destination line width for C2P */
int width, height; /* Screen size for centered C2P */ int width, height; /* Screen size for centered C2P */
#ifdef HAVE_OPENGL
OSMesaContext ctx; /* OpenGL OSMesa context */
#endif
SDL_Rect *SDL_modelist[NUM_MODELISTS][SDL_NUMMODES+1]; SDL_Rect *SDL_modelist[NUM_MODELISTS][SDL_NUMMODES+1];
xbiosmode_t *videomodes[NUM_MODELISTS][SDL_NUMMODES+1]; xbiosmode_t *videomodes[NUM_MODELISTS][SDL_NUMMODES+1];
...@@ -123,5 +130,8 @@ enum { ...@@ -123,5 +130,8 @@ enum {
#define XBIOS_pitch (this->hidden->pitch) #define XBIOS_pitch (this->hidden->pitch)
#define XBIOS_width (this->hidden->width) #define XBIOS_width (this->hidden->width)
#define XBIOS_height (this->hidden->height) #define XBIOS_height (this->hidden->height)
#ifdef HAVE_OPENGL
#define XBIOS_ctx (this->hidden->ctx)
#endif
#endif /* _SDL_xbios_h */ #endif /* _SDL_xbios_h */
...@@ -5,8 +5,7 @@ dnl Setup for automake ...@@ -5,8 +5,7 @@ dnl Setup for automake
SDL_VERSION=1.2.7 SDL_VERSION=1.2.7
dnl Detect the canonical host and target build environment dnl Detect the canonical host and target build environment
AC_CANONICAL_HOST AC_CANONICAL_SYSTEM
AC_CANONICAL_TARGET
dnl Setup for automake dnl Setup for automake
AM_INIT_AUTOMAKE(SDL_tests, $SDL_VERSION) AM_INIT_AUTOMAKE(SDL_tests, $SDL_VERSION)
...@@ -36,9 +35,13 @@ case "$target" in ...@@ -36,9 +35,13 @@ case "$target" in
*-*-aix*) *-*-aix*)
if test x$ac_cv_prog_gcc = xyes; then if test x$ac_cv_prog_gcc = xyes; then
CFLAGS="-mthreads" CFLAGS="-mthreads"
fi fi
SYS_GL_LIBS="" SYS_GL_LIBS=""
;; ;;
*-*-mint*)
MATHLIB="-lm"
SYS_GL_LIBS="-lOSMesa"
;;
*) *)
MATHLIB="-lm" MATHLIB="-lm"
AC_PATH_X AC_PATH_X
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment