Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WiP] GTK: add OpenGL ES support #813

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desmume/src/frontend/posix/gtk/graphics.ui
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<item translatable="yes">Null</item>
<item translatable="yes">SoftRasterizer</item>
<item translatable="yes">OpenGL</item>
<item translatable="yes">OpenGL ES</item>
rofl0r marked this conversation as resolved.
Show resolved Hide resolved
</items>
</object>
<packing>
Expand Down
26 changes: 20 additions & 6 deletions desmume/src/frontend/posix/gtk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
#include "OGLRender_3_2.h"
#endif

#ifdef HAVE_GLES3
#include "OGLRender_ES3.h"
#endif

#if defined(HAVE_LIBOSMESA)
#include "osmesa_3Demu.h"
#else
Expand Down Expand Up @@ -349,6 +353,9 @@ GPU3DInterface *core3DList[] = {
#ifdef HAVE_OPENGL
&gpu3Dgl,
#endif
#ifdef HAVE_GLES3
&gpu3Dgl_ES_3_0,
#endif
};

int multisampleSizes[] = {0, 2, 4, 8, 16, 32};
Expand Down Expand Up @@ -2229,9 +2236,11 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g
wHCInterpolate = GTK_TOGGLE_BUTTON(gtk_builder_get_object(builder, "hc_interpolate"));
g_object_unref(builder);

#ifndef HAVE_GLES3
gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(coreCombo), 3);
#endif
#ifndef HAVE_OPENGL
gtk_combo_box_text_remove(GTK_COMBO_BOX_TEXT(coreCombo), 2);
gtk_grid_remove_row(wGrid, 4);
#endif
gtk_combo_box_set_active(coreCombo, cur3DCore);

Expand Down Expand Up @@ -2270,7 +2279,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g
// Change only if needed
if (sel3DCore != cur3DCore)
{
if (sel3DCore == 2)
if (sel3DCore >= 2)
{
#if !defined(HAVE_OPENGL)
sel3DCore = RENDERID_SOFTRASTERIZER;
Expand All @@ -2282,7 +2291,7 @@ static void GraphicsSettingsDialog(GSimpleAction *action, GVariant *parameter, g
#else
if (!is_sdl_initialized())
{
init_sdl_3Demu();
init_sdl_3Demu(sel3DCore==3);
}
#endif
}
Expand Down Expand Up @@ -3819,6 +3828,11 @@ common_gtk_main(GApplication *app, gpointer user_data)
OGLCreateRenderer_3_2_Func = OGLCreateRenderer_3_2;
#endif

#if defined(HAVE_GLES3) && defined(OGLRENDER_ES3_H)
OGLLoadEntryPoints_ES_3_0_Func = OGLLoadEntryPoints_ES_3_0;
OGLCreateRenderer_ES_3_0_Func = OGLCreateRenderer_ES_3_0;
#endif

//Set the 3D emulation to use
int core = my_config->engine_3d;
// setup the gdk 3D emulation;
Expand All @@ -3829,15 +3843,15 @@ common_gtk_main(GApplication *app, gpointer user_data)
core = config.core3D;

// Check if it is valid
if (!(core >= 0 && core <= 2)) {
if (!(core >= 0 && core <= 3)) {
// If it is invalid, reset it to SoftRasterizer
core = 1;
}
//Set this too for clarity
my_config->engine_3d = core;
}

if (core == 2)
if (core >= 2)
{
#if !defined(HAVE_OPENGL)
core = RENDERID_SOFTRASTERIZER;
Expand All @@ -3849,7 +3863,7 @@ common_gtk_main(GApplication *app, gpointer user_data)
#else
if (!is_sdl_initialized())
{
init_sdl_3Demu();
init_sdl_3Demu(core==3);
}
#endif
}
Expand Down
17 changes: 13 additions & 4 deletions desmume/src/frontend/posix/gtk/sdl_3Demu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool deinit_sdl_3Demu(void)
return ret;
}

bool init_sdl_3Demu(void)
bool init_sdl_3Demu(bool useES)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
Expand All @@ -59,9 +59,18 @@ bool init_sdl_3Demu(void)
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
if(useES)
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
}
else
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
}

win = SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, real_framebuffer_width,
real_framebuffer_height, SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN);
Expand Down
2 changes: 1 addition & 1 deletion desmume/src/frontend/posix/gtk/sdl_3Demu.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#ifndef SDL_3DEMU_H
#define SDL_3DEMU_H

bool init_sdl_3Demu(void);
bool init_sdl_3Demu(bool useES);
bool deinit_sdl_3Demu(void);
bool is_sdl_initialized(void);

Expand Down
9 changes: 9 additions & 0 deletions desmume/src/frontend/posix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dep_pcap = dependency('pcap')
dep_zlib = dependency('zlib')
dep_threads = dependency('threads')
dep_gl = dependency('gl', required: false)
dep_gles3 = dependency('glesv2', required: false)
dep_openal = dependency('openal', required: get_option('openal'))
dep_alsa = dependency('alsa', required: false)
dep_soundtouch = dependency('soundtouch', required: false)
Expand Down Expand Up @@ -176,6 +177,14 @@ if dep_gl.found()
]
endif

if dep_gles3.found()
dependencies += dep_gles3
add_global_arguments('-DHAVE_GLES3', language: ['c', 'cpp'])
libdesmume_src += [
'../../OGLRender_ES3.cpp',
]
endif

if dep_openal.found()
dependencies += dep_openal
libdesmume_src += [
Expand Down
Loading