From cbeae46c0b0258fd1be8760d9a6a38e7706e9862 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 15 Jan 2021 13:13:39 +1100 Subject: [PATCH] [client] egl: move rotation into the fragment shader --- client/renderers/EGL/cursor.c | 37 ++------------------ client/renderers/EGL/shader/cursor.vert | 38 +++++++++++++++------ client/renderers/EGL/shader/cursor_rgb.frag | 25 ++------------ 3 files changed, 32 insertions(+), 68 deletions(-) diff --git a/client/renderers/EGL/cursor.c b/client/renderers/EGL/cursor.c index 2fd0a8fa..d7dc5571 100644 --- a/client/renderers/EGL/cursor.c +++ b/client/renderers/EGL/cursor.c @@ -97,48 +97,15 @@ static bool egl_cursor_tex_init(struct CursorTex * t, static inline void egl_cursor_tex_uniforms(EGL_Cursor * cursor, struct CursorTex * t, bool mono) { - float x, y, w, h; - - switch(cursor->rotate) - { - case LG_ROTATE_UP: - x = cursor->x; - y = cursor->y; - w = cursor->w; - h = cursor->h; - break; - - case LG_ROTATE_DOWN: - x = -cursor->x; - y = -cursor->y; - w = cursor->w; - h = cursor->h; - break; - - case LG_ROTATE_LEFT: - x = cursor->y; - y = -cursor->x; - w = cursor->h; - h = cursor->w; - break; - - case LG_ROTATE_RIGHT: - x = -cursor->y; - y = cursor->x; - w = cursor->h; - h = cursor->w; - break; - } - if (mono) { - glUniform4f(t->uMousePos, x, y, w, h / 2); + glUniform4f(t->uMousePos, cursor->x, cursor->y, cursor->w, cursor->h / 2); glUniform1i(t->uRotate , cursor->rotate); glUniform1i(t->uCBMode , cursor->cbMode); } else { - glUniform4f(t->uMousePos, x, y, w, h); + glUniform4f(t->uMousePos, cursor->x, cursor->y, cursor->w, cursor->h); glUniform1i(t->uRotate , cursor->rotate); glUniform1i(t->uCBMode , cursor->cbMode); } diff --git a/client/renderers/EGL/shader/cursor.vert b/client/renderers/EGL/shader/cursor.vert index 4a289fb5..63866a97 100644 --- a/client/renderers/EGL/shader/cursor.vert +++ b/client/renderers/EGL/shader/cursor.vert @@ -4,22 +4,40 @@ layout(location = 0) in vec3 vertexPosition_modelspace; layout(location = 1) in vec2 vertexUV; uniform vec4 mouse; +uniform lowp int rotate; out highp vec2 uv; void main() { - gl_Position.xyz = vertexPosition_modelspace; - gl_Position.w = 1.0; + vec2 muv = vertexPosition_modelspace.xy; + muv.x += 1.0f; + muv.y -= 1.0f; + muv.x *= mouse.z; + muv.y *= mouse.w; + muv.x += mouse.x; + muv.y -= mouse.y; - gl_Position.x += 1.0f; - gl_Position.y -= 1.0f; - - gl_Position.x *= mouse.z; - gl_Position.y *= mouse.w; - - gl_Position.x += mouse.x; - gl_Position.y -= mouse.y; + if (rotate == 0) // up + { + gl_Position.xy = muv; + } + else if (rotate == 1) // down + { + gl_Position.x = -muv.x; + gl_Position.y = -muv.y; + } + else if (rotate == 2) // left + { + gl_Position.x = -muv.y; + gl_Position.y = muv.x; + } + else if (rotate == 3) // right + { + gl_Position.x = muv.y; + gl_Position.y = -muv.x; + } + gl_Position.w = 1.0; uv = vertexUV; } diff --git a/client/renderers/EGL/shader/cursor_rgb.frag b/client/renderers/EGL/shader/cursor_rgb.frag index 2c4c6e2b..8b0ed763 100644 --- a/client/renderers/EGL/shader/cursor_rgb.frag +++ b/client/renderers/EGL/shader/cursor_rgb.frag @@ -2,36 +2,15 @@ in highp vec2 uv; out highp vec4 color; -uniform int rotate; uniform sampler2D sampler1; +uniform lowp int rotate; uniform int cbMode; void main() { - highp vec2 ruv; - if (rotate == 0) // up - { - ruv = uv; - } - else if (rotate == 1) // down - { - ruv.x = -uv.x + 1.0f; - ruv.y = -uv.y + 1.0f; - } - else if (rotate == 2) // left - { - ruv.x = -uv.y + 1.0f; - ruv.y = uv.x; - } - else if (rotate == 3) // right - { - ruv.x = uv.y; - ruv.y = -uv.x + 1.0f; - } - - color = texture(sampler1, ruv); + color = texture(sampler1, uv); if (cbMode > 0) {