gltestsrc: implement checkers pattern with GLSL

This commit is contained in:
Wang Xin-yu (王昕宇) 2014-09-28 10:51:09 +08:00 committed by Matthew Waters
parent 81c38c1d2b
commit eae09179f0
2 changed files with 90 additions and 158 deletions

View file

@ -188,6 +188,23 @@ gst_gl_test_src_smpte (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
#endif
}
/* *INDENT-OFF* */
static const GLfloat positions[] = {
-1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, -1.0, 0.0, 1.0,
-1.0, -1.0, 0.0, 1.0,
};
static const GLfloat identitiy_matrix[] = {
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
};
/* *INDENT-ON* */
void
gst_gl_test_src_shader (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
{
@ -195,21 +212,6 @@ gst_gl_test_src_shader (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
GstGLFuncs *gl = v->context->gl_vtable;
/* *INDENT-OFF* */
const GLfloat positions[] = {
-1.0, 1.0, 0.0, 1.0,
1.0, 1.0, 0.0, 1.0,
1.0, -1.0, 0.0, 1.0,
-1.0, -1.0, 0.0, 1.0,
};
const GLfloat identitiy_matrix[] = {
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
};
const GLfloat uvs[] = {
0.0, 1.0,
1.0, 1.0,
@ -306,168 +308,72 @@ gst_gl_test_src_blue (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
gst_gl_test_src_unicolor (v, buffer, w, h, vts_colors + COLOR_BLUE);
}
static void
gst_gl_test_src_checkers (GstGLTestSrc * v, gint checker_width)
{
GstGLFuncs *gl = v->context->gl_vtable;
GLushort indices[] = { 0, 1, 2, 3, 0 };
GLint attr_position_loc = 0;
if (gst_gl_context_get_gl_api (v->context)) {
gst_gl_context_clear_shader (v->context);
gl->BindTexture (GL_TEXTURE_2D, 0);
gl->Disable (GL_TEXTURE_2D);
gst_gl_shader_use (v->shader);
attr_position_loc =
gst_gl_shader_get_attribute_location (v->shader, "position");
/* Load the vertex position */
gl->VertexAttribPointer (attr_position_loc, 4, GL_FLOAT,
GL_FALSE, 0, positions);
gl->EnableVertexAttribArray (attr_position_loc);
gst_gl_shader_set_uniform_matrix_4fv (v->shader, "mvp",
1, GL_FALSE, identitiy_matrix);
gst_gl_shader_set_uniform_1f (v->shader, "double_checker_width",
checker_width * 2);
gl->DrawElements (GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, indices);
gl->DisableVertexAttribArray (attr_position_loc);
gst_gl_context_clear_shader (v->context);
}
}
void
gst_gl_test_src_checkers1 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = π
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
for (y = 0; y < h; y++) {
p->color = vts_colors + COLOR_GREEN;
p->paint_hline (p, 0, y, w);
for (x = (y % 2); x < w; x += 2) {
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y, 1);
}
}
#endif
gst_gl_test_src_checkers (v, 1);
}
void
gst_gl_test_src_checkers2 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
p->color = vts_colors + COLOR_GREEN;
for (y = 0; y < h; y++) {
p->paint_hline (p, 0, y, w);
}
for (y = 0; y < h; y += 2) {
for (x = ((y % 4) == 0) ? 0 : 2; x < w; x += 4) {
guint len = (x < (w - 1)) ? 2 : (w - x);
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y + 0, len);
if (G_LIKELY ((y + 1) < h)) {
p->paint_hline (p, x, y + 1, len);
}
}
}
#endif
gst_gl_test_src_checkers (v, 2);
}
void
gst_gl_test_src_checkers4 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
gst_gl_test_src_checkers (v, 4);
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
p->color = vts_colors + COLOR_GREEN;
for (y = 0; y < h; y++) {
p->paint_hline (p, 0, y, w);
}
for (y = 0; y < h; y += 4) {
for (x = ((y % 8) == 0) ? 0 : 4; x < w; x += 8) {
guint len = (x < (w - 3)) ? 4 : (w - x);
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y + 0, len);
if (G_LIKELY ((y + 1) < h)) {
p->paint_hline (p, x, y + 1, len);
if (G_LIKELY ((y + 2) < h)) {
p->paint_hline (p, x, y + 2, len);
if (G_LIKELY ((y + 3) < h)) {
p->paint_hline (p, x, y + 3, len);
}
}
}
}
}
#endif
}
void
gst_gl_test_src_checkers8 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
{
#if 0
int x, y;
paintinfo pi = { NULL, };
paintinfo *p = &pi;
struct fourcc_list_struct *fourcc;
p->width = w;
p->height = h;
fourcc = v->fourcc;
if (fourcc == NULL)
return;
fourcc->paint_setup (p, dest);
p->paint_hline = fourcc->paint_hline;
p->color = vts_colors + COLOR_GREEN;
for (y = 0; y < h; y++) {
p->paint_hline (p, 0, y, w);
}
for (y = 0; y < h; y += 8) {
for (x = ((GST_ROUND_UP_8 (y) % 16) == 0) ? 0 : 8; x < w; x += 16) {
guint len = (x < (w - 7)) ? 8 : (w - x);
p->color = vts_colors + COLOR_RED;
p->paint_hline (p, x, y + 0, len);
if (G_LIKELY ((y + 1) < h)) {
p->paint_hline (p, x, y + 1, len);
if (G_LIKELY ((y + 2) < h)) {
p->paint_hline (p, x, y + 2, len);
if (G_LIKELY ((y + 3) < h)) {
p->paint_hline (p, x, y + 3, len);
if (G_LIKELY ((y + 4) < h)) {
p->paint_hline (p, x, y + 4, len);
if (G_LIKELY ((y + 5) < h)) {
p->paint_hline (p, x, y + 5, len);
if (G_LIKELY ((y + 6) < h)) {
p->paint_hline (p, x, y + 6, len);
if (G_LIKELY ((y + 7) < h)) {
p->paint_hline (p, x, y + 7, len);
}
}
}
}
}
}
}
}
}
#endif
gst_gl_test_src_checkers (v, 8);
}
void

View file

@ -301,6 +301,24 @@ const gchar *mandelbrot_fragment_src = "uniform float time; \
gl_FragColor = iterate_pixel(fractal_position); \
}";
const gchar *checkers_vertex_src = "attribute vec4 position; \
uniform mat4 mvp; \
void main() \
{ \
gl_Position = mvp * position; \
}";
const gchar *checkers_fragment_src = "uniform float double_checker_width; \
void main() \
{ \
vec2 xy_index= floor((gl_FragCoord.xy-vec2(0.5,0.5))/double_checker_width); \
vec2 xy_mod=mod(xy_index,vec2(2.0,2.0)); \
float result=mod(xy_mod.x+xy_mod.y,2.0); \
gl_FragColor.rgb=step(result,vec3(0.5,0.5,0.5)); \
}";
static void
gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
{
@ -333,15 +351,23 @@ gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
gltestsrc->make_image = gst_gl_test_src_blue;
break;
case GST_GL_TEST_SRC_CHECKERS1:
gltestsrc->vertex_src = checkers_vertex_src;
gltestsrc->fragment_src = checkers_fragment_src;
gltestsrc->make_image = gst_gl_test_src_checkers1;
break;
case GST_GL_TEST_SRC_CHECKERS2:
gltestsrc->vertex_src = checkers_vertex_src;
gltestsrc->fragment_src = checkers_fragment_src;
gltestsrc->make_image = gst_gl_test_src_checkers2;
break;
case GST_GL_TEST_SRC_CHECKERS4:
gltestsrc->vertex_src = checkers_vertex_src;
gltestsrc->fragment_src = checkers_fragment_src;
gltestsrc->make_image = gst_gl_test_src_checkers4;
break;
case GST_GL_TEST_SRC_CHECKERS8:
gltestsrc->vertex_src = checkers_vertex_src;
gltestsrc->fragment_src = checkers_fragment_src;
gltestsrc->make_image = gst_gl_test_src_checkers8;
break;
case GST_GL_TEST_SRC_CIRCULAR: