mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-27 09:38:17 +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);
|
||||
|
||||
/* 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) {
|
||||
gint64 running_time;
|
||||
|
@ -1213,6 +1213,7 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
|
|||
case GST_STATE_CHANGE_READY_TO_PAUSED:
|
||||
{
|
||||
GSList *walk = mix->sinkpads;
|
||||
gint i = 0;
|
||||
|
||||
GstElement *parent = GST_ELEMENT (gst_element_get_parent (mix));
|
||||
GstStructure *structure =
|
||||
|
@ -1244,9 +1245,10 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
|
|||
walk = g_slist_next (walk);
|
||||
sink_pad->display = gst_gl_display_new ();
|
||||
}
|
||||
mix->array_buffers =
|
||||
g_array_sized_new (FALSE, TRUE, sizeof (GstBuffer *),
|
||||
mix->next_sinkpad);
|
||||
mix->array_buffers = g_ptr_array_sized_new (mix->next_sinkpad);
|
||||
for (i = 0; i < mix->next_sinkpad; ++i) {
|
||||
g_ptr_array_add (mix->array_buffers, NULL);
|
||||
}
|
||||
GST_LOG_OBJECT (mix, "starting collectpads");
|
||||
gst_collect_pads_start (mix->collect);
|
||||
break;
|
||||
|
@ -1256,7 +1258,7 @@ gst_gl_mixer_change_state (GstElement * element, GstStateChange transition)
|
|||
GSList *walk = mix->sinkpads;
|
||||
GST_LOG_OBJECT (mix, "stopping collectpads");
|
||||
gst_collect_pads_stop (mix->collect);
|
||||
g_array_free (mix->array_buffers, TRUE);
|
||||
g_ptr_array_free (mix->array_buffers, TRUE);
|
||||
while (walk) {
|
||||
GstGLMixerPad *sink_pad = GST_GL_MIXER_PAD (walk->data);
|
||||
walk = g_slist_next (walk);
|
||||
|
|
|
@ -46,7 +46,7 @@ typedef gboolean (*GstGLMixerSetCaps) (GstGLMixer* mixer,
|
|||
GstCaps* outcaps);
|
||||
typedef void (*GstGLMixerReset) (GstGLMixer *mixer);
|
||||
typedef gboolean (*GstGLMixerProcessFunc) (GstGLMixer *mix,
|
||||
GArray *buffers, GstBuffer *outbuf);
|
||||
GPtrArray *buffers, GstBuffer *outbuf);
|
||||
|
||||
struct _GstGLMixer
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ struct _GstGLMixer
|
|||
/* sinkpads, a GSList of GstGLMixerPads */
|
||||
GSList *sinkpads;
|
||||
|
||||
GArray *array_buffers;
|
||||
GPtrArray *array_buffers;
|
||||
|
||||
gint numpads;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ static gboolean gst_gl_mosaic_init_shader (GstGLMixer * mixer,
|
|||
GstCaps * outcaps);
|
||||
|
||||
static gboolean gst_gl_mosaic_proc (GstGLMixer * mixer,
|
||||
GArray * buffers, GstBuffer * outbuf);
|
||||
GPtrArray * buffers, GstBuffer * outbuf);
|
||||
static void gst_gl_mosaic_callback (gpointer stuff);
|
||||
|
||||
//vertex source
|
||||
|
@ -180,7 +180,7 @@ gst_gl_mosaic_init_shader (GstGLMixer * mixer, GstCaps * outcaps)
|
|||
}
|
||||
|
||||
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);
|
||||
GstGLBuffer *gl_out_buffer = GST_GL_BUFFER (outbuf);
|
||||
|
@ -201,89 +201,10 @@ gst_gl_mosaic_callback (gpointer 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 yrot = 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_texture_loc = 0;
|
||||
|
||||
|
@ -294,6 +215,15 @@ gst_gl_mosaic_callback (gpointer stuff)
|
|||
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);
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
|
||||
glDisable (GL_TEXTURE_RECTANGLE_ARB);
|
||||
|
@ -310,27 +240,98 @@ gst_gl_mosaic_callback (gpointer stuff)
|
|||
attr_texture_loc =
|
||||
gst_gl_shader_get_attribute_location (mosaic->shader, "a_texCoord");
|
||||
|
||||
//Load the vertex position
|
||||
glVertexAttribPointerARB (attr_position_loc, 3, GL_FLOAT,
|
||||
GL_FALSE, 5 * sizeof (GLfloat), v_vertices);
|
||||
while (do_next && count < mosaic->input_gl_buffers->len && count < 6) {
|
||||
GstGLBuffer *gl_in_buffer =
|
||||
g_ptr_array_index (mosaic->input_gl_buffers, count);
|
||||
|
||||
//Load the texture coordinate
|
||||
glVertexAttribPointerARB (attr_texture_loc, 2, GL_FLOAT,
|
||||
GL_FALSE, 5 * sizeof (GLfloat), &v_vertices[3]);
|
||||
if (gl_in_buffer && gl_in_buffer->texture) {
|
||||
GLuint texture = gl_in_buffer->texture;
|
||||
GLfloat width = (GLfloat) gl_in_buffer->width;
|
||||
GLfloat height = (GLfloat) gl_in_buffer->height;
|
||||
|
||||
glEnableVertexAttribArrayARB (attr_position_loc);
|
||||
glEnableVertexAttribArrayARB (attr_texture_loc);
|
||||
const GLfloat v_vertices[] = {
|
||||
|
||||
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);
|
||||
//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,
|
||||
//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_texture_loc);
|
||||
|
@ -341,7 +342,7 @@ gst_gl_mosaic_callback (gpointer stuff)
|
|||
|
||||
gst_gl_shader_use (NULL);
|
||||
|
||||
xrot += 0.3f;
|
||||
yrot += 0.2f;
|
||||
zrot += 0.4f;
|
||||
xrot += 0.6f;
|
||||
yrot += 0.4f;
|
||||
zrot += 0.8f;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ struct _GstGLMosaic
|
|||
GstGLMixer mixer;
|
||||
|
||||
GstGLShader *shader;
|
||||
GArray *input_gl_buffers;
|
||||
GPtrArray *input_gl_buffers;
|
||||
};
|
||||
|
||||
struct _GstGLMosaicClass
|
||||
|
|
Loading…
Reference in a new issue