From c274c81fa35e36165b04c1ae4facb29ae97b30ab Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Tue, 11 Feb 2020 21:05:05 +0000 Subject: [PATCH] Install shader files --- meson.build | 12 ++++++++++++ src/render.c | 30 +++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index 9f10d31..6c1b763 100644 --- a/meson.build +++ b/meson.build @@ -9,6 +9,7 @@ project( ) buildtype = get_option('buildtype') +prefix = get_option('prefix') c_args = [ '-D_GNU_SOURCE', @@ -74,6 +75,17 @@ dependencies = [ client_protos, ] +config = configuration_data() + +config.set('PREFIX', '"' + prefix + '"') + +configure_file( + output: 'config.h', + configuration: config, +) + +install_subdir('shaders', install_dir: 'share/wayvnc') + executable( 'wayvnc', sources, diff --git a/src/render.c b/src/render.c index 89bca70..0a6e1e7 100644 --- a/src/render.c +++ b/src/render.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Andri Yngvason + * Copyright (c) 2019 - 2020 Andri Yngvason * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -31,9 +31,12 @@ #include "logging.h" #include "render.h" #include "dmabuf.h" +#include "config.h" #define MAYBE_UNUSED __attribute__((unused)) +#define SHADER_PATH PREFIX "share/wayvnc/shaders" + enum { ATTR_INDEX_POS = 0, ATTR_INDEX_TEXTURE, @@ -216,9 +219,22 @@ alloc_failure: return NULL; } -static int gl_load_shader_from_file(GLuint* dst, const char* path, GLenum type) +static char* read_file_at_path(const char* prefix, const char* file) { - char* source = read_file(path); + char path[256]; + + snprintf(path, sizeof(path), "%s/%s", prefix, file); + path[sizeof(path) - 1] = '\0'; + + return read_file(path); +} + +static int gl_load_shader_from_file(GLuint* dst, const char* file, GLenum type) +{ + char* source = read_file_at_path("shaders", file); + if (!source) + source = read_file_at_path(SHADER_PATH, file); + if (!source) return -1; @@ -381,13 +397,13 @@ int renderer_init(struct renderer* self, uint32_t width, uint32_t height) goto late_extension_failure; if (gl_compile_shader_program(&self->dmabuf_shader_program, - "shaders/dmabuf-vertex.glsl", - "shaders/dmabuf-fragment.glsl") < 0) + "dmabuf-vertex.glsl", + "dmabuf-fragment.glsl") < 0) goto shader_failure; if (gl_compile_shader_program(&self->texture_shader_program, - "shaders/texture-vertex.glsl", - "shaders/texture-fragment.glsl") < 0) + "texture-vertex.glsl", + "texture-fragment.glsl") < 0) goto shader_failure; self->width = width;