Compare commits

..

2 Commits

Author SHA1 Message Date
de9c93663b Remove GL Lighting 2024-06-18 17:56:01 -04:00
4156520e88 Remove ES3 Support 2024-06-18 17:31:58 -04:00
12 changed files with 30 additions and 441 deletions

View File

@ -11,20 +11,10 @@ if(GLES_COMPATIBILITY_LAYER_USE_DEFAULT_INCLUDE_PATH)
target_include_directories(gles-compatibility-layer PUBLIC include) target_include_directories(gles-compatibility-layer PUBLIC include)
endif() 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 # Shaders
include(cmake/util.cmake) include(cmake/util.cmake)
set(SHADER_FOLDER "es2") embed_resource(gles-compatibility-layer "src/shaders/main.vsh")
if(GLES_COMPATIBILITY_LAYER_USE_ES3) embed_resource(gles-compatibility-layer "src/shaders/main.fsh")
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")
# 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)

View File

@ -81,22 +81,10 @@ extern "C" {
#define GL_DEPTH_BUFFER_BIT 0x100 #define GL_DEPTH_BUFFER_BIT 0x100
#define GL_COLOR_BUFFER_BIT 0x4000 #define GL_COLOR_BUFFER_BIT 0x4000
#define GL_NO_ERROR 0 #define GL_NO_ERROR 0
#define GL_NORMAL_ARRAY 0x8075
#define GL_LIGHTING 0xb50
#define GL_LIGHT0 0x4000
#define GL_LIGHT1 0x4001
#define GL_RESCALE_NORMAL 0x803a
#define GL_AMBIENT 0x1200
#define GL_DIFFUSE 0x1201
#define GL_SPECULAR 0x1202
#define GL_POSITION 0x1203
#define GL_LIGHT_MODEL_AMBIENT 0xb53
#define GL_BYTE 0x1400 #define GL_BYTE 0x1400
#define GL_ACCUM 0x100 #define GL_ACCUM 0x100
#define GL_ALPHA 0x1906 #define GL_ALPHA 0x1906
#define GL_NONE 0 #define GL_NONE 0
#define GL_LINE_SMOOTH 0xb20
#define GL_SMOOTH_LINE_WIDTH_RANGE 0xb22
#define GL_ALIASED_LINE_WIDTH_RANGE 0x846e #define GL_ALIASED_LINE_WIDTH_RANGE 0x846e
typedef float GLfloat; typedef float GLfloat;
@ -160,32 +148,15 @@ void glDisable(GLenum cap);
void glCullFace(GLenum mode); void glCullFace(GLenum mode);
void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z); void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height); void glViewport(GLint x, GLint y, GLsizei width, GLsizei height);
void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz); __attribute__((unavailable)) void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz);
GLboolean glIsEnabled(GLenum cap); GLboolean glIsEnabled(GLenum cap);
void glGetIntegerv(GLenum pname, GLint *data); void glGetIntegerv(GLenum pname, GLint *data);
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data); void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *data);
void glGenBuffers(GLsizei n, GLuint *buffers); void glGenBuffers(GLsizei n, GLuint *buffers);
GLenum glGetError(); GLenum glGetError();
void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data); void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
void glNormalPointer(GLenum type, GLsizei stride, const void *pointer);
void glLightfv(GLenum light, GLenum pname, const GLfloat *params);
void glLightModelfv(GLenum pname, const GLfloat *params);
void glPixelStorei(GLenum pname, GLint param); 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 // Init
typedef void *(*getProcAddress_t)(const char *); typedef void *(*getProcAddress_t)(const char *);
void init_gles_compatibility_layer(getProcAddress_t); void init_gles_compatibility_layer(getProcAddress_t);

View File

@ -115,10 +115,6 @@ static GLuint get_shader() {
} }
// Init // 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) { void init_gles_compatibility_layer(getProcAddress_t new_getProcAddress) {
// Setup Passthrough // Setup Passthrough
getProcAddress = new_getProcAddress; getProcAddress = new_getProcAddress;
@ -129,13 +125,6 @@ void init_gles_compatibility_layer(getProcAddress_t new_getProcAddress) {
// Reset Static Variables // Reset Static Variables
reset_variables(); reset_variables();
// Setup VAO
#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3
GLuint vao;
real_glGenVertexArrays()(1, &vao);
real_glBindVertexArray()(vao);
#endif
// Load Shader // Load Shader
GLuint program = get_shader(); GLuint program = get_shader();
real_glUseProgram()(program); real_glUseProgram()(program);
@ -172,10 +161,6 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
if (use_color_pointer && (gl_state.array_pointers.color.size != 4 || gl_state.array_pointers.color.type != GL_UNSIGNED_BYTE)) { if (use_color_pointer && (gl_state.array_pointers.color.size != 4 || gl_state.array_pointers.color.type != GL_UNSIGNED_BYTE)) {
ERR("Unsupported Color Conifguration"); ERR("Unsupported Color Conifguration");
} }
int use_normal_pointer = gl_state.lighting.enabled && gl_state.array_pointers.normal.enabled;
if (use_normal_pointer && gl_state.array_pointers.normal.type != GL_BYTE) {
ERR("Unsupported Normal Conifguration");
}
int use_texture = gl_state.texture_2d && gl_state.array_pointers.tex_coord.enabled; int use_texture = gl_state.texture_2d && gl_state.array_pointers.tex_coord.enabled;
if (use_texture && (gl_state.array_pointers.tex_coord.size != 2 || gl_state.array_pointers.tex_coord.type != GL_FLOAT)) { if (use_texture && (gl_state.array_pointers.tex_coord.size != 2 || gl_state.array_pointers.tex_coord.type != GL_FLOAT)) {
ERR("Unsupported Texture Conifguration"); ERR("Unsupported Texture Conifguration");
@ -220,49 +205,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); 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);
lazy_attrib(a_normal);
if (gl_state.lighting.enabled) {
lazy_uniform(u_lighting_ambient);
real_glUniform4f()(u_lighting_ambient_handle, gl_state.lighting.ambient.red, gl_state.lighting.ambient.green, gl_state.lighting.ambient.blue, gl_state.lighting.ambient.alpha);
light_source_t *light_source;
#define light_source_uniforms(number) \
light_source = &gl_state.lighting.light_sources[number]; \
lazy_uniform(u_lighting_light_source_##number); \
real_glUniform1i()(u_lighting_light_source_##number##_handle, light_source->enabled); \
lazy_uniform(u_lighting_light_source_##number##_position); \
real_glUniform3f()(u_lighting_light_source_##number##_position_handle, light_source->position.x, light_source->position.y, light_source->position.z); \
lazy_uniform(u_lighting_light_source_##number##_diffuse); \
real_glUniform4f()(u_lighting_light_source_##number##_diffuse_handle, light_source->diffuse.red, light_source->diffuse.green, light_source->diffuse.blue, light_source->diffuse.alpha);
light_source_uniforms(0);
light_source_uniforms(1);
// Normal
if (use_normal_pointer) {
real_glVertexAttribPointer()(a_normal_handle, 3, gl_state.array_pointers.normal.type, 1, gl_state.array_pointers.normal.stride, gl_state.array_pointers.normal.pointer);
real_glEnableVertexAttribArray()(a_normal_handle);
} else {
real_glVertexAttrib3f()(a_normal_handle, gl_state.normal.x, gl_state.normal.y, gl_state.normal.z);
}
// Normal Rescale Factor (See Pages 46-47 Of https://registry.khronos.org/OpenGL/specs/gl/glspec15.pdf)
float normal_rescale_factor = 1;
if (gl_state.rescale_normal) {
normal_rescale_factor = 1.0f / sqrtf(powf(model_view->data[0][2], 2) + powf(model_view->data[1][2], 2) + powf(model_view->data[2][2], 2));
}
lazy_uniform(u_normal_rescale_factor);
real_glUniform1f()(u_normal_rescale_factor_handle, normal_rescale_factor);
}
// Fog // Fog
lazy_uniform(u_fog); lazy_uniform(u_fog);
real_glUniform1i()(u_fog_handle, gl_state.fog.enabled); real_glUniform1i()(u_fog_handle, gl_state.fog.enabled);
@ -298,9 +240,6 @@ void glDrawArrays(GLenum mode, GLint first, GLsizei count) {
if (use_color_pointer) { if (use_color_pointer) {
real_glDisableVertexAttribArray()(a_color_handle); real_glDisableVertexAttribArray()(a_color_handle);
} }
if (use_normal_pointer) {
real_glDisableVertexAttribArray()(a_normal_handle);
}
real_glDisableVertexAttribArray()(a_vertex_coords_handle); real_glDisableVertexAttribArray()(a_vertex_coords_handle);
if (use_texture) { if (use_texture) {
real_glDisableVertexAttribArray()(a_texture_coords_handle); real_glDisableVertexAttribArray()(a_texture_coords_handle);

View File

@ -121,29 +121,10 @@ GL_FUNC(glBufferSubData, void, (GLenum target, GLintptr offset, GLsizeiptr size,
void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) { void glBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) {
real_glBufferSubData()(target, offset, size, 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)); GL_FUNC(glPixelStorei, void, (GLenum pname, GLint param));
void glPixelStorei(GLenum pname, GLint param) { void glPixelStorei(GLenum pname, GLint param) {
real_glPixelStorei()(pname, param); real_glPixelStorei()(pname, param);
} }
void glNormal3f(__attribute__((unused)) GLfloat nx, __attribute__((unused)) GLfloat ny, __attribute__((unused)) GLfloat nz) {
// Ignore
}

View File

@ -1,48 +0,0 @@
#version 100
precision highp float;
// Matrices
uniform mat4 u_projection;
uniform mat4 u_model_view;
uniform mat4 u_texture;
// Texture
attribute vec3 a_vertex_coords;
attribute vec2 a_texture_coords;
varying vec4 v_texture_pos;
// Color
attribute vec4 a_color;
varying vec4 v_color;
// Normal
attribute 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
varying 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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -6,9 +6,6 @@ uniform sampler2D u_texture_unit;
// Color // Color
varying vec4 v_color; varying vec4 v_color;
varying vec4 v_texture_pos; varying vec4 v_texture_pos;
// Highlight Mode
uniform bool u_highlight_mode;
uniform vec4 u_highlight_mode_color;
// Alpha Test // Alpha Test
uniform bool u_alpha_test; uniform bool u_alpha_test;
// Fog // Fog
@ -24,14 +21,8 @@ void main(void) {
// Texture // Texture
if (u_has_texture) { if (u_has_texture) {
vec4 texture_color = texture2D(u_texture_unit, v_texture_pos.xy); 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 // Fog
if (u_fog) { if (u_fog) {
float fog_factor; float fog_factor;

22
src/shaders/main.vsh Normal file
View File

@ -0,0 +1,22 @@
#version 100
precision highp float;
// Matrices
uniform mat4 u_projection;
uniform mat4 u_model_view;
uniform mat4 u_texture;
// Texture
attribute vec3 a_vertex_coords;
attribute vec2 a_texture_coords;
varying vec4 v_texture_pos;
// Color
attribute vec4 a_color;
varying vec4 v_color;
// Fog
varying 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);
}

View File

@ -10,13 +10,6 @@
{ \ { \
.enabled = 0 \ .enabled = 0 \
} }
#define init_light_source \
.enabled = 0, \
.position = { \
.x = 0, \
.y = 0, \
.z = 1 \
}
static gl_state_t init_gl_state = { static gl_state_t init_gl_state = {
.color = { .color = {
.red = 1, .red = 1,
@ -24,17 +17,10 @@ static gl_state_t init_gl_state = {
.blue = 1, .blue = 1,
.alpha = 1 .alpha = 1
}, },
.normal = {
.x = 0,
.y = 0,
.z = 1
},
.rescale_normal = 0,
.array_pointers = { .array_pointers = {
.vertex = init_array_pointer, .vertex = init_array_pointer,
.color = init_array_pointer, .color = init_array_pointer,
.tex_coord = init_array_pointer, .tex_coord = init_array_pointer
.normal = init_array_pointer
}, },
.matrix_stacks = { .matrix_stacks = {
.mode = GL_MODELVIEW .mode = GL_MODELVIEW
@ -52,38 +38,6 @@ static gl_state_t init_gl_state = {
}, },
.start = 0, .start = 0,
.end = 1 .end = 1
},
.lighting = {
.enabled = 0,
.light_sources = {
{
init_light_source,
.diffuse = {
.red = 1,
.green = 1,
.blue = 1,
.alpha = 1
}
},
{
init_light_source,
.diffuse = {
.red = 0,
.green = 0,
.blue = 0,
.alpha = 0
}
}
},
.ambient = {
.red = 0.2f,
.green = 0.2f,
.blue = 0.2f,
.alpha = 0.2f
}
},
.highlight_mode = {
.enabled = 0
} }
}; };
gl_state_t gl_state; gl_state_t gl_state;
@ -100,13 +54,6 @@ void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
gl_state.color.alpha = alpha; gl_state.color.alpha = alpha;
} }
// Change Normal
void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) {
gl_state.normal.x = nx;
gl_state.normal.y = ny;
gl_state.normal.z = nz;
}
// Array Pointer Storage // Array Pointer Storage
#define ARRAY_POINTER_FUNC(func, name) \ #define ARRAY_POINTER_FUNC(func, name) \
void func(GLint size, GLenum type, GLsizei stride, const void *pointer) { \ void func(GLint size, GLenum type, GLsizei stride, const void *pointer) { \
@ -118,10 +65,6 @@ void glNormal3f(GLfloat nx, GLfloat ny, GLfloat nz) {
ARRAY_POINTER_FUNC(glVertexPointer, vertex) ARRAY_POINTER_FUNC(glVertexPointer, vertex)
ARRAY_POINTER_FUNC(glColorPointer, color) ARRAY_POINTER_FUNC(glColorPointer, color)
ARRAY_POINTER_FUNC(glTexCoordPointer, tex_coord) ARRAY_POINTER_FUNC(glTexCoordPointer, tex_coord)
static ARRAY_POINTER_FUNC(fake_glNormalPointer, normal)
void glNormalPointer(GLenum type, GLsizei stride, const void *pointer) {
fake_glNormalPointer(0, type, stride, pointer);
}
static array_pointer_t *get_array_pointer(GLenum array) { static array_pointer_t *get_array_pointer(GLenum array) {
switch (array) { switch (array) {
case GL_VERTEX_ARRAY: { case GL_VERTEX_ARRAY: {
@ -133,9 +76,6 @@ static array_pointer_t *get_array_pointer(GLenum array) {
case GL_TEXTURE_COORD_ARRAY: { case GL_TEXTURE_COORD_ARRAY: {
return &gl_state.array_pointers.tex_coord; return &gl_state.array_pointers.tex_coord;
} }
case GL_NORMAL_ARRAY: {
return &gl_state.array_pointers.normal;
}
default: { default: {
ERR("Unsupported Array Pointer: %i", array); ERR("Unsupported Array Pointer: %i", array);
} }
@ -160,10 +100,6 @@ void glEnable(GLenum cap) {
gl_state.texture_2d = 1; gl_state.texture_2d = 1;
break; break;
} }
case GL_RESCALE_NORMAL: {
gl_state.rescale_normal = 1;
break;
}
case GL_COLOR_MATERIAL: { case GL_COLOR_MATERIAL: {
// Ignore // Ignore
break; break;
@ -172,15 +108,6 @@ void glEnable(GLenum cap) {
gl_state.fog.enabled = 1; gl_state.fog.enabled = 1;
break; break;
} }
case GL_LIGHTING: {
gl_state.lighting.enabled = 1;
break;
}
case GL_LIGHT0:
case GL_LIGHT1: {
gl_state.lighting.light_sources[cap - GL_LIGHT0].enabled = 1;
break;
}
default: { default: {
real_glEnable()(cap); real_glEnable()(cap);
break; break;
@ -198,10 +125,6 @@ void glDisable(GLenum cap) {
gl_state.texture_2d = 0; gl_state.texture_2d = 0;
break; break;
} }
case GL_RESCALE_NORMAL: {
gl_state.rescale_normal = 0;
break;
}
case GL_COLOR_MATERIAL: { case GL_COLOR_MATERIAL: {
// Ignore // Ignore
break; break;
@ -210,15 +133,6 @@ void glDisable(GLenum cap) {
gl_state.fog.enabled = 0; gl_state.fog.enabled = 0;
break; break;
} }
case GL_LIGHTING: {
gl_state.lighting.enabled = 0;
break;
}
case GL_LIGHT0:
case GL_LIGHT1: {
gl_state.lighting.light_sources[cap - GL_LIGHT0].enabled = 0;
break;
}
default: { default: {
real_glDisable()(cap); real_glDisable()(cap);
break; break;
@ -286,51 +200,3 @@ void glGetFloatv(GLenum pname, GLfloat *params) {
} }
} }
} }
// Configure Light Sources
void glLightfv(GLenum light, GLenum pname, const GLfloat *params) {
light_source_t *light_source = &gl_state.lighting.light_sources[light - GL_LIGHT0];
if (pname == GL_DIFFUSE) {
light_source->diffuse.red = params[0];
light_source->diffuse.green = params[1];
light_source->diffuse.blue = params[2];
light_source->diffuse.alpha = params[3];
} else if (pname == GL_POSITION) {
// Transform Position By Modelview Matrix
matrix_t model_view = gl_state.matrix_stacks.model_view.stack[gl_state.matrix_stacks.model_view.i];
GLfloat out[4];
for (int i = 0; i < 4; i++) {
GLfloat result = 0;
for (int j = 0; j < 4; j++) {
result += model_view.data[j][i] * params[j];
}
out[i] = result;
}
// Store
light_source->position.x = out[0];
light_source->position.y = out[1];
light_source->position.z = out[2];
}
}
// Global Ambient Lighting
void glLightModelfv(GLenum pname, const GLfloat *params) {
if (pname == GL_LIGHT_MODEL_AMBIENT) {
gl_state.lighting.ambient.red = params[0];
gl_state.lighting.ambient.green = params[1];
gl_state.lighting.ambient.blue = params[2];
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;
}

View File

@ -33,18 +33,9 @@ typedef struct {
const void *pointer; const void *pointer;
} array_pointer_t; } array_pointer_t;
// Light
typedef struct {
GLboolean enabled;
position_t position;
color_t diffuse;
} light_source_t;
// GL State // GL State
typedef struct { typedef struct {
color_t color; color_t color;
position_t normal;
GLboolean rescale_normal;
struct { struct {
GLenum mode; GLenum mode;
matrix_stack_t model_view; matrix_stack_t model_view;
@ -55,7 +46,6 @@ typedef struct {
array_pointer_t vertex; array_pointer_t vertex;
array_pointer_t color; array_pointer_t color;
array_pointer_t tex_coord; array_pointer_t tex_coord;
array_pointer_t normal;
} array_pointers; } array_pointers;
GLboolean alpha_test; GLboolean alpha_test;
GLboolean texture_2d; GLboolean texture_2d;
@ -66,15 +56,6 @@ typedef struct {
GLfloat start; GLfloat start;
GLfloat end; GLfloat end;
} fog; } fog;
struct {
GLboolean enabled;
light_source_t light_sources[2];
color_t ambient;
} lighting;
struct {
GLboolean enabled;
color_t color;
} highlight_mode;
} gl_state_t; } gl_state_t;
extern gl_state_t gl_state; extern gl_state_t gl_state;
void _init_gles_compatibility_layer_state(); void _init_gles_compatibility_layer_state();

View File

@ -50,11 +50,7 @@ static void load_header(std::string filename) {
} }
static void load_headers() { static void load_headers() {
header_lines.clear(); header_lines.clear();
#ifdef GLES_COMPATIBILITY_LAYER_USE_ES3
load_header("/usr/include/GLES3/gl3.h");
#else
load_header("/usr/include/GLES2/gl2.h"); load_header("/usr/include/GLES2/gl2.h");
#endif
} }
// Run Test // Run Test