From b524c077a4eed35ee40db05f07e2b2e150d32b14 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 28 Mar 2019 15:53:15 +1100 Subject: [PATCH] [client] egl: remove the rest of the shaders into seperate files --- VERSION | 2 +- client/renderers/egl/CMakeLists.txt | 13 +++ client/renderers/egl/alert.c | 64 +++------------ client/renderers/egl/cursor.c | 72 +++-------------- client/renderers/egl/fps.c | 64 +++------------ client/renderers/egl/shader/alert.frag | 11 +++ client/renderers/egl/shader/alert.vert | 21 +++++ client/renderers/egl/shader/alert_bg.frag | 9 +++ client/renderers/egl/shader/cursor.vert | 25 ++++++ client/renderers/egl/shader/cursor_mono.frag | 14 ++++ client/renderers/egl/shader/cursor_rgb.frag | 11 +++ client/renderers/egl/shader/fps.frag | 11 +++ client/renderers/egl/shader/fps.vert | 22 ++++++ client/renderers/egl/shader/fps_bg.frag | 8 ++ client/renderers/egl/shader/splash_bg.frag | 13 +++ client/renderers/egl/shader/splash_bg.vert | 17 ++++ client/renderers/egl/shader/splash_logo.frag | 11 +++ client/renderers/egl/shader/splash_logo.vert | 16 ++++ client/renderers/egl/splash.c | 83 +++----------------- 19 files changed, 240 insertions(+), 247 deletions(-) create mode 100644 client/renderers/egl/shader/alert.frag create mode 100644 client/renderers/egl/shader/alert.vert create mode 100644 client/renderers/egl/shader/alert_bg.frag create mode 100644 client/renderers/egl/shader/cursor.vert create mode 100644 client/renderers/egl/shader/cursor_mono.frag create mode 100644 client/renderers/egl/shader/cursor_rgb.frag create mode 100644 client/renderers/egl/shader/fps.frag create mode 100644 client/renderers/egl/shader/fps.vert create mode 100644 client/renderers/egl/shader/fps_bg.frag create mode 100644 client/renderers/egl/shader/splash_bg.frag create mode 100644 client/renderers/egl/shader/splash_bg.vert create mode 100644 client/renderers/egl/shader/splash_logo.frag create mode 100644 client/renderers/egl/shader/splash_logo.vert diff --git a/VERSION b/VERSION index 28e1a1a4..75a9f77d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -a12-116-gf09ee0bdb3+1 \ No newline at end of file +a12-117-g10f7efecb2+1 \ No newline at end of file diff --git a/client/renderers/egl/CMakeLists.txt b/client/renderers/egl/CMakeLists.txt index 72a0b490..4bdf10d3 100644 --- a/client/renderers/egl/CMakeLists.txt +++ b/client/renderers/egl/CMakeLists.txt @@ -14,6 +14,19 @@ make_object( shader/desktop.vert shader/desktop_rgb.frag shader/desktop_yuv.frag + shader/cursor.vert + shader/cursor_rgb.frag + shader/cursor_mono.frag + shader/fps.vert + shader/fps.frag + shader/fps_bg.frag + shader/alert.vert + shader/alert.frag + shader/alert_bg.frag + shader/splash_bg.vert + shader/splash_bg.frag + shader/splash_logo.vert + shader/splash_logo.frag ) add_library(renderer_egl STATIC diff --git a/client/renderers/egl/alert.c b/client/renderers/egl/alert.c index 9da9cac8..9125b6a4 100644 --- a/client/renderers/egl/alert.c +++ b/client/renderers/egl/alert.c @@ -28,6 +28,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include +// these headers are auto generated by cmake +#include "alert.vert.h" +#include "alert.frag.h" +#include "alert_bg.frag.h" + struct EGL_Alert { const LG_Font * font; @@ -51,57 +56,6 @@ struct EGL_Alert GLint uScreenBG, uSizeBG, uColorBG; }; -static const char vertex_shader[] = "\ -#version 300 es\n\ -\ -layout(location = 0) in vec3 vertexPosition_modelspace;\ -layout(location = 1) in vec2 vertexUV;\ -\ -uniform vec2 screen;\ -uniform vec2 size;\ -uniform vec4 color;\ -\ -out highp vec2 uv;\ -out highp vec4 c;\ -\ -void main()\ -{\ - gl_Position.xyz = vertexPosition_modelspace; \ - gl_Position.w = 1.0; \ - gl_Position.xy *= screen.xy * size.xy; \ -\ - uv = vertexUV;\ - c = color;\ -}\ -"; - -static const char frag_shader[] = "\ -#version 300 es\n\ -\ -in highp vec2 uv;\ -out highp vec4 color;\ -\ -uniform sampler2D sampler1;\ -\ -void main()\ -{\ - color = texture(sampler1, uv);\ -}\ -"; - -static const char frag_shaderBG[] = "\ -#version 300 es\n\ -\ -in highp vec4 c;\ -out highp vec4 color;\ -\ -void main()\ -{\ - color = c;\ -}\ -"; - - bool egl_alert_init(EGL_Alert ** alert, const LG_Font * font, LG_FontObj fontObj) { *alert = (EGL_Alert *)malloc(sizeof(EGL_Alert)); @@ -137,16 +91,16 @@ bool egl_alert_init(EGL_Alert ** alert, const LG_Font * font, LG_FontObj fontObj if (!egl_shader_compile((*alert)->shader, - vertex_shader, sizeof(vertex_shader), - frag_shader , sizeof(frag_shader ))) + b_shader_alert_vert, b_shader_alert_vert_size, + b_shader_alert_frag, b_shader_alert_frag_size)) { DEBUG_ERROR("Failed to compile the alert shader"); return false; } if (!egl_shader_compile((*alert)->shaderBG, - vertex_shader, sizeof(vertex_shader), - frag_shaderBG, sizeof(frag_shaderBG))) + b_shader_alert_vert , b_shader_alert_vert_size, + b_shader_alert_bg_frag, b_shader_alert_bg_frag_size)) { DEBUG_ERROR("Failed to compile the alert shader"); return false; diff --git a/client/renderers/egl/cursor.c b/client/renderers/egl/cursor.c index 2bf713a2..a3cc0bc1 100644 --- a/client/renderers/egl/cursor.c +++ b/client/renderers/egl/cursor.c @@ -28,6 +28,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include +// these headers are auto generated by cmake +#include "cursor.vert.h" +#include "cursor_rgb.frag.h" +#include "cursor_mono.frag.h" + struct EGL_Cursor { LG_Lock lock; @@ -59,65 +64,6 @@ struct EGL_Cursor struct EGL_Model * model; }; -static const char vertex_shader[] = "\ -#version 300 es\n\ -\ -layout(location = 0) in vec3 vertexPosition_modelspace;\ -layout(location = 1) in vec2 vertexUV;\ -\ -uniform vec4 mouse;\ -\ -out highp vec2 uv;\ -\ -void main()\ -{\ - gl_Position.xyz = vertexPosition_modelspace;\ - gl_Position.w = 1.0;\ - \ - 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;\ - \ - uv = vertexUV;\ -}\ -"; - -static const char frag_mouse_mono[] = "\ -#version 300 es\n\ -\ -in highp vec2 uv;\ -out highp vec4 color;\ -\ -uniform sampler2D sampler1;\ - \ -void main()\ -{\ - highp vec4 tmp = texture(sampler1, uv);\ - if (tmp.rgb == vec3(0.0, 0.0, 0.0))\ - discard;\ - color = tmp;\ -}\ -"; - -static const char frag_rgba[] = "\ -#version 300 es\n\ -\ -in highp vec2 uv;\ -out highp vec4 color;\ -\ -uniform sampler2D sampler1;\ - \ -void main()\ -{\ - color = texture(sampler1, uv);\ -}\ -"; - bool egl_cursor_init(EGL_Cursor ** cursor) { *cursor = (EGL_Cursor *)malloc(sizeof(EGL_Cursor)); @@ -156,8 +102,8 @@ bool egl_cursor_init(EGL_Cursor ** cursor) if (!egl_shader_compile( (*cursor)->shader, - vertex_shader, sizeof(vertex_shader), - frag_rgba , sizeof(frag_rgba ))) + b_shader_cursor_vert , b_shader_cursor_vert_size, + b_shader_cursor_rgb_frag, b_shader_cursor_rgb_frag_size)) { DEBUG_ERROR("Failed to compile the cursor shader"); return false; @@ -165,8 +111,8 @@ bool egl_cursor_init(EGL_Cursor ** cursor) if (!egl_shader_compile( (*cursor)->shaderMono, - vertex_shader , sizeof(vertex_shader ), - frag_mouse_mono, sizeof(frag_mouse_mono))) + b_shader_cursor_vert , b_shader_cursor_vert_size, + b_shader_cursor_mono_frag, b_shader_cursor_mono_frag_size)) { DEBUG_ERROR("Failed to compile the cursor mono shader"); return false; diff --git a/client/renderers/egl/fps.c b/client/renderers/egl/fps.c index 990cfc9a..9808ceca 100644 --- a/client/renderers/egl/fps.c +++ b/client/renderers/egl/fps.c @@ -28,6 +28,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include +// these headers are auto generated by cmake +#include "fps.vert.h" +#include "fps.frag.h" +#include "fps_bg.frag.h" + struct EGL_FPS { const LG_Font * font; @@ -46,57 +51,6 @@ struct EGL_FPS GLint uScreenBG, uSizeBG; }; -static const char vertex_shader[] = "\ -#version 300 es\n\ -\ -layout(location = 0) in vec3 vertexPosition_modelspace;\ -layout(location = 1) in vec2 vertexUV;\ -\ -uniform vec2 screen;\ -uniform vec2 size;\ -\ -out highp vec2 uv;\ -\ -void main()\ -{\ - gl_Position.xyz = vertexPosition_modelspace; \ - gl_Position.w = 1.0; \ - gl_Position.xy *= screen.xy * size.xy; \ - gl_Position.x -= 1.0 - (screen.x * size.x);\ - gl_Position.y += 1.0 - (screen.y * size.y);\ - gl_Position.x += screen.x * 10.0; \ - gl_Position.y -= screen.y * 10.0; \ -\ - uv = vertexUV;\ -}\ -"; - -static const char frag_shader[] = "\ -#version 300 es\n\ -\ -in highp vec2 uv;\ -out highp vec4 color;\ -\ -uniform sampler2D sampler1;\ -\ -void main()\ -{\ - color = texture(sampler1, uv);\ -}\ -"; - -static const char frag_shaderBG[] = "\ -#version 300 es\n\ -\ -out highp vec4 color;\ -\ -void main()\ -{\ - color = vec4(0.0, 0.0, 1.0, 0.5);\ -}\ -"; - - bool egl_fps_init(EGL_FPS ** fps, const LG_Font * font, LG_FontObj fontObj) { *fps = (EGL_FPS *)malloc(sizeof(EGL_FPS)); @@ -131,16 +85,16 @@ bool egl_fps_init(EGL_FPS ** fps, const LG_Font * font, LG_FontObj fontObj) if (!egl_shader_compile((*fps)->shader, - vertex_shader, sizeof(vertex_shader), - frag_shader , sizeof(frag_shader ))) + b_shader_fps_vert, b_shader_fps_vert_size, + b_shader_fps_frag, b_shader_fps_frag_size)) { DEBUG_ERROR("Failed to compile the fps shader"); return false; } if (!egl_shader_compile((*fps)->shaderBG, - vertex_shader, sizeof(vertex_shader), - frag_shaderBG, sizeof(frag_shaderBG))) + b_shader_fps_vert , b_shader_fps_vert_size, + b_shader_fps_bg_frag, b_shader_fps_bg_frag_size)) { DEBUG_ERROR("Failed to compile the fps shader"); return false; diff --git a/client/renderers/egl/shader/alert.frag b/client/renderers/egl/shader/alert.frag new file mode 100644 index 00000000..a435c6d9 --- /dev/null +++ b/client/renderers/egl/shader/alert.frag @@ -0,0 +1,11 @@ +#version 300 es + +in highp vec2 uv; +out highp vec4 color; + +uniform sampler2D sampler1; + +void main() +{ + color = texture(sampler1, uv); +} diff --git a/client/renderers/egl/shader/alert.vert b/client/renderers/egl/shader/alert.vert new file mode 100644 index 00000000..aaf736c2 --- /dev/null +++ b/client/renderers/egl/shader/alert.vert @@ -0,0 +1,21 @@ +#version 300 es + +layout(location = 0) in vec3 vertexPosition_modelspace; +layout(location = 1) in vec2 vertexUV; + +uniform vec2 screen; +uniform vec2 size; +uniform vec4 color; + +out highp vec2 uv; +out highp vec4 c; + +void main() +{ + gl_Position.xyz = vertexPosition_modelspace; + gl_Position.w = 1.0; + gl_Position.xy *= screen.xy * size.xy; + + uv = vertexUV; + c = color; +} diff --git a/client/renderers/egl/shader/alert_bg.frag b/client/renderers/egl/shader/alert_bg.frag new file mode 100644 index 00000000..c247c3ee --- /dev/null +++ b/client/renderers/egl/shader/alert_bg.frag @@ -0,0 +1,9 @@ +#version 300 es + +in highp vec4 c; +out highp vec4 color; + +void main() +{ + color = c; +} diff --git a/client/renderers/egl/shader/cursor.vert b/client/renderers/egl/shader/cursor.vert new file mode 100644 index 00000000..4a289fb5 --- /dev/null +++ b/client/renderers/egl/shader/cursor.vert @@ -0,0 +1,25 @@ +#version 300 es + +layout(location = 0) in vec3 vertexPosition_modelspace; +layout(location = 1) in vec2 vertexUV; + +uniform vec4 mouse; + +out highp vec2 uv; + +void main() +{ + gl_Position.xyz = vertexPosition_modelspace; + gl_Position.w = 1.0; + + 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; + + uv = vertexUV; +} diff --git a/client/renderers/egl/shader/cursor_mono.frag b/client/renderers/egl/shader/cursor_mono.frag new file mode 100644 index 00000000..9afaf2da --- /dev/null +++ b/client/renderers/egl/shader/cursor_mono.frag @@ -0,0 +1,14 @@ +#version 300 es + +in highp vec2 uv; +out highp vec4 color; + +uniform sampler2D sampler1; + +void main() +{ + highp vec4 tmp = texture(sampler1, uv); + if (tmp.rgb == vec3(0.0, 0.0, 0.0)) + discard; + color = tmp; +} diff --git a/client/renderers/egl/shader/cursor_rgb.frag b/client/renderers/egl/shader/cursor_rgb.frag new file mode 100644 index 00000000..a435c6d9 --- /dev/null +++ b/client/renderers/egl/shader/cursor_rgb.frag @@ -0,0 +1,11 @@ +#version 300 es + +in highp vec2 uv; +out highp vec4 color; + +uniform sampler2D sampler1; + +void main() +{ + color = texture(sampler1, uv); +} diff --git a/client/renderers/egl/shader/fps.frag b/client/renderers/egl/shader/fps.frag new file mode 100644 index 00000000..a435c6d9 --- /dev/null +++ b/client/renderers/egl/shader/fps.frag @@ -0,0 +1,11 @@ +#version 300 es + +in highp vec2 uv; +out highp vec4 color; + +uniform sampler2D sampler1; + +void main() +{ + color = texture(sampler1, uv); +} diff --git a/client/renderers/egl/shader/fps.vert b/client/renderers/egl/shader/fps.vert new file mode 100644 index 00000000..7d35ddc0 --- /dev/null +++ b/client/renderers/egl/shader/fps.vert @@ -0,0 +1,22 @@ +#version 300 es + +layout(location = 0) in vec3 vertexPosition_modelspace; +layout(location = 1) in vec2 vertexUV; + +uniform vec2 screen; +uniform vec2 size; + +out highp vec2 uv; + +void main() +{ + gl_Position.xyz = vertexPosition_modelspace; + gl_Position.w = 1.0; + gl_Position.xy *= screen.xy * size.xy; + gl_Position.x -= 1.0 - (screen.x * size.x); + gl_Position.y += 1.0 - (screen.y * size.y); + gl_Position.x += screen.x * 10.0; + gl_Position.y -= screen.y * 10.0; + + uv = vertexUV; +} diff --git a/client/renderers/egl/shader/fps_bg.frag b/client/renderers/egl/shader/fps_bg.frag new file mode 100644 index 00000000..5a33e8d1 --- /dev/null +++ b/client/renderers/egl/shader/fps_bg.frag @@ -0,0 +1,8 @@ +#version 300 es + +out highp vec4 color; + +void main() +{ + color = vec4(0.0, 0.0, 1.0, 0.5); +} diff --git a/client/renderers/egl/shader/splash_bg.frag b/client/renderers/egl/shader/splash_bg.frag new file mode 100644 index 00000000..058afdbe --- /dev/null +++ b/client/renderers/egl/shader/splash_bg.frag @@ -0,0 +1,13 @@ +#version 300 es + +in highp vec3 pos; +in highp float a; +out highp vec4 color; + +uniform sampler2D sampler1; + +void main() +{ + highp float d = 1.0 - sqrt(pos.x * pos.x + pos.y * pos.y) / 2.0; + color = vec4(0.234375 * d, 0.015625f * d, 0.425781f * d, a); +} diff --git a/client/renderers/egl/shader/splash_bg.vert b/client/renderers/egl/shader/splash_bg.vert new file mode 100644 index 00000000..d47bc73c --- /dev/null +++ b/client/renderers/egl/shader/splash_bg.vert @@ -0,0 +1,17 @@ +#version 300 es + +layout(location = 0) in vec3 vertexPosition_modelspace; + +uniform float alpha; + +out highp vec3 pos; +out highp float a; + +void main() +{ + gl_Position.xyz = vertexPosition_modelspace; + gl_Position.w = 1.0; + + pos = vertexPosition_modelspace; + a = alpha; +} diff --git a/client/renderers/egl/shader/splash_logo.frag b/client/renderers/egl/shader/splash_logo.frag new file mode 100644 index 00000000..bd09551c --- /dev/null +++ b/client/renderers/egl/shader/splash_logo.frag @@ -0,0 +1,11 @@ +#version 300 es + +out highp vec4 color; +in highp float a; + +uniform sampler2D sampler1; + +void main() +{ + color = vec4(1.0, 1.0, 1.0, a); +} diff --git a/client/renderers/egl/shader/splash_logo.vert b/client/renderers/egl/shader/splash_logo.vert new file mode 100644 index 00000000..a717f3a1 --- /dev/null +++ b/client/renderers/egl/shader/splash_logo.vert @@ -0,0 +1,16 @@ +#version 300 es + +layout(location = 0) in vec3 vertexPosition_modelspace; + +uniform vec2 scale; + +out highp float a; + +void main() +{ + gl_Position.xyz = vertexPosition_modelspace; + gl_Position.y *= scale.y; + gl_Position.w = 1.0; + + a = scale.x; +} diff --git a/client/renderers/egl/splash.c b/client/renderers/egl/splash.c index e1b53c09..435bfc6a 100644 --- a/client/renderers/egl/splash.c +++ b/client/renderers/egl/splash.c @@ -31,6 +31,12 @@ Place, Suite 330, Boston, MA 02111-1307 USA #include #include +// these headers are auto generated by cmake +#include "splash_bg.vert.h" +#include "splash_bg.frag.h" +#include "splash_logo.vert.h" +#include "splash_logo.frag.h" + struct EGL_Splash { EGL_Shader * bgShader; @@ -44,75 +50,6 @@ struct EGL_Splash GLint uScale; }; -static const char vertex_bgShader[] = "\ -#version 300 es\n\ -\ -layout(location = 0) in vec3 vertexPosition_modelspace;\ -\ -uniform float alpha;\ -\ -out highp vec3 pos; \ -out highp float a; \ -\ -void main()\ -{\ - gl_Position.xyz = vertexPosition_modelspace; \ - gl_Position.w = 1.0; \ -\ - pos = vertexPosition_modelspace; \ - a = alpha; \ -}\ -"; - -static const char frag_bgShader[] = "\ -#version 300 es\n\ -\ -in highp vec3 pos;\ -in highp float a;\ -out highp vec4 color;\ -\ -uniform sampler2D sampler1;\ -\ -void main()\ -{\ - highp float d = 1.0 - sqrt(pos.x * pos.x + pos.y * pos.y) / 2.0; \ - color = vec4(0.234375 * d, 0.015625f * d, 0.425781f * d, a); \ -}\ -"; - -static const char vertex_logoShader[] = "\ -#version 300 es\n\ -\ -layout(location = 0) in vec3 vertexPosition_modelspace;\ -\ -uniform vec2 scale;\ -\ -out highp float a; \ -\ -void main()\ -{\ - gl_Position.xyz = vertexPosition_modelspace; \ - gl_Position.y *= scale.y; \ - gl_Position.w = 1.0; \ -\ - a = scale.x; \ -}\ -"; - -static const char frag_logoShader[] = "\ -#version 300 es\n\ -\ -out highp vec4 color;\ -in highp float a;\ -\ -uniform sampler2D sampler1;\ -\ -void main()\ -{\ - color = vec4(1.0, 1.0, 1.0, a);\ -}\ -"; - bool egl_splash_init(EGL_Splash ** splash) { *splash = (EGL_Splash *)malloc(sizeof(EGL_Splash)); @@ -131,8 +68,8 @@ bool egl_splash_init(EGL_Splash ** splash) } if (!egl_shader_compile((*splash)->bgShader, - vertex_bgShader, sizeof(vertex_bgShader), - frag_bgShader , sizeof(frag_bgShader ))) + b_shader_splash_bg_vert, b_shader_splash_bg_vert_size, + b_shader_splash_bg_frag, b_shader_splash_bg_frag_size)) { DEBUG_ERROR("Failed to compile the splash bgShader"); return false; @@ -155,8 +92,8 @@ bool egl_splash_init(EGL_Splash ** splash) } if (!egl_shader_compile((*splash)->logoShader, - vertex_logoShader, sizeof(vertex_logoShader), - frag_logoShader , sizeof(frag_logoShader ))) + b_shader_splash_logo_vert, b_shader_splash_logo_vert_size, + b_shader_splash_logo_frag, b_shader_splash_logo_frag_size)) { DEBUG_ERROR("Failed to compile the splash logoShader"); return false;