Added osmesa "backend" for OpenGL (off-screen) rendering

in gtk port.
This is enabled with --enable-osmesa configure switch and
shouldn't break (or change) anything when the switch is not
used.
If someone feels like porting that to glade port, go ahead...
but there's a number of opengl/gtkglext/etc. issues that will
need to be fixed first.
This commit is contained in:
yabause 2009-01-03 23:37:26 +00:00
parent 7a245ef399
commit 68fd04ca2c
6 changed files with 118 additions and 5 deletions

View File

@ -55,6 +55,19 @@ dnl - Check for the OpenGL includes
AC_CHECK_HEADERS([GL/gl.h])
AC_CHECK_HEADERS([GL/glu.h])
dnl - if --enable-osmesa is used, check for it
AC_ARG_ENABLE(osmesa,
[AC_HELP_STRING(--enable-osmesa, use off-screen mesa)],
[
if test "x$enableval" = "xyes" ; then
AC_CHECK_LIB(OSMesa, main,[
useosmesa=yes
AC_DEFINE(HAVE_LIBOSMESA)
LIBS="-lOSMesa $LIBS"
])
fi
])
dnl - Check for GTK and/or libglade
GLIB_VER=2.8
GTK_VER=2.6
@ -79,12 +92,14 @@ AC_PROVIDE_IFELSE([PKG_PROG_PKG_CONFIG], [
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
if test ! "x$useosmesa" = "xyes" ; then
PKG_CHECK_MODULES(GTKGLEXT,
"gtkglext-1.0",
HAVE_GTKGLEXT=yes,
HAVE_GTKGLEXT=no)
AC_SUBST(GTKGLEXT_CFLAGS)
AC_SUBST(GTKGLEXT_LIBS)
fi
PKG_CHECK_MODULES(GTHREAD,
"gthread-2.0",
@ -128,6 +143,9 @@ if test "x$HAVE_SDL" = "xyes"; then
UI_DIR="gtk $UI_DIR"
fi
dnl - the glade port has a weird relation to gtkglext and doesn't
dnl - works yet with osmesa, feel free to fix it :)
if test ! "x$useosmesa" = "xyes" ; then
if test "x$HAVE_LIBGLADE" = "xyes"; then
AC_PROVIDE_IFELSE([IT_PROG_INTLTOOL],[
# libglade requires SDL too
@ -147,12 +165,13 @@ if test "x$HAVE_SDL" = "xyes"; then
echo "WARNING: intltool and/or gettext are not available therefore the gtk-glade interface won't be installed. The gtk-glade UI requires intltool and gettext."
])
fi
fi
fi
dnl Set compiler library flags per target.
case $target in
*linux* | *bsd*)
LIBS="$LIBS -lGL -lGLU"
LIBS="$LIBS -lGLU"
;;
*mingw*)
LIBS="$LIBS -ldxguid -ldxerr8 -ldsound -lopengl32 -lws2_32 -mwindows"

View File

@ -307,6 +307,10 @@ static void createShaders()
{
hasShaders = true;
#ifdef HAVE_LIBOSMESA
NOSHADERS(1);
#endif
if (glCreateShader == NULL || //use ==NULL instead of !func to avoid always true warnings for some systems
glShaderSource == NULL ||
glCompileShader == NULL ||
@ -419,7 +423,11 @@ static char OGLInit(void)
INITOGLEXT(PFNGLGETPROGRAMIVPROC,glGetProgramiv)
INITOGLEXT(PFNGLGETPROGRAMINFOLOGPROC,glGetProgramInfoLog)
INITOGLEXT(PFNGLVALIDATEPROGRAMPROC,glValidateProgram)
#ifdef HAVE_LIBOSMESA
glBlendFuncSeparateEXT = NULL;
#else
INITOGLEXT(PFNGLBLENDFUNCSEPARATEEXTPROC,glBlendFuncSeparateEXT)
#endif
INITOGLEXT(PFNGLGETUNIFORMLOCATIONPROC,glGetUniformLocation)
INITOGLEXT(PFNGLUNIFORM1IPROC,glUniform1i)
#endif

View File

@ -16,6 +16,7 @@ desmume_SOURCES = \
../sndsdl.cpp \
../ctrlssdl.h ../ctrlssdl.cpp \
gdk_3Demu.cpp gdk_3Demu.h \
osmesa_3Demu.cpp osmesa_3Demu.h \
main.cpp
desmume_LDADD = ../libdesmume.a \
$(SDL_LIBS) $(GTK_LIBS) $(GTKGLEXT_LIBS) $(GTHREAD_LIBS)

View File

@ -43,13 +43,18 @@
#include "gdbstub.h"
#endif
#ifdef GTKGLEXT_AVAILABLE
#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA)
#include <GL/gl.h>
#include <GL/glu.h>
#include <gtk/gtkgl.h>
#include "OGLRender.h"
#ifdef GTKGLEXT_AVAILABLE
#include <gtk/gtkgl.h>
#include "gdk_3Demu.h"
#endif
#ifdef HAVE_LIBOSMESA
#include "osmesa_3Demu.h"
#endif
#endif
#include "DeSmuME.xpm"
@ -98,7 +103,7 @@ NULL
GPU3DInterface *core3DList[] = {
&gpu3DNull
#ifdef GTKGLEXT_AVAILABLE
#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA)
,
&gpu3Dgl
#endif
@ -1895,10 +1900,14 @@ common_gtk_main( struct configured_features *my_config)
{
int use_null_3d = my_config->disable_3d;
#ifdef GTKGLEXT_AVAILABLE
#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA)
if ( !use_null_3d) {
/* setup the gdk 3D emulation */
#ifdef GTKGLEXT_AVAILABLE
if ( init_opengl_gdk_3Demu()) {
#else
if ( init_osmesa_3Demu()) {
#endif
NDS_3D_SetDriver ( 1);
if (!gpu3D->NDS_3D_Init ()) {

View File

@ -0,0 +1,53 @@
/*
Copyright (C) 2009 Guillaume Duhamel
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_LIBOSMESA
#include <GL/osmesa.h>
#include "../OGLRender.h"
#include <stdlib.h>
#include <stdio.h>
static bool osmesa_beginOpenGL(void) {
return 1;
}
static void osmesa_endOpenGL(void) {
}
static bool osmesa_init(void) {
return true;
}
int init_osmesa_3Demu(void) {
void * buffer;
OSMesaContext ctx;
ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
buffer = malloc(256 * 192 * 4);
OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, 256, 192);
oglrender_init = osmesa_init;
oglrender_beginOpenGL = osmesa_beginOpenGL;
oglrender_endOpenGL = osmesa_endOpenGL;
return 1;
}
#endif

View File

@ -0,0 +1,23 @@
/*
Copyright (C) 2009 Guillaume Duhamel
This file is part of DeSmuME
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DeSmuME 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_LIBOSMESA
int init_osmesa_3Demu( void);
#endif