mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-28 18:18:38 +00:00
[393/906] glmosaic: for now it's a cube mosaic
Also use GPtrArray instead of GArray in glmixer. And add a pipeline to tests/pieplines
This commit is contained in:
parent
ea2962e44f
commit
aeb793497d
4 changed files with 116 additions and 113 deletions
|
@ -910,7 +910,7 @@ gst_gl_mixer_process_buffers (GstGLMixer * mix, GstBuffer * outbuf)
|
||||||
gst_object_sync_values (G_OBJECT (pad), stream_time);
|
gst_object_sync_values (G_OBJECT (pad), stream_time);
|
||||||
|
|
||||||
/* put buffer into array */
|
/* put buffer into array */
|
||||||
g_array_insert_val (mix->array_buffers, array_index, mixcol->buffer);
|
mix->array_buffers->pdata[array_index] = mixcol->buffer;
|
||||||
|
|
||||||
if (pad == mix->master) {
|
if (pad == mix->master) {
|
||||||
gint64 running_time;
|
gint64 running_time;
|
||||||
|
@ -1213,6 +1213,7 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
|
||||||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||||
{
|
{
|
||||||
GSList *walk = mix->sinkpads;
|
GSList *walk = mix->sinkpads;
|
||||||
|
gint i = 0;
|
||||||
|
|
||||||
GstElement *parent = GST_ELEMENT (gst_element_get_parent (mix));
|
GstElement *parent = GST_ELEMENT (gst_element_get_parent (mix));
|
||||||
GstStructure *structure =
|
GstStructure *structure =
|
||||||
|
@ -1244,9 +1245,10 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
|
||||||
walk = g_slist_next (walk);
|
walk = g_slist_next (walk);
|
||||||
sink_pad->display = gst_gl_display_new ();
|
sink_pad->display = gst_gl_display_new ();
|
||||||
}
|
}
|
||||||
mix->array_buffers =
|
mix->array_buffers = g_ptr_array_sized_new (mix->next_sinkpad);
|
||||||
g_array_sized_new (FALSE, TRUE, sizeof (GstBuffer *),
|
for (i = 0; i < mix->next_sinkpad; ++i) {
|
||||||
mix->next_sinkpad);
|
g_ptr_array_add (mix->array_buffers, NULL);
|
||||||
|
}
|
||||||
GST_LOG_OBJECT (mix, "starting collectpads");
|
GST_LOG_OBJECT (mix, "starting collectpads");
|
||||||
gst_collect_pads_start (mix->collect);
|
gst_collect_pads_start (mix->collect);
|
||||||
break;
|
break;
|
||||||
|
@ -1256,7 +1258,7 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
|
||||||
GSList *walk = mix->sinkpads;
|
GSList *walk = mix->sinkpads;
|
||||||
GST_LOG_OBJECT (mix, "stopping collectpads");
|
GST_LOG_OBJECT (mix, "stopping collectpads");
|
||||||
gst_collect_pads_stop (mix->collect);
|
gst_collect_pads_stop (mix->collect);
|
||||||
g_array_free (mix->array_buffers, TRUE);
|
g_ptr_array_free (mix->array_buffers, TRUE);
|
||||||
while (walk) {
|
while (walk) {
|
||||||
GstGLMixerPad *sink_pad = GST_GL_MIXER_PAD (walk->data);
|
GstGLMixerPad *sink_pad = GST_GL_MIXER_PAD (walk->data);
|
||||||
walk = g_slist_next (walk);
|
walk = g_slist_next (walk);
|
||||||
|
|
|
@ -46,7 +46,7 @@ typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer,
|
||||||
GstCaps* outcaps);
|
GstCaps* outcaps);
|
||||||
typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
|
typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
|
||||||
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix,
|
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix,
|
||||||
GArray *buffers, GstBuffer *outbuf);
|
GPtrArray *buffers, GstBuffer *outbuf);
|
||||||
|
|
||||||
struct _GstGLMixer
|
struct _GstGLMixer
|
||||||
{
|
{
|
||||||
|
@ -62,7 +62,7 @@ struct _GstGLMixer
|
||||||
/* sinkpads, a GSList of GstGLMixerPads */
|
/* sinkpads, a GSList of GstGLMixerPads */
|
||||||
GSList *sinkpads;
|
GSList *sinkpads;
|
||||||
|
|
||||||
GArray *array_buffers;
|
GPtrArray *array_buffers;
|
||||||
|
|
||||||
gint numpads;
|
gint numpads;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ static gboolean gst_gl_mosaic_init_shader (GstGLMixer * mixer,
|
||||||
GstCaps * outcaps);
|
GstCaps * outcaps);
|
||||||
|
|
||||||
static gboolean gst_gl_mosaic_proc (GstGLMixer * mixer,
|
static gboolean gst_gl_mosaic_proc (GstGLMixer * mixer,
|
||||||
GArray * buffers, GstBuffer * outbuf);
|
GPtrArray * buffers, GstBuffer * outbuf);
|
||||||
static void gst_gl_mosaic_callback (gpointer stuff);
|
static void gst_gl_mosaic_callback (gpointer stuff);
|
||||||
|
|
||||||
//vertex source
|
//vertex source
|
||||||
|
@ -180,7 +180,7 @@ gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_gl_mosaic_proc (GstGLMixer * mix, GArray * buffers, GstBuffer * outbuf)
|
gst_gl_mosaic_proc (GstGLMixer * mix, GPtrArray * buffers, GstBuffer * outbuf)
|
||||||
{
|
{
|
||||||
GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
|
GstGLMosaic *mosaic = GST_GL_MOSAIC (mix);
|
||||||
GstGLBuffer *gl_out_buffer = GST_GL_BUFFER (outbuf);
|
GstGLBuffer *gl_out_buffer = GST_GL_BUFFER (outbuf);
|
||||||
|
@ -201,89 +201,10 @@ gst_gl_mosaic_callback (gpointer stuff)
|
||||||
{
|
{
|
||||||
GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff);
|
GstGLMosaic *mosaic = GST_GL_MOSAIC (stuff);
|
||||||
|
|
||||||
GstGLBuffer *gl_in_buffer =
|
|
||||||
g_array_index (mosaic->input_gl_buffers, GstGLBuffer *, 0);
|
|
||||||
GLuint texture = gl_in_buffer->texture;
|
|
||||||
GLfloat width = (GLfloat) gl_in_buffer->width;
|
|
||||||
GLfloat height = (GLfloat) gl_in_buffer->height;
|
|
||||||
|
|
||||||
static GLfloat xrot = 0;
|
static GLfloat xrot = 0;
|
||||||
static GLfloat yrot = 0;
|
static GLfloat yrot = 0;
|
||||||
static GLfloat zrot = 0;
|
static GLfloat zrot = 0;
|
||||||
|
|
||||||
const GLfloat v_vertices[] = {
|
|
||||||
|
|
||||||
//front face
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
width, 0.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
width, height,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
0.0f, height,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
//back face
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
width, 0.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
0.0f, height,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
width, height,
|
|
||||||
//right face
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
width, 0.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
0.0f, height,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
width, height,
|
|
||||||
//left face
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
width, 0.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
width, height,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
0.0f, height,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
//top face
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
width, 0.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
0.0f, height,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
width, height,
|
|
||||||
//bottom face
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
width, 0.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
width, height,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
0.0f, height,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
GLushort indices[] = {
|
|
||||||
0, 1, 2,
|
|
||||||
0, 2, 3,
|
|
||||||
4, 5, 6,
|
|
||||||
4, 6, 7,
|
|
||||||
8, 9, 10,
|
|
||||||
8, 10, 11,
|
|
||||||
12, 13, 14,
|
|
||||||
12, 14, 15,
|
|
||||||
16, 17, 18,
|
|
||||||
16, 18, 19,
|
|
||||||
20, 21, 22,
|
|
||||||
20, 22, 23
|
|
||||||
};
|
|
||||||
|
|
||||||
GLint attr_position_loc = 0;
|
GLint attr_position_loc = 0;
|
||||||
GLint attr_texture_loc = 0;
|
GLint attr_texture_loc = 0;
|
||||||
|
|
||||||
|
@ -294,6 +215,15 @@ gst_gl_mosaic_callback (gpointer stuff)
|
||||||
0.0f, 0.0f, 0.0f, 1.0f
|
0.0f, 0.0f, 0.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const GLushort indices[] = {
|
||||||
|
0, 1, 2,
|
||||||
|
0, 2, 3
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
gint count = 0;
|
||||||
|
gboolean do_next = TRUE;
|
||||||
|
|
||||||
gst_gl_shader_use (NULL);
|
gst_gl_shader_use (NULL);
|
||||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||||
glDisable (GL_TEXTURE_RECTANGLE_ARB);
|
glDisable (GL_TEXTURE_RECTANGLE_ARB);
|
||||||
|
@ -310,27 +240,98 @@ gst_gl_mosaic_callback (gpointer stuff)
|
||||||
attr_texture_loc =
|
attr_texture_loc =
|
||||||
gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");
|
gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");
|
||||||
|
|
||||||
//Load the vertex position
|
while (do_next && count < mosaic->input_gl_buffers->len && count < 6) {
|
||||||
glVertexAttribPointerARB (attr_position_loc, 3, GL_FLOAT,
|
GstGLBuffer *gl_in_buffer =
|
||||||
GL_FALSE, 5 * sizeof (GLfloat), v_vertices);
|
g_ptr_array_index (mosaic->input_gl_buffers, count);
|
||||||
|
|
||||||
//Load the texture coordinate
|
if (gl_in_buffer && gl_in_buffer->texture) {
|
||||||
glVertexAttribPointerARB (attr_texture_loc, 2, GL_FLOAT,
|
GLuint texture = gl_in_buffer->texture;
|
||||||
GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]);
|
GLfloat width = (GLfloat) gl_in_buffer->width;
|
||||||
|
GLfloat height = (GLfloat) gl_in_buffer->height;
|
||||||
|
|
||||||
glEnableVertexAttribArrayARB (attr_position_loc);
|
const GLfloat v_vertices[] = {
|
||||||
glEnableVertexAttribArrayARB (attr_texture_loc);
|
|
||||||
|
|
||||||
glActiveTextureARB (GL_TEXTURE0_ARB);
|
//front face
|
||||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
|
1.0f, 1.0f, -1.0f,
|
||||||
gst_gl_shader_set_uniform_1i (mosaic->shader, "s_texture", 0);
|
width, 0.0f,
|
||||||
gst_gl_shader_set_uniform_1f (mosaic->shader, "xrot_degree", xrot);
|
1.0f, -1.0f, -1.0f,
|
||||||
gst_gl_shader_set_uniform_1f (mosaic->shader, "yrot_degree", yrot);
|
width, height,
|
||||||
gst_gl_shader_set_uniform_1f (mosaic->shader, "zrot_degree", zrot);
|
-1.0f, -1.0f, -1.0f,
|
||||||
gst_gl_shader_set_uniform_matrix_4fv (mosaic->shader, "u_matrix", 1, GL_FALSE,
|
0.0f, height,
|
||||||
matrix);
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
//right face
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
width, 0.0f,
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
0.0f, height,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
width, height,
|
||||||
|
//left face
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
width, 0.0f,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
width, height,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
0.0f, height,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
//top face
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
width, 0.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
0.0f, height,
|
||||||
|
1.0f, -1.0f, -1.0f,
|
||||||
|
width, height,
|
||||||
|
//bottom face
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
width, 0.0f,
|
||||||
|
1.0f, 1.0f, -1.0f,
|
||||||
|
width, height,
|
||||||
|
-1.0f, 1.0f, -1.0f,
|
||||||
|
0.0f, height,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
//back face
|
||||||
|
1.0f, 1.0f, 1.0f,
|
||||||
|
width, 0.0f,
|
||||||
|
-1.0f, 1.0f, 1.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
-1.0f, -1.0f, 1.0f,
|
||||||
|
0.0f, height,
|
||||||
|
1.0f, -1.0f, 1.0f,
|
||||||
|
width, height
|
||||||
|
};
|
||||||
|
|
||||||
glDrawElements (GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices);
|
glVertexAttribPointerARB (attr_position_loc, 3, GL_FLOAT,
|
||||||
|
GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count]);
|
||||||
|
|
||||||
|
glVertexAttribPointerARB (attr_texture_loc, 2, GL_FLOAT,
|
||||||
|
GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[5 * 4 * count + 3]);
|
||||||
|
|
||||||
|
glEnableVertexAttribArrayARB (attr_position_loc);
|
||||||
|
glEnableVertexAttribArrayARB (attr_texture_loc);
|
||||||
|
|
||||||
|
glActiveTextureARB (GL_TEXTURE0_ARB);
|
||||||
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
|
||||||
|
gst_gl_shader_set_uniform_1i (mosaic->shader, "s_texture", 0);
|
||||||
|
gst_gl_shader_set_uniform_1f (mosaic->shader, "xrot_degree", xrot);
|
||||||
|
gst_gl_shader_set_uniform_1f (mosaic->shader, "yrot_degree", yrot);
|
||||||
|
gst_gl_shader_set_uniform_1f (mosaic->shader, "zrot_degree", zrot);
|
||||||
|
gst_gl_shader_set_uniform_matrix_4fv (mosaic->shader, "u_matrix", 1,
|
||||||
|
GL_FALSE, matrix);
|
||||||
|
|
||||||
|
glDrawElements (GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
|
||||||
|
|
||||||
|
++count;
|
||||||
|
} else {
|
||||||
|
do_next = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
glDisableVertexAttribArrayARB (attr_position_loc);
|
glDisableVertexAttribArrayARB (attr_position_loc);
|
||||||
glDisableVertexAttribArrayARB (attr_texture_loc);
|
glDisableVertexAttribArrayARB (attr_texture_loc);
|
||||||
|
@ -341,7 +342,7 @@ gst_gl_mosaic_callback (gpointer stuff)
|
||||||
|
|
||||||
gst_gl_shader_use (NULL);
|
gst_gl_shader_use (NULL);
|
||||||
|
|
||||||
xrot += 0.3f;
|
xrot += 0.6f;
|
||||||
yrot += 0.2f;
|
yrot += 0.4f;
|
||||||
zrot += 0.4f;
|
zrot += 0.8f;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct _GstGLMosaic
|
||||||
GstGLMixer mixer;
|
GstGLMixer mixer;
|
||||||
|
|
||||||
GstGLShader *shader;
|
GstGLShader *shader;
|
||||||
GArray *input_gl_buffers;
|
GPtrArray *input_gl_buffers;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstGLMosaicClass
|
struct _GstGLMosaicClass
|
||||||
|
|
Loading…
Reference in a new issue