Allow to use OpenGL (not GLES).
GLES is still the default, except on Mac OS X. Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
3904cf58b2
commit
030d6d5a62
4 changed files with 92 additions and 20 deletions
|
@ -1,12 +1,30 @@
|
|||
include(FindPkgConfig)
|
||||
|
||||
find_package(SDL2 REQUIRED)
|
||||
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
|
||||
pkg_search_module(GLES2 REQUIRED glesv2)
|
||||
add_executable(sa2)
|
||||
|
||||
set(IMGUI_PATH "imgui/imgui")
|
||||
set(IMGUI_CLUB_PATH "imgui/imgui_club")
|
||||
|
||||
add_executable(sa2)
|
||||
find_package(SDL2 REQUIRED)
|
||||
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
|
||||
|
||||
# the default is to use GLES
|
||||
set (SA2_USE_OPENGL 0)
|
||||
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set (SA2_USE_OPENGL 1)
|
||||
endif()
|
||||
|
||||
|
||||
if (${SA2_USE_OPENGL})
|
||||
pkg_search_module(GLES2 REQUIRED opengl)
|
||||
else()
|
||||
pkg_search_module(GLES2 REQUIRED glesv2)
|
||||
target_compile_definitions(sa2 PRIVATE
|
||||
IMGUI_IMPL_OPENGL_ES2
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
set(SOURCE_FILES
|
||||
main.cpp
|
||||
|
@ -86,7 +104,6 @@ target_include_directories(sa2 PRIVATE
|
|||
)
|
||||
|
||||
target_compile_definitions(sa2 PRIVATE
|
||||
IMGUI_IMPL_OPENGL_ES2
|
||||
IMGUI_USER_CONFIG="frontends/sdl/imgui/imconfig.h"
|
||||
)
|
||||
|
||||
|
|
|
@ -7,7 +7,16 @@
|
|||
// "Supported versions are: 1.00 ES"
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
#define SDL_CONTEXT_MAJOR 2
|
||||
#define SA2_CONTEXT_FLAGS 0
|
||||
#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_ES
|
||||
#define SA2_CONTEXT_MAJOR_VERSION 2
|
||||
#define SA2_CONTEXT_MINOR_VERSION 0
|
||||
|
||||
// this is defined in gl2ext.h and nowhere in gl3.h
|
||||
#define SA2_IMAGE_FORMAT GL_BGRA_EXT
|
||||
|
||||
// this is used in all cases for GL_BGRA_EXT
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#elif defined(IMGUI_IMPL_OPENGL_ES3)
|
||||
|
||||
|
@ -20,13 +29,40 @@
|
|||
// "Supported versions are: 1.00 ES, 3.00 ES, and 3.10 ES"
|
||||
|
||||
#include <GLES3/gl3.h>
|
||||
#define SDL_CONTEXT_MAJOR 3
|
||||
#define SA2_CONTEXT_FLAGS 0
|
||||
#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_ES
|
||||
#define SA2_CONTEXT_MAJOR_VERSION 3
|
||||
#define SA2_CONTEXT_MINOR_VERSION 0
|
||||
|
||||
// this is defined in gl2ext.h and nowhere in gl3.h
|
||||
#define SA2_IMAGE_FORMAT GL_BGRA_EXT
|
||||
|
||||
// "310 es" is accepted on a Pi4, but the imgui shaders do not compile
|
||||
// this is used in all cases for GL_BGRA_EXT
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#elif defined(__APPLE__)
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
#define SA2_CONTEXT_FLAGS SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG
|
||||
#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_CORE
|
||||
#define SA2_CONTEXT_MAJOR_VERSION 3
|
||||
#define SA2_CONTEXT_MINOR_VERSION 2
|
||||
|
||||
#define SA2_IMAGE_FORMAT GL_RGBA
|
||||
|
||||
#else
|
||||
|
||||
#include <SDL_opengl.h>
|
||||
#define SA2_CONTEXT_FLAGS 0
|
||||
#define SA2_CONTEXT_PROFILE_MASK SDL_GL_CONTEXT_PROFILE_CORE
|
||||
#define SA2_CONTEXT_MAJOR_VERSION 3
|
||||
#define SA2_CONTEXT_MINOR_VERSION 2
|
||||
|
||||
#define SA2_IMAGE_FORMAT GL_RGBA
|
||||
|
||||
#endif
|
||||
|
||||
// this is used in all cases for GL_BGRA_EXT
|
||||
#include <GLES2/gl2ext.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_sdl.h"
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace sa2
|
|||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
|
||||
const GLenum format = GL_BGRA_EXT; // this is defined in gl2ext.h and nowhere in gl3.h
|
||||
const GLenum format = SA2_IMAGE_FORMAT;
|
||||
const GLenum type = GL_UNSIGNED_BYTE;
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, nullptr);
|
||||
|
||||
|
@ -48,7 +48,7 @@ namespace sa2
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
|
||||
const GLenum format = GL_BGRA_EXT; // this is defined in gl2ext.h and nowhere in gl3.h
|
||||
const GLenum format = SA2_IMAGE_FORMAT;
|
||||
const GLenum type = GL_UNSIGNED_BYTE;
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
|
||||
// reset to default state
|
||||
|
|
|
@ -12,16 +12,35 @@
|
|||
#include <iostream>
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
std::string safeGlGetString(GLenum name)
|
||||
{
|
||||
const char * str = reinterpret_cast<const char *>(glGetString(name));
|
||||
if (str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "<MISSING>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace sa2
|
||||
{
|
||||
|
||||
SDLImGuiFrame::SDLImGuiFrame(const common2::EmulatorOptions & options)
|
||||
: SDLFrame(options)
|
||||
{
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, SDL_CONTEXT_MAJOR); // from local gles.h
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SA2_CONTEXT_FLAGS);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SA2_CONTEXT_PROFILE_MASK);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, SA2_CONTEXT_MAJOR_VERSION); // from local gles.h
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, SA2_CONTEXT_MINOR_VERSION);
|
||||
|
||||
// Create window with graphics context
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
|
@ -49,11 +68,11 @@ namespace sa2
|
|||
|
||||
// Setup Platform/Renderer backends
|
||||
std::cerr << "IMGUI_VERSION: " << IMGUI_VERSION << std::endl;
|
||||
std::cerr << "GL_VENDOR: " << glGetString(GL_VENDOR) << std::endl;
|
||||
std::cerr << "GL_RENDERER: " << glGetString(GL_RENDERER) << std::endl;
|
||||
std::cerr << "GL_VERSION: " << glGetString(GL_VERSION) << std::endl;
|
||||
std::cerr << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
|
||||
// const char* runtime_gl_extensions = (const char*)glGetString(GL_EXTENSIONS);
|
||||
std::cerr << "GL_VENDOR: " << safeGlGetString(GL_VENDOR) << std::endl;
|
||||
std::cerr << "GL_RENDERER: " << safeGlGetString(GL_RENDERER) << std::endl;
|
||||
std::cerr << "GL_VERSION: " << safeGlGetString(GL_VERSION) << std::endl;
|
||||
std::cerr << "GL_SHADING_LANGUAGE_VERSION: " << safeGlGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;
|
||||
// const char* runtime_gl_extensions = (const char*)safeGlGetString(GL_EXTENSIONS);
|
||||
// std::cerr << "GL_EXTENSIONS: " << runtime_gl_extensions << std::endl;
|
||||
|
||||
// Setup Dear ImGui context
|
||||
|
|
Loading…
Add table
Reference in a new issue