summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-03-15 15:45:20 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2013-11-03 12:15:35 +0100
commit6f14e5905d04da492f160cac6ac5a6fc7fd00134 (patch)
tree21b19b2a23062b0a66601b50ac20c0dadd255fe2 /src
parent0a098393c2fe7e40a02b44481194534ad2572d70 (diff)
build: replace genshader by binary linker
Instead of generating C source files, we now use our binary-linker make target which can link in any arbitrary binary file. This way, we can delete genshader and instead link the files directly. This speeds up compilation and makes the code more consistent. We also strip the shaders from useless comments and whitespaces to reduce memory consumption. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/genshader.c173
-rw-r--r--src/text_gltex.c17
-rw-r--r--src/text_gltex_atlas.frag (renamed from src/static_gltex.frag)0
-rw-r--r--src/text_gltex_atlas.vert (renamed from src/static_gltex.vert)0
-rw-r--r--src/uterm_drm3d_blend.frag (renamed from src/static_blend.frag)0
-rw-r--r--src/uterm_drm3d_blend.vert (renamed from src/static_blend.vert)0
-rw-r--r--src/uterm_drm3d_blit.frag (renamed from src/static_blit.frag)0
-rw-r--r--src/uterm_drm3d_blit.vert (renamed from src/static_blit.vert)0
-rw-r--r--src/uterm_drm3d_fill.frag (renamed from src/static_fill.frag)0
-rw-r--r--src/uterm_drm3d_fill.vert (renamed from src/static_fill.vert)0
-rw-r--r--src/uterm_drm3d_render.c47
11 files changed, 47 insertions, 190 deletions
diff --git a/src/genshader.c b/src/genshader.c
deleted file mode 100644
index f0430f3..0000000
--- a/src/genshader.c
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * kmscon - Generate Shader Files
- *
- * Copyright (c) 2011-2012 David Herrmann <dh.herrmann@googlemail.com>
- * Copyright (c) 2011 University of Tuebingen
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files
- * (the "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * Shader Generator
- * This takes as arguments shaders and creates a C-source file which
- * contains these shaders as constants.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-static char *read_file(const char *path, size_t *size)
-{
- FILE *ffile;
- ssize_t len;
- char *buf;
-
- ffile = fopen(path, "rb");
- if (!ffile) {
- fprintf(stderr, "genshader: cannot open %s: %m\n", path);
- abort();
- }
-
- if (fseek(ffile, 0, SEEK_END) != 0) {
- fprintf(stderr, "genshader: cannot seek %s: %m\n", path);
- abort();
- }
-
- len = ftell(ffile);
- if (len < 0) {
- fprintf(stderr, "genshader: cannot tell %s: %m\n", path);
- abort();
- }
-
- if (len < 1) {
- fprintf(stderr, "genshader: empty file %s\n", path);
- abort();
- }
-
- rewind(ffile);
-
- buf = malloc(len + 1);
- if (!buf) {
- fprintf(stderr, "genshader: memory allocation failed\n");
- abort();
- }
-
- if (len != fread(buf, 1, len, ffile)) {
- fprintf(stderr, "genshader: cannot read %s: %m\n", path);
- abort();
- }
-
- buf[len] = 0;
- *size = len;
- fclose(ffile);
-
- return buf;
-}
-
-static const char *get_basename(const char *path)
-{
- const char *res;
-
- res = strrchr(path, '/');
- if (!res || !*++res)
- return path;
-
- return res;
-}
-
-static void write_seq(FILE *out, const char *src, size_t len)
-{
- size_t i;
-
- for (i = 0; i < len; ++i) {
- if (src[i] == '\n') {
- fwrite("\\n\"\n\"", 5, 1, out);
- } else if (src[i] == '"') {
- fwrite("\\\"", 2, 1, out);
- } else {
- fwrite(&src[i], 1, 1, out);
- }
- }
-}
-
-static void write_name(FILE *out, const char *name)
-{
- size_t i, len;
-
- len = strlen(name);
- for (i = 0; i < len; ++i) {
- if ((name[i] >= 'A' && name[i] <= 'Z') ||
- (name[i] >= 'a' && name[i] <= 'z') ||
- (name[i] >= '0' && name[i] <= '9'))
- fwrite(&name[i], 1, 1, out);
- else
- fwrite("_", 1, 1, out);
- }
-}
-
-static void write_single_file(FILE *out, const char *path)
-{
- static const char c1[] = "const char *gl_";
- static const char c2[] = " = \"";
- static const char c3[] = "\";\n";
- const char *name;
- char *content;
- size_t len;
-
- name = get_basename(path);
- content = read_file(path, &len);
-
- fwrite(c1, sizeof(c1) - 1, 1, out);
- write_name(out, name);
- fwrite(c2, sizeof(c2) - 1, 1, out);
- write_seq(out, content, len);
- fwrite(c3, sizeof(c3) - 1, 1, out);
-
- free(content);
-}
-
-int main(int argc, char *argv[])
-{
- FILE *out;
- size_t i;
- static const char c0[] = "/* This file was generated "
- "by genshader.c */\n";
-
- if (argc < 2) {
- fprintf(stderr, "genshader: use ./genshader <outputfile> [<shader-files> ...]\n");
- abort();
- }
-
- out = fopen(argv[1], "wb");
- if (!out) {
- fprintf(stderr, "genshader: cannot open %s: %m\n", argv[1]);
- abort();
- }
-
- fwrite(c0, sizeof(c0) - 1, 1, out);
- for (i = 2; i < argc; ++i) {
- write_single_file(out, argv[i]);
- }
-
- fclose(out);
-
- return EXIT_SUCCESS;
-}
diff --git a/src/text_gltex.c b/src/text_gltex.c
index beb0bba..20f7eb3 100644
--- a/src/text_gltex.c
+++ b/src/text_gltex.c
@@ -141,13 +141,16 @@ static void free_glyph(void *data)
free(glyph);
}
-extern const char *gl_static_gltex_vert;
-extern const char *gl_static_gltex_frag;
+extern const char _binary_src_text_gltex_atlas_vert_bin_start[];
+extern const char _binary_src_text_gltex_atlas_vert_bin_end[];
+extern const char _binary_src_text_gltex_atlas_frag_bin_start[];
+extern const char _binary_src_text_gltex_atlas_frag_bin_end[];
static int gltex_set(struct kmscon_text *txt)
{
struct gltex *gt = txt->data;
- int ret;
+ int ret, vlen, flen;
+ const char *vert, *frag;
static char *attr[] = { "position", "texture_position",
"fgcolor", "bgcolor" };
GLint s;
@@ -177,10 +180,14 @@ static int gltex_set(struct kmscon_text *txt)
goto err_bold_htable;
}
+ vert = _binary_src_text_gltex_atlas_vert_bin_start;
+ vlen = _binary_src_text_gltex_atlas_vert_bin_end - vert;
+ frag = _binary_src_text_gltex_atlas_frag_bin_start;
+ flen = _binary_src_text_gltex_atlas_frag_bin_end - frag;
gl_clear_error();
- ret = gl_shader_new(&gt->shader, gl_static_gltex_vert, -1,
- gl_static_gltex_frag, -1, attr, 4, log_llog, NULL);
+ ret = gl_shader_new(&gt->shader, vert, vlen, frag, flen, attr, 4,
+ log_llog, NULL);
if (ret)
goto err_bold_htable;
diff --git a/src/static_gltex.frag b/src/text_gltex_atlas.frag
index 7804011..7804011 100644
--- a/src/static_gltex.frag
+++ b/src/text_gltex_atlas.frag
diff --git a/src/static_gltex.vert b/src/text_gltex_atlas.vert
index e99e1b4..e99e1b4 100644
--- a/src/static_gltex.vert
+++ b/src/text_gltex_atlas.vert
diff --git a/src/static_blend.frag b/src/uterm_drm3d_blend.frag
index 669558d..669558d 100644
--- a/src/static_blend.frag
+++ b/src/uterm_drm3d_blend.frag
diff --git a/src/static_blend.vert b/src/uterm_drm3d_blend.vert
index 82b598d..82b598d 100644
--- a/src/static_blend.vert
+++ b/src/uterm_drm3d_blend.vert
diff --git a/src/static_blit.frag b/src/uterm_drm3d_blit.frag
index 8b36d9e..8b36d9e 100644
--- a/src/static_blit.frag
+++ b/src/uterm_drm3d_blit.frag
diff --git a/src/static_blit.vert b/src/uterm_drm3d_blit.vert
index 82b598d..82b598d 100644
--- a/src/static_blit.vert
+++ b/src/uterm_drm3d_blit.vert
diff --git a/src/static_fill.frag b/src/uterm_drm3d_fill.frag
index 9241ce0..9241ce0 100644
--- a/src/static_fill.frag
+++ b/src/uterm_drm3d_fill.frag
diff --git a/src/static_fill.vert b/src/uterm_drm3d_fill.vert
index eccc975..eccc975 100644
--- a/src/static_fill.vert
+++ b/src/uterm_drm3d_fill.vert
diff --git a/src/uterm_drm3d_render.c b/src/uterm_drm3d_render.c
index 698d199..aecaf67 100644
--- a/src/uterm_drm3d_render.c
+++ b/src/uterm_drm3d_render.c
@@ -54,12 +54,18 @@
#define LOG_SUBSYSTEM "uterm_drm3d_render"
-extern const char *gl_static_fill_vert;
-extern const char *gl_static_fill_frag;
-extern const char *gl_static_blend_vert;
-extern const char *gl_static_blend_frag;
-extern const char *gl_static_blit_vert;
-extern const char *gl_static_blit_frag;
+extern const char _binary_src_uterm_drm3d_blend_vert_bin_start[];
+extern const char _binary_src_uterm_drm3d_blend_vert_bin_end[];
+extern const char _binary_src_uterm_drm3d_blend_frag_bin_start[];
+extern const char _binary_src_uterm_drm3d_blend_frag_bin_end[];
+extern const char _binary_src_uterm_drm3d_blit_vert_bin_start[];
+extern const char _binary_src_uterm_drm3d_blit_vert_bin_end[];
+extern const char _binary_src_uterm_drm3d_blit_frag_bin_start[];
+extern const char _binary_src_uterm_drm3d_blit_frag_bin_end[];
+extern const char _binary_src_uterm_drm3d_fill_vert_bin_start[];
+extern const char _binary_src_uterm_drm3d_fill_vert_bin_end[];
+extern const char _binary_src_uterm_drm3d_fill_frag_bin_start[];
+extern const char _binary_src_uterm_drm3d_fill_frag_bin_end[];
static int init_shaders(struct uterm_video *video)
{
@@ -68,6 +74,10 @@ static int init_shaders(struct uterm_video *video)
char *fill_attr[] = { "position", "color" };
char *blend_attr[] = { "position", "texture_position" };
char *blit_attr[] = { "position", "texture_position" };
+ int blend_vlen, blend_flen, blit_vlen, blit_flen, fill_vlen, fill_flen;
+ const char *blend_vert, *blend_frag;
+ const char *blit_vert, *blit_frag;
+ const char *fill_vert, *fill_frag;
if (v3d->sinit == 1)
return -EFAULT;
@@ -76,8 +86,21 @@ static int init_shaders(struct uterm_video *video)
v3d->sinit = 1;
- ret = gl_shader_new(&v3d->fill_shader, gl_static_fill_vert, -1,
- gl_static_fill_frag, -1, fill_attr, 2, log_llog,
+ blend_vert = _binary_src_uterm_drm3d_blend_vert_bin_start;
+ blend_vlen = _binary_src_uterm_drm3d_blend_vert_bin_end - blend_vert;
+ blend_frag = _binary_src_uterm_drm3d_blend_frag_bin_start;
+ blend_flen = _binary_src_uterm_drm3d_blend_frag_bin_end - blend_frag;
+ blit_vert = _binary_src_uterm_drm3d_blit_vert_bin_start;
+ blit_vlen = _binary_src_uterm_drm3d_blit_vert_bin_end - blit_vert;
+ blit_frag = _binary_src_uterm_drm3d_blit_frag_bin_start;
+ blit_flen = _binary_src_uterm_drm3d_blit_frag_bin_end - blit_frag;
+ fill_vert = _binary_src_uterm_drm3d_fill_vert_bin_start;
+ fill_vlen = _binary_src_uterm_drm3d_fill_vert_bin_end - fill_vert;
+ fill_frag = _binary_src_uterm_drm3d_fill_frag_bin_start;
+ fill_flen = _binary_src_uterm_drm3d_fill_frag_bin_end - fill_frag;
+
+ ret = gl_shader_new(&v3d->fill_shader, fill_vert, fill_vlen,
+ fill_frag, fill_flen, fill_attr, 2, log_llog,
NULL);
if (ret)
return ret;
@@ -85,8 +108,8 @@ static int init_shaders(struct uterm_video *video)
v3d->uni_fill_proj = gl_shader_get_uniform(v3d->fill_shader,
"projection");
- ret = gl_shader_new(&v3d->blend_shader, gl_static_blend_vert, -1,
- gl_static_blend_frag, -1, blend_attr, 2, log_llog,
+ ret = gl_shader_new(&v3d->blend_shader, blend_vert, blend_vlen,
+ blend_frag, blend_flen, blend_attr, 2, log_llog,
NULL);
if (ret)
return ret;
@@ -100,8 +123,8 @@ static int init_shaders(struct uterm_video *video)
v3d->uni_blend_bgcol = gl_shader_get_uniform(v3d->blend_shader,
"bgcolor");
- ret = gl_shader_new(&v3d->blit_shader, gl_static_blit_vert, -1,
- gl_static_blit_frag, -1, blit_attr, 2, log_llog,
+ ret = gl_shader_new(&v3d->blit_shader, blit_vert, blit_vlen,
+ blit_frag, blit_flen, blit_attr, 2, log_llog,
NULL);
if (ret)
return ret;