OpenGL: Buildfixes and CMake cleanup

This commit is contained in:
Vicki Pfau 2021-08-28 22:29:27 -07:00
parent bc37f48e29
commit c217802829
6 changed files with 44 additions and 34 deletions

View File

@ -397,6 +397,7 @@ if(CMAKE_SYSTEM_NAME MATCHES ".*BSD|DragonFly")
else()
find_feature(USE_EDITLINE "libedit")
endif()
if(BUILD_GL)
find_package(OpenGL QUIET)
if(NOT OPENGL_FOUND)
@ -405,9 +406,16 @@ if(BUILD_GL)
set(OPENGL_LIBRARY OpenGL::GL)
endif()
endif()
if(BUILD_GL)
list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c)
list(APPEND FEATURE_DEFINES BUILD_GL)
list(APPEND DEPENDENCY_LIB ${OPENGL_LIBRARY})
include_directories(${OPENGL_INCLUDE_DIR})
endif()
if(NOT BUILD_GL AND NOT LIBMGBA_ONLY)
set(OPENGL_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(BUILD_GLES2 AND NOT BUILD_GL)
find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
@ -415,31 +423,32 @@ if(BUILD_GLES2 AND NOT BUILD_GL)
set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
endif()
endif()
if(NOT BUILD_GLES2 AND NOT BUILD_GLES3 AND NOT LIBMGBA_ONLY)
set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(BUILD_GL)
list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c)
list(APPEND FEATURE_DEFINES BUILD_GL)
list(APPEND DEPENDENCY_LIB ${OPENGL_LIBRARY})
include_directories(${OPENGL_INCLUDE_DIR})
endif()
if(BUILD_GLES2)
list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
list(APPEND FEATURE_DEFINES BUILD_GLES2)
list(APPEND DEPENDENCY_LIB ${OPENGLES2_LIBRARY})
include_directories(${OPENGLES2_INCLUDE_DIR})
endif()
if(BUILD_GLES3)
if(BUILD_GLES3 AND NOT BUILD_GL)
find_path(OPENGLES3_INCLUDE_DIR NAMES GLES3/gl3.h)
find_library(OPENGLES3_LIBRARY NAMES GLESv3 GLESv2)
list(APPEND FEATURE_DEFINES BUILD_GLES3)
if(NOT OPENGLES3_INCLUDE_DIR OR NOT OPENGLES3_LIBRARY)
set(BUILD_GLES3 OFF CACHE BOOL "OpenGL|ES 3 not found" FORCE)
else()
set(OPENGLES2_LIBRARY ${OPENGLES3_LIBRARY} CACHE PATH "" FORCE)
endif()
endif()
if(BUILD_GLES3)
list(APPEND FEATURE_DEFINES BUILD_GLES3)
list(APPEND DEPENDENCY_LIB ${OPENGLES3_LIBRARY})
include_directories(${OPENGLES3_INCLUDE_DIR})
endif()
if(BUILD_GLES2 OR BUILD_GLES3)
list(APPEND FEATURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
endif()
if(NOT BUILD_GLES2 AND NOT BUILD_GLES3 AND NOT LIBMGBA_ONLY)
set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(DISABLE_DEPS)
set(USE_GDB_STUB OFF)

View File

@ -24,7 +24,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Core Widgets Network Multimedia)
if(NOT BUILD_GL AND NOT BUILD_GLES2)
if(NOT BUILD_GL AND NOT BUILD_GLES2 AND NOT BUILD_GLES3)
message(WARNING "OpenGL is recommended to build the Qt port")
endif()

View File

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Display.h"
#include "CoreController.h"
#include "ConfigController.h"
#include "DisplayGL.h"
#include "DisplayQt.h"
@ -14,23 +15,23 @@
using namespace QGBA;
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
Display::Driver Display::s_driver = Display::Driver::OPENGL;
#else
Display::Driver Display::s_driver = Display::Driver::QT;
#endif
Display* Display::create(QWidget* parent) {
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
QSurfaceFormat format;
format.setSwapInterval(1);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
#endif
switch (s_driver) {
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
case Driver::OPENGL:
#if defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
format.setVersion(2, 0);
} else {
@ -65,7 +66,7 @@ Display* Display::create(QWidget* parent) {
return new DisplayQt(parent);
default:
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
return new DisplayGL(format, parent);
#else
return new DisplayQt(parent);
@ -101,7 +102,7 @@ void Display::configure(ConfigController* config) {
interframeBlending(opts->interframeBlending);
filter(opts->resampleVideo);
config->updateOption("showOSD");
#if defined(BUILD_GL) || defined(BUILD_GLES2)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (opts->shader) {
struct VDir* shader = VDirOpen(opts->shader);
if (shader && supportsShaders()) {

View File

@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DisplayGL.h"
#if defined(BUILD_GL) || defined(BUILD_GLES2)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
#include <QApplication>
#include <QMutexLocker>
@ -24,7 +24,7 @@
#ifdef BUILD_GL
#include "platform/opengl/gl.h"
#endif
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#include "platform/opengl/gles2.h"
#ifdef _WIN32
#include <epoxy/wgl.h>
@ -294,13 +294,13 @@ void PainterGL::create() {
#ifdef BUILD_GL
mGLContext* glBackend;
#endif
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
mGLES2Context* gl2Backend;
#endif
m_window = std::make_unique<QOpenGLPaintDevice>();
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
auto version = m_format.version();
if (version >= qMakePair(2, 0)) {
gl2Backend = static_cast<mGLES2Context*>(malloc(sizeof(mGLES2Context)));
@ -326,7 +326,7 @@ void PainterGL::create() {
};
m_backend->init(m_backend, 0);
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (m_supportsShaders) {
m_shader.preprocessShader = static_cast<void*>(&reinterpret_cast<mGLES2Context*>(m_backend)->initialShader);
}
@ -343,7 +343,7 @@ void PainterGL::destroy() {
return;
}
makeCurrent();
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (m_shader.passes) {
mGLES2ShaderFree(&m_shader);
}
@ -420,7 +420,7 @@ void PainterGL::filter(bool filter) {
void PainterGL::start() {
makeCurrent();
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (m_supportsShaders && m_shader.passes) {
mGLES2ShaderAttach(reinterpret_cast<mGLES2Context*>(m_backend), static_cast<mGLES2Shader*>(m_shader.passes), m_shader.nPasses);
}
@ -598,7 +598,7 @@ void PainterGL::setShaders(struct VDir* dir) {
if (!supportsShaders()) {
return;
}
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (m_shader.passes) {
mGLES2ShaderDetach(reinterpret_cast<mGLES2Context*>(m_backend));
mGLES2ShaderFree(&m_shader);
@ -612,7 +612,7 @@ void PainterGL::clearShaders() {
if (!supportsShaders()) {
return;
}
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (m_shader.passes) {
mGLES2ShaderDetach(reinterpret_cast<mGLES2Context*>(m_backend));
mGLES2ShaderFree(&m_shader);
@ -625,7 +625,7 @@ VideoShader* PainterGL::shaders() {
}
int PainterGL::glTex() {
#ifdef BUILD_GLES2
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (supportsShaders()) {
mGLES2Context* gl2Backend = reinterpret_cast<mGLES2Context*>(m_backend);
return gl2Backend->tex;

View File

@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#pragma once
#if defined(BUILD_GL) || defined(BUILD_GLES2)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
#include "Display.h"

View File

@ -29,7 +29,7 @@ CXX_GUARD_START
#pragma GCC diagnostic pop
#endif
#if defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
#include "gl-common.h"
#include "platform/opengl/gles2.h"
#endif
@ -72,7 +72,7 @@ struct mSDLRenderer {
#ifdef BUILD_GL
struct mGLContext gl;
#endif
#if defined(BUILD_GLES2) || defined(USE_EPOXY)
#if defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
struct mGLES2Context gl2;
#endif