Commit 6213689b authored by Romain Vimont's avatar Romain Vimont
Browse files

opengl: insert shader headers at compile time

The version and precision header strings are different for OpenGL and
OpenGL ES.

Insert them directly into the shader string literal, instead of
initializing renderer fields and inserting them at runtime.
parent 1ec5a769
......@@ -169,12 +169,23 @@ InitStereoMatrix(GLfloat matrix_out[static 3*3],
#undef ROW
}
/* https://en.wikipedia.org/wiki/OpenGL_Shading_Language#Versions */
#ifdef USE_OPENGL_ES2
# define SHADER_VERSION "#version 100\n"
/* In OpenGL ES, the fragment language has no default precision qualifier for
* floating point types. */
# define FRAGMENT_SHADER_PRECISION "precision highp float;\n"
#else
# define SHADER_VERSION "#version 120\n"
# define FRAGMENT_SHADER_PRECISION
#endif
static char *
BuildVertexShader(const struct vlc_gl_renderer *renderer)
{
/* Basic vertex shader */
static const char *template =
"#version %u\n"
SHADER_VERSION
"attribute vec2 PicCoordsIn;\n"
"varying vec2 PicCoords;\n"
"attribute vec3 VertexPosition;\n"
......@@ -188,8 +199,8 @@ BuildVertexShader(const struct vlc_gl_renderer *renderer)
" * vec4(VertexPosition, 1.0);\n"
"}";
char *code;
if (asprintf(&code, template, renderer->glsl_version) < 0)
char *code = strdup(template);
if (!code)
return NULL;
if (renderer->dump_shaders)
......@@ -204,9 +215,9 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
struct vlc_gl_sampler *sampler = renderer->sampler;
static const char *template =
"#version %u\n"
SHADER_VERSION
"%s" /* extensions */
"%s" /* precision header */
FRAGMENT_SHADER_PRECISION
"%s" /* vlc_texture definition */
"varying vec2 PicCoords;\n"
"void main() {\n"
......@@ -217,8 +228,7 @@ BuildFragmentShader(struct vlc_gl_renderer *renderer)
? sampler->shader.extensions : "";
char *code;
int ret = asprintf(&code, template, renderer->glsl_version, extensions,
renderer->glsl_precision_header, sampler->shader.body);
int ret = asprintf(&code, template, extensions, sampler->shader.body);
if (ret < 0)
return NULL;
......@@ -328,13 +338,6 @@ vlc_gl_renderer_New(vlc_gl_t *gl, const struct vlc_gl_api *api,
renderer->api = api;
renderer->vt = vt;
renderer->dump_shaders = var_InheritInteger(gl, "verbose") >= 4;
#if defined(USE_OPENGL_ES2)
renderer->glsl_version = 100;
renderer->glsl_precision_header = "precision highp float;\n";
#else
renderer->glsl_version = 120;
renderer->glsl_precision_header = "";
#endif
int ret = opengl_link_program(renderer);
if (ret != VLC_SUCCESS)
......
......@@ -50,12 +50,6 @@ struct vlc_gl_renderer
/* True to dump shaders */
bool dump_shaders;
/* GLSL version, set by the caller. 100 for GLSL ES, 120 for desktop GLSL */
unsigned glsl_version;
/* Precision header, set by the caller. In OpenGLES, the fragment language
* has no default precision qualifier for floating point types. */
const char *glsl_precision_header;
GLuint program_id;
struct {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment