From c4001c727a2bd61de39a2d491eb32e2a790aafe2 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 29 Mar 2019 00:15:14 +1100 Subject: [PATCH] [client] egl: added new super+N binding to increase image gain This feture is to allow the use of the key combination +N to increase the brightness of the screen when using monitors with poor backlighting. Can help in some games. N = Night vision --- VERSION | 2 +- client/renderers/EGL/desktop.c | 35 ++++++++++++++++++++ client/renderers/EGL/shader/desktop_rgb.frag | 4 +++ client/renderers/EGL/shader/desktop_yuv.frag | 5 +++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index bdefff8e..f225eb43 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -a12-124-g5aef2422e0+1 \ No newline at end of file +a12-124-gfd4cfc2ff3+1 \ No newline at end of file diff --git a/client/renderers/EGL/desktop.c b/client/renderers/EGL/desktop.c index 16ec0199..42acb343 100644 --- a/client/renderers/EGL/desktop.c +++ b/client/renderers/EGL/desktop.c @@ -28,6 +28,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include +#include "interface/app.h" + // these headers are auto generated by cmake #include "desktop.vert.h" #include "desktop_rgb.frag.h" @@ -45,6 +47,7 @@ struct EGL_Desktop // uniforms GLint uDesktopPos; + GLint uNV, uNVGain; // internals enum EGL_PixelFormat pixFmt; @@ -52,8 +55,16 @@ struct EGL_Desktop unsigned int pitch; const uint8_t * data; bool update; + + // night vision + KeybindHandle kbNV; + bool nv; + int nvGain; }; +// forwards +void egl_desktop_toggle_nv(SDL_Scancode key, void * opaque); + bool egl_desktop_init(EGL_Desktop ** desktop) { *desktop = (EGL_Desktop *)malloc(sizeof(EGL_Desktop)); @@ -108,9 +119,19 @@ bool egl_desktop_init(EGL_Desktop ** desktop) egl_model_set_default((*desktop)->model); egl_model_set_texture((*desktop)->model, (*desktop)->texture); + (*desktop)->kbNV = app_register_keybind(SDL_SCANCODE_N, egl_desktop_toggle_nv, *desktop); + return true; } + +void egl_desktop_toggle_nv(SDL_Scancode key, void * opaque) +{ + EGL_Desktop * desktop = (EGL_Desktop *)opaque; + if (++desktop->nvGain == 4) + desktop->nvGain = 0; +} + void egl_desktop_free(EGL_Desktop ** desktop) { if (!*desktop) @@ -121,6 +142,8 @@ void egl_desktop_free(EGL_Desktop ** desktop) egl_shader_free (&(*desktop)->shader_yuv ); egl_model_free (&(*desktop)->model ); + app_release_keybind(&(*desktop)->kbNV); + free(*desktop); *desktop = NULL; } @@ -172,7 +195,11 @@ bool egl_desktop_perform_update(EGL_Desktop * desktop, const bool sourceChanged) if (sourceChanged) { if (desktop->shader) + { desktop->uDesktopPos = egl_shader_get_uniform_location(desktop->shader, "position"); + desktop->uNV = egl_shader_get_uniform_location(desktop->shader, "nv" ); + desktop->uNVGain = egl_shader_get_uniform_location(desktop->shader, "nvGain" ); + } if (!egl_texture_setup( desktop->texture, @@ -208,5 +235,13 @@ void egl_desktop_render(EGL_Desktop * desktop, const float x, const float y, con egl_shader_use(desktop->shader); glUniform4f(desktop->uDesktopPos, x, y, scaleX, scaleY); + if (desktop->nvGain) + { + glUniform1i(desktop->uNV, 1); + glUniform1f(desktop->uNVGain, (float)(desktop->nvGain+1)); + } + else + glUniform1i(desktop->uNV, 0); + egl_model_render(desktop->model); } \ No newline at end of file diff --git a/client/renderers/EGL/shader/desktop_rgb.frag b/client/renderers/EGL/shader/desktop_rgb.frag index a435c6d9..19966525 100644 --- a/client/renderers/EGL/shader/desktop_rgb.frag +++ b/client/renderers/EGL/shader/desktop_rgb.frag @@ -4,8 +4,12 @@ in highp vec2 uv; out highp vec4 color; uniform sampler2D sampler1; +uniform int nv; +uniform highp float nvGain; void main() { color = texture(sampler1, uv); + if (nv == 1) + color *= nvGain; } diff --git a/client/renderers/EGL/shader/desktop_yuv.frag b/client/renderers/EGL/shader/desktop_yuv.frag index 98643bc3..2e1efbb2 100644 --- a/client/renderers/EGL/shader/desktop_yuv.frag +++ b/client/renderers/EGL/shader/desktop_yuv.frag @@ -3,6 +3,9 @@ in highp vec2 uv; out highp vec4 color; +uniform int nv; +uniform highp float nvGain; + uniform sampler2D sampler1; uniform sampler2D sampler2; uniform sampler2D sampler3; @@ -24,4 +27,6 @@ void main() ); color = yuv * yuv_to_rgb; + if (nv == 1) + color *= nvGain; }