[083/906] finish to implement the glfilter: example : gst-launch-0.10 videotestsrc num_buffers = 100 ! glgraphicmaker ! glfiltercube ! glimagesink

git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@495 93df14bb-0f41-7a43-8087-d3e2a2f0e464
This commit is contained in:
Julien Isorce 2008-06-07 21:56:00 +00:00 committed by Matthew Waters
parent 59dc400b7e
commit 43e4bedbe5
8 changed files with 47 additions and 27 deletions

View file

@ -47,6 +47,7 @@ gst_gl_buffer_init (GstGLBuffer* buffer, gpointer g_class)
buffer->texture = 0;
buffer->texture_u = 0;
buffer->texture_v = 0;
buffer->textureGL = 0;
buffer->width = 0;
buffer->height = 0;
}

View file

@ -45,6 +45,7 @@ struct _GstGLBuffer {
GLuint texture;
GLuint texture_u;
GLuint texture_v;
GLuint textureGL;
gint width;
gint height;

View file

@ -130,6 +130,10 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
display->rejectedDepthBuffer = 0;
display->rejectedTextureFBO = 0;
display->displayedTexture = 0;
display->displayedTextureWidth = 0;
display->displayedTextureHeight = 0;
display->requestedTexture = 0;
display->requestedTexture_u = 0;
display->requestedTexture_v = 0;
@ -213,8 +217,8 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
"void main(void) {\n"
" float r,g,b,y,u,v;\n"
" vec2 nxy=gl_TexCoord[0].xy;\n"
" y=texture2DRect(Ytex,nxy).r;\n"
" u=texture2DRect(Utex,nxy*0.5).r;\n"
" y=texture2DRect(Ytex,nxy*0.5).r;\n"
" u=texture2DRect(Utex,nxy).r;\n"
" v=texture2DRect(Vtex,nxy*0.5).r;\n"
" y=1.1643*(y-0.0625);\n"
" u=u-0.5;\n"
@ -1175,7 +1179,7 @@ gst_gl_display_textureRequested (GstGLDisplay * display, GstVideoFormat video_fo
void
gst_gl_display_textureChanged (GstGLDisplay* display, GstVideoFormat video_format,
GLuint texture, GLuint texture_u, GLuint texture_v,
gint width, gint height, gpointer data)
gint width, gint height, gpointer data, GLuint* outputTexture)
{
gst_gl_display_lock (display);
display->candidateTexture = texture;
@ -1187,6 +1191,9 @@ gst_gl_display_textureChanged (GstGLDisplay* display, GstVideoFormat video_forma
display->candidateData = data;
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_CHANGE, display);
g_cond_wait (display->cond_fill, display->mutex);
//Here texture width and height are always the same than the fbo
if (outputTexture)
*outputTexture = display->textureFBO;
gst_gl_display_unlock (display);
}
@ -1223,12 +1230,18 @@ gst_gl_display_videoChanged (GstGLDisplay* display, GstVideoFormat video_format,
/* Called by gst_gl elements */
gboolean
gst_gl_display_postRedisplay (GstGLDisplay* display)
gst_gl_display_postRedisplay (GstGLDisplay* display, GLuint texture, gint width , gint height)
{
gboolean isAlive = TRUE;
gst_gl_display_lock (display);
isAlive = display->isAlive;
if (texture)
{
display->displayedTexture = texture;
display->displayedTextureWidth = width;
display->displayedTextureHeight = height;
}
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_REDISPLAY, display);
gst_gl_display_unlock (display);
@ -1390,8 +1403,8 @@ void gst_gl_display_draw(void)
if (display->clientDrawCallback)
{
gboolean doRedisplay =
display->clientDrawCallback(display->textureFBO,
display->textureFBOWidth, display->textureFBOHeight);
display->clientDrawCallback(display->displayedTexture,
display->displayedTextureWidth, display->displayedTextureHeight);
glFlush();
glutSwapBuffers();
@ -1408,17 +1421,17 @@ void gst_gl_display_draw(void)
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->textureFBO);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->displayedTexture);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBegin (GL_QUADS);
glTexCoord2i (display->textureFBOWidth, 0);
glTexCoord2i (display->displayedTextureWidth, 0);
glVertex2f (1.0f, 1.0f);
glTexCoord2i (0, 0);
glVertex2f (-1.0f, 1.0f);
glTexCoord2i (0, display->textureFBOHeight);
glTexCoord2i (0, display->displayedTextureHeight);
glVertex2f (-1.0f, -1.0f);
glTexCoord2i (display->textureFBOWidth, display->textureFBOHeight);
glTexCoord2i (display->displayedTextureWidth, display->displayedTextureHeight);
glVertex2f (1.0f, -1.0f);
glEnd ();

View file

@ -139,6 +139,11 @@ struct _GstGLDisplay {
GLuint rejectedDepthBuffer;
GLuint rejectedTextureFBO;
//displayed texture
GLuint displayedTexture;
GLuint displayedTextureWidth;
GLuint displayedTextureHeight;
GLuint requestedTexture;
GLuint requestedTexture_u;
GLuint requestedTexture_v;
@ -232,13 +237,13 @@ void gst_gl_display_textureRequested (GstGLDisplay* display, GstVideoFormat form
guint* texture_u, guint* texture_v);
void gst_gl_display_textureChanged (GstGLDisplay* display, GstVideoFormat video_format,
GLuint texture, GLuint texture_u, GLuint texture_v,
gint width, gint height, gpointer data);
gint width, gint height, gpointer data, GLuint* outputTexture);
void gst_gl_display_clearTexture (GstGLDisplay* display, guint texture,
guint texture_u, guint texture_v);
void gst_gl_display_videoChanged (GstGLDisplay* display, GstVideoFormat video_format,
gpointer data);
gboolean gst_gl_display_postRedisplay (GstGLDisplay* display);
gboolean gst_gl_display_postRedisplay (GstGLDisplay* display, GLuint texture, gint width, gint height);
void gst_gl_display_requestFBO (GstGLDisplay* display, gint width, gint height,
guint* fbo, guint* depthbuffer, guint* texture);
void gst_gl_display_useFBO (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight,

View file

@ -211,8 +211,6 @@ gst_gl_filter_prepare_output_buffer (GstBaseTransform* trans,
*buf = GST_BUFFER (gl_outbuf);
gst_buffer_set_caps (*buf, caps);
g_print ("gstglfilter: gst_gl_filter_prepare_output_buffer\n");
return GST_FLOW_OK;
}
@ -249,8 +247,6 @@ gst_gl_filter_transform (GstBaseTransform* bt, GstBuffer* inbuf,
filter = GST_GL_FILTER (bt);
g_print ("gstglfilter: gst_gl_filter_transform\n");
gst_gl_filter_do_transform (filter, gl_inbuf, gl_outbuf);
return GST_FLOW_OK;

View file

@ -74,10 +74,13 @@ gst_gl_filter_cube_class_init (GstGLFilterCubeClass * klass)
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filter_cube_filter;
}
static gint c = 0;
static void
gst_gl_filter_cube_init (GstGLFilterCube* filter,
GstGLFilterCubeClass* klass)
{
c += 1;
}
static void
@ -114,16 +117,17 @@ gst_gl_filter_cube_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
{
GstGLFilterCube* cube_filter = GST_GL_FILTER_CUBE(filter);
g_print ("gstglfiltercube: gst_gl_filter_cube_filter\n");
//blocking call, generate a FBO
gst_gl_display_useFBO (filter->display, filter->width, filter->height,
filter->fbo, filter->depthbuffer, filter->texture, gst_gl_filter_cube_callback,
inbuf->width, inbuf->height, inbuf->texture);
inbuf->width, inbuf->height, inbuf->textureGL);
outbuf->width = filter->width;
outbuf->height = filter->height;
outbuf->texture = filter->texture;
outbuf->texture = inbuf->texture;
outbuf->texture_u = inbuf->texture_u;
outbuf->texture_v = inbuf->texture_v;
outbuf->textureGL = filter->texture;
return TRUE;
}
@ -136,8 +140,6 @@ gst_gl_filter_cube_callback (guint width, guint height, guint texture)
static GLfloat yrot = 0;
static GLfloat zrot = 0;
g_print ("gstglfiltercube: gst_gl_filter_cube_callback\n");
glEnable(GL_DEPTH_TEST);
glEnable (GL_TEXTURE_RECTANGLE_ARB);

View file

@ -424,6 +424,7 @@ gst_gl_graphicmaker_transform (GstBaseTransform* trans, GstBuffer* inbuf,
{
GstGLGraphicmaker* graphicmaker;
GstGLBuffer* gl_outbuf = GST_GL_BUFFER (outbuf);
guint outputTexture = 0;
graphicmaker = GST_GL_GRAPHICMAKER (trans);
@ -433,7 +434,7 @@ gst_gl_graphicmaker_transform (GstBaseTransform* trans, GstBuffer* inbuf,
//blocking call
gst_gl_display_textureChanged(graphicmaker->display, graphicmaker->video_format,
gl_outbuf->texture, gl_outbuf->texture_u, gl_outbuf->texture_v,
gl_outbuf->width, gl_outbuf->height, GST_BUFFER_DATA (inbuf));
gl_outbuf->width, gl_outbuf->height, GST_BUFFER_DATA (inbuf), &gl_outbuf->textureGL);
return GST_FLOW_OK;
}

View file

@ -418,7 +418,7 @@ gst_glimage_sink_render (GstBaseSink* bsink, GstBuffer* buf)
//is not gl
else
{
//if glimagesink has not the display yet
//if glimagesink has not the display yet
if (glimage_sink->display == NULL)
{
@ -449,7 +449,7 @@ gst_glimage_sink_render (GstBaseSink* bsink, GstBuffer* buf)
//blocking call
gst_gl_display_textureChanged(glimage_sink->display, glimage_sink->format,
gl_buffer->texture, gl_buffer->texture_u, gl_buffer->texture_v,
gl_buffer->width, gl_buffer->height, GST_BUFFER_DATA (buf));
gl_buffer->width, gl_buffer->height, GST_BUFFER_DATA (buf), &gl_buffer->textureGL);
//gl_buffer is created in this block, so the gl buffer is already referenced
}
@ -465,7 +465,8 @@ gst_glimage_sink_render (GstBaseSink* bsink, GstBuffer* buf)
glimage_sink->stored_buffer = gl_buffer;
//redisplay opengl scene
isAlive = gst_gl_display_postRedisplay (glimage_sink->display);
isAlive = gst_gl_display_postRedisplay (glimage_sink->display,
gl_buffer->textureGL, gl_buffer->width, gl_buffer->height);
if (isAlive)
return GST_FLOW_OK;
@ -515,7 +516,7 @@ gst_glimage_sink_expose (GstXOverlay* overlay)
//redisplay opengl scene
if (glimage_sink->display)
gst_gl_display_postRedisplay (glimage_sink->display);
gst_gl_display_postRedisplay (glimage_sink->display, 0, 0, 0);
}