diff -urN SDL12/src/video/directfb/Makefile.am SDL12/src/video/directfb/Makefile.am --- SDL12/src/video/directfb/Makefile.am 2003-05-03 22:48:37.000000000 +0300 +++ SDL12/src/video/directfb/Makefile.am 2004-04-17 01:36:02.908677304 +0300 @@ -3,12 +3,16 @@ INCLUDES = $(DIRECTFB_CFLAGS) +AM_CPPFLAGS = -DHAVE_DIRECTFBGL + noinst_LTLIBRARIES = libvideo_directfb.la libvideo_directfb_la_SOURCES = $(DIRECTFB_SRCS) libvideo_directfb_la_LIBADD = $(DIRECTFB_LIBS) # The SDL DirectFB video driver sources DIRECTFB_SRCS = \ + SDL_DirectFB_GL.c \ + SDL_DirectFB_GL.h \ SDL_DirectFB_events.c \ SDL_DirectFB_events.h \ SDL_DirectFB_video.c \ diff -urN SDL12/src/video/directfb/SDL_DirectFB_GL.c SDL12/src/video/directfb/SDL_DirectFB_GL.c --- SDL12/src/video/directfb/SDL_DirectFB_GL.c 1970-01-01 02:00:00.000000000 +0200 +++ SDL12/src/video/directfb/SDL_DirectFB_GL.c 2004-04-17 01:31:44.374980400 +0300 @@ -0,0 +1,227 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_wingl.c,v 1.8 2002/08/20 00:20:06 slouken Exp $"; +#endif + +#ifdef HAVE_DIRECTFBGL + +/* DirectFB implementation of SDL OpenGL support */ + +#include +#include +#include +#include + +#include +#include + + +#include +#include + +#include "SDL_opengl.h" +#include "SDL_error.h" +#include "SDL_sysvideo.h" +#include "SDL_DirectFB_video.h" +#include "SDL_DirectFB_GL.h" + + +/* Make the current context active */ +int +DirectFB_GL_MakeCurrent(SDL_VideoDevice *this) +{ + DFBResult ret; + struct private_hwdata *hwdata = this->screen->hwdata; + + if (!hwdata || !hwdata->gl) + return -1; + + /* Lock GL context. */ + ret = hwdata->gl->Lock (hwdata->gl); + if (ret) + SetDirectFBerror ("IDirectFBGL::Lock", ret); + + return ret; +} + +/* Get attribute data. */ +int +DirectFB_GL_GetAttribute (SDL_VideoDevice *this, SDL_GLattr attrib, int* value) +{ + DFBResult ret; + DFBGLAttributes attr; + struct private_hwdata *hwdata = this->screen->hwdata; + + if (!hwdata || !hwdata->gl) + return -1; + + /* Query attributes. */ + ret = hwdata->gl->GetAttributes (hwdata->gl, &attr); + if (ret) + { + SetDirectFBerror ("IDirectFBGL::GetAttributes", ret); + return -1; + } + + switch (attrib) + { + case SDL_GL_RED_SIZE: + *value = attr.red_size; + break; + case SDL_GL_GREEN_SIZE: + *value = attr.green_size; + break; + case SDL_GL_BLUE_SIZE: + *value = attr.blue_size; + break; + case SDL_GL_ALPHA_SIZE: + *value = attr.alpha_size; + break; + case SDL_GL_DOUBLEBUFFER: + *value = attr.double_buffer; + break; + case SDL_GL_BUFFER_SIZE: + *value = attr.buffer_size; + break; + case SDL_GL_DEPTH_SIZE: + *value = attr.depth_size; + break; + case SDL_GL_STENCIL_SIZE: + *value = attr.stencil_size; + break; + case SDL_GL_ACCUM_RED_SIZE: + *value = attr.accum_red_size; + break; + case SDL_GL_ACCUM_GREEN_SIZE: + *value = attr.accum_green_size; + break; + case SDL_GL_ACCUM_BLUE_SIZE: + *value = attr.accum_blue_size; + break; + case SDL_GL_ACCUM_ALPHA_SIZE: + *value = attr.accum_alpha_size; + break; + case SDL_GL_STEREO: + *value = attr.stereo; + break; + + default: + return -1; + } + + return 0; +} + +void +DirectFB_GL_SwapBuffers(SDL_VideoDevice *this) +{ + DFBResult ret; + struct private_hwdata *hwdata = this->screen->hwdata; + + if (!hwdata || !hwdata->gl) + return; + + /* Unlock GL context. */ + ret = hwdata->gl->Unlock (hwdata->gl); + if (ret) + { + SetDirectFBerror ("IDirectFBGL::Unlock", ret); + return; + } + + /* Flip surface. */ + hwdata->surface->Flip (hwdata->surface, NULL, 0); + + /* Lock GL context. */ + ret = hwdata->gl->Lock (hwdata->gl); + if (ret) + SetDirectFBerror ("IDirectFBGL::Lock", ret); +} + +void * +DirectFB_GL_GetProcAddress(SDL_VideoDevice *this, const char* proc) +{ + if (this->gl_data->glGetProcAddress) + return this->gl_data->glGetProcAddress (proc); + + return NULL; +} + +void +DirectFB_GL_UnloadLibrary(SDL_VideoDevice *this) +{ + if (this->gl_config.driver_loaded) { + dlclose (this->gl_config.dll_handle); + + this->gl_data->glGetProcAddress = NULL; + + this->gl_config.dll_handle = NULL; + this->gl_config.driver_loaded = 0; + } +} + +int +DirectFB_GL_LoadLibrary(SDL_VideoDevice *this, const char* path) +{ + void* handle; + int dlopen_flags; + +#ifdef RTLD_GLOBAL + dlopen_flags = RTLD_LAZY | RTLD_GLOBAL; +#else + dlopen_flags = RTLD_LAZY; +#endif + if (!path) + path = getenv ("SDL_VIDEO_GL_DRIVER"); + handle = dlopen (path, dlopen_flags); + + if (handle == NULL) + { + SDL_SetError ("Could not load OpenGL library"); + return -1; + } + + DirectFB_GL_UnloadLibrary (this); + + this->gl_data->glGetProcAddress = + (void*(*)(const char*)) dlsym (handle, "glXGetProcAddress"); + + this->gl_config.dll_handle = handle; + this->gl_config.driver_loaded = 1; + + if (path) + { + strncpy (this->gl_config.driver_path, path, + sizeof (this->gl_config.driver_path)-1); + } + else + { + strcpy (this->gl_config.driver_path, ""); + } + + return 0; +} + +#endif /* HAVE_DIRECTFBGL */ diff -urN SDL12/src/video/directfb/SDL_DirectFB_GL.h SDL12/src/video/directfb/SDL_DirectFB_GL.h --- SDL12/src/video/directfb/SDL_DirectFB_GL.h 1970-01-01 02:00:00.000000000 +0200 +++ SDL12/src/video/directfb/SDL_DirectFB_GL.h 2004-04-17 01:17:16.109976744 +0300 @@ -0,0 +1,48 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 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 +*/ + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id: SDL_wingl_c.h,v 1.4 2002/03/06 11:23:08 slouken Exp $"; +#endif + +/* DirectFBGL implementation of SDL OpenGL support */ + +#include "SDL_sysvideo.h" + +struct SDL_PrivateGLData { + int gl_active; /* to stop switching drivers while we have a valid context */ + +#ifdef HAVE_DIRECTFBGL + void * (*glGetProcAddress)(const char *); +#endif /* HAVE_DIRECTFBGL */ +}; + +/* OpenGL functions */ +#ifdef HAVE_DIRECTFBGL +extern int DirectFB_GL_LoadLibrary(SDL_VideoDevice *this, const char *patch); +extern int DirectFB_GL_MakeCurrent(SDL_VideoDevice *this); +extern void DirectFB_GL_SwapBuffers(SDL_VideoDevice *this); +extern int DirectFB_GL_GetAttribute(SDL_VideoDevice *this, SDL_GLattr attrib, int* value); +extern void *DirectFB_GL_GetProcAddress(SDL_VideoDevice *this, const char* proc); +#endif + diff -urN SDL12/src/video/directfb/SDL_DirectFB_video.c SDL12/src/video/directfb/SDL_DirectFB_video.c --- SDL12/src/video/directfb/SDL_DirectFB_video.c 2004-02-13 20:39:01.000000000 +0200 +++ SDL12/src/video/directfb/SDL_DirectFB_video.c 2004-04-17 03:16:38.756089024 +0300 @@ -40,6 +40,9 @@ #include #include +#ifdef HAVE_DIRECTFBGL +#include +#endif #include "SDL.h" #include "SDL_error.h" @@ -51,6 +54,7 @@ #include "SDL_DirectFB_video.h" #include "SDL_DirectFB_events.h" #include "SDL_DirectFB_yuv.h" +#include "SDL_DirectFB_GL.h" /* The implementation dependent data for the window manager cursor */ struct WMcursor { @@ -103,6 +107,7 @@ static void DirectFB_DeleteDevice(SDL_VideoDevice *device) { free(device->hidden); + free(device->gl_data); free(device); } @@ -116,12 +121,17 @@ { memset (device, 0, (sizeof *device)); device->hidden = (struct SDL_PrivateVideoData *) 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 || device->gl_data == NULL) { SDL_OutOfMemory(); if (device) { + if (device->hidden) + free (device->hidden); + if (device->gl_data) + free (device->gl_data); free (device); } return(0); @@ -146,6 +156,15 @@ device->FlipHWSurface = DirectFB_FlipHWSurface; device->FreeHWSurface = DirectFB_FreeHWSurface; device->ShowWMCursor = DirectFB_ShowWMCursor; + +#ifdef HAVE_DIRECTFBGL + device->GL_LoadLibrary = DirectFB_GL_LoadLibrary; + device->GL_GetProcAddress = DirectFB_GL_GetProcAddress; + device->GL_GetAttribute = DirectFB_GL_GetAttribute; + device->GL_MakeCurrent = DirectFB_GL_MakeCurrent; + device->GL_SwapBuffers = DirectFB_GL_SwapBuffers; +#endif + device->SetCaption = NULL; device->SetIcon = NULL; device->IconifyWindow = NULL; @@ -215,11 +234,6 @@ return DFENUM_OK; } -struct private_hwdata { - IDirectFBSurface *surface; - IDirectFBPalette *palette; -}; - void SetDirectFBerror (const char *function, DFBResult code) { const char *error = DirectFBErrorString (code); @@ -607,6 +621,13 @@ current->hwdata->palette->Release (current->hwdata->palette); current->hwdata->palette = NULL; } +#ifdef HAVE_DIRECTFBGL + if (current->hwdata->gl) + { + current->hwdata->gl->Release (current->hwdata->gl); + current->hwdata->gl = NULL; + } +#endif } else if (!current->hwdata) { @@ -650,6 +671,9 @@ } } + if (flags & (SDL_OPENGL | SDL_FULLSCREEN)) + flags |= SDL_DOUBLEBUF; + /* Create primary surface */ dsc.flags = DSDESC_CAPS | DSDESC_PIXELFORMAT; dsc.caps = DSCAPS_PRIMARY | ((flags & SDL_DOUBLEBUF) ? DSCAPS_FLIPPING : 0); @@ -683,6 +707,24 @@ if (dsc.caps & DSCAPS_FLIPPING) current->flags |= SDL_DOUBLEBUF; +#ifdef HAVE_DIRECTFBGL + if (flags & SDL_OPENGL) + { + IDirectFBGL *gl; + + ret = surface->GetGL (surface, &gl); + if (ret == DFB_OK) + { + current->hwdata->gl = gl; + current->flags |= SDL_OPENGL; + if (DirectFB_GL_LoadLibrary(this, NULL) < 0) + return NULL; + } + else + DirectFBError ("surface->GetGL", ret); + } +#endif + surface->GetPixelFormat (surface, &pixelformat); DFBToSDLPixelFormat (pixelformat, current->format); @@ -1087,6 +1129,12 @@ { IDirectFBSurface *surface = this->screen->hwdata->surface; IDirectFBPalette *palette = this->screen->hwdata->palette; + IDirectFBGL *gl = this->screen->hwdata->gl; + +#ifdef HAVE_DIRECTFBGL + if (gl) + gl->Release (gl); +#endif if (palette) palette->Release (palette); @@ -1096,6 +1144,7 @@ this->screen->hwdata->surface = NULL; this->screen->hwdata->palette = NULL; + this->screen->hwdata->gl = NULL; } if (HIDDEN->c2frame) diff -urN SDL12/src/video/directfb/SDL_DirectFB_video.h SDL12/src/video/directfb/SDL_DirectFB_video.h --- SDL12/src/video/directfb/SDL_DirectFB_video.h 2004-01-04 18:49:24.000000000 +0200 +++ SDL12/src/video/directfb/SDL_DirectFB_video.h 2004-04-17 01:51:35.251939584 +0300 @@ -59,6 +59,13 @@ DFBRectangle c2framesize; /* CRTC2 screen size */ }; +struct private_hwdata { + IDirectFBSurface *surface; + IDirectFBPalette *palette; + IDirectFBGL *gl; +}; + + #define HIDDEN (this->hidden) void SetDirectFBerror (const char *function, DFBResult code);