Linux Port (GTK): Fix OSMesa context creation. (Regression from r4905. Fixes #119.)

- Also do some code cleanup.
This commit is contained in:
rogerman 2017-11-24 00:28:49 -08:00
parent b9ada994df
commit 010efff31b
6 changed files with 230 additions and 163 deletions

View File

@ -75,7 +75,7 @@ AM_CONDITIONAL([HAVE_GL], [test "${have_gl_h}" = "yes"])
dnl - if --enable-osmesa is used, check for it dnl - if --enable-osmesa is used, check for it
AC_ARG_ENABLE([osmesa], AC_ARG_ENABLE([osmesa],
[AC_HELP_STRING([--enable-osmesa], [use off-screen mesa])], [AC_HELP_STRING([--enable-osmesa], [use off-screen mesa, overrides GLX])],
[osmesa=$enableval], [osmesa=$enableval],
[osmesa=no]) [osmesa=no])

View File

@ -1,22 +1,20 @@
/* /*
Copyright (C) 2013 The Lemon Man Copyright (C) 2013 The Lemon Man
Copyright (C) 2013-2017 DeSmuME team
This file is part of DeSmuME This file is free software: you can redistribute it and/or modify
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
DeSmuME is distributed in the hope that it will be useful, This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software along with the this software. If not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifdef HAVE_GL_GLX #ifdef HAVE_GL_GLX
#include <stdio.h> #include <stdio.h>
@ -24,9 +22,11 @@
#include <GL/glx.h> #include <GL/glx.h>
#include "../OGLRender.h" #include "../OGLRender.h"
#include "glx_3Demu.h"
static bool glx_beginOpenGL(void) { return 1; } static bool glx_beginOpenGL(void) { return 1; }
static void glx_endOpenGL(void) { } static void glx_endOpenGL(void) { }
static bool glx_init(void) { return true; } static bool glx_init(void) { return is_glx_initialized(); }
static int xerror_handler(Display *dpy, XErrorEvent *ev) { return 0; } static int xerror_handler(Display *dpy, XErrorEvent *ev) { return 0; }
static GLXContext ctx = NULL; static GLXContext ctx = NULL;
@ -34,7 +34,7 @@ static GLXPbuffer pbuf;
typedef GLXContext (*wtf)(Display*, GLXFBConfig, GLXContext, Bool, const int*); typedef GLXContext (*wtf)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
int deinit_glx_3Demu(void) bool deinit_glx_3Demu(void)
{ {
Display *dpy = glXGetCurrentDisplay(); Display *dpy = glXGetCurrentDisplay();
@ -53,7 +53,7 @@ int deinit_glx_3Demu(void)
return false; return false;
} }
int init_glx_3Demu(void) bool init_glx_3Demu(void)
{ {
Display *dpy = XOpenDisplay(NULL); Display *dpy = XOpenDisplay(NULL);
XVisualInfo *vis; XVisualInfo *vis;
@ -159,7 +159,7 @@ int init_glx_3Demu(void)
bool is_glx_initialized(void) bool is_glx_initialized(void)
{ {
return ctx != NULL; return (ctx != NULL);
} }
#endif // HAVE_GLX #endif // HAVE_GLX

View File

@ -1,25 +1,27 @@
/* /*
Copyright (C) 2013 The Lemon Man Copyright (C) 2013 The Lemon Man
Copyright (C) 2013-2017 DeSmuME team
This file is part of DeSmuME This file is free software: you can redistribute it and/or modify
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
DeSmuME is distributed in the hope that it will be useful, This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software along with the this software. If not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifdef HAVE_GL_GLX #ifndef GLX_3DEMU_H
int init_glx_3Demu(void); #define GLX_3DEMU_H
int deinit_glx_3Demu(void);
bool init_glx_3Demu(void);
bool deinit_glx_3Demu(void);
bool is_glx_initialized(void); bool is_glx_initialized(void);
#endif
#endif // GLX_3DEMU_H

View File

@ -1,22 +1,19 @@
/* main.cpp - this file is part of DeSmuME /*
* Copyright (C) 2007 Pascal Giard (evilynux)
* Copyright (C) 2006-2016 DeSmuME Team Copyright (C) 2006-2017 DeSmuME team
* Copyright (C) 2007 Pascal Giard (evilynux)
* This file is free software: you can redistribute it and/or modify
* This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or
* the Free Software Foundation; either version 2, or (at your option) (at your option) any later version.
* any later version.
* This file is distributed in the hope that it will be useful,
* This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License along with the this software. If not, see <http://www.gnu.org/licenses/>.
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/ */
#ifndef GTK_UI #ifndef GTK_UI
@ -65,17 +62,25 @@
#include "filter/videofilter.h" #include "filter/videofilter.h"
#ifdef GDB_STUB #ifdef GDB_STUB
#include "armcpu.h" #include "armcpu.h"
#include "gdbstub.h" #include "gdbstub.h"
#endif #endif
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX)
#include <GL/gl.h> #define HAVE_OPENGL
#include <GL/glu.h> #endif
#include "OGLRender.h"
#include "OGLRender_3_2.h" #ifdef HAVE_OPENGL
#include "osmesa_3Demu.h" #include <GL/gl.h>
#include "glx_3Demu.h" #include <GL/glu.h>
#include "OGLRender.h"
#include "OGLRender_3_2.h"
#endif
#if defined(HAVE_GL_GLX)
#include "glx_3Demu.h"
#elif defined(HAVE_LIBOSMESA)
#include "osmesa_3Demu.h"
#endif #endif
#include "config.h" #include "config.h"
@ -617,7 +622,7 @@ NULL
GPU3DInterface *core3DList[] = { GPU3DInterface *core3DList[] = {
&gpu3DNull, &gpu3DNull,
&gpu3DRasterize, &gpu3DRasterize,
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
&gpu3Dgl, &gpu3Dgl,
#endif #endif
}; };
@ -693,7 +698,7 @@ fill_configured_features( class configured_features *config,
{ "3d-render", 0, 0, G_OPTION_ARG_INT, &config->engine_3d, "Select 3D rendering engine. Available engines:\n" { "3d-render", 0, 0, G_OPTION_ARG_INT, &config->engine_3d, "Select 3D rendering engine. Available engines:\n"
"\t\t\t\t 0 = 3d disabled\n" "\t\t\t\t 0 = 3d disabled\n"
"\t\t\t\t 1 = internal rasterizer (default)\n" "\t\t\t\t 1 = internal rasterizer (default)\n"
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
"\t\t\t\t 2 = opengl\n" "\t\t\t\t 2 = opengl\n"
#endif #endif
,"ENGINE"}, ,"ENGINE"},
@ -737,12 +742,12 @@ fill_configured_features( class configured_features *config,
// Check if the commandLine argument was actually passed // Check if the commandLine argument was actually passed
if (config->engine_3d != -1) { if (config->engine_3d != -1) {
if (config->engine_3d != 0 && config->engine_3d != 1 if (config->engine_3d != 0 && config->engine_3d != 1
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
&& config->engine_3d != 2 && config->engine_3d != 2
#endif #endif
) { ) {
g_printerr("Currently available ENGINES: 0, 1" g_printerr("Currently available ENGINES: 0, 1"
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
", 2" ", 2"
#endif #endif
"\n"); "\n");
@ -2185,8 +2190,8 @@ static void GraphicsSettingsDialog() {
coreCombo = gtk_combo_box_text_new(); coreCombo = gtk_combo_box_text_new();
gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 0, "Null"); gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 0, "Null");
gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 1, "Software Raserizer"); gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 1, "SoftRasterizer");
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 2, "OpenGL"); gtk_combo_box_text_insert_text(GTK_COMBO_BOX_TEXT(coreCombo), 2, "OpenGL");
#endif #endif
gtk_combo_box_set_active(GTK_COMBO_BOX(coreCombo), cur3DCore); gtk_combo_box_set_active(GTK_COMBO_BOX(coreCombo), cur3DCore);
@ -2230,17 +2235,17 @@ static void GraphicsSettingsDialog() {
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 0, 0); static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 0, 0);
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
// OpenGL Multisample // OpenGL Multisample
wMultisample = gtk_check_button_new_with_label("Multisample (OpenGL)"); wMultisample = gtk_check_button_new_with_label("Multisample Antialiasing (OpenGL)");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wMultisample), CommonSettings.GFX3D_Renderer_Multisample); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wMultisample), CommonSettings.GFX3D_Renderer_Multisample);
gtk_table_attach(GTK_TABLE(wTable), wMultisample, 1, 2, 2, 3, gtk_table_attach(GTK_TABLE(wTable), wMultisample, 1, 2, 2, 3,
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 10, 0); static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), 10, 0);
#endif #endif
// SoftwareRasterizer High Color Interpolation // SoftRasterizer High Color Interpolation
wHCInterpolate = gtk_check_button_new_with_label("High Resolution Color Interpolation (SoftwareRasterizer)"); wHCInterpolate = gtk_check_button_new_with_label("High Resolution Color Interpolation (SoftRasterizer)");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wHCInterpolate), CommonSettings.GFX3D_HighResolutionInterpolateColor); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(wHCInterpolate), CommonSettings.GFX3D_HighResolutionInterpolateColor);
gtk_table_attach(GTK_TABLE(wTable), wHCInterpolate, 1, 2, 3, 4, gtk_table_attach(GTK_TABLE(wTable), wHCInterpolate, 1, 2, 3, 4,
static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL), static_cast<GtkAttachOptions>(GTK_EXPAND | GTK_FILL),
@ -2256,20 +2261,31 @@ static void GraphicsSettingsDialog() {
int sel3DCore = gtk_combo_box_get_active(GTK_COMBO_BOX(coreCombo)); int sel3DCore = gtk_combo_box_get_active(GTK_COMBO_BOX(coreCombo));
// Change only if needed // Change only if needed
if (sel3DCore != cur3DCore) { if (sel3DCore != cur3DCore)
#if defined(HAVE_LIBOSMESA) {
if (sel3DCore == 2 && !is_osmesa_initialized()) { if (sel3DCore == 2)
init_osmesa_3Demu(); {
} #if !defined(HAVE_OPENGL)
sel3DCore = RENDERID_SOFTRASTERIZER;
#elif defined(HAVE_GL_GLX) #elif defined(HAVE_GL_GLX)
if (sel3DCore == 2 && !is_glx_initialized()) { if (!is_glx_initialized())
{
init_glx_3Demu(); init_glx_3Demu();
} }
#elif defined(HAVE_LIBOSMESA)
if (!is_osmesa_initialized())
{
init_osmesa_3Demu();
}
#endif #endif
}
if (GPU->Change3DRendererByID(sel3DCore)) { if (GPU->Change3DRendererByID(sel3DCore))
{
config.core3D = sel3DCore; config.core3D = sel3DCore;
} else { }
else
{
GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER); GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER);
g_printerr("3D renderer initialization failed!\nFalling back to 3D core: %s\n", core3DList[RENDERID_SOFTRASTERIZER]->name); g_printerr("3D renderer initialization failed!\nFalling back to 3D core: %s\n", core3DList[RENDERID_SOFTRASTERIZER]->name);
config.core3D = RENDERID_SOFTRASTERIZER; config.core3D = RENDERID_SOFTRASTERIZER;
@ -2292,7 +2308,7 @@ static void GraphicsSettingsDialog() {
CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wSmoothing)); CommonSettings.GFX3D_Renderer_TextureSmoothing = config.textureSmoothing = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wSmoothing));
CommonSettings.GFX3D_Renderer_TextureScalingFactor = config.textureUpscale = scale; CommonSettings.GFX3D_Renderer_TextureScalingFactor = config.textureUpscale = scale;
CommonSettings.GFX3D_HighResolutionInterpolateColor = config.highColorInterpolation = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wHCInterpolate)); CommonSettings.GFX3D_HighResolutionInterpolateColor = config.highColorInterpolation = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wHCInterpolate));
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX) #ifdef HAVE_OPENGL
CommonSettings.GFX3D_Renderer_Multisample = config.multisampling = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wMultisample)); CommonSettings.GFX3D_Renderer_Multisample = config.multisampling = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wMultisample));
#endif #endif
} }
@ -3348,8 +3364,10 @@ common_gtk_main( class configured_features *my_config)
gtk_toggle_action_set_active((GtkToggleAction *)action, FALSE); gtk_toggle_action_set_active((GtkToggleAction *)action, FALSE);
} }
#if defined(HAVE_OPENGL) && defined(OGLRENDER_3_2_H)
OGLLoadEntryPoints_3_2_Func = OGLLoadEntryPoints_3_2; OGLLoadEntryPoints_3_2_Func = OGLLoadEntryPoints_3_2;
OGLCreateRenderer_3_2_Func = OGLCreateRenderer_3_2; OGLCreateRenderer_3_2_Func = OGLCreateRenderer_3_2;
#endif
//Set the 3D emulation to use //Set the 3D emulation to use
int core = my_config->engine_3d; int core = my_config->engine_3d;
@ -3362,23 +3380,29 @@ common_gtk_main( class configured_features *my_config)
// Check if it is valid // Check if it is valid
if (!(core >= 0 && core <= 2)) { if (!(core >= 0 && core <= 2)) {
// If it is invalid, reset it to softwareRasterizer // If it is invalid, reset it to SoftRasterizer
core = 1; core = 1;
} }
//Set this too for clarity //Set this too for clarity
my_config->engine_3d = core; my_config->engine_3d = core;
} }
#if defined(HAVE_LIBOSMESA) || defined(HAVE_GL_GLX)
if(core == 2) if (core == 2)
{ {
#if defined(HAVE_LIBOSMESA) #if !defined(HAVE_OPENGL)
core = init_osmesa_3Demu() core = RENDERID_SOFTRASTERIZER;
#elif defined(HAVE_GL_GLX) #elif defined(HAVE_GL_GLX)
core = init_glx_3Demu() if (!is_glx_initialized())
#endif {
? 2 : RENDERID_NULL; init_glx_3Demu();
}
#elif defined(HAVE_LIBOSMESA)
if (!is_osmesa_initialized())
{
init_osmesa_3Demu();
} }
#endif #endif
}
if (!GPU->Change3DRendererByID(core)) { if (!GPU->Change3DRendererByID(core)) {
GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER); GPU->Change3DRendererByID(RENDERID_SOFTRASTERIZER);
@ -3443,10 +3467,10 @@ common_gtk_main( class configured_features *my_config)
desmume_free(); desmume_free();
#if defined(HAVE_LIBOSMESA) #if defined(HAVE_GL_GLX)
deinit_osmesa_3Demu();
#elif defined(HAVE_GL_GLX)
deinit_glx_3Demu(); deinit_glx_3Demu();
#elif defined(HAVE_LIBOSMESA)
deinit_osmesa_3Demu();
#endif #endif
/* Unload joystick */ /* Unload joystick */

View File

@ -1,60 +1,98 @@
/* /*
Copyright (C) 2009 Guillaume Duhamel Copyright (C) 2009 Guillaume Duhamel
Copyright (C) 2009-2017 DeSmuME team
This file is part of DeSmuME This file is free software: you can redistribute it and/or modify
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
DeSmuME is distributed in the hope that it will be useful, This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software along with the this software. If not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifdef HAVE_LIBOSMESA #ifdef HAVE_LIBOSMESA
#include <stdlib.h> #include <stdlib.h>
#include <GL/osmesa.h> #include <GL/osmesa.h>
#include "../OGLRender.h" #include "../OGLRender.h"
#include "../OGLRender_3_2.h"
#include "osmesa_3Demu.h" #include "osmesa_3Demu.h"
static void *buffer = NULL;
static OSMesaContext ctx = NULL;
static bool osmesa_beginOpenGL(void) { return 1; } static bool osmesa_beginOpenGL(void) { return 1; }
static void osmesa_endOpenGL(void) { } static void osmesa_endOpenGL(void) { }
static bool osmesa_init(void) { return true; } static bool osmesa_init(void) { return is_osmesa_initialized(); }
static void * buffer = NULL;
static OSMesaContext ctx;
void deinit_osmesa_3Demu (void) void deinit_osmesa_3Demu (void)
{ {
free(buffer); free(buffer);
buffer = NULL;
OSMesaDestroyContext(ctx); OSMesaDestroyContext(ctx);
ctx = NULL;
} }
int init_osmesa_3Demu(void) bool init_osmesa_3Demu(void)
{ {
if (!ctx) #if (((OSMESA_MAJOR_VERSION * 100) + OSMESA_MINOR_VERSION) >= 1102) && defined(OSMESA_CONTEXT_MAJOR_VERSION)
static const int attributes_3_2_core_profile[] = {
OSMESA_FORMAT, OSMESA_RGBA,
OSMESA_DEPTH_BITS, 24,
OSMESA_STENCIL_BITS, 8,
OSMESA_ACCUM_BITS, 0,
OSMESA_PROFILE, OSMESA_CORE_PROFILE,
OSMESA_CONTEXT_MAJOR_VERSION, 3,
OSMESA_CONTEXT_MINOR_VERSION, 2,
0 };
ctx = OSMesaCreateContextAttribs(attributes_3_2_core_profile, NULL);
if (ctx == NULL)
{ {
printf("OSMesaCreateContext failed!\n"); printf("OSMesa: Could not create a 3.2 Core Profile context. Will attempt to create a 2.1 compatibility context...\n");
static const int attributes_2_1[] = {
OSMESA_FORMAT, OSMESA_RGBA,
OSMESA_DEPTH_BITS, 24,
OSMESA_STENCIL_BITS, 8,
OSMESA_ACCUM_BITS, 0,
OSMESA_PROFILE, OSMESA_COMPAT_PROFILE,
OSMESA_CONTEXT_MAJOR_VERSION, 2,
OSMESA_CONTEXT_MINOR_VERSION, 1,
0 };
ctx = OSMesaCreateContextAttribs(attributes_2_1, NULL);
}
#endif
if (ctx == NULL)
{
ctx = OSMesaCreateContextExt(OSMESA_RGBA, 24, 8, 0, NULL);
if (ctx == NULL)
{
printf("OSMesa: OSMesaCreateContextExt() failed!\n");
return false; return false;
} }
}
buffer = malloc(256 * 192 * 4); buffer = malloc(GPU_FRAMEBUFFER_NATIVE_WIDTH * GPU_FRAMEBUFFER_NATIVE_HEIGHT * sizeof(uint32_t));
if (!buffer) if (!buffer)
{ {
printf("Could not allocate enough memory!\n"); printf("OSMesa: Could not allocate enough memory for the context!\n");
return false; return false;
} }
if (!OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, 256, 192)) if (!OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, GPU_FRAMEBUFFER_NATIVE_WIDTH, GPU_FRAMEBUFFER_NATIVE_HEIGHT))
{ {
printf("OSMesaMakeCurrent failed!\n"); printf("OSMesa: OSMesaMakeCurrent() failed!\n");
free(buffer); free(buffer);
return false; return false;
} }
@ -68,6 +106,7 @@ int init_osmesa_3Demu(void)
bool is_osmesa_initialized(void) bool is_osmesa_initialized(void)
{ {
return ctx != NULL; return (ctx != NULL);
} }
#endif #endif

View File

@ -1,25 +1,27 @@
/* /*
Copyright (C) 2009 Guillaume Duhamel Copyright (C) 2009 Guillaume Duhamel
Copyright (C) 2009-2017 DeSmuME team
This file is part of DeSmuME This file is free software: you can redistribute it and/or modify
DeSmuME is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or the Free Software Foundation, either version 2 of the License, or
(at your option) any later version. (at your option) any later version.
DeSmuME is distributed in the hope that it will be useful, This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with DeSmuME; if not, write to the Free Software along with the this software. If not, see <http://www.gnu.org/licenses/>.
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
*/
#ifdef HAVE_LIBOSMESA #ifndef OSMESA_3DEMU_H
int init_osmesa_3Demu(void); #define OSMESA_3DEMU_H
bool init_osmesa_3Demu(void);
void deinit_osmesa_3Demu(void); void deinit_osmesa_3Demu(void);
bool is_osmesa_initialized(void); bool is_osmesa_initialized(void);
#endif
#endif // OSMESA_3DEMU_H