mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-08-05 18:24:08 +00:00
[client] egl: move shaders into seperate files and build into objects
This commit is contained in:
@@ -1,13 +1,22 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
project(renderer_egl LANGUAGES C)
|
||||
|
||||
find_package(PkgConfig)
|
||||
include(GNUInstallDirs)
|
||||
include(MakeObject)
|
||||
|
||||
pkg_check_modules(RENDERER_EGL_PKGCONFIG REQUIRED
|
||||
egl
|
||||
wayland-egl
|
||||
gl
|
||||
)
|
||||
|
||||
make_object(
|
||||
EGL_SHADER
|
||||
shader/desktop.vert
|
||||
shader/desktop_rgb.frag
|
||||
shader/desktop_yuv.frag
|
||||
)
|
||||
|
||||
add_library(renderer_egl STATIC
|
||||
egl.c
|
||||
shader.c
|
||||
@@ -19,6 +28,7 @@ add_library(renderer_egl STATIC
|
||||
draw.c
|
||||
splash.c
|
||||
alert.c
|
||||
${EGL_SHADER_OBJS}
|
||||
)
|
||||
|
||||
target_link_libraries(renderer_egl
|
||||
@@ -28,5 +38,6 @@ target_link_libraries(renderer_egl
|
||||
target_include_directories(renderer_egl
|
||||
PRIVATE
|
||||
src
|
||||
${EGL_SHADER_INCS}
|
||||
${RENDERER_EGL_PKGCONFIG_INCLUDE_DIRS}
|
||||
)
|
||||
|
@@ -28,6 +28,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// these headers are auto generated by cmake
|
||||
#include "desktop.vert.h"
|
||||
#include "desktop_rgb.frag.h"
|
||||
#include "desktop_yuv.frag.h"
|
||||
|
||||
struct EGL_Desktop
|
||||
{
|
||||
EGL_Texture * texture;
|
||||
@@ -49,74 +54,6 @@ struct EGL_Desktop
|
||||
bool update;
|
||||
};
|
||||
|
||||
static const char vertex_shader[] = "\
|
||||
#version 300 es\n\
|
||||
\
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;\
|
||||
layout(location = 1) in vec2 vertexUV;\
|
||||
\
|
||||
uniform vec4 position;\
|
||||
\
|
||||
out highp vec2 uv;\
|
||||
\
|
||||
void main()\
|
||||
{\
|
||||
gl_Position.xyz = vertexPosition_modelspace; \
|
||||
gl_Position.w = 1.0; \
|
||||
gl_Position.x -= position.x; \
|
||||
gl_Position.y -= position.y; \
|
||||
gl_Position.x *= position.z; \
|
||||
gl_Position.y *= position.w; \
|
||||
\
|
||||
uv = vertexUV;\
|
||||
}\
|
||||
";
|
||||
|
||||
|
||||
static const char frag_generic[] = "\
|
||||
#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_yuv[] = "\
|
||||
#version 300 es\n\
|
||||
\
|
||||
in highp vec2 uv;\
|
||||
out highp vec4 color;\
|
||||
\
|
||||
uniform sampler2D sampler1;\
|
||||
uniform sampler2D sampler2;\
|
||||
uniform sampler2D sampler3;\
|
||||
\
|
||||
void main()\
|
||||
{\
|
||||
highp vec4 yuv = vec4(\
|
||||
texture(sampler1, uv).r,\
|
||||
texture(sampler2, uv).r,\
|
||||
texture(sampler3, uv).r,\
|
||||
1.0\
|
||||
);\
|
||||
\
|
||||
highp mat4 yuv_to_rgb = mat4(\
|
||||
1.0, 0.0 , 1.402, -0.701,\
|
||||
1.0, -0.344, -0.714, 0.529,\
|
||||
1.0, 1.772, 0.0 , -0.886,\
|
||||
1.0, 1.0 , 1.0 , 1.0\
|
||||
);\
|
||||
\
|
||||
color = yuv * yuv_to_rgb;\
|
||||
}\
|
||||
";
|
||||
|
||||
bool egl_desktop_init(EGL_Desktop ** desktop)
|
||||
{
|
||||
*desktop = (EGL_Desktop *)malloc(sizeof(EGL_Desktop));
|
||||
@@ -147,16 +84,16 @@ bool egl_desktop_init(EGL_Desktop ** desktop)
|
||||
}
|
||||
|
||||
if (!egl_shader_compile((*desktop)->shader_generic,
|
||||
vertex_shader, sizeof(vertex_shader),
|
||||
frag_generic , sizeof(frag_generic)))
|
||||
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
||||
b_shader_desktop_rgb_frag, b_shader_desktop_rgb_frag_size))
|
||||
{
|
||||
DEBUG_ERROR("Failed to compile the generic desktop shader");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!egl_shader_compile((*desktop)->shader_yuv,
|
||||
vertex_shader, sizeof(vertex_shader),
|
||||
frag_yuv , sizeof(frag_yuv )))
|
||||
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
||||
b_shader_desktop_yuv_frag, b_shader_desktop_yuv_frag_size))
|
||||
{
|
||||
DEBUG_ERROR("Failed to compile the yuv desktop shader");
|
||||
return false;
|
||||
|
20
client/renderers/egl/shader/desktop.vert
Normal file
20
client/renderers/egl/shader/desktop.vert
Normal file
@@ -0,0 +1,20 @@
|
||||
#version 300 es
|
||||
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 vertexUV;
|
||||
|
||||
uniform vec4 position;
|
||||
|
||||
out highp vec2 uv;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position.xyz = vertexPosition_modelspace;
|
||||
gl_Position.w = 1.0;
|
||||
gl_Position.x -= position.x;
|
||||
gl_Position.y -= position.y;
|
||||
gl_Position.x *= position.z;
|
||||
gl_Position.y *= position.w;
|
||||
|
||||
uv = vertexUV;
|
||||
}
|
11
client/renderers/egl/shader/desktop_rgb.frag
Normal file
11
client/renderers/egl/shader/desktop_rgb.frag
Normal file
@@ -0,0 +1,11 @@
|
||||
#version 300 es
|
||||
|
||||
in highp vec2 uv;
|
||||
out highp vec4 color;
|
||||
|
||||
uniform sampler2D sampler1;
|
||||
|
||||
void main()
|
||||
{
|
||||
color = texture(sampler1, uv);
|
||||
}
|
27
client/renderers/egl/shader/desktop_yuv.frag
Normal file
27
client/renderers/egl/shader/desktop_yuv.frag
Normal file
@@ -0,0 +1,27 @@
|
||||
#version 300 es
|
||||
|
||||
in highp vec2 uv;
|
||||
out highp vec4 color;
|
||||
|
||||
uniform sampler2D sampler1;
|
||||
uniform sampler2D sampler2;
|
||||
uniform sampler2D sampler3;
|
||||
|
||||
void main()
|
||||
{
|
||||
highp vec4 yuv = vec4(
|
||||
texture(sampler1, uv).r,
|
||||
texture(sampler2, uv).r,
|
||||
texture(sampler3, uv).r,
|
||||
1.0
|
||||
);
|
||||
|
||||
highp mat4 yuv_to_rgb = mat4(
|
||||
1.0, 0.0 , 1.402, -0.701,
|
||||
1.0, -0.344, -0.714, 0.529,
|
||||
1.0, 1.772, 0.0 , -0.886,
|
||||
1.0, 1.0 , 1.0 , 1.0
|
||||
);
|
||||
|
||||
color = yuv * yuv_to_rgb;
|
||||
}
|
Reference in New Issue
Block a user