Skip to content
Commits on Source (5)
......@@ -75,12 +75,13 @@ precision HIGHPRECISION float;
* snippet.
*/
compile_const int c_variant = DEF_VARIANT;
compile_const bool c_input_is_premult = DEF_INPUT_IS_PREMULT;
compile_const bool c_green_tint = DEF_GREEN_TINT;
compile_const int c_color_pre_curve = DEF_COLOR_PRE_CURVE;
compile_const int c_color_mapping = DEF_COLOR_MAPPING;
compile_const int c_color_post_curve = DEF_COLOR_POST_CURVE;
compile_const bool c_input_is_premult = DEF_INPUT_IS_PREMULT;
compile_const bool c_green_tint = DEF_GREEN_TINT;
compile_const bool c_wireframe = DEF_WIREFRAME;
compile_const bool c_need_color_pipeline =
c_color_pre_curve != SHADER_COLOR_CURVE_IDENTITY ||
c_color_mapping != SHADER_COLOR_MAPPING_IDENTITY ||
......@@ -122,6 +123,7 @@ uniform sampler2D tex;
#endif
varying HIGHPRECISION vec2 v_texcoord;
varying HIGHPRECISION vec4 v_color;
uniform sampler2D tex1;
uniform sampler2D tex2;
uniform float view_alpha;
......@@ -413,6 +415,9 @@ main()
/* Electrical (non-linear) RGBA values, may be premult or not */
color = sample_input_texture();
if (c_wireframe)
color *= v_color;
if (c_need_color_pipeline)
color = color_pipeline(color); /* Produces straight alpha */
......
......@@ -72,6 +72,12 @@ enum gl_shader_color_mapping {
SHADER_COLOR_MAPPING_MATRIX,
};
enum gl_shader_attrib_loc {
SHADER_ATTRIB_LOC_POSITION = 0,
SHADER_ATTRIB_LOC_TEXCOORD,
SHADER_ATTRIB_LOC_COLOR,
};
/** GL shader requirements key
*
* This structure is used as a binary blob key for building and searching
......@@ -88,6 +94,7 @@ struct gl_shader_requirements
unsigned variant:4; /* enum gl_shader_texture_variant */
bool input_is_premult:1;
bool green_tint:1;
bool wireframe:1;
unsigned color_pre_curve:2; /* enum gl_shader_color_curve */
unsigned color_mapping:2; /* enum gl_shader_color_mapping */
......@@ -96,7 +103,7 @@ struct gl_shader_requirements
* The total size of all bitfields plus pad_bits_ must fill up exactly
* how many bytes the compiler allocates for them together.
*/
unsigned pad_bits_:19;
unsigned pad_bits_:18;
};
static_assert(sizeof(struct gl_shader_requirements) ==
4 /* total bitfield size in bytes */,
......@@ -153,9 +160,9 @@ struct gl_renderer {
struct weston_log_scope *renderer_scope;
bool fragment_shader_debug;
bool fan_debug;
bool wireframe_debug;
struct weston_binding *fragment_binding;
struct weston_binding *fan_binding;
struct weston_binding *wireframe_binding;
EGLenum platform;
EGLDisplay egl_display;
......@@ -164,8 +171,10 @@ struct gl_renderer {
uint32_t gl_version;
struct wl_array vertices;
struct wl_array vtxcnt;
/* Vertex streams. */
struct wl_array position_stream;
struct wl_array color_stream;
struct wl_array indices[2];
EGLDeviceEXT egl_device;
const char *drm_device;
......
This diff is collapsed.
......@@ -238,8 +238,11 @@ create_vertex_shader_config_string(const struct gl_shader_requirements *req)
char *str;
size = asprintf(&str,
"#define DEF_TEXCOORD_INPUT %s\n",
gl_shader_texcoord_input_to_string(req->texcoord_input));
"#define DEF_TEXCOORD_INPUT %s\n"
"#define DEF_WIREFRAME %s\n",
gl_shader_texcoord_input_to_string(req->texcoord_input),
req->wireframe ? "true" : "false");
if (size < 0)
return NULL;
return str;
......@@ -254,12 +257,14 @@ create_fragment_shader_config_string(const struct gl_shader_requirements *req)
size = asprintf(&str,
"#define DEF_GREEN_TINT %s\n"
"#define DEF_INPUT_IS_PREMULT %s\n"
"#define DEF_WIREFRAME %s\n"
"#define DEF_COLOR_PRE_CURVE %s\n"
"#define DEF_COLOR_MAPPING %s\n"
"#define DEF_COLOR_POST_CURVE %s\n"
"#define DEF_VARIANT %s\n",
req->green_tint ? "true" : "false",
req->input_is_premult ? "true" : "false",
req->wireframe ? "true" : "false",
gl_shader_color_curve_to_string(req->color_pre_curve),
gl_shader_color_mapping_to_string(req->color_mapping),
gl_shader_color_curve_to_string(req->color_post_curve),
......@@ -325,9 +330,15 @@ gl_shader_create(struct gl_renderer *gr,
shader->program = glCreateProgram();
glAttachShader(shader->program, shader->vertex_shader);
glAttachShader(shader->program, shader->fragment_shader);
glBindAttribLocation(shader->program, 0, "position");
glBindAttribLocation(shader->program, SHADER_ATTRIB_LOC_POSITION,
"position");
if (requirements->texcoord_input == SHADER_TEXCOORD_INPUT_ATTRIB)
glBindAttribLocation(shader->program, 1, "texcoord");
glBindAttribLocation(shader->program,
SHADER_ATTRIB_LOC_TEXCOORD, "texcoord");
if (requirements->wireframe)
glBindAttribLocation(shader->program, SHADER_ATTRIB_LOC_COLOR,
"color");
glLinkProgram(shader->program);
glGetProgramiv(shader->program, GL_LINK_STATUS, &status);
......
......@@ -25,6 +25,9 @@
* SOFTWARE.
*/
/* For annotating shader compile-time constant arguments */
#define compile_const const
/* enum gl_shader_texcoord_input */
#define SHADER_TEXCOORD_INPUT_ATTRIB 0
#define SHADER_TEXCOORD_INPUT_SURFACE 1
......@@ -43,17 +46,24 @@ uniform mat4 surface_to_buffer;
attribute vec2 position;
attribute vec2 texcoord;
attribute vec4 color;
/* Match the varying precision to the fragment shader */
varying FRAG_PRECISION vec2 v_texcoord;
varying FRAG_PRECISION vec4 v_color;
compile_const int c_texcoord_input = DEF_TEXCOORD_INPUT;
compile_const bool c_wireframe = DEF_WIREFRAME;
void main()
{
gl_Position = proj * vec4(position, 0.0, 1.0);
#if DEF_TEXCOORD_INPUT == SHADER_TEXCOORD_INPUT_ATTRIB
v_texcoord = texcoord;
#elif DEF_TEXCOORD_INPUT == SHADER_TEXCOORD_INPUT_SURFACE
v_texcoord = vec2(surface_to_buffer * vec4(position, 0.0, 1.0));
#endif
if (c_texcoord_input == SHADER_TEXCOORD_INPUT_ATTRIB)
v_texcoord = texcoord;
else if (c_texcoord_input == SHADER_TEXCOORD_INPUT_SURFACE)
v_texcoord = vec2(surface_to_buffer * vec4(position, 0.0, 1.0));
if (c_wireframe)
v_color = color;
}
......@@ -151,7 +151,7 @@ Enable fragment debugging for gl-renderer.
.RE
- KEY_F :
.RS 4
Enable fan debugging for gl-renderer.
Enable wireframe debugging for gl-renderer.
.RE
- KEY_R :
.RS 4
......
......@@ -105,6 +105,17 @@ do { \
#define DIV_ROUND_UP(n, d) \
({ typeof(d) tmp = (d); ((n) + tmp - 1) / tmp; })
/**
* Round up to the next multiple of a power of 2.
*
* @param a the value to round up.
* @param n the power of 2.
* @return the rounded up value.
*/
#ifndef ROUND_UP_N
#define ROUND_UP_N(a, n) (((a) + (n) - 1) & ~((n) - 1))
#endif
/**
* Returns a pointer to the containing struct of a given member item.
*
......