mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-22 05:27:20 +00:00
[client] egl: move shaders into seperate files and build into objects
This commit is contained in:
parent
52c4e15c76
commit
d5a52241b0
34
client/cmake/MakeObject.cmake
Normal file
34
client/cmake/MakeObject.cmake
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
function(make_object out_var)
|
||||||
|
set(result)
|
||||||
|
set(result_h)
|
||||||
|
foreach(in_f ${ARGN})
|
||||||
|
file(RELATIVE_PATH out_f ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/${in_f}")
|
||||||
|
set(out_h "${CMAKE_CURRENT_BINARY_DIR}/${out_f}.h")
|
||||||
|
set(out_f "${CMAKE_CURRENT_BINARY_DIR}/${out_f}.o")
|
||||||
|
string(REGEX REPLACE "[/.]" "_" sym_in ${in_f})
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT ${out_f}
|
||||||
|
COMMAND ${CMAKE_LINKER} -r -b binary -o ${out_f} ${in_f}
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} --rename-section .data=.rodata,CONTENTS,ALLOC,LOAD,READONLY,DATA ${out_f} ${out_f}
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${sym_in}_start=b_${sym_in} ${out_f} ${out_f}
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} --redefine-sym _binary_${sym_in}_end=b_${sym_in}_end ${out_f} ${out_f}
|
||||||
|
COMMAND ${CMAKE_OBJCOPY} --strip-symbol _binary_${sym_in}_size ${out_f} ${out_f}
|
||||||
|
DEPENDS ${in_f}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
COMMENT "Creating object from ${in_f}"
|
||||||
|
VERBATIM
|
||||||
|
)
|
||||||
|
|
||||||
|
file(WRITE ${out_h} "extern const char b_${sym_in}[];\n")
|
||||||
|
file(APPEND ${out_h} "extern const char b_${sym_in}_end[];\n")
|
||||||
|
file(APPEND ${out_h} "#define b_${sym_in}_size (b_${sym_in}_end - b_${sym_in})\n")
|
||||||
|
|
||||||
|
get_filename_component(h_dir ${out_h} DIRECTORY)
|
||||||
|
list(APPEND result_h ${h_dir})
|
||||||
|
list(APPEND result ${out_f})
|
||||||
|
endforeach()
|
||||||
|
list(REMOVE_DUPLICATES result_h)
|
||||||
|
|
||||||
|
set(${out_var}_OBJS "${result}" PARENT_SCOPE)
|
||||||
|
set(${out_var}_INCS "${result_h}" PARENT_SCOPE)
|
||||||
|
endfunction()
|
@ -1,13 +1,22 @@
|
|||||||
cmake_minimum_required(VERSION 3.6)
|
cmake_minimum_required(VERSION 3.6)
|
||||||
project(renderer_egl LANGUAGES C)
|
project(renderer_egl LANGUAGES C)
|
||||||
|
|
||||||
find_package(PkgConfig)
|
include(GNUInstallDirs)
|
||||||
|
include(MakeObject)
|
||||||
|
|
||||||
pkg_check_modules(RENDERER_EGL_PKGCONFIG REQUIRED
|
pkg_check_modules(RENDERER_EGL_PKGCONFIG REQUIRED
|
||||||
egl
|
egl
|
||||||
wayland-egl
|
wayland-egl
|
||||||
gl
|
gl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
make_object(
|
||||||
|
EGL_SHADER
|
||||||
|
shader/desktop.vert
|
||||||
|
shader/desktop_rgb.frag
|
||||||
|
shader/desktop_yuv.frag
|
||||||
|
)
|
||||||
|
|
||||||
add_library(renderer_egl STATIC
|
add_library(renderer_egl STATIC
|
||||||
egl.c
|
egl.c
|
||||||
shader.c
|
shader.c
|
||||||
@ -19,6 +28,7 @@ add_library(renderer_egl STATIC
|
|||||||
draw.c
|
draw.c
|
||||||
splash.c
|
splash.c
|
||||||
alert.c
|
alert.c
|
||||||
|
${EGL_SHADER_OBJS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(renderer_egl
|
target_link_libraries(renderer_egl
|
||||||
@ -28,5 +38,6 @@ target_link_libraries(renderer_egl
|
|||||||
target_include_directories(renderer_egl
|
target_include_directories(renderer_egl
|
||||||
PRIVATE
|
PRIVATE
|
||||||
src
|
src
|
||||||
|
${EGL_SHADER_INCS}
|
||||||
${RENDERER_EGL_PKGCONFIG_INCLUDE_DIRS}
|
${RENDERER_EGL_PKGCONFIG_INCLUDE_DIRS}
|
||||||
)
|
)
|
||||||
|
@ -28,6 +28,11 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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
|
struct EGL_Desktop
|
||||||
{
|
{
|
||||||
EGL_Texture * texture;
|
EGL_Texture * texture;
|
||||||
@ -49,74 +54,6 @@ struct EGL_Desktop
|
|||||||
bool update;
|
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)
|
bool egl_desktop_init(EGL_Desktop ** desktop)
|
||||||
{
|
{
|
||||||
*desktop = (EGL_Desktop *)malloc(sizeof(EGL_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,
|
if (!egl_shader_compile((*desktop)->shader_generic,
|
||||||
vertex_shader, sizeof(vertex_shader),
|
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
||||||
frag_generic , sizeof(frag_generic)))
|
b_shader_desktop_rgb_frag, b_shader_desktop_rgb_frag_size))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to compile the generic desktop shader");
|
DEBUG_ERROR("Failed to compile the generic desktop shader");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!egl_shader_compile((*desktop)->shader_yuv,
|
if (!egl_shader_compile((*desktop)->shader_yuv,
|
||||||
vertex_shader, sizeof(vertex_shader),
|
b_shader_desktop_vert , b_shader_desktop_vert_size,
|
||||||
frag_yuv , sizeof(frag_yuv )))
|
b_shader_desktop_yuv_frag, b_shader_desktop_yuv_frag_size))
|
||||||
{
|
{
|
||||||
DEBUG_ERROR("Failed to compile the yuv desktop shader");
|
DEBUG_ERROR("Failed to compile the yuv desktop shader");
|
||||||
return false;
|
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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user