From 3ee682f6f26dd4344f0701ae346d10250c040d8e Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Mon, 27 May 2024 03:43:28 -0400 Subject: [PATCH] Outsource glfwGetProcAddress --- CMakeLists.txt | 22 +--------------------- include/GLES/gl.h | 4 +++- src/draw.c | 5 ++++- src/passthrough.c | 5 +++-- src/passthrough.h | 11 +++-------- test/CMakeLists.txt | 5 ++++- test/src/main.cpp | 2 +- 7 files changed, 19 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 149ed0d..aed19b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,24 +27,4 @@ embed_resource(gles-compatibility-layer "src/shaders/${SHADER_FOLDER}/main.vsh") embed_resource(gles-compatibility-layer "src/shaders/${SHADER_FOLDER}/main.fsh") # Warnings -target_compile_options(gles-compatibility-layer PRIVATE -Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference) - -# GLFW/SDL -option(GLES_COMPATIBILITY_LAYER_USE_SDL "Use SDL" TRUE) -if(GLES_COMPATIBILITY_LAYER_USE_SDL) - target_compile_definitions(gles-compatibility-layer PUBLIC GLES_COMPATIBILITY_LAYER_USE_SDL) -endif() - -# Dependencies -set(GLES_COMPATIBILITY_LAYER_DEPENDENCY "" CACHE STRING "Compatibility Layer Dependency") -if(GLES_COMPATIBILITY_LAYER_DEPENDENCY STREQUAL "") - if(GLES_COMPATIBILITY_LAYER_USE_SDL) - find_package(SDL2 REQUIRED) - target_link_libraries(gles-compatibility-layer SDL2::SDL2) - else() - find_package(glfw3 3.3 REQUIRED) - target_link_libraries(gles-compatibility-layer glfw) - endif() -else() - target_link_libraries(gles-compatibility-layer "${GLES_COMPATIBILITY_LAYER_DEPENDENCY}") -endif() +target_compile_options(gles-compatibility-layer PRIVATE -Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference) \ No newline at end of file diff --git a/include/GLES/gl.h b/include/GLES/gl.h index b285e6a..78a4692 100644 --- a/include/GLES/gl.h +++ b/include/GLES/gl.h @@ -186,7 +186,9 @@ void glGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params); void extra_enable_highlight_mode(float red, float green, float blue, float alpha); void extra_disable_highlight_mode(); -void init_gles_compatibility_layer(); +// Init +typedef void *(*getProcAddress_t)(const char *); +void init_gles_compatibility_layer(getProcAddress_t); #ifdef __cplusplus } diff --git a/src/draw.c b/src/draw.c index 8dcf06d..602a926 100644 --- a/src/draw.c +++ b/src/draw.c @@ -119,7 +119,10 @@ static GLuint get_shader() { GL_FUNC(glGenVertexArrays, void, (GLsizei n, GLuint *arrays)); GL_FUNC(glBindVertexArray, void, (GLuint array)); #endif -void init_gles_compatibility_layer() { +void init_gles_compatibility_layer(getProcAddress_t new_getProcAddress) { + // Setup Passthrough + getProcAddress = new_getProcAddress; + // State _init_gles_compatibility_layer_state(); diff --git a/src/passthrough.c b/src/passthrough.c index de77113..96cd117 100644 --- a/src/passthrough.c +++ b/src/passthrough.c @@ -1,7 +1,8 @@ -#include - #include "passthrough.h" +// Get GL Function +getProcAddress_t getProcAddress; + // Simple v1.1 -> v2.0 Passthrough Functions GL_FUNC(glLineWidth, void, (GLfloat width)); void glLineWidth(GLfloat width) { diff --git a/src/passthrough.h b/src/passthrough.h index c90ec17..b335db9 100644 --- a/src/passthrough.h +++ b/src/passthrough.h @@ -1,10 +1,4 @@ -#ifdef GLES_COMPATIBILITY_LAYER_USE_SDL -#include -#else -#define GLFW_INCLUDE_NONE -#include -#define SDL_GL_GetProcAddress glfwGetProcAddress -#endif +#include #include "log.h" @@ -21,6 +15,7 @@ extern void add_test(const char *function_name); #endif // Load GL Function +extern getProcAddress_t getProcAddress; #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) #define GL_APIENTRY __stdcall #else @@ -32,7 +27,7 @@ extern void add_test(const char *function_name); real_##name##_t real_##name() { \ static real_##name##_t func = NULL; \ if (!func) { \ - func = (real_##name##_t) SDL_GL_GetProcAddress(#name); \ + func = (real_##name##_t) getProcAddress(#name); \ if (!func) { \ ERR("Error Resolving GL Symbol: " #name); \ } \ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 688ce8b..d227fef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,10 +2,13 @@ cmake_minimum_required(VERSION 3.16.0) project(gles-compatibility-layer-test) # Build Library -set(GLES_COMPATIBILITY_LAYER_USE_SDL FALSE CACHE BOOL "" FORCE) add_subdirectory(.. gles-compatibility-layer) target_compile_definitions(gles-compatibility-layer PRIVATE GLES_COMPATIBILITY_LAYER_TESTING) # Build add_executable(main src/main.cpp) target_link_libraries(main gles-compatibility-layer) + +# GLFW +find_package(glfw3 3.3 REQUIRED) +target_link_libraries(main glfw) \ No newline at end of file diff --git a/test/src/main.cpp b/test/src/main.cpp index 6cce22d..916cd3f 100644 --- a/test/src/main.cpp +++ b/test/src/main.cpp @@ -110,7 +110,7 @@ int main() { glfwMakeContextCurrent(glfw_window); // Setup Compatibility Layer - init_gles_compatibility_layer(); + init_gles_compatibility_layer((getProcAddress_t) glfwGetProcAddress); // Run Tests load_headers();