Commit 6927f1cb authored by Patrice Mandin's avatar Patrice Mandin

Factorize OSMesa OpenGL code for Atari drivers

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40990
parent 6eba7953
...@@ -1130,14 +1130,22 @@ CheckMacGL() ...@@ -1130,14 +1130,22 @@ CheckMacGL()
} }
dnl Check for Mesa offscreen rendering dnl Check for Mesa offscreen rendering
CheckOSMesa() CheckAtariOSMesa()
{ {
if test x$enable_video = xyes -a x$enable_video_opengl = xyes; then if test "x$enable_video" = "xyes" -a "x$enable_video_opengl" = "xyes"; then
AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes) AC_PATH_PROG(OSMESA_CONFIG, osmesa-config, no)
AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm) if test "x$OSMESA_CONFIG" = "xno" -o "x$enable_atari_ldg" = "xno"; then
if test x$have_osmesa_hdr = xyes -a x$have_osmesa_lib = xyes; then AC_CHECK_HEADER(GL/osmesa.h, have_osmesa_hdr=yes)
CFLAGS="$CFLAGS -DHAVE_OPENGL" AC_CHECK_LIB(OSMesa, OSMesaCreateContext, have_osmesa_lib=yes, have_osmesa_lib=no, -lm)
SYSTEM_LIBS="$SYSTEM_LIBS -lOSMesa" if test "x$have_osmesa_hdr" = "xyes" -a "x$have_osmesa_lib" = "xyes"; then
CFLAGS="$CFLAGS -DHAVE_OPENGL"
SYSTEM_LIBS="$SYSTEM_LIBS -lOSMesa"
fi
else
OSMESA_CFLAGS=`$OSMESA_CONFIG --cflags`
OSMESA_LIBS=`$OSMESA_CONFIG --libs`
CFLAGS="$CFLAGS -DHAVE_OPENGL $OSMESA_CFLAGS"
SYSTEM_LIBS="$SYSTEM_LIBS $OSMESA_LIBS"
fi fi
fi fi
} }
...@@ -2584,8 +2592,8 @@ case "$target" in ...@@ -2584,8 +2592,8 @@ case "$target" in
CheckAtariGemVideo CheckAtariGemVideo
CheckAtariAudio CheckAtariAudio
CheckAtariLdg CheckAtariLdg
CheckAtariOSMesa
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
......
...@@ -747,6 +747,8 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) ...@@ -747,6 +747,8 @@ SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
#define __SDL_NOGETPROCADDR__ #define __SDL_NOGETPROCADDR__
#elif defined(__QNXNTO__) && (_NTO_VERSION < 630) #elif defined(__QNXNTO__) && (_NTO_VERSION < 630)
#define __SDL_NOGETPROCADDR__ #define __SDL_NOGETPROCADDR__
#elif defined(__MINT__)
#define __SDL_NOGETPROCADDR__
#endif #endif
#ifdef __SDL_NOGETPROCADDR__ #ifdef __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) video->func=func; #define SDL_PROC(ret,func,params) video->func=func;
......
...@@ -12,6 +12,8 @@ ATARICOMMON_SRCS = \ ...@@ -12,6 +12,8 @@ ATARICOMMON_SRCS = \
SDL_atarieddi_s.h \ SDL_atarieddi_s.h \
SDL_atarievents.c \ SDL_atarievents.c \
SDL_atarievents_c.h \ SDL_atarievents_c.h \
SDL_atarigl.c \
SDL_atarigl_c.h \
SDL_atarikeys.h \ SDL_atarikeys.h \
SDL_atarimxalloc.c \ SDL_atarimxalloc.c \
SDL_atarimxalloc_c.h \ SDL_atarimxalloc_c.h \
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
/* Atari OSMesa.ldg implementation of SDL OpenGL support */
/*--- Includes ---*/
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
#include "SDL_video.h"
#include "SDL_error.h"
#include "SDL_endian.h"
#include "SDL_atarigl_c.h"
/*--- Variables ---*/
/*--- Functions prototypes ---*/
static void ConvertNull(SDL_Surface *surface);
static void Convert565To555be(SDL_Surface *surface);
static void Convert565To555le(SDL_Surface *surface);
static void Convert565le(SDL_Surface *surface);
static void ConvertBGRAToABGR(SDL_Surface *surface);
/*--- Public functions ---*/
int SDL_AtariGL_Init(_THIS, SDL_Surface *current)
{
#ifdef HAVE_OPENGL
GLenum osmesa_format;
SDL_PixelFormat *pixel_format;
Uint32 redmask;
SDL_AtariGL_Quit(this); /* Destroy previous context if exist */
/* Init OpenGL context using OSMesa */
gl_convert = ConvertNull;
pixel_format = current->format;
redmask = pixel_format->Rmask;
switch (pixel_format->BitsPerPixel) {
case 15:
/* 1555, big and little endian, unsupported */
osmesa_format = OSMESA_RGB_565;
if (redmask == 31<<10) {
gl_convert = Convert565To555be;
} else {
gl_convert = Convert565To555le;
}
break;
case 16:
if (redmask == 31<<11) {
osmesa_format = OSMESA_RGB_565;
} else {
/* 565, little endian, unsupported */
osmesa_format = OSMESA_RGB_565;
gl_convert = Convert565le;
}
break;
case 24:
if (redmask == 255<<16) {
osmesa_format = OSMESA_RGB;
} else {
osmesa_format = OSMESA_BGR;
}
break;
case 32:
if (redmask == 255<<16) {
osmesa_format = OSMESA_ARGB;
} else if (redmask == 255<<8) {
osmesa_format = OSMESA_BGRA;
} else if (redmask == 255<<24) {
osmesa_format = OSMESA_RGBA;
} else {
/* ABGR format unsupported */
osmesa_format = OSMESA_BGRA;
gl_convert = ConvertBGRAToABGR;
}
break;
default:
osmesa_format = OSMESA_COLOR_INDEX;
break;
}
gl_ctx = OSMesaCreateContextExt( osmesa_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 );
gl_active = (gl_ctx != NULL);
return (gl_active);
#else
return 0;
#endif
}
void SDL_AtariGL_Quit(_THIS)
{
#ifdef HAVE_OPENGL
/* Shutdown OpenGL context */
if (gl_ctx) {
OSMesaDestroyContext(gl_ctx);
gl_ctx = NULL;
}
#endif
gl_active = 0;
}
int SDL_AtariGL_LoadLibrary(_THIS, const char *path)
{
#ifdef HAVE_OPENGL
/* Library is always opened */
this->gl_config.driver_loaded = 1;
#endif
return 0;
}
void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc)
{
void *func = NULL;
#ifdef HAVE_OPENGL
if (gl_ctx != NULL) {
func = OSMesaGetProcAddress(proc);
}
#endif
return func;
}
int SDL_AtariGL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
{
#ifdef HAVE_OPENGL
GLenum mesa_attrib;
SDL_Surface *surface;
if (gl_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;
#else
return -1;
#endif
}
int SDL_AtariGL_MakeCurrent(_THIS)
{
#ifdef HAVE_OPENGL
SDL_Surface *surface;
GLenum type;
if (gl_ctx == NULL) {
SDL_SetError("Invalid OpenGL context");
return -1;
}
surface = this->screen;
if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
type = GL_UNSIGNED_SHORT_5_6_5;
} else {
type = GL_UNSIGNED_BYTE;
}
if (!OSMesaMakeCurrent(gl_ctx, surface->pixels, type, surface->w, surface->h)) {
SDL_SetError("Can not make OpenGL context current");
return -1;
}
/* OSMesa draws upside down */
OSMesaPixelStore(OSMESA_Y_UP, 0);
return 0;
#else
return -1;
#endif
}
void SDL_AtariGL_SwapBuffers(_THIS)
{
#ifdef HAVE_OPENGL
if (gl_ctx == NULL) {
return;
}
gl_convert(this->screen);
#endif
}
/*--- Private functions ---*/
static void ConvertNull(SDL_Surface *surface)
{
}
static void Convert565To555be(SDL_Surface *surface)
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >> 1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
*pixel++ = (color & 0x1f)|((color>>1) & 0xffe0);
}
line += pitch;
}
}
static void Convert565To555le(SDL_Surface *surface)
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
color = (color & 0x1f)|((color>>1) & 0xffe0);
*pixel++ = SDL_Swap16(color);
}
line += pitch;
}
}
static void Convert565le(SDL_Surface *surface)
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
*pixel++ = SDL_Swap16(color);
}
line += pitch;
}
}
static void ConvertBGRAToABGR(SDL_Surface *surface)
{
int x,y, pitch;
unsigned long *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>2;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned long color = *pixel;
*pixel++ = (color<<24)|(color>>8);
}
line += pitch;
}
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2004 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
slouken@libsdl.org
*/
/* Atari OSMesa.ldg implementation of SDL OpenGL support */
#ifndef _SDL_ATARIGL_H_
#define _SDL_ATARIGL_H_
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
#include "SDL_sysvideo.h"
#define _THIS SDL_VideoDevice *this
struct SDL_PrivateGLData {
/* to stop switching drivers while we have a valid context */
int gl_active;
/* for unsupported OSMesa buffer formats */
void (*ConvertSurface)(SDL_Surface *surface);
#ifdef HAVE_OPENGL
OSMesaContext ctx;
#endif
};
/* Old variable names */
#define gl_active (this->gl_data->gl_active)
#define gl_ctx (this->gl_data->ctx)
#define gl_convert (this->gl_data->ConvertSurface)
/* OpenGL functions */
extern int SDL_AtariGL_Init(_THIS, SDL_Surface *current);
extern void SDL_AtariGL_Quit(_THIS);
extern int SDL_AtariGL_LoadLibrary(_THIS, const char *path);
extern void *SDL_AtariGL_GetProcAddress(_THIS, const char *proc);
extern int SDL_AtariGL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
extern int SDL_AtariGL_MakeCurrent(_THIS);
extern void SDL_AtariGL_SwapBuffers(_THIS);
#endif /* _SDL_ATARIGL_H_ */
...@@ -37,10 +37,6 @@ static char rcsid = ...@@ -37,10 +37,6 @@ static char rcsid =
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
/* Mint includes */ /* Mint includes */
#include <gem.h> #include <gem.h>
#include <gemx.h> #include <gemx.h>
...@@ -60,6 +56,8 @@ static char rcsid = ...@@ -60,6 +56,8 @@ static char rcsid =
#include "SDL_ataric2p_s.h" #include "SDL_ataric2p_s.h"
#include "SDL_atarieddi_s.h" #include "SDL_atarieddi_s.h"
#include "SDL_atarimxalloc_c.h" #include "SDL_atarimxalloc_c.h"
#include "SDL_atarigl_c.h"
#include "SDL_gemvideo.h" #include "SDL_gemvideo.h"
#include "SDL_gemevents_c.h" #include "SDL_gemevents_c.h"
#include "SDL_gemmouse_c.h" #include "SDL_gemmouse_c.h"
...@@ -114,19 +112,7 @@ static void refresh_window(_THIS, int winhandle, short *rect); ...@@ -114,19 +112,7 @@ static void refresh_window(_THIS, int winhandle, short *rect);
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
/* OpenGL functions */ /* OpenGL functions */
static int GEM_GL_LoadLibrary(_THIS, const char *path);
static void *GEM_GL_GetProcAddress(_THIS, const char *proc);
static int GEM_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
static int GEM_GL_MakeCurrent(_THIS);
static void GEM_GL_SwapBuffers(_THIS); static void GEM_GL_SwapBuffers(_THIS);
static void GEM_GL_ConvertNull(SDL_Surface *surface);
static void GEM_GL_Convert565To555be(SDL_Surface *surface);
static void GEM_GL_Convert565To555le(SDL_Surface *surface);
static void GEM_GL_Convert565le(SDL_Surface *surface);
static void GEM_GL_ConvertBGRAToABGR(SDL_Surface *surface);
static void (*GEM_GL_Convert)(SDL_Surface *surface);
#endif #endif
/* GEM driver bootstrap functions */ /* GEM driver bootstrap functions */
...@@ -157,6 +143,8 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex) ...@@ -157,6 +143,8 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex)
memset(device, 0, (sizeof *device)); memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *) device->hidden = (struct SDL_PrivateVideoData *)
malloc((sizeof *device->hidden)); malloc((sizeof *device->hidden));
device->gl_data = (struct SDL_PrivateGLData *)
malloc((sizeof *device->gl_data));
} }
if ( (device == NULL) || (device->hidden == NULL) ) { if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory(); SDL_OutOfMemory();
...@@ -166,6 +154,7 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex) ...@@ -166,6 +154,7 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex)
return(0); return(0);
} }
memset(device->hidden, 0, (sizeof *device->hidden)); memset(device->hidden, 0, (sizeof *device->hidden));
memset(device->gl_data, 0, sizeof(*device->gl_data));
/* Set the function pointers */ /* Set the function pointers */
device->VideoInit = GEM_VideoInit; device->VideoInit = GEM_VideoInit;
...@@ -200,10 +189,10 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex) ...@@ -200,10 +189,10 @@ static SDL_VideoDevice *GEM_CreateDevice(int devindex)
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
/* OpenGL functions */ /* OpenGL functions */
device->GL_LoadLibrary = GEM_GL_LoadLibrary; device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
device->GL_GetProcAddress = GEM_GL_GetProcAddress; device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
device->GL_GetAttribute = GEM_GL_GetAttribute; device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
device->GL_MakeCurrent = GEM_GL_MakeCurrent; device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
device->GL_SwapBuffers = GEM_GL_SwapBuffers; device->GL_SwapBuffers = GEM_GL_SwapBuffers;
#endif #endif
...@@ -483,10 +472,6 @@ int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -483,10 +472,6 @@ int GEM_VideoInit(_THIS, SDL_PixelFormat *vformat)
printf("sdl:video:gem: VideoInit(): done\n"); printf("sdl:video:gem: VideoInit(): done\n");
#endif #endif
#ifdef HAVE_OPENGL
this->gl_config.driver_loaded = 1;
#endif
/* We're done! */ /* We're done! */
return(0); return(0);
} }
...@@ -507,11 +492,7 @@ SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) ...@@ -507,11 +492,7 @@ SDL_Rect **GEM_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
static void GEM_FreeBuffers(_THIS) static void GEM_FreeBuffers(_THIS)
{ {
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
/* Shutdown OpenGL context */ SDL_AtariGL_Quit(this);
if (GEM_ctx) {
OSMesaDestroyContext(GEM_ctx);
GEM_ctx = NULL;
}
#endif #endif
/* Release buffer */ /* Release buffer */
...@@ -760,59 +741,10 @@ SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -760,59 +741,10 @@ SDL_Surface *GEM_SetVideoMode(_THIS, SDL_Surface *current,
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
if (flags & SDL_OPENGL) { if (flags & SDL_OPENGL) {
GLenum format = OSMESA_COLOR_INDEX; /* 8 bits */ if (!SDL_AtariGL_Init(this, current)) {
/* Init OpenGL context using OSMesa */
GEM_GL_Convert = GEM_GL_ConvertNull;
switch (VDI_bpp) {
case 15:
/* 1555, big and little endian, unsupported */
format = OSMESA_RGB_565;
if (VDI_redmask == 31<<10) {
GEM_GL_Convert = GEM_GL_Convert565To555be;
} else {
GEM_GL_Convert = GEM_GL_Convert565To555le;
}
break;
case 16:
if (VDI_redmask == 31<<11) {
format = OSMESA_RGB_565;
} else {
/* 565, little endian, unsupported */
format = OSMESA_RGB_565;
GEM_GL_Convert = GEM_GL_Convert565le;
}
break;
case 24:
if (VDI_redmask == 255<<16) {
format = OSMESA_RGB;
} else {
format = OSMESA_BGR;
}
break;
case 32:
if (VDI_redmask == 255<<16) {
format = OSMESA_ARGB;
} else if (VDI_redmask == 255<<8) {
format = OSMESA_BGRA;
} else if (VDI_redmask == 255<<24) {
format = OSMESA_RGBA;
} else {
/* ABGR format unsupported */
format = OSMESA_BGRA;
GEM_GL_Convert = GEM_GL_ConvertBGRAToABGR;
}
break;
}
GEM_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 (!GEM_ctx) {
GEM_FreeBuffers(this); GEM_FreeBuffers(this);
SDL_SetError("OSMesaCreateContext failed"); SDL_SetError("Can not create OpenGL context");
return(NULL); return NULL;
} }
modeflags |= SDL_OPENGL; modeflags |= SDL_OPENGL;
...@@ -1356,188 +1288,14 @@ static void refresh_window(_THIS, int winhandle, short *rect) ...@@ -1356,188 +1288,14 @@ static void refresh_window(_THIS, int winhandle, short *rect)
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
static int GEM_GL_LoadLibrary(_THIS, const char *path)
{
/* Library is always opened */
this->gl_config.driver_loaded = 1;
return 0;
}
static void *GEM_GL_GetProcAddress(_THIS, const char *proc)
{
void *func = NULL;
if (GEM_ctx != NULL) {
func = OSMesaGetProcAddress(proc);
}
return func;
}
static int GEM_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
{
GLenum mesa_attrib;
if (GEM_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:
mesa_attrib = GL_DOUBLEBUFFER;
break;
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 GEM_GL_MakeCurrent(_THIS)
{
SDL_Surface *surface;
GLenum type;
if (GEM_ctx == NULL) {
return -1;
}
surface = this->screen;
if ((surface->format->BitsPerPixel == 15) || (surface->format->BitsPerPixel == 16)) {
type = GL_UNSIGNED_SHORT_5_6_5;
} else {
type = GL_UNSIGNED_BYTE;
}
if (!OSMesaMakeCurrent(GEM_ctx, surface->pixels, type, surface->w, surface->h)) {
SDL_SetError("Can not make OpenGL context current");
return -1;
}
/* OSMesa draws upside down */
OSMesaPixelStore(OSMESA_Y_UP, 0);
return 0;
}
static void GEM_GL_SwapBuffers(_THIS) static void GEM_GL_SwapBuffers(_THIS)
{ {
GEM_GL_Convert(this->screen); if (gl_ctx == NULL) {
GEM_FlipHWSurface(this, this->screen); return;
}
static void GEM_GL_ConvertNull(SDL_Surface *surface)
{
}
static void GEM_GL_Convert565To555be(SDL_Surface *surface)
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >> 1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
*pixel++ = (color & 0x1f)|((color>>1) & 0xffe0);
}
line += pitch;
}
}
static void GEM_GL_Convert565To555le(SDL_Surface *surface)
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
color = (color & 0x1f)|((color>>1) & 0xffe0);
*pixel++ = SDL_Swap16(color);
}
line += pitch;
}
}
static void GEM_GL_Convert565le(SDL_Surface *surface)
{
int x,y, pitch;
unsigned short *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>1;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned short color = *pixel;
*pixel++ = SDL_Swap16(color);
}
line += pitch;
} }
}
static void GEM_GL_ConvertBGRAToABGR(SDL_Surface *surface)
{
int x,y, pitch;
unsigned long *line, *pixel;
line = surface->pixels;
pitch = surface->pitch >>2;
for (y=0; y<surface->h; y++) {
pixel = line;
for (x=0; x<surface->w; x++) {
unsigned long color = *pixel;
*pixel++ = (color<<24)|(color>>8);
}
line += pitch; gl_convert(this->screen);
} GEM_FlipHWSurface(this, this->screen);
} }
#endif #endif
...@@ -28,10 +28,6 @@ static char rcsid = ...@@ -28,10 +28,6 @@ static char rcsid =
#ifndef _SDL_gemvideo_h #ifndef _SDL_gemvideo_h
#define _SDL_gemvideo_h #define _SDL_gemvideo_h
#ifdef HAVE_OPENGL
#include <GL/osmesa.h>
#endif
#include "SDL_sysvideo.h" #include "SDL_sysvideo.h"
#include "SDL_mutex.h" #include "SDL_mutex.h"
...@@ -89,10 +85,6 @@ struct SDL_PrivateVideoData { ...@@ -89,10 +85,6 @@ struct SDL_PrivateVideoData {
SDL_bool fullscreen; /* Fullscreen or windowed mode ? */ SDL_bool fullscreen; /* Fullscreen or windowed mode ? */
SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; /* Mode list */ SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; /* Mode list */
SDL_Surface *icon; /* The icon */ SDL_Surface *icon; /* The icon */
#ifdef HAVE_OPENGL
OSMesaContext ctx; /* OSMesa OpenGL context */
#endif
}; };
/* Hidden structure -> variables names */ /* Hidden structure -> variables names */
...@@ -139,8 +131,6 @@ struct SDL_PrivateVideoData { ...@@ -139,8 +131,6 @@ struct SDL_PrivateVideoData {
#define GEM_buffer2 (this->hidden->buffer2) #define GEM_buffer2 (this->hidden->buffer2)
#define GEM_bufops (this->hidden->buf2scr_ops) #define GEM_bufops (this->hidden->buf2scr_ops)
#define GEM_ctx (this->hidden->ctx)
#define VDI_FBMASK(amask, rmask, gmask, bmask) \ #define VDI_FBMASK(amask, rmask, gmask, bmask) \
VDI_alphamask = (amask); \ VDI_alphamask = (amask); \
VDI_redmask = (rmask); \ VDI_redmask = (rmask); \
......
...@@ -37,10 +37,6 @@ static char rcsid = ...@@ -37,10 +37,6 @@ 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>
...@@ -57,6 +53,7 @@ static char rcsid = ...@@ -57,6 +53,7 @@ static char rcsid =
#include "SDL_ataric2p_s.h" #include "SDL_ataric2p_s.h"
#include "SDL_atarievents_c.h" #include "SDL_atarievents_c.h"
#include "SDL_atarimxalloc_c.h" #include "SDL_atarimxalloc_c.h"
#include "SDL_atarigl_c.h"
#include "SDL_xbios.h" #include "SDL_xbios.h"
#define XBIOS_VID_DRIVER_NAME "xbios" #define XBIOS_VID_DRIVER_NAME "xbios"
...@@ -80,10 +77,6 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); ...@@ -80,10 +77,6 @@ static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
/* OpenGL functions */ /* 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); static void XBIOS_GL_SwapBuffers(_THIS);
#endif #endif
...@@ -196,6 +189,8 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) ...@@ -196,6 +189,8 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
memset(device, 0, (sizeof *device)); memset(device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *) device->hidden = (struct SDL_PrivateVideoData *)
malloc((sizeof *device->hidden)); malloc((sizeof *device->hidden));
device->gl_data = (struct SDL_PrivateGLData *)
malloc((sizeof *device->gl_data));
} }
if ( (device == NULL) || (device->hidden == NULL) ) { if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory(); SDL_OutOfMemory();
...@@ -205,6 +200,7 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) ...@@ -205,6 +200,7 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
return(0); return(0);
} }
memset(device->hidden, 0, (sizeof *device->hidden)); memset(device->hidden, 0, (sizeof *device->hidden));
memset(device->gl_data, 0, sizeof(*device->gl_data));
/* Video functions */ /* Video functions */
device->VideoInit = XBIOS_VideoInit; device->VideoInit = XBIOS_VideoInit;
...@@ -221,10 +217,10 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) ...@@ -221,10 +217,10 @@ static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
/* OpenGL functions */ /* OpenGL functions */
device->GL_LoadLibrary = XBIOS_GL_LoadLibrary; device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
device->GL_GetProcAddress = XBIOS_GL_GetProcAddress; device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
device->GL_GetAttribute = XBIOS_GL_GetAttribute; device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
device->GL_MakeCurrent = XBIOS_GL_MakeCurrent; device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
device->GL_SwapBuffers = XBIOS_GL_SwapBuffers; device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
#endif #endif
...@@ -415,10 +411,6 @@ static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -415,10 +411,6 @@ 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);
} }
...@@ -439,11 +431,7 @@ static void XBIOS_FreeBuffers(_THIS) ...@@ -439,11 +431,7 @@ static void XBIOS_FreeBuffers(_THIS)
int i; int i;
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
/* Shutdown OpenGL context */ SDL_AtariGL_Quit(this);
if (XBIOS_ctx) {
OSMesaDestroyContext(XBIOS_ctx);
XBIOS_ctx = NULL;
}
#endif #endif
for (i=0;i<2;i++) { for (i=0;i<2;i++) {
...@@ -583,23 +571,10 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, ...@@ -583,23 +571,10 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
if (flags & SDL_OPENGL) { if (flags & SDL_OPENGL) {
GLenum format; if (!SDL_AtariGL_Init(this, current)) {
/* 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); XBIOS_FreeBuffers(this);
SDL_SetError("OSMesaCreateContext failed"); SDL_SetError("Can not create OpenGL context");
return(NULL); return NULL;
} }
modeflags |= SDL_OPENGL; modeflags |= SDL_OPENGL;
...@@ -899,113 +874,14 @@ static void XBIOS_VideoQuit(_THIS) ...@@ -899,113 +874,14 @@ static void XBIOS_VideoQuit(_THIS)
#ifdef HAVE_OPENGL #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;
}
/* OSMesa draws upside down */
OSMesaPixelStore(OSMESA_Y_UP, 0);
return 0;
}
static void XBIOS_GL_SwapBuffers(_THIS) static void XBIOS_GL_SwapBuffers(_THIS)
{ {
if (XBIOS_ctx == NULL) { if (gl_ctx == NULL) {
return; return;
} }
XBIOS_FlipHWSurface(this, this->screen); XBIOS_FlipHWSurface(this, this->screen);
XBIOS_GL_MakeCurrent(this); SDL_AtariGL_MakeCurrent(this);
} }
#endif #endif
...@@ -28,10 +28,6 @@ static char rcsid = ...@@ -28,10 +28,6 @@ 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"
...@@ -73,9 +69,6 @@ struct SDL_PrivateVideoData { ...@@ -73,9 +69,6 @@ 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];
...@@ -130,8 +123,5 @@ enum { ...@@ -130,8 +123,5 @@ 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 */
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