diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-03-15 14:52:05 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-03 12:12:29 +0100 |
commit | 0a098393c2fe7e40a02b44481194534ad2572d70 (patch) | |
tree | a913ff1e50aaf2ef2ac4aed705cc57bc6f4c355d /src | |
parent | 924a732e7cf26c571f29ff97ba7e8089c7db54c0 (diff) |
shl: shader: add "len" parameter to shader sources
Shader sources may not be 0 terminated if we mmap() them. Hence, we need
to pass the length to the shader compiler. As glShaderSource() allows this
<0 as zero-terminated strings, we can simply add a parameter for the
shader length.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/shl_gl.h | 3 | ||||
-rw-r--r-- | src/shl_gl_shader.c | 16 | ||||
-rw-r--r-- | src/text_gltex.c | 4 | ||||
-rw-r--r-- | src/uterm_drm3d_render.c | 14 |
4 files changed, 22 insertions, 15 deletions
diff --git a/src/shl_gl.h b/src/shl_gl.h index ccff76b..c194433 100644 --- a/src/shl_gl.h +++ b/src/shl_gl.h @@ -71,7 +71,8 @@ float *gl_m4_stack_tip(struct gl_m4_stack *stack); struct gl_shader; -int gl_shader_new(struct gl_shader **out, const char *vert, const char *frag, +int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, + const char *frag, int frag_len, char **attr, size_t attr_count, llog_submit_t llog, void *llog_data); void gl_shader_ref(struct gl_shader *shader); diff --git a/src/shl_gl_shader.c b/src/shl_gl_shader.c index 093d786..68764e8 100644 --- a/src/shl_gl_shader.c +++ b/src/shl_gl_shader.c @@ -106,10 +106,10 @@ bool gl_has_error(struct gl_shader *shader) } static int compile_shader(struct gl_shader *shader, GLenum type, - const char *source) + const char *source, int len) { char msg[512]; - GLint status = 1; + GLint status = 1, size; GLuint s; s = glCreateShader(type); @@ -118,7 +118,8 @@ static int compile_shader(struct gl_shader *shader, GLenum type, return GL_NONE; } - glShaderSource(s, 1, &source, NULL); + size = len; + glShaderSource(s, 1, &source, &size); glCompileShader(s); glGetShaderiv(s, GL_COMPILE_STATUS, &status); @@ -132,7 +133,8 @@ static int compile_shader(struct gl_shader *shader, GLenum type, return s; } -int gl_shader_new(struct gl_shader **out, const char *vert, const char *frag, +int gl_shader_new(struct gl_shader **out, const char *vert, int vert_len, + const char *frag, int frag_len, char **attr, size_t attr_count, llog_submit_t llog, void *llog_data) { @@ -154,13 +156,15 @@ int gl_shader_new(struct gl_shader **out, const char *vert, const char *frag, llog_debug(shader, "new shader"); - shader->vshader = compile_shader(shader, GL_VERTEX_SHADER, vert); + shader->vshader = compile_shader(shader, GL_VERTEX_SHADER, vert, + vert_len); if (shader->vshader == GL_NONE) { ret = -EFAULT; goto err_free; } - shader->fshader = compile_shader(shader, GL_FRAGMENT_SHADER, frag); + shader->fshader = compile_shader(shader, GL_FRAGMENT_SHADER, frag, + frag_len); if (shader->fshader == GL_NONE) { ret = -EFAULT; goto err_vshader; diff --git a/src/text_gltex.c b/src/text_gltex.c index b0abcbd..beb0bba 100644 --- a/src/text_gltex.c +++ b/src/text_gltex.c @@ -179,8 +179,8 @@ static int gltex_set(struct kmscon_text *txt) gl_clear_error(); - ret = gl_shader_new(>->shader, gl_static_gltex_vert, - gl_static_gltex_frag, attr, 4, log_llog, NULL); + ret = gl_shader_new(>->shader, gl_static_gltex_vert, -1, + gl_static_gltex_frag, -1, attr, 4, log_llog, NULL); if (ret) goto err_bold_htable; diff --git a/src/uterm_drm3d_render.c b/src/uterm_drm3d_render.c index c7a213d..698d199 100644 --- a/src/uterm_drm3d_render.c +++ b/src/uterm_drm3d_render.c @@ -76,16 +76,17 @@ static int init_shaders(struct uterm_video *video) v3d->sinit = 1; - ret = gl_shader_new(&v3d->fill_shader, gl_static_fill_vert, - gl_static_fill_frag, fill_attr, 2, log_llog, NULL); + ret = gl_shader_new(&v3d->fill_shader, gl_static_fill_vert, -1, + gl_static_fill_frag, -1, fill_attr, 2, log_llog, + NULL); if (ret) return ret; v3d->uni_fill_proj = gl_shader_get_uniform(v3d->fill_shader, "projection"); - ret = gl_shader_new(&v3d->blend_shader, gl_static_blend_vert, - gl_static_blend_frag, blend_attr, 2, log_llog, + ret = gl_shader_new(&v3d->blend_shader, gl_static_blend_vert, -1, + gl_static_blend_frag, -1, blend_attr, 2, log_llog, NULL); if (ret) return ret; @@ -99,8 +100,9 @@ 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, - gl_static_blit_frag, blit_attr, 2, log_llog, NULL); + ret = gl_shader_new(&v3d->blit_shader, gl_static_blit_vert, -1, + gl_static_blit_frag, -1, blit_attr, 2, log_llog, + NULL); if (ret) return ret; |