mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-31 19:42:26 +00:00
gltestsrc: implement checkers pattern with GLSL
https://bugzilla.gnome.org/show_bug.cgi?id=737505
This commit is contained in:
parent
341b336e71
commit
e6212f5156
2 changed files with 91 additions and 158 deletions
|
@ -188,6 +188,23 @@ gst_gl_test_src_smpte (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
||||||
#endif
|
#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
|
void
|
||||||
gst_gl_test_src_shader (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
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;
|
GstGLFuncs *gl = v->context->gl_vtable;
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
/* *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[] = {
|
const GLfloat uvs[] = {
|
||||||
0.0, 1.0,
|
0.0, 1.0,
|
||||||
1.0, 1.0,
|
1.0, 1.0,
|
||||||
|
@ -306,168 +308,71 @@ 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);
|
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, "checker_width", checker_width);
|
||||||
|
|
||||||
|
gl->DrawElements (GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_SHORT, indices);
|
||||||
|
|
||||||
|
gl->DisableVertexAttribArray (attr_position_loc);
|
||||||
|
|
||||||
|
gst_gl_context_clear_shader (v->context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_test_src_checkers1 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
gst_gl_test_src_checkers1 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
||||||
{
|
{
|
||||||
#if 0
|
gst_gl_test_src_checkers (v, 1);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_test_src_checkers2 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
gst_gl_test_src_checkers2 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
||||||
{
|
{
|
||||||
#if 0
|
gst_gl_test_src_checkers (v, 2);
|
||||||
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;
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_gl_test_src_checkers4 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
gst_gl_test_src_checkers4 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
||||||
{
|
{
|
||||||
#if 0
|
gst_gl_test_src_checkers (v, 4);
|
||||||
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;
|
|
||||||
|
|
||||||
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
|
void
|
||||||
gst_gl_test_src_checkers8 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
gst_gl_test_src_checkers8 (GstGLTestSrc * v, GstBuffer * buffer, int w, int h)
|
||||||
{
|
{
|
||||||
#if 0
|
gst_gl_test_src_checkers (v, 8);
|
||||||
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;
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -301,6 +301,26 @@ const gchar *mandelbrot_fragment_src = "uniform float time; \
|
||||||
gl_FragColor = iterate_pixel(fractal_position); \
|
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 checker_width; \
|
||||||
|
void main() \
|
||||||
|
{ \
|
||||||
|
vec2 xy_index= floor((gl_FragCoord.xy-vec2(0.5,0.5))/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.r=step(result,0.5); \
|
||||||
|
gl_FragColor.g=1.0-gl_FragColor.r; \
|
||||||
|
gl_FragColor.ba=vec2(0,1); \
|
||||||
|
}";
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
|
gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
|
||||||
{
|
{
|
||||||
|
@ -333,15 +353,23 @@ gst_gl_test_src_set_pattern (GstGLTestSrc * gltestsrc, gint pattern_type)
|
||||||
gltestsrc->make_image = gst_gl_test_src_blue;
|
gltestsrc->make_image = gst_gl_test_src_blue;
|
||||||
break;
|
break;
|
||||||
case GST_GL_TEST_SRC_CHECKERS1:
|
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;
|
gltestsrc->make_image = gst_gl_test_src_checkers1;
|
||||||
break;
|
break;
|
||||||
case GST_GL_TEST_SRC_CHECKERS2:
|
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;
|
gltestsrc->make_image = gst_gl_test_src_checkers2;
|
||||||
break;
|
break;
|
||||||
case GST_GL_TEST_SRC_CHECKERS4:
|
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;
|
gltestsrc->make_image = gst_gl_test_src_checkers4;
|
||||||
break;
|
break;
|
||||||
case GST_GL_TEST_SRC_CHECKERS8:
|
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;
|
gltestsrc->make_image = gst_gl_test_src_checkers8;
|
||||||
break;
|
break;
|
||||||
case GST_GL_TEST_SRC_CIRCULAR:
|
case GST_GL_TEST_SRC_CIRCULAR:
|
||||||
|
|
Loading…
Reference in a new issue