Outsource glfwGetProcAddress

This commit is contained in:
TheBrokenRail 2024-05-27 03:43:28 -04:00
parent 67a8d026aa
commit 3ee682f6f2
7 changed files with 19 additions and 35 deletions

View File

@ -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") embed_resource(gles-compatibility-layer "src/shaders/${SHADER_FOLDER}/main.fsh")
# Warnings # Warnings
target_compile_options(gles-compatibility-layer PRIVATE -Wall -Wextra -Werror -Wpointer-arith -Wshadow -Wnull-dereference) 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()

View File

@ -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_enable_highlight_mode(float red, float green, float blue, float alpha);
void extra_disable_highlight_mode(); 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 #ifdef __cplusplus
} }

View File

@ -119,7 +119,10 @@ static GLuint get_shader() {
GL_FUNC(glGenVertexArrays, void, (GLsizei n, GLuint *arrays)); GL_FUNC(glGenVertexArrays, void, (GLsizei n, GLuint *arrays));
GL_FUNC(glBindVertexArray, void, (GLuint array)); GL_FUNC(glBindVertexArray, void, (GLuint array));
#endif #endif
void init_gles_compatibility_layer() { void init_gles_compatibility_layer(getProcAddress_t new_getProcAddress) {
// Setup Passthrough
getProcAddress = new_getProcAddress;
// State // State
_init_gles_compatibility_layer_state(); _init_gles_compatibility_layer_state();

View File

@ -1,7 +1,8 @@
#include <GLES/gl.h>
#include "passthrough.h" #include "passthrough.h"
// Get GL Function
getProcAddress_t getProcAddress;
// Simple v1.1 -> v2.0 Passthrough Functions // Simple v1.1 -> v2.0 Passthrough Functions
GL_FUNC(glLineWidth, void, (GLfloat width)); GL_FUNC(glLineWidth, void, (GLfloat width));
void glLineWidth(GLfloat width) { void glLineWidth(GLfloat width) {

View File

@ -1,10 +1,4 @@
#ifdef GLES_COMPATIBILITY_LAYER_USE_SDL #include <GLES/gl.h>
#include <SDL.h>
#else
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#define SDL_GL_GetProcAddress glfwGetProcAddress
#endif
#include "log.h" #include "log.h"
@ -21,6 +15,7 @@ extern void add_test(const char *function_name);
#endif #endif
// Load GL Function // Load GL Function
extern getProcAddress_t getProcAddress;
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__) #if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
#define GL_APIENTRY __stdcall #define GL_APIENTRY __stdcall
#else #else
@ -32,7 +27,7 @@ extern void add_test(const char *function_name);
real_##name##_t real_##name() { \ real_##name##_t real_##name() { \
static real_##name##_t func = NULL; \ static real_##name##_t func = NULL; \
if (!func) { \ if (!func) { \
func = (real_##name##_t) SDL_GL_GetProcAddress(#name); \ func = (real_##name##_t) getProcAddress(#name); \
if (!func) { \ if (!func) { \
ERR("Error Resolving GL Symbol: " #name); \ ERR("Error Resolving GL Symbol: " #name); \
} \ } \

View File

@ -2,10 +2,13 @@ cmake_minimum_required(VERSION 3.16.0)
project(gles-compatibility-layer-test) project(gles-compatibility-layer-test)
# Build Library # Build Library
set(GLES_COMPATIBILITY_LAYER_USE_SDL FALSE CACHE BOOL "" FORCE)
add_subdirectory(.. gles-compatibility-layer) add_subdirectory(.. gles-compatibility-layer)
target_compile_definitions(gles-compatibility-layer PRIVATE GLES_COMPATIBILITY_LAYER_TESTING) target_compile_definitions(gles-compatibility-layer PRIVATE GLES_COMPATIBILITY_LAYER_TESTING)
# Build # Build
add_executable(main src/main.cpp) add_executable(main src/main.cpp)
target_link_libraries(main gles-compatibility-layer) target_link_libraries(main gles-compatibility-layer)
# GLFW
find_package(glfw3 3.3 REQUIRED)
target_link_libraries(main glfw)

View File

@ -110,7 +110,7 @@ int main() {
glfwMakeContextCurrent(glfw_window); glfwMakeContextCurrent(glfw_window);
// Setup Compatibility Layer // Setup Compatibility Layer
init_gles_compatibility_layer(); init_gles_compatibility_layer((getProcAddress_t) glfwGetProcAddress);
// Run Tests // Run Tests
load_headers(); load_headers();