Skip to content

Commit

Permalink
OpenGL Renderer: Finalize all renderer-client integration to "just wo…
Browse files Browse the repository at this point in the history
…rk".

- These changes now presume that standard OpenGL and OpenGL ES are mutually exclusive. We will NOT support running a standard OpenGL context and an OpenGL ES context in the same process.
- Clients must explicitly request supporting the OpenGL 3D renderer in their build configuration. Build configurations must define ENABLE_OPENGL_STANDARD (replacing the HAVE_OPENGL macro) or ENABLE_OPENGL_ES. If neither macro is defined, then the OpenGL 3D renderer will be assumed unavailable.
- Meson and Autotools now use better header/library checks for OpenGL functionality with their associated context type.
- Add a new Code::Blocks project file that can make builds for CLI, GTK, and GTK2.
- GTK and GTK2 ports now have the option to run a legacy OpenGL context, a 3.2 Core Profile context, or simply choosing the best context automatically like before.
- GTK and GTK2 ports have GLX and EGL as new context types. OSMesa and SDL have been updated to the latest design pattern.
- GTK and GTK2 ports can now be configured (via Meson or Autotools) to use a GLX, OSMesa, EGL, or SDL context.
- OSMesa contexts are now marked as deprecated. I don't know of anyone who still uses them, and I've never been able to get it to work correctly for years. Now that we have GLX contexts for compatibility purposes, OSMesa contexts are now completely redundant.
- Fix a bug with the GTK port where ancient GPUs without FBO support can still run framebuffers at custom sizes.
- For POSIX ports, move all "avout" and context creation files to the "shared" directory for better file organization.
  • Loading branch information
rogerman committed Aug 2, 2024
1 parent 0a78fa2 commit ca566eb
Show file tree
Hide file tree
Showing 44 changed files with 3,567 additions and 1,076 deletions.
14 changes: 11 additions & 3 deletions desmume/src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ libdesmume_a_SOURCES = \
wifi.cpp wifi.h \
mic.h \
MMU.cpp MMU.h MMU_timing.h NDSSystem.cpp NDSSystem.h registers.h \
OGLRender.h OGLRender_3_2.h \
ROMReader.cpp ROMReader.h \
render3D.cpp render3D.h \
rtc.cpp rtc.h \
Expand Down Expand Up @@ -230,8 +229,17 @@ libdesmume_a_SOURCES += \
utils/AsmJit/x86/x86util.h
endif

if HAVE_GL
libdesmume_a_SOURCES += OGLRender.cpp OGLRender_3_2.cpp
if ENABLE_OPENGL_ES
libdesmume_a_SOURCES += \
OGLRender.h OGLRender_3_2.h \
OGLRender.cpp OGLRender_3_2.cpp \
OGLRender_ES3.h OGLRender_ES3.cpp
else
if ENABLE_OPENGL_STANDARD
libdesmume_a_SOURCES += \
OGLRender.h OGLRender_3_2.h \
OGLRender.cpp OGLRender_3_2.cpp
endif
endif

if HAVE_OPENAL
Expand Down
89 changes: 40 additions & 49 deletions desmume/src/OGLRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,15 @@
#include "render3D.h"
#include "types.h"

// OPENGL PLATFORM-SPECIFIC INCLUDES
#if defined(__ANGLE__) || defined(__ANDROID__)
#define OPENGL_VARIANT_ES
#define _NO_SDL_TYPES
#include <GLES3/gl3.h>
#define __gles2_gl2_h_ // Guard against including the gl2.h file.
#include <GLES2/gl2ext.h> // "gl3ext.h" is just a stub file. The real extension header is "gl2ext.h".
// The macros ENABLE_OPENGL_STANDARD and ENABLE_OPENGL_ES are used in client build configs.
// If a client wants to use OpenGL, they must declare one of these two macros somewhere in
// their build config or declare it in some precompiled header.

// Ignore dynamic linking
#define OGLEXT(procPtr, func)
#define INITOGLEXT(procPtr, func)
#define EXTERNOGLEXT(procPtr, func)
#elif defined(__EMSCRIPTEN__)
#define OPENGL_VARIANT_ES
#include <SDL_opengl.h>
#include <emscripten/emscripten.h>

// Ignore dynamic linking
#define OGLEXT(procPtr, func)
#define INITOGLEXT(procPtr, func)
#define EXTERNOGLEXT(procPtr, func)
#elif defined(_WIN32)
#define OPENGL_VARIANT_STANDARD
// OPENGL PLATFORM-SPECIFIC INCLUDES
#if defined(_WIN32)
#ifndef ENABLE_OPENGL_STANDARD
#define ENABLE_OPENGL_STANDARD // TODO: Declare this in the Visual Studio project file.
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <GL/gl.h>
Expand All @@ -63,15 +49,10 @@
#define INITOGLEXT(procPtr, func) func = (procPtr)wglGetProcAddress(#func);
#define EXTERNOGLEXT(procPtr, func) extern procPtr func;
#elif defined(__APPLE__)
#include <TargetConditionals.h>

#if TARGET_OS_IPHONE
#define OPENGL_VARIANT_ES
#if defined(ENABLE_OPENGL_ES)
#include <OpenGLES/ES3/gl.h>
#include <OpenGLES/ES3/glext.h>
#else
#define OPENGL_VARIANT_STANDARD

#elif defined(ENABLE_OPENGL_STANDARD)
#ifdef OGLRENDER_3_2_H
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
Expand All @@ -93,36 +74,46 @@
#define INITOGLEXT(procPtr, func)
#define EXTERNOGLEXT(procPtr, func)
#else
#define OPENGL_VARIANT_STANDARD
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glx.h>
#if defined(ENABLE_OPENGL_ES)
#include <GLES3/gl3.h>
#define __gles2_gl2_h_ // Guard against including the gl2.h file.
#include <GLES2/gl2ext.h> // "gl3ext.h" is just a stub file. The real extension header is "gl2ext.h".

// Ignore dynamic linking
#define OGLEXT(procPtr, func)
#define INITOGLEXT(procPtr, func)
#define EXTERNOGLEXT(procPtr, func)
#elif defined(ENABLE_OPENGL_STANDARD)
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glx.h>

#ifdef OGLRENDER_3_2_H
#include "utils/glcorearb.h"
#else
/* This is a workaround needed to compile against nvidia GL headers */
#ifndef GL_ALPHA_BLEND_EQUATION_ATI
#undef GL_VERSION_1_3
#ifdef OGLRENDER_3_2_H
#include "utils/glcorearb.h"
#else
// This is a workaround needed to compile against nvidia GL headers
#ifndef GL_ALPHA_BLEND_EQUATION_ATI
#undef GL_VERSION_1_3
#endif
#endif
#endif

#define OGLEXT(procPtr, func) procPtr func = NULL;
#define INITOGLEXT(procPtr, func) func = (procPtr)glXGetProcAddress((const GLubyte *) #func);
#define EXTERNOGLEXT(procPtr, func) extern procPtr func;
#define OGLEXT(procPtr, func) procPtr func = NULL;
#define INITOGLEXT(procPtr, func) func = (procPtr)glXGetProcAddress((const GLubyte *) #func);
#define EXTERNOGLEXT(procPtr, func) extern procPtr func;
#endif
#endif

// Check minimum OpenGL header version
#if defined(OPENGL_VARIANT_STANDARD)
#if !defined(GL_VERSION_2_1)
#error OpenGL requires v2.1 headers or later.
#endif
#elif defined(OPENGL_VARIANT_ES)
#if defined(ENABLE_OPENGL_ES)
#if !defined(GL_ES_VERSION_3_0)
#error OpenGL ES requires v3.0 headers or later.
#endif
#elif defined(ENABLE_OPENGL_STANDARD)
#if !defined(GL_VERSION_2_1)
#error Standard OpenGL requires v2.1 headers or later.
#endif
#else
#error Unknown OpenGL variant.
#error No OpenGL variant selected. You must declare ENABLE_OPENGL_STANDARD or ENABLE_OPENGL_ES in your build configuration.
#endif

// OPENGL LEGACY CORE FUNCTIONS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4416,6 +4416,8 @@
ABD2CE4426E05CB000FB15F7 /* DeSmuME (x86_64h).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DeSmuME (x86_64h).app"; sourceTree = BUILT_PRODUCTS_DIR; };
ABD42045172319D1006A9B46 /* FileMigrationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileMigrationDelegate.h; sourceTree = "<group>"; };
ABD42046172319D1006A9B46 /* FileMigrationDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileMigrationDelegate.mm; sourceTree = "<group>"; };
ABDD89EF2C30BE97003482B7 /* OGLRender_ES3.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OGLRender_ES3.h; sourceTree = "<group>"; };
ABDD89F02C30BE97003482B7 /* OGLRender_ES3.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = OGLRender_ES3.cpp; sourceTree = "<group>"; };
ABDDF7C41898F024007583C1 /* Icon_DisplayToggle_420x420.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_DisplayToggle_420x420.png; path = images/Icon_DisplayToggle_420x420.png; sourceTree = "<group>"; };
ABDDF7C71898F032007583C1 /* Icon_FrameAdvance_420x420.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_FrameAdvance_420x420.png; path = images/Icon_FrameAdvance_420x420.png; sourceTree = "<group>"; };
ABDDF7C81898F032007583C1 /* Icon_FrameJump_420x420.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon_FrameJump_420x420.png; path = images/Icon_FrameJump_420x420.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5692,6 +5694,7 @@
ABD1FEC01345AC8400AF11D1 /* NDSSystem.cpp */,
ABD1FEC11345AC8400AF11D1 /* OGLRender.cpp */,
AB68A0DA16B139BC00DE0546 /* OGLRender_3_2.cpp */,
ABDD89F02C30BE97003482B7 /* OGLRender_ES3.cpp */,
ABD1FEC21345AC8400AF11D1 /* path.cpp */,
ABD1FEC31345AC8400AF11D1 /* rasterize.cpp */,
ABD1FEC41345AC8400AF11D1 /* readwrite.cpp */,
Expand Down Expand Up @@ -5739,6 +5742,7 @@
ABD1FE8C1345AC8400AF11D1 /* NDSSystem.h */,
ABD1FE8D1345AC8400AF11D1 /* OGLRender.h */,
ABBB421516B4A5F30012E5AB /* OGLRender_3_2.h */,
ABDD89EF2C30BE97003482B7 /* OGLRender_ES3.h */,
ABD1FE8F1345AC8400AF11D1 /* PACKED.h */,
ABD1FE8E1345AC8400AF11D1 /* PACKED_END.h */,
ABD1FE901345AC8400AF11D1 /* path.h */,
Expand Down
4 changes: 2 additions & 2 deletions desmume/src/frontend/cocoa/DeSmuME_Prefix.pch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (C) 2011 Roger Manuel
Copyright (C) 2012-2021 DeSmuME team
Copyright (C) 2012-2024 DeSmuME team

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
Expand All @@ -22,7 +22,7 @@

#define HOST_DARWIN
#define DESMUME_COCOA
#define HAVE_OPENGL
#define ENABLE_OPENGL_STANDARD
#define HAVE_LIBZ
//#define HAVE_LUA
//#define HAVE_AV_CONFIG_H
Expand Down
4 changes: 2 additions & 2 deletions desmume/src/frontend/cocoa/openemu/DeSmuME_Prefix_OpenEmu.pch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2012-2022 DeSmuME team
Copyright (C) 2012-2024 DeSmuME team

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
Expand All @@ -21,7 +21,7 @@

#define HOST_DARWIN
#define DESMUME_COCOA
#define HAVE_OPENGL
#define ENABLE_OPENGL_STANDARD
#define HAVE_LIBZ
#define FT2_BUILD_LIBRARY

Expand Down
4 changes: 2 additions & 2 deletions desmume/src/frontend/modules/ImageOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "formats/rbmp.h"
#include "GPU.h"

static u8* Convert15To24(const u16* src, int width, int height)
u8* Convert15To24(const u16* src, int width, int height)
{
u8 *tmp_buffer;
u8 *tmp_inc;
Expand Down Expand Up @@ -66,4 +66,4 @@ int NDS_WriteBMP_32bppBuffer(int width, int height, const void* buf, const char
{
bool ok = rbmp_save_image(filename,buf,width,height,width*4,(rbmp_source_type)(RBMP_SOURCE_TYPE_ARGB8888 | RBMP_SOURCE_TYPE_YFLIPPED));
return ok?1:0;
}
}
14 changes: 11 additions & 3 deletions desmume/src/frontend/posix/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ libdesmume_a_SOURCES = \
../../wifi.cpp ../../wifi.h \
../../mic.h \
../../MMU.cpp ../../MMU.h ../../MMU_timing.h ../../NDSSystem.cpp ../../NDSSystem.h ../../registers.h \
../../OGLRender.h ../../OGLRender_3_2.h \
../../ROMReader.cpp ../../ROMReader.h \
../../render3D.cpp ../../render3D.h \
../../rtc.cpp ../../rtc.h \
Expand Down Expand Up @@ -211,8 +210,17 @@ endif

libdesmume_a_SOURCES += shared/desmume_config.cpp shared/desmume_config.h

if HAVE_GL
libdesmume_a_SOURCES += ../../OGLRender.cpp ../../OGLRender_3_2.cpp
if ENABLE_OPENGL_ES
libdesmume_a_SOURCES += \
../../OGLRender.h ../../OGLRender_3_2.h \
../../OGLRender.cpp ../../OGLRender_3_2.cpp \
../../OGLRender_ES3.h ../../OGLRender_ES3.cpp
else
if ENABLE_OPENGL_STANDARD
libdesmume_a_SOURCES += \
../../OGLRender.h ../../OGLRender_3_2.h \
../../OGLRender.cpp ../../OGLRender_3_2.cpp
endif
endif

if HAVE_OPENAL
Expand Down
Loading

0 comments on commit ca566eb

Please sign in to comment.