diff --git a/CMakeLists.txt b/CMakeLists.txt index aed19b5..8d4ee7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,20 +11,10 @@ if(GLES_COMPATIBILITY_LAYER_USE_DEFAULT_INCLUDE_PATH) target_include_directories(gles-compatibility-layer PUBLIC include) endif() -# GL Version -option(GLES_COMPATIBILITY_LAYER_USE_ES3 "Use OpenGL ES 3" TRUE) -if(GLES_COMPATIBILITY_LAYER_USE_ES3) - target_compile_definitions(gles-compatibility-layer PUBLIC GLES_COMPATIBILITY_LAYER_USE_ES3) -endif() - # Shaders include(cmake/util.cmake) -set(SHADER_FOLDER "es2") -if(GLES_COMPATIBILITY_LAYER_USE_ES3) - set(SHADER_FOLDER "es3") -endif() -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/main.vsh") +embed_resource(gles-compatibility-layer "src/shaders/main.fsh") # Warnings 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 78a4692..c3f3e23 100644 --- a/include/GLES/gl.h +++ b/include/GLES/gl.h @@ -172,20 +172,6 @@ void glLightfv(GLenum light, GLenum pname, const GLfloat *params); void glLightModelfv(GLenum pname, const GLfloat *params); void glPixelStorei(GLenum pname, GLint param); -// Not Part Of OpenGL ES 1.1 -#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3 -#define GL_SAMPLES_PASSED_ARB 0x8c2f // GL_ANY_SAMPLES_PASSED -#define GL_QUERY_RESULT_AVAILABLE_ARB 0x8867 // GL_QUERY_RESULT_AVAILABLE -#define GL_QUERY_RESULT_ARB 0x8866 // GL_QUERY_RESULT -void glGenQueriesARB(GLsizei n, GLuint *ids); -void glDeleteQueriesARB(GLsizei n, const GLuint *ids); -void glBeginQueryARB(GLenum target, GLuint id); -void glEndQueryARB(GLenum target); -void glGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params); -#endif -void extra_enable_highlight_mode(float red, float green, float blue, float alpha); -void extra_disable_highlight_mode(); - // Init typedef void *(*getProcAddress_t)(const char *); void init_gles_compatibility_layer(getProcAddress_t); diff --git a/src/draw.c b/src/draw.c index 602a926..69324a0 100644 --- a/src/draw.c +++ b/src/draw.c @@ -115,10 +115,6 @@ static GLuint get_shader() { } // Init -#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3 -GL_FUNC(glGenVertexArrays, void, (GLsizei n, GLuint *arrays)); -GL_FUNC(glBindVertexArray, void, (GLuint array)); -#endif void init_gles_compatibility_layer(getProcAddress_t new_getProcAddress) { // Setup Passthrough getProcAddress = new_getProcAddress; @@ -129,13 +125,6 @@ void init_gles_compatibility_layer(getProcAddress_t new_getProcAddress) { // Reset Static Variables reset_variables(); - // Setup VAO -#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3 - GLuint vao; - real_glGenVertexArrays()(1, &vao); - real_glBindVertexArray()(vao); -#endif - // Load Shader GLuint program = get_shader(); real_glUseProgram()(program); @@ -220,14 +209,6 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) { real_glVertexAttrib4f()(a_color_handle, gl_state.color.red, gl_state.color.green, gl_state.color.blue, gl_state.color.alpha); } - // Highlight Mode - lazy_uniform(u_highlight_mode); - real_glUniform1i()(u_highlight_mode_handle, gl_state.highlight_mode.enabled); - if (gl_state.highlight_mode.enabled) { - lazy_uniform(u_highlight_mode_color); - real_glUniform4f()(u_highlight_mode_color_handle, gl_state.highlight_mode.color.red, gl_state.highlight_mode.color.green, gl_state.highlight_mode.color.blue, gl_state.highlight_mode.color.alpha); - } - // Lighting lazy_uniform(u_lighting); real_glUniform1i()(u_lighting_handle, gl_state.lighting.enabled); diff --git a/src/passthrough.c b/src/passthrough.c index 96cd117..f325ebe 100644 --- a/src/passthrough.c +++ b/src/passthrough.c @@ -121,28 +121,6 @@ GL_FUNC(glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size, void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) { real_glBufferSubData()(target, offset, size, data); } -#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3 -GL_FUNC(glGenQueries, void, (GLsizei n, GLuint *ids)); -void glGenQueriesARB(GLsizei n, GLuint *ids) { - real_glGenQueries()(n, ids); -} -GL_FUNC(glDeleteQueries, void, (GLsizei n, const GLuint *ids)); -void glDeleteQueriesARB(GLsizei n, const GLuint *ids) { - real_glDeleteQueries()(n, ids); -} -GL_FUNC(glBeginQuery, void, (GLenum target, GLuint id)); -void glBeginQueryARB(GLenum target, GLuint id) { - real_glBeginQuery()(target, id); -} -GL_FUNC(glEndQuery, void, (GLenum target)); -void glEndQueryARB(GLenum target) { - real_glEndQuery()(target); -} -GL_FUNC(glGetQueryObjectuiv, void, (GLuint id, GLenum pname, GLuint *params)); -void glGetQueryObjectuivARB(GLuint id, GLenum pname, GLuint *params) { - real_glGetQueryObjectuiv()(id, pname, params); -} -#endif GL_FUNC(glPixelStorei, void, (GLenum pname, GLint param)); void glPixelStorei(GLenum pname, GLint param) { real_glPixelStorei()(pname, param); diff --git a/src/shaders/es3/main.fsh b/src/shaders/es3/main.fsh deleted file mode 100644 index 253455e..0000000 --- a/src/shaders/es3/main.fsh +++ /dev/null @@ -1,52 +0,0 @@ -#version 300 es -precision highp float; -// Result -out vec4 frag_color; -// Texture -uniform bool u_has_texture; -uniform sampler2D u_texture_unit; -// Color -in vec4 v_color; -in vec4 v_texture_pos; -// Highlight Mode -uniform bool u_highlight_mode; -uniform vec4 u_highlight_mode_color; -// Alpha Test -uniform bool u_alpha_test; -// Fog -uniform bool u_fog; -uniform vec4 u_fog_color; -uniform bool u_fog_is_linear; -uniform float u_fog_start; -uniform float u_fog_end; -in vec4 v_fog_eye_position; -// Main -void main(void) { - frag_color = v_color; - // Texture - if (u_has_texture) { - vec4 texture_color = texture(u_texture_unit, v_texture_pos.xy); - if (u_highlight_mode) { - texture_color.rgb = u_highlight_mode_color.rgb; - texture_color.a *= u_highlight_mode_color.a; - frag_color = texture_color; - } else { - frag_color *= texture_color; - } - } - // Fog - if (u_fog) { - float fog_factor; - if (u_fog_is_linear) { - fog_factor = (u_fog_end - length(v_fog_eye_position)) / (u_fog_end - u_fog_start); - } else { - fog_factor = exp(-u_fog_start * length(v_fog_eye_position)); - } - fog_factor = clamp(fog_factor, 0.0, 1.0); - frag_color.rgb = mix(frag_color, u_fog_color, 1.0 - fog_factor).rgb; - } - // Alpha Test - if (u_alpha_test && frag_color.a <= 0.1) { - discard; - } -} diff --git a/src/shaders/es3/main.vsh b/src/shaders/es3/main.vsh deleted file mode 100644 index 9185c20..0000000 --- a/src/shaders/es3/main.vsh +++ /dev/null @@ -1,48 +0,0 @@ -#version 300 es -precision highp float; -// Matrices -uniform mat4 u_projection; -uniform mat4 u_model_view; -uniform mat4 u_texture; -// Texture -in vec3 a_vertex_coords; -in vec2 a_texture_coords; -out vec4 v_texture_pos; -// Color -in vec4 a_color; -out vec4 v_color; -// Normal -in vec3 a_normal; -uniform float u_normal_rescale_factor; -// Lighting -uniform bool u_lighting; -uniform vec4 u_lighting_ambient; -uniform bool u_lighting_light_source_0; -uniform vec3 u_lighting_light_source_0_position; -uniform vec4 u_lighting_light_source_0_diffuse; -uniform bool u_lighting_light_source_1; -uniform vec3 u_lighting_light_source_1_position; -uniform vec4 u_lighting_light_source_1_diffuse; -// Fog -out vec4 v_fog_eye_position; -// Main -void main(void) { - v_texture_pos = u_texture * vec4(a_texture_coords.xy, 0.0, 1.0); - gl_Position = u_projection * u_model_view * vec4(a_vertex_coords.xyz, 1.0); - v_color = a_color; - v_fog_eye_position = u_model_view * vec4(a_vertex_coords.xyz, 1.0); - - // Lighting - if (u_lighting) { - vec4 transformed_normal = u_model_view * vec4(a_normal, 0.0) * u_normal_rescale_factor; - vec4 total_light = u_lighting_ambient; - if (u_lighting_light_source_0) { - total_light += max(0.0, dot(transformed_normal.xyz, u_lighting_light_source_0_position)) * u_lighting_light_source_0_diffuse; - } - if (u_lighting_light_source_1) { - total_light += max(0.0, dot(transformed_normal.xyz, u_lighting_light_source_1_position)) * u_lighting_light_source_1_diffuse; - } - total_light = clamp(total_light, 0.0, 1.0); - v_color *= total_light; - } -} diff --git a/src/shaders/es2/main.fsh b/src/shaders/main.fsh similarity index 75% rename from src/shaders/es2/main.fsh rename to src/shaders/main.fsh index ac02588..6ec0a19 100644 --- a/src/shaders/es2/main.fsh +++ b/src/shaders/main.fsh @@ -6,9 +6,6 @@ uniform sampler2D u_texture_unit; // Color varying vec4 v_color; varying vec4 v_texture_pos; -// Highlight Mode -uniform bool u_highlight_mode; -uniform vec4 u_highlight_mode_color; // Alpha Test uniform bool u_alpha_test; // Fog @@ -24,13 +21,7 @@ void main(void) { // Texture if (u_has_texture) { vec4 texture_color = texture2D(u_texture_unit, v_texture_pos.xy); - if (u_highlight_mode) { - texture_color.rgb = u_highlight_mode_color.rgb; - texture_color.a *= u_highlight_mode_color.a; - gl_FragColor = texture_color; - } else { - gl_FragColor *= texture_color; - } + gl_FragColor *= texture_color; } // Fog if (u_fog) { diff --git a/src/shaders/es2/main.vsh b/src/shaders/main.vsh similarity index 100% rename from src/shaders/es2/main.vsh rename to src/shaders/main.vsh diff --git a/src/state.c b/src/state.c index 136c65a..473c1d9 100644 --- a/src/state.c +++ b/src/state.c @@ -81,9 +81,6 @@ static gl_state_t init_gl_state = { .blue = 0.2f, .alpha = 0.2f } - }, - .highlight_mode = { - .enabled = 0 } }; gl_state_t gl_state; @@ -322,15 +319,3 @@ void glLightModelfv(GLenum pname, const GLfloat *params) { gl_state.lighting.ambient.alpha = params[3]; } } - -// Highlight Mode -void extra_enable_highlight_mode(float red, float green, float blue, float alpha) { - gl_state.highlight_mode.enabled = 1; - gl_state.highlight_mode.color.red = red; - gl_state.highlight_mode.color.green = green; - gl_state.highlight_mode.color.blue = blue; - gl_state.highlight_mode.color.alpha = alpha; -} -void extra_disable_highlight_mode() { - gl_state.highlight_mode.enabled = 0; -} diff --git a/src/state.h b/src/state.h index 5933265..5c3c9bc 100644 --- a/src/state.h +++ b/src/state.h @@ -71,10 +71,6 @@ typedef struct { light_source_t light_sources[2]; color_t ambient; } lighting; - struct { - GLboolean enabled; - color_t color; - } highlight_mode; } gl_state_t; extern gl_state_t gl_state; void _init_gles_compatibility_layer_state(); diff --git a/test/src/main.cpp b/test/src/main.cpp index 916cd3f..e807ec8 100644 --- a/test/src/main.cpp +++ b/test/src/main.cpp @@ -50,11 +50,7 @@ static void load_header(std::string filename) { } static void load_headers() { header_lines.clear(); -#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3 - load_header("/usr/include/GLES3/gl3.h"); -#else load_header("/usr/include/GLES2/gl2.h"); -#endif } // Run Test