diff --git a/client/renderers/EGL/CMakeLists.txt b/client/renderers/EGL/CMakeLists.txt index 956aaa5f..824e1e7b 100644 --- a/client/renderers/EGL/CMakeLists.txt +++ b/client/renderers/EGL/CMakeLists.txt @@ -36,7 +36,7 @@ make_object( make_defines( "${CMAKE_CURRENT_SOURCE_DIR}/shader/desktop_rgb.frag" - "${CMAKE_CURRENT_BINARY_DIR}/shader/desktop_rgh.def.h" + "${CMAKE_CURRENT_BINARY_DIR}/shader/desktop_rgb.def.h" ) add_library(renderer_EGL STATIC @@ -53,7 +53,7 @@ add_library(renderer_EGL STATIC splash.c alert.c ${EGL_SHADER_OBJS} - "${EGL_SHADER_INCS}/desktop_rgh.def.h" + "${EGL_SHADER_INCS}/desktop_rgb.def.h" ) target_link_libraries(renderer_EGL diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index 45b27adf..50fd6c0c 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -33,7 +33,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA // these headers are auto generated by cmake #include "desktop.vert.h" #include "desktop_rgb.frag.h" -#include "desktop_rgh.def.h" +#include "desktop_rgb.def.h" struct DesktopShader { @@ -61,6 +61,9 @@ struct EGL_Desktop // shader instances struct DesktopShader shader_generic; + // scale algorithm + int scaleAlgo; + // night vision int nvMax; int nvGain; @@ -71,6 +74,7 @@ struct EGL_Desktop // forwards void egl_desktop_toggle_nv(int key, void * opaque); +void egl_desktop_toggle_scale_algo(int key, void * opaque); static bool egl_init_desktop_shader( struct DesktopShader * shader, @@ -136,6 +140,7 @@ bool egl_desktop_init(EGL_Desktop ** desktop, EGLDisplay * display) egl_model_set_texture((*desktop)->model, (*desktop)->texture); app_registerKeybind(KEY_N, egl_desktop_toggle_nv, *desktop, "Toggle night vision mode"); + app_registerKeybind(KEY_S, egl_desktop_toggle_scale_algo, *desktop, "Toggle scale algorithm"); (*desktop)->nvMax = option_get_int("egl", "nvGainMax"); (*desktop)->nvGain = option_get_int("egl", "nvGain" ); @@ -155,6 +160,30 @@ void egl_desktop_toggle_nv(int key, void * opaque) else app_alert(LG_ALERT_INFO, "NV Gain + %d", desktop->nvGain - 1); } +static const char * egl_desktop_scale_algo_name(int algorithm) +{ + switch (algorithm) + { + case EGL_SCALE_AUTO: + return "Automatic (downscale: linear, upscale: nearest)"; + case EGL_SCALE_NEAREST: + return "Nearest"; + case EGL_SCALE_LINEAR: + return "Linear"; + default: + return "(unknown)"; + } +} + +void egl_desktop_toggle_scale_algo(int key, void * opaque) +{ + EGL_Desktop * desktop = (EGL_Desktop *)opaque; + if (++desktop->scaleAlgo == EGL_SCALE_MAX) + desktop->scaleAlgo = 0; + + app_alert(LG_ALERT_INFO, "Scale Algorithm: %s", egl_desktop_scale_algo_name(desktop->scaleAlgo)); +} + void egl_desktop_free(EGL_Desktop ** desktop) { if (!*desktop) @@ -248,18 +277,26 @@ bool egl_desktop_render(EGL_Desktop * desktop, const float x, const float y, if (!desktop->shader) return false; - int scaleAlgo = LG_SCALE_NEAREST; + int scaleAlgo = EGL_SCALE_NEAREST; - switch (scaleType) + switch (desktop->scaleAlgo) { - case EGL_DESKTOP_NOSCALE: - case EGL_DESKTOP_UPSCALE: - scaleAlgo = LG_SCALE_NEAREST; + case EGL_SCALE_AUTO: + switch (scaleType) + { + case EGL_DESKTOP_NOSCALE: + case EGL_DESKTOP_UPSCALE: + scaleAlgo = EGL_SCALE_NEAREST; + break; + + case EGL_DESKTOP_DOWNSCALE: + scaleAlgo = EGL_SCALE_LINEAR; + break; + } break; - case EGL_DESKTOP_DOWNSCALE: - scaleAlgo = LG_SCALE_LINEAR; - break; + default: + scaleAlgo = desktop->scaleAlgo; } const struct DesktopShader * shader = desktop->shader; diff --git a/client/renderers/EGL/shader/desktop_rgb.frag b/client/renderers/EGL/shader/desktop_rgb.frag index 45abb8b1..51d6db62 100644 --- a/client/renderers/EGL/shader/desktop_rgb.frag +++ b/client/renderers/EGL/shader/desktop_rgb.frag @@ -1,7 +1,9 @@ #version 300 es -#define LG_SCALE_NEAREST 0 -#define LG_SCALE_LINEAR 1 +#define EGL_SCALE_AUTO 0 +#define EGL_SCALE_NEAREST 1 +#define EGL_SCALE_LINEAR 2 +#define EGL_SCALE_MAX 3 in highp vec2 uv; out highp vec4 color; @@ -41,11 +43,11 @@ void main() switch (scaleAlgo) { - case LG_SCALE_NEAREST: + case EGL_SCALE_NEAREST: color = texelFetch(sampler1, ivec2(ruv * size), 0); break; - case LG_SCALE_LINEAR: + case EGL_SCALE_LINEAR: color = texture(sampler1, ruv); break; }