[104/906] start to add a glfilteredge that proceeds edge detection using GLSL

git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@517 93df14bb-0f41-7a43-8087-d3e2a2f0e464
This commit is contained in:
Julien Isorce 2008-06-13 00:01:26 +00:00 committed by Tim-Philipp Müller
parent e9f924910c
commit 8685e547b4
4 changed files with 104 additions and 10 deletions

View file

@ -28,11 +28,13 @@
static void gst_gl_display_finalize (GObject * object); static void gst_gl_display_finalize (GObject * object);
static gpointer gst_gl_display_glutThreadFunc (GstGLDisplay* display); static gpointer gst_gl_display_glutThreadFunc (GstGLDisplay* display);
static void gst_gl_display_glutCreateWindow (GstGLDisplay* display); static void gst_gl_display_glutCreateWindow (GstGLDisplay* display);
static void gst_gldisplay_glutGenerateOutputVideoFBO (GstGLDisplay *display); static void gst_gl_display_glutGenerateOutputVideoFBO (GstGLDisplay *display);
static void gst_gl_display_glutGenerateFBO (GstGLDisplay *display); static void gst_gl_display_glutGenerateFBO (GstGLDisplay *display);
static void gst_gl_display_glutUseFBO (GstGLDisplay *display); static void gst_gl_display_glutUseFBO (GstGLDisplay *display);
static void gst_gl_display_glutUseFBO2 (GstGLDisplay *display); static void gst_gl_display_glutUseFBO2 (GstGLDisplay *display);
static void gst_gl_display_glutDestroyFBO (GstGLDisplay *display); static void gst_gl_display_glutDestroyFBO (GstGLDisplay *display);
static void gst_gl_display_glutInitShader (GstGLDisplay *display);
static void gst_gl_display_glutDestroyShader (GstGLDisplay *display);
static void gst_gl_display_glutDestroyWindow (GstGLDisplay* display); static void gst_gl_display_glutDestroyWindow (GstGLDisplay* display);
static void gst_gl_display_glutSetVisibleWindow (GstGLDisplay* display); static void gst_gl_display_glutSetVisibleWindow (GstGLDisplay* display);
static void gst_gl_display_glutReshapeWindow (GstGLDisplay* display); static void gst_gl_display_glutReshapeWindow (GstGLDisplay* display);
@ -106,6 +108,8 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
display->cond_create = g_cond_new (); display->cond_create = g_cond_new ();
display->cond_destroy = g_cond_new (); display->cond_destroy = g_cond_new ();
display->cond_download = g_cond_new (); display->cond_download = g_cond_new ();
display->cond_initShader = g_cond_new ();
display->cond_destroyShader = g_cond_new ();
display->fbo = 0; display->fbo = 0;
display->depthBuffer = 0; display->depthBuffer = 0;
@ -204,6 +208,11 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
display->GLSLProgram_to_I420_YV12 = 0; display->GLSLProgram_to_I420_YV12 = 0;
display->GLSLProgram_to_AYUV = 0; display->GLSLProgram_to_AYUV = 0;
display->requestedTextShader = NULL;
display->requestedHandleShader = 0;
display->usedHandleShader = 0;
display->rejectedHandleShader = 0;
//YUY2:r,g,a //YUY2:r,g,a
//UYVY:a,b,r //UYVY:a,b,r
display->textFProgram_YUY2_UYVY = display->textFProgram_YUY2_UYVY =
@ -370,6 +379,14 @@ gst_gl_display_finalize (GObject *object)
g_cond_free (display->cond_download); g_cond_free (display->cond_download);
display->cond_download = NULL; display->cond_download = NULL;
} }
if (display->cond_initShader) {
g_cond_free (display->cond_initShader);
display->cond_initShader = NULL;
}
if (display->cond_destroyShader) {
g_cond_free (display->cond_destroyShader);
display->cond_destroyShader = NULL;
}
if (display->cond_generateFBO) { if (display->cond_generateFBO) {
g_cond_free (display->cond_generateFBO); g_cond_free (display->cond_generateFBO);
display->cond_generateFBO = NULL; display->cond_generateFBO = NULL;
@ -595,7 +612,7 @@ gst_gl_display_glutCreateWindow (GstGLDisplay *display)
/* Called by the idle funtion */ /* Called by the idle funtion */
static void static void
gst_gldisplay_glutGenerateOutputVideoFBO (GstGLDisplay *display) gst_gl_display_glutGenerateOutputVideoFBO (GstGLDisplay *display)
{ {
glutSetWindow (display->glutWinId); glutSetWindow (display->glutWinId);
@ -821,7 +838,8 @@ gst_gl_display_glutUseFBO (GstGLDisplay *display)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//the opengl scene //the opengl scene
display->glsceneFBO_cb (display->inputTextureWidth, display->inputTextureHeight, display->inputTexture); display->glsceneFBO_cb (display->inputTextureWidth, display->inputTextureHeight, display->inputTexture,
display->usedHandleShader);
glDrawBuffer(GL_NONE); glDrawBuffer(GL_NONE);
@ -890,9 +908,8 @@ gst_gl_display_glutUseFBO2 (GstGLDisplay *display)
/* Called by the idle funtion */ /* Called by the idle funtion */
static void static void
gst_gl_display_glutDestroyFBO (GstGLDisplay *display) gst_gl_display_glutDestroyFBO (GstGLDisplay* display)
{ {
glutSetWindow (display->glutWinId); glutSetWindow (display->glutWinId);
glDeleteFramebuffersEXT (1, &display->rejectedFBO); glDeleteFramebuffersEXT (1, &display->rejectedFBO);
@ -906,6 +923,27 @@ gst_gl_display_glutDestroyFBO (GstGLDisplay *display)
} }
/* Called by the idle funtion */
static void
gst_gl_display_glutInitShader (GstGLDisplay* display)
{
glutSetWindow (display->glutWinId);
display->requestedHandleShader = gst_gl_display_loadGLSLprogram (display->requestedTextShader);
g_cond_signal (display->cond_initShader);
}
/* Called by the idle funtion */
static void
gst_gl_display_glutDestroyShader (GstGLDisplay* display)
{
glutSetWindow (display->glutWinId);
glDeleteObjectARB (display->rejectedHandleShader);
g_cond_signal (display->cond_destroyShader);
}
/* Called by the idle function */ /* Called by the idle function */
static void static void
gst_gl_display_glutDestroyWindow (GstGLDisplay *display) gst_gl_display_glutDestroyWindow (GstGLDisplay *display)
@ -1127,7 +1165,13 @@ gst_gl_display_glutDispatchAction (GstGLDisplayMsg* msg)
gst_gl_display_glutUseFBO2 (msg->display); gst_gl_display_glutUseFBO2 (msg->display);
break; break;
case GST_GL_DISPLAY_ACTION_OVFBO: case GST_GL_DISPLAY_ACTION_OVFBO:
gst_gldisplay_glutGenerateOutputVideoFBO (msg->display); gst_gl_display_glutGenerateOutputVideoFBO (msg->display);
break;
case GST_GL_DISPLAY_ACTION_GENSHADER:
gst_gl_display_glutInitShader (msg->display);
break;
case GST_GL_DISPLAY_ACTION_DELSHADER:
gst_gl_display_glutDestroyShader (msg->display);
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
@ -1161,6 +1205,8 @@ gst_gl_display_checkMsgValidity (GstGLDisplayMsg *msg)
case GST_GL_DISPLAY_ACTION_USEFBO: case GST_GL_DISPLAY_ACTION_USEFBO:
case GST_GL_DISPLAY_ACTION_USEFBO2: case GST_GL_DISPLAY_ACTION_USEFBO2:
case GST_GL_DISPLAY_ACTION_OVFBO: case GST_GL_DISPLAY_ACTION_OVFBO:
case GST_GL_DISPLAY_ACTION_GENSHADER:
case GST_GL_DISPLAY_ACTION_DELSHADER:
//msg is out of date if the associated display is not in the map //msg is out of date if the associated display is not in the map
if (!g_hash_table_lookup (gst_gl_display_map, GINT_TO_POINTER (msg->glutWinId))) if (!g_hash_table_lookup (gst_gl_display_map, GINT_TO_POINTER (msg->glutWinId)))
valid = FALSE; valid = FALSE;
@ -1413,7 +1459,8 @@ gst_gl_display_requestFBO (GstGLDisplay* display, gint width, gint height,
void void
gst_gl_display_useFBO (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight, gst_gl_display_useFBO (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight,
guint fbo, guint depthbuffer, guint textureFBO, GLCB cb, guint fbo, guint depthbuffer, guint textureFBO, GLCB cb,
guint inputTextureWidth, guint inputTextureHeight, guint inputTexture) guint inputTextureWidth, guint inputTextureHeight, guint inputTexture,
GLhandleARB handleShader)
{ {
gst_gl_display_lock (display); gst_gl_display_lock (display);
display->usedFBO = fbo; display->usedFBO = fbo;
@ -1425,6 +1472,7 @@ gst_gl_display_useFBO (GstGLDisplay* display, gint textureFBOWidth, gint texture
display->inputTextureWidth = inputTextureWidth; display->inputTextureWidth = inputTextureWidth;
display->inputTextureHeight = inputTextureHeight; display->inputTextureHeight = inputTextureHeight;
display->inputTexture = inputTexture; display->inputTexture = inputTexture;
display->usedHandleShader = handleShader;
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_USEFBO, display); gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_USEFBO, display);
g_cond_wait (display->cond_useFBO, display->mutex); g_cond_wait (display->cond_useFBO, display->mutex);
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
@ -1478,6 +1526,31 @@ gst_gl_display_initDonwloadFBO (GstGLDisplay* display, gint width, gint height)
} }
/* Called by gst_gl elements */
void
gst_gl_display_initShader (GstGLDisplay* display, gchar* textShader, GLhandleARB* handleShader)
{
gst_gl_display_lock (display);
display->requestedTextShader = textShader;
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_GENSHADER, display);
g_cond_wait (display->cond_initShader, display->mutex);
*handleShader = display->requestedHandleShader;
gst_gl_display_unlock (display);
}
/* Called by gst_gl elements */
void
gst_gl_display_destroyShader (GstGLDisplay* display, GLhandleARB shader)
{
gst_gl_display_lock (display);
display->rejectedHandleShader = shader;
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_DELSHADER, display);
g_cond_wait (display->cond_destroyShader, display->mutex);
gst_gl_display_unlock (display);
}
/* Called by gst_gl elements */ /* Called by gst_gl elements */
void void
gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId) gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId)

View file

@ -56,7 +56,9 @@ typedef enum {
GST_GL_DISPLAY_ACTION_DELFBO, GST_GL_DISPLAY_ACTION_DELFBO,
GST_GL_DISPLAY_ACTION_USEFBO, GST_GL_DISPLAY_ACTION_USEFBO,
GST_GL_DISPLAY_ACTION_USEFBO2, GST_GL_DISPLAY_ACTION_USEFBO2,
GST_GL_DISPLAY_ACTION_OVFBO GST_GL_DISPLAY_ACTION_OVFBO,
GST_GL_DISPLAY_ACTION_GENSHADER,
GST_GL_DISPLAY_ACTION_DELSHADER
} GstGLDisplayAction; } GstGLDisplayAction;
@ -82,7 +84,7 @@ typedef void (* CRCB) ( GLuint, GLuint );
typedef gboolean (* CDCB) ( GLuint, GLuint, GLuint); typedef gboolean (* CDCB) ( GLuint, GLuint, GLuint);
//opengl scene callback //opengl scene callback
typedef void (* GLCB) ( GLuint, GLuint, GLuint); typedef void (* GLCB) ( GLuint, GLuint, GLuint, GLhandleARB);
typedef void (* GLCB2) ( gpointer* p1, gpointer* p2, gint w, gint h); typedef void (* GLCB2) ( gpointer* p1, gpointer* p2, gint w, gint h);
struct _GstGLDisplay { struct _GstGLDisplay {
@ -101,6 +103,8 @@ struct _GstGLDisplay {
GCond* cond_useFBO2; GCond* cond_useFBO2;
GCond* cond_destroyFBO; GCond* cond_destroyFBO;
GCond* cond_download; GCond* cond_download;
GCond* cond_initShader;
GCond* cond_destroyShader;
GCond* cond_create; GCond* cond_create;
GCond* cond_destroy; GCond* cond_destroy;
@ -220,6 +224,12 @@ struct _GstGLDisplay {
gchar* textFProgram_to_AYUV; gchar* textFProgram_to_AYUV;
GLhandleARB GLSLProgram_to_AYUV; GLhandleARB GLSLProgram_to_AYUV;
//requested shader
gchar* requestedTextShader;
GLhandleARB requestedHandleShader;
GLhandleARB usedHandleShader;
GLhandleARB rejectedHandleShader;
//client callbacks //client callbacks
CRCB clientReshapeCallback; CRCB clientReshapeCallback;
CDCB clientDrawCallback; CDCB clientDrawCallback;
@ -263,13 +273,16 @@ void gst_gl_display_requestFBO (GstGLDisplay* display, gint width, gint height,
guint* fbo, guint* depthbuffer, guint* texture); guint* fbo, guint* depthbuffer, guint* texture);
void gst_gl_display_useFBO (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight, void gst_gl_display_useFBO (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight,
guint fbo, guint depthbuffer, guint textureFBO, GLCB cb, guint fbo, guint depthbuffer, guint textureFBO, GLCB cb,
guint inputTextureWidth, guint inputTextureHeight, guint inputTexture); guint inputTextureWidth, guint inputTextureHeight, guint inputTexture,
GLhandleARB handleShader);
void gst_gl_display_useFBO2 (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight, void gst_gl_display_useFBO2 (GstGLDisplay* display, gint textureFBOWidth, gint textureFBOheight,
guint fbo, guint depthbuffer, guint textureFBO, GLCB2 cb, guint fbo, guint depthbuffer, guint textureFBO, GLCB2 cb,
gpointer* p1, gpointer* p2); gpointer* p1, gpointer* p2);
void gst_gl_display_rejectFBO (GstGLDisplay* display, guint fbo, void gst_gl_display_rejectFBO (GstGLDisplay* display, guint fbo,
guint depthbuffer, guint texture); guint depthbuffer, guint texture);
void gst_gl_display_initDonwloadFBO (GstGLDisplay* display, gint width, gint height); void gst_gl_display_initDonwloadFBO (GstGLDisplay* display, gint width, gint height);
void gst_gl_display_initShader (GstGLDisplay* display, gchar* textShader, GLhandleARB* handleShader);
void gst_gl_display_destroyShader (GstGLDisplay* display, GLhandleARB shader);
void gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId); void gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId);
#endif #endif

View file

@ -103,6 +103,7 @@ gst_gl_filter_class_init (GstGLFilterClass * klass)
klass->set_caps = NULL; klass->set_caps = NULL;
klass->filter = NULL; klass->filter = NULL;
klass->onInitFBO = NULL; klass->onInitFBO = NULL;
klass->onReset = NULL;
} }
static void static void
@ -147,6 +148,11 @@ gst_gl_filter_get_property (GObject * object, guint prop_id,
static void static void
gst_gl_filter_reset (GstGLFilter* filter) gst_gl_filter_reset (GstGLFilter* filter)
{ {
GstGLFilterClass* filter_class = GST_GL_FILTER_GET_CLASS (filter);
if (filter_class->onReset)
filter_class->onReset (filter);
if (filter->display) if (filter->display)
{ {
//blocking call, delete the FBO //blocking call, delete the FBO

View file

@ -44,6 +44,7 @@ typedef gboolean (*GstGLFilterSetCaps) (GstGLFilter* filter,
typedef gboolean (*GstGLFilterProcessFunc) (GstGLFilter *filter, typedef gboolean (*GstGLFilterProcessFunc) (GstGLFilter *filter,
GstGLBuffer *inbuf, GstGLBuffer *outbuf); GstGLBuffer *inbuf, GstGLBuffer *outbuf);
typedef void (*GstGLFilterOnInitFBO) (GstGLFilter *filter); typedef void (*GstGLFilterOnInitFBO) (GstGLFilter *filter);
typedef void (*GstGLFilterOnReset) (GstGLFilter *filter);
struct _GstGLFilter struct _GstGLFilter
{ {
@ -67,6 +68,7 @@ struct _GstGLFilterClass
GstGLFilterSetCaps set_caps; GstGLFilterSetCaps set_caps;
GstGLFilterProcessFunc filter; GstGLFilterProcessFunc filter;
GstGLFilterOnInitFBO onInitFBO; GstGLFilterOnInitFBO onInitFBO;
GstGLFilterOnReset onReset;
}; };
GType gst_gl_filter_get_type(void); GType gst_gl_filter_get_type(void);