Revert "OpenGL: Attempt to fix some build configurations (fixes #1839)"

This reverts commit d68bf5bd1a.
This commit is contained in:
Vicki Pfau 2020-08-04 23:17:09 -07:00
parent d68bf5bd1a
commit cee1a3e08c
11 changed files with 50 additions and 72 deletions

View File

@ -70,7 +70,7 @@ if(NOT LIBMGBA_ONLY)
set(SKIP_LIBRARY OFF CACHE BOOL "Skip building the library (useful for only building libretro or OpenEmu cores)")
set(BUILD_GL ON CACHE BOOL "Build with OpenGL")
set(BUILD_GLES2 ON CACHE BOOL "Build with OpenGL|ES 2")
set(BUILD_GLES3 ON CACHE BOOL "Build with OpenGL|ES 3")
set(BUILD_GLES3 OFF CACHE BOOL "Build with OpenGL|ES 3")
set(USE_EPOXY ON CACHE STRING "Build with libepoxy")
set(DISABLE_DEPS OFF CACHE BOOL "Build without dependencies")
set(DISTBUILD OFF CACHE BOOL "Build distribution packages")
@ -427,7 +427,6 @@ 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)
@ -437,26 +436,18 @@ endif()
if(NOT BUILD_GL)
set(OPENGL_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(BUILD_GLES2 AND NOT BUILD_RASPI)
if(BUILD_GLES2 AND NOT BUILD_RASPI AND NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|Darwin|Linux|.*BSD|DragonFly|Haiku)$")
find_path(OPENGLES2_INCLUDE_DIR NAMES GLES2/gl2.h)
find_library(OPENGLES2_LIBRARY NAMES GLESv2 GLESv2_CM)
if(NOT OPENGLES2_INCLUDE_DIR OR NOT OPENGLES2_LIBRARY)
set(BUILD_GLES2 OFF CACHE BOOL "OpenGL|ES 2 not found" FORCE)
endif()
endif()
if(BUILD_GLES3)
find_path(OPENGLES3_INCLUDE_DIR NAMES GLES3/gl3.h)
find_library(OPENGLES3_LIBRARY NAMES GLESv3 GLESv2)
if(NOT OPENGLES3_INCLUDE_DIR OR NOT OPENGLES3_LIBRARY)
set(BUILD_GLES3 OFF CACHE BOOL "OpenGL|ES 3 not found" FORCE)
endif()
if(NOT BUILD_GLES2)
set(OPENGLES2_LIBRARY "" CACHE PATH "" FORCE)
endif()
if(BUILD_GL)
list(APPEND OS_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c
${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c)
list(APPEND DEPENDENCY_LIB ${OPENGL_LIBRARY})
include_directories(${OPENGL_INCLUDE_DIR})
endif()
@ -466,9 +457,11 @@ if(BUILD_GLES2)
include_directories(${OPENGLES2_INCLUDE_DIR})
endif()
if(BUILD_GLES3)
list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
list(APPEND DEPENDENCY_LIB ${OPENGLES3_LIBRARY})
include_directories(${OPENGLES3_INCLUDE_DIR})
find_path(OPENGLES3_INCLUDE_DIR NAMES GLES3/gl3.h)
find_library(OPENGLES3_LIBRARY NAMES GLESv3 GLESv2)
if(NOT OPENGLES3_INCLUDE_DIR OR NOT OPENGLES3_LIBRARY)
set(BUILD_GLES3 OFF CACHE BOOL "OpenGL|ES 3 not found" FORCE)
endif()
endif()
if(DISABLE_DEPS)
@ -707,7 +700,7 @@ endif()
if(USE_EPOXY)
list(APPEND OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gl.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/opengl/gles2.c)
add_definitions(-DBUILD_GL -DBUILD_GLES2 -DBUILD_GLES3)
add_definitions(-DBUILD_GL -DBUILD_GLES2)
list(APPEND FEATURES EPOXY)
include_directories(AFTER ${EPOXY_INCLUDE_DIRS})
link_directories(${EPOXY_LIBRARY_DIRS})
@ -904,7 +897,7 @@ else()
endif()
if(BUILD_GL)
add_definitions(-DBUILD_GL -DBUILD_GLES2 -DBUILD_GLES3)
add_definitions(-DBUILD_GL)
endif()
if(BUILD_GLES2)

View File

@ -16,7 +16,7 @@ CXX_GUARD_START
#include <mgba/internal/gba/renderers/common.h>
#include <mgba/internal/gba/video.h>
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef USE_EPOXY
#include <epoxy/gl.h>

View File

@ -18,7 +18,7 @@
#ifndef DISABLE_THREADING
#include <mgba/feature/thread-proxy.h>
#endif
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#include <mgba/internal/gba/renderers/gl.h>
#endif
#include <mgba/internal/gba/renderers/proxy.h>
@ -131,7 +131,7 @@ struct GBACore {
struct mCore d;
struct GBAVideoRenderer dummyRenderer;
struct GBAVideoSoftwareRenderer renderer;
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
struct GBAVideoGLRenderer glRenderer;
#endif
#ifndef MINIMAL_CORE
@ -189,7 +189,7 @@ static bool _GBACoreInit(struct mCore* core) {
GBAVideoSoftwareRendererCreate(&gbacore->renderer);
gbacore->renderer.outputBuffer = NULL;
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
GBAVideoGLRendererCreate(&gbacore->glRenderer);
gbacore->glRenderer.outputTex = -1;
#endif
@ -241,7 +241,7 @@ static bool _GBACoreSupportsFeature(const struct mCore* core, enum mCoreFeature
UNUSED(core);
switch (feature) {
case mCORE_FEATURE_OPENGL:
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
return true;
#else
return false;
@ -353,7 +353,7 @@ static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, c
}
struct GBACore* gbacore = (struct GBACore*) core;
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (strcmp("videoScale", option) == 0) {
if (config != &core->config) {
mCoreConfigCopyValue(&core->config, config, "videoScale");
@ -371,7 +371,7 @@ static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, c
if (gbacore->renderer.outputBuffer) {
renderer = &gbacore->renderer.d;
}
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (gbacore->glRenderer.outputTex != (unsigned) -1 && mCoreConfigGetIntValue(&core->config, "hwaccelVideo", &fakeBool) && fakeBool) {
mCoreConfigGetIntValue(&core->config, "videoScale", &gbacore->glRenderer.scale);
renderer = &gbacore->glRenderer.d;
@ -393,7 +393,7 @@ static void _GBACoreReloadConfigOption(struct mCore* core, const char* option, c
}
static void _GBACoreDesiredVideoDimensions(const struct mCore* core, unsigned* width, unsigned* height) {
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
const struct GBACore* gbacore = (const struct GBACore*) core;
int scale = gbacore->glRenderer.scale;
#else
@ -413,7 +413,7 @@ static void _GBACoreSetVideoBuffer(struct mCore* core, color_t* buffer, size_t s
}
static void _GBACoreSetVideoGLTex(struct mCore* core, unsigned texid) {
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
struct GBACore* gbacore = (struct GBACore*) core;
gbacore->glRenderer.outputTex = texid;
#else
@ -547,7 +547,7 @@ static void _GBACoreReset(struct mCore* core) {
struct GBACore* gbacore = (struct GBACore*) core;
struct GBA* gba = (struct GBA*) core->board;
if (gbacore->renderer.outputBuffer
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
|| gbacore->glRenderer.outputTex != (unsigned) -1
#endif
) {
@ -556,7 +556,7 @@ static void _GBACoreReset(struct mCore* core) {
renderer = &gbacore->renderer.d;
}
int fakeBool ATTRIBUTE_UNUSED;
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
if (gbacore->glRenderer.outputTex != (unsigned) -1 && mCoreConfigGetIntValue(&core->config, "hwaccelVideo", &fakeBool) && fakeBool) {
mCoreConfigGetIntValue(&core->config, "videoScale", &gbacore->glRenderer.scale);
renderer = &gbacore->glRenderer.d;

View File

@ -5,7 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba/internal/gba/renderers/gl.h>
#ifdef BUILD_GLES3
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#include <mgba/core/cache-set.h>
#include <mgba/internal/arm/macros.h>

View File

@ -159,7 +159,6 @@ static void mGLES2ContextInit(struct VideoBackend* v, WHandle handle) {
mGLES2ShaderInit(&context->finalShader, 0, 0, 0, 0, false, 0, 0);
mGLES2ShaderInit(&context->interframeShader, 0, _interframeFragmentShader, -1, -1, false, 0, 0);
#ifdef BUILD_GLES3
if (context->initialShader.vao != (GLuint) -1) {
glBindVertexArray(context->initialShader.vao);
glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
@ -169,7 +168,6 @@ static void mGLES2ContextInit(struct VideoBackend* v, WHandle handle) {
glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
glBindVertexArray(0);
}
#endif
glDeleteFramebuffers(1, &context->finalShader.fbo);
glDeleteTextures(1, &context->finalShader.tex);
@ -307,12 +305,9 @@ void _drawShader(struct mGLES2Context* context, struct mGLES2Shader* shader) {
glUseProgram(shader->program);
glUniform1i(shader->texLocation, 0);
glUniform2f(shader->texSizeLocation, context->d.width - padW, context->d.height - padH);
#ifdef BUILD_GLES3
if (shader->vao != (GLuint) -1) {
glBindVertexArray(shader->vao);
} else
#endif
{
} else {
glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
glEnableVertexAttribArray(shader->positionLocation);
glVertexAttribPointer(shader->positionLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
@ -404,11 +399,9 @@ void mGLES2ContextDrawFrame(struct VideoBackend* v) {
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glUseProgram(0);
#ifdef BUILD_GLES3
if (context->finalShader.vao != (GLuint) -1) {
glBindVertexArray(0);
}
#endif
}
void mGLES2ContextPostFrame(struct VideoBackend* v, const void* frame) {
@ -523,7 +516,6 @@ void mGLES2ShaderInit(struct mGLES2Shader* shader, const char* vs, const char* f
shader->uniforms[i].location = glGetUniformLocation(shader->program, shader->uniforms[i].name);
}
#ifdef BUILD_GLES3
const GLubyte* extensions = glGetString(GL_EXTENSIONS);
if (shaderBuffer[0] == _gles2Header || version[0] >= '3' || (extensions && strstr((const char*) extensions, "_vertex_array_object") != NULL)) {
glGenVertexArrays(1, &shader->vao);
@ -531,9 +523,7 @@ void mGLES2ShaderInit(struct mGLES2Shader* shader, const char* vs, const char* f
glEnableVertexAttribArray(shader->positionLocation);
glVertexAttribPointer(shader->positionLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
glBindVertexArray(0);
} else
#endif
{
} else {
shader->vao = -1;
}
@ -545,11 +535,9 @@ void mGLES2ShaderDeinit(struct mGLES2Shader* shader) {
glDeleteShader(shader->fragmentShader);
glDeleteProgram(shader->program);
glDeleteFramebuffers(1, &shader->fbo);
#ifdef BUILD_GLES3
if (shader->vao != (GLuint) -1) {
glDeleteVertexArrays(1, &shader->vao);
}
#endif
}
void mGLES2ShaderAttach(struct mGLES2Context* context, struct mGLES2Shader* shaders, size_t nShaders) {
@ -567,20 +555,16 @@ void mGLES2ShaderAttach(struct mGLES2Context* context, struct mGLES2Shader* shad
glClearColor(0.f, 0.f, 0.f, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
#ifdef BUILD_GLES3
if (context->shaders[i].vao != (GLuint) -1) {
glBindVertexArray(context->shaders[i].vao);
glBindBuffer(GL_ARRAY_BUFFER, context->vbo);
glEnableVertexAttribArray(context->shaders[i].positionLocation);
glVertexAttribPointer(context->shaders[i].positionLocation, 2, GL_FLOAT, GL_FALSE, 0, NULL);
}
#endif
}
#ifdef BUILD_GLES3
if (context->initialShader.vao != (GLuint) -1) {
glBindVertexArray(0);
}
#endif
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

View File

@ -22,9 +22,6 @@ CXX_GUARD_START
#endif
#else
#include <GLES2/gl2.h>
#ifdef BUILD_GLES3
#include <GLES3/gl3.h>
#endif
#endif
#include "platform/video-backend.h"

View File

@ -24,7 +24,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(Qt5 COMPONENTS Core Widgets OpenGL Network Multimedia)
if(NOT BUILD_GL AND NOT BUILD_GLES2 AND NOT BUILD_GLES3)
if(NOT BUILD_GL AND NOT BUILD_GLES2)
message(WARNING "OpenGL is recommended to build the Qt port")
endif()
@ -241,7 +241,7 @@ if(NOT DEFINED DATADIR)
set(DATADIR ${CMAKE_INSTALL_DATADIR}/${BINARY_NAME})
endif()
endif()
if(BUILD_GLES2 OR BUILD_GLES3 OR BUILD_EPOXY)
if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/res/shaders DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
endif()
install(FILES ${CMAKE_SOURCE_DIR}/res/nointro.dat DESTINATION ${DATADIR} COMPONENT ${BINARY_NAME}-qt)
@ -291,8 +291,8 @@ if(WIN32)
endif()
list(APPEND QT_LIBRARIES Qt5::Widgets Qt5::Network)
if(BUILD_GL OR BUILD_GLES2 OR BUILD_GLES3 OR BUILD_EPOXY)
list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY} ${OPENGLES3_LIBRARY})
if(BUILD_GL OR BUILD_GLES2 OR BUILD_EPOXY)
list(APPEND QT_LIBRARIES Qt5::OpenGL ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
endif()
if(QT_STATIC)
find_library(QTPCRE NAMES qtpcre2 qtpcre)
@ -302,7 +302,7 @@ if(QT_STATIC)
endif()
list(APPEND QT_LIBRARIES Qt5::QWindowsIntegrationPlugin ${QWINDOWS_DEPS} dwmapi uxtheme imm32 -static-libgcc -static-libstdc++)
set_target_properties(Qt5::Core PROPERTIES INTERFACE_LINK_LIBRARIES "${QTPCRE};version;winmm;ssl;crypto;ws2_32;iphlpapi;crypt32;userenv;netapi32;wtsapi32")
set_target_properties(Qt5::Gui PROPERTIES INTERFACE_LINK_LIBRARIES ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY} ${OPENGLES3_LIBRARY})
set_target_properties(Qt5::Gui PROPERTIES INTERFACE_LINK_LIBRARIES ${OPENGL_LIBRARY} ${OPENGLES2_LIBRARY})
elseif(APPLE)
find_package(Cups)
find_package(Qt5PrintSupport)

View File

@ -10,21 +10,21 @@
using namespace QGBA;
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || 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(BUILD_GLES3) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
QSurfaceFormat format;
format.setSwapInterval(1);
format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
#endif
switch (s_driver) {
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
case Driver::OPENGL:
if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES) {
format.setVersion(3, 0);
@ -44,7 +44,7 @@ Display* Display::create(QWidget* parent) {
return new DisplayQt(parent);
default:
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(BUILD_GLES3) || defined(USE_EPOXY)
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
return new DisplayGL(format, parent);
#else
return new DisplayQt(parent);

View File

@ -27,8 +27,12 @@ Q_OBJECT
public:
enum class Driver {
QT = 0,
#if defined(BUILD_GL) || defined(BUILD_GLES2) || defined(USE_EPOXY)
OPENGL = 1,
#endif
#ifdef BUILD_GL
OPENGL1 = 2,
#endif
};
Display(QWidget* parent = nullptr);

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) || defined(BUILD_GLES3)
#if defined(BUILD_GL) || defined(BUILD_GLES2)
#include "CoreController.h"
@ -23,7 +23,7 @@
#ifdef BUILD_GL
#include "platform/opengl/gl.h"
#endif
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
#include "platform/opengl/gles2.h"
#ifdef _WIN32
#include <epoxy/wgl.h>
@ -265,7 +265,7 @@ PainterGL::PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion)
#ifdef BUILD_GL
mGLContext* glBackend;
#endif
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
mGLES2Context* gl2Backend;
#endif
@ -284,7 +284,7 @@ PainterGL::PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion)
epoxy_handle_external_wglMakeCurrent();
#endif
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
auto version = m_gl->format().version();
QStringList extensions = QString(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS))).split(' ');
if (forceVersion != 1 && ((version == qMakePair(2, 1) && extensions.contains("GL_ARB_framebuffer_object")) || version.first > 2)) {
@ -316,7 +316,7 @@ PainterGL::PainterGL(QWindow* surface, QOpenGLContext* parent, int forceVersion)
};
m_backend->init(m_backend, 0);
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
if (m_supportsShaders) {
m_shader.preprocessShader = static_cast<void*>(&reinterpret_cast<mGLES2Context*>(m_backend)->initialShader);
}
@ -337,7 +337,7 @@ PainterGL::~PainterGL() {
#if defined(_WIN32) && defined(USE_EPOXY)
epoxy_handle_external_wglMakeCurrent();
#endif
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
if (m_shader.passes) {
mGLES2ShaderFree(&m_shader);
}
@ -411,7 +411,7 @@ void PainterGL::start() {
epoxy_handle_external_wglMakeCurrent();
#endif
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
if (m_supportsShaders && m_shader.passes) {
mGLES2ShaderAttach(reinterpret_cast<mGLES2Context*>(m_backend), static_cast<mGLES2Shader*>(m_shader.passes), m_shader.nPasses);
}
@ -552,7 +552,7 @@ void PainterGL::setShaders(struct VDir* dir) {
if (!supportsShaders()) {
return;
}
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
if (!m_started) {
m_gl->makeCurrent(m_surface);
#if defined(_WIN32) && defined(USE_EPOXY)
@ -576,7 +576,7 @@ void PainterGL::clearShaders() {
if (!supportsShaders()) {
return;
}
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
if (!m_started) {
m_gl->makeCurrent(m_surface);
#if defined(_WIN32) && defined(USE_EPOXY)
@ -598,7 +598,7 @@ VideoShader* PainterGL::shaders() {
}
int PainterGL::glTex() {
#if defined(BUILD_GLES2) || defined(BUILD_GLES3)
#ifdef BUILD_GLES2
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) || defined(BUILD_GLES3)
#if defined(BUILD_GL) || defined(BUILD_GLES2)
#include "Display.h"