diff --git a/app/src/main/tinywrapper/es3_overrides.h b/app/src/main/tinywrapper/es3_overrides.h index cb4e33c..3e93ca8 100644 --- a/app/src/main/tinywrapper/es3_overrides.h +++ b/app/src/main/tinywrapper/es3_overrides.h @@ -27,6 +27,13 @@ void glGetTexImage( GLenum target, GLenum type, void * pixels); +void glGetQueryObjectiv( GLuint id, + GLenum pname, + GLint * params); + +void glDepthRange(GLdouble nearVal, + GLdouble farVal); + GLESOVERRIDE(glClearDepth) GLESOVERRIDE(glMapBuffer) GLESOVERRIDE(glGetTexLevelParameteriv) @@ -61,4 +68,6 @@ GLESOVERRIDE(glTexSubImage2D) GLESOVERRIDE(glCopyTexSubImage2D) GLESOVERRIDE(glTexParameteri) GLESOVERRIDE(glBindFragDataLocation) -GLESOVERRIDE(glGetTexImage) \ No newline at end of file +GLESOVERRIDE(glGetTexImage) +GLESOVERRIDE(glGetQueryObjectiv) +GLESOVERRIDE(glDepthRange) \ No newline at end of file diff --git a/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp b/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp index 324fd18..394d4a4 100644 --- a/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp +++ b/app/src/main/tinywrapper/glsl_optimizer/src/code/ir_print_glsl_visitor.cpp @@ -135,8 +135,10 @@ char * IR_TO_GLSL::Convert( if (state) { + bool print_precision = false; if(state->es_shader && state->language_version >= 300){ - res.append("#version %i es\nprecision %s float;\nprecision %s int;\n", state->language_version, "highp", "highp"); + res.append("#version %i es\n", state->language_version); + print_precision = true; } else res.append("#version %i\n", state->language_version); @@ -170,6 +172,27 @@ char * IR_TO_GLSL::Convert( if (state->EXT_texture_array_enable) res.append("#extension GL_EXT_texture_array : enable\n"); + // Search for internal GL variables and enable extensions based on them + foreach_in_list(ir_instruction, ir, instructions) + { + // Skip non-variables + if(ir->ir_type != ir_type_variable) continue; + auto* var = (ir_variable*)ir; + // Skip non-internal variables + if(strstr(var->name, "gl_") != var->name) continue; + const char* name = var->name; + // If gl_ClipDistance or gl_CullDistance is in use, enable the corresponding GLES extension + if((strstr(name, "gl_ClipDistance") != nullptr || strstr(name, "gl_CullDistance") != nullptr) && !state->EXT_clip_cull_distance_enable) { + state->EXT_clip_cull_distance_enable = true; + res.append("#extension GL_EXT_clip_cull_distance : enable\n"); + } + + } + + if(print_precision) { + res.append("precision %s float;\nprecision %s int;\n", "highp", "highp"); + } + for (unsigned i = 0; i < state->num_user_structures; i++) { const glsl_type* const s = state->user_structures[i]; diff --git a/app/src/main/tinywrapper/main.c b/app/src/main/tinywrapper/main.c index 875a645..a592fd0 100644 --- a/app/src/main/tinywrapper/main.c +++ b/app/src/main/tinywrapper/main.c @@ -236,6 +236,20 @@ void glGetIntegerv(GLenum pname, GLint* data) { } } +void glGetQueryObjectiv( GLuint id, + GLenum pname, + GLint * params) { + if(!current_context) return; + // This is not recommended but i don't care + es3_functions.glGetQueryObjectuiv(id, pname, (GLuint*)params); +} + +void glDepthRange(GLdouble nearVal, + GLdouble farVal) { + if(!current_context) return; + es3_functions.glDepthRangef((GLfloat)nearVal, (GLfloat)farVal); +} + void glDebugMessageControl( GLenum source, GLenum type, GLenum severity,