[109/906] git-svn-id: svn://svn.wobow.com/GStreamer_playground/gst-plugins-gl@543 93df14bb-0f41-7a43-8087-d3e2a2f0e464

This commit is contained in:
Julien Isorce 2008-06-23 18:56:29 +00:00 committed by Tim-Philipp Müller
parent 49e944778e
commit 886bd3ee7d
2 changed files with 42 additions and 172 deletions

View file

@ -55,7 +55,6 @@ void gst_gl_display_onClose (void);
void gst_gl_display_make_texture (GstGLDisplay* display); void gst_gl_display_make_texture (GstGLDisplay* display);
void gst_gl_display_fill_texture (GstGLDisplay* display); void gst_gl_display_fill_texture (GstGLDisplay* display);
void gst_gl_display_draw_texture (GstGLDisplay* display); void gst_gl_display_draw_texture (GstGLDisplay* display);
void gst_gl_display_draw_graphic (GstGLDisplay* display);
void gst_gl_display_fill_video (GstGLDisplay* display); void gst_gl_display_fill_video (GstGLDisplay* display);
void gst_gl_display_gen_texture (GstGLDisplay* display, guint* pTexture); void gst_gl_display_gen_texture (GstGLDisplay* display, guint* pTexture);
void gst_gl_display_del_texture (GstGLDisplay* display, guint* pTexture); void gst_gl_display_del_texture (GstGLDisplay* display, guint* pTexture);
@ -119,10 +118,6 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
display->textureFBOWidth = 0; display->textureFBOWidth = 0;
display->textureFBOHeight = 0; display->textureFBOHeight = 0;
display->graphicFBO = 0;
display->graphicDepthBuffer = 0;
display->graphicTexture = 0;
display->requestedFBO = 0; display->requestedFBO = 0;
display->requestedDepthBuffer = 0; display->requestedDepthBuffer = 0;
display->requestedTextureFBOWidth = 0; display->requestedTextureFBOWidth = 0;
@ -146,6 +141,9 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
display->displayedTextureWidth = 0; display->displayedTextureWidth = 0;
display->displayedTextureHeight = 0; display->displayedTextureHeight = 0;
display->resize_width = 0;
display->resize_height = 0;
display->preparedTexture = 0; display->preparedTexture = 0;
display->currentTexture = 0; display->currentTexture = 0;
@ -176,8 +174,6 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
display->winId = 0; display->winId = 0;
display->win_xpos = 0; display->win_xpos = 0;
display->win_ypos = 0; display->win_ypos = 0;
display->glcontext_width = 0;
display->glcontext_height = 0;
display->visible = FALSE; display->visible = FALSE;
display->isAlive = TRUE; display->isAlive = TRUE;
display->clientReshapeCallback = NULL; display->clientReshapeCallback = NULL;
@ -224,8 +220,8 @@ gst_gl_display_init (GstGLDisplay *display, GstGLDisplayClass *klass)
"void main(void) {\n" "void main(void) {\n"
" float r,g,b,y,u,v;\n" " float r,g,b,y,u,v;\n"
" vec2 nxy=gl_TexCoord[0].xy;\n" " vec2 nxy=gl_TexCoord[0].xy;\n"
" y=texture2DRect(Ytex,nxy).r;\n" " y=texture2DRect(Ytex,nxy*0.5).r;\n"
" u=texture2DRect(Utex,nxy*0.5).r;\n" " u=texture2DRect(Utex,nxy).r;\n"
" v=texture2DRect(Vtex,nxy*0.5).r;\n" " v=texture2DRect(Vtex,nxy*0.5).r;\n"
" y=1.1643*(y-0.0625);\n" " y=1.1643*(y-0.0625);\n"
" u=u-0.5;\n" " u=u-0.5;\n"
@ -460,7 +456,7 @@ gst_gl_display_glutCreateWindow (GstGLDisplay *display)
//prepare opengl context //prepare opengl context
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowPosition(display->win_xpos, display->win_ypos); glutInitWindowPosition(display->win_xpos, display->win_ypos);
glutInitWindowSize(display->glcontext_width, display->glcontext_height); glutInitWindowSize(display->textureFBOWidth, display->textureFBOHeight);
//create opengl context //create opengl context
sprintf(buffer, "%d", glutWinId); sprintf(buffer, "%d", glutWinId);
@ -614,50 +610,8 @@ gst_gl_display_glutGenerateOutputVideoFBO (GstGLDisplay *display)
{ {
GST_DEBUG ("Context %d, EXT_framebuffer_object supported: yes", display->glutWinId); GST_DEBUG ("Context %d, EXT_framebuffer_object supported: yes", display->glutWinId);
//-- init graphic frame buffer object (GL texture -> GL scene)
//setup FBO
glGenFramebuffersEXT (1, &display->graphicFBO);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->graphicFBO);
//setup the render buffer for depth
glGenRenderbuffersEXT(1, &display->graphicDepthBuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, display->graphicDepthBuffer);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT,
display->glcontext_width, display->glcontext_height);
//setup a texture to render to
glGenTextures (1, &display->graphicTexture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, display->graphicTexture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
display->glcontext_width, display->glcontext_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//attach the texture to the FBO to renderer to
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_RECTANGLE_ARB, display->graphicTexture, 0);
//attach the depth render buffer to the FBO
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, display->graphicDepthBuffer);
checkFramebufferStatus();
g_assert (glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) ==
GL_FRAMEBUFFER_COMPLETE_EXT);
//unbind the FBO
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
//-- init output frame buffer object (GL -> video) //-- init output frame buffer object (GL -> video)
display->outputWidth = display->glcontext_width;
display->outputHeight = display->glcontext_height;
//setup FBO //setup FBO
glGenFramebuffersEXT (1, &display->videoFBO); glGenFramebuffersEXT (1, &display->videoFBO);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->videoFBO); glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, display->videoFBO);
@ -984,10 +938,6 @@ gst_gl_display_glutDestroyWindow (GstGLDisplay *display)
glDeleteFramebuffersEXT (1, &display->fbo); glDeleteFramebuffersEXT (1, &display->fbo);
glDeleteRenderbuffersEXT(1, &display->depthBuffer); glDeleteRenderbuffersEXT(1, &display->depthBuffer);
glDeleteFramebuffersEXT (1, &display->graphicFBO);
glDeleteRenderbuffersEXT(1, &display->graphicDepthBuffer);
glDeleteTextures (1, &display->graphicTexture);
glDeleteFramebuffersEXT (1, &display->videoFBO); glDeleteFramebuffersEXT (1, &display->videoFBO);
glDeleteRenderbuffersEXT(1, &display->videoDepthBuffer); glDeleteRenderbuffersEXT(1, &display->videoDepthBuffer);
glDeleteTextures (1, &display->videoTexture); glDeleteTextures (1, &display->videoTexture);
@ -1031,8 +981,7 @@ static void
gst_gl_display_glutReshapeWindow (GstGLDisplay* display) gst_gl_display_glutReshapeWindow (GstGLDisplay* display)
{ {
glutSetWindow (display->glutWinId); glutSetWindow (display->glutWinId);
glutReshapeWindow (display->glcontext_width, display->glcontext_height); glutReshapeWindow (display->resize_width, display->resize_height);
//should reset glcontext_width and height
} }
@ -1074,7 +1023,6 @@ static void
gst_gl_display_glutUpdateVideo (GstGLDisplay * display) gst_gl_display_glutUpdateVideo (GstGLDisplay * display)
{ {
glutSetWindow (display->glutWinId); glutSetWindow (display->glutWinId);
gst_gl_display_draw_graphic (display);
gst_gl_display_fill_video (display); gst_gl_display_fill_video (display);
g_cond_signal (display->cond_video); g_cond_signal (display->cond_video);
} }
@ -1228,22 +1176,19 @@ gst_gl_display_new (void)
/* Init an opengl context */ /* Init an opengl context */
void void
gst_gl_display_initGLContext (GstGLDisplay *display, gst_gl_display_init_gl_context (GstGLDisplay *display,
GLint x, GLint y, GLint x, GLint y,
GLint graphic_width, GLint graphic_height, GLint width, GLint height,
GLint video_width, GLint video_height, gulong winId,
gulong winId, gboolean visible)
gboolean visible)
{ {
gst_gl_display_lock (display); gst_gl_display_lock (display);
display->winId = winId; display->winId = winId;
display->win_xpos = x; display->win_xpos = x;
display->win_ypos = y; display->win_ypos = y;
display->glcontext_width = graphic_width; display->textureFBOWidth = width;
display->glcontext_height = graphic_height; display->textureFBOHeight = height;
display->textureFBOWidth = video_width;
display->textureFBOHeight = video_height;
display->visible = visible; display->visible = visible;
//if no glut_thread exists, create it with a window associated to the display //if no glut_thread exists, create it with a window associated to the display
@ -1331,8 +1276,8 @@ void
gst_gl_display_resizeWindow (GstGLDisplay* display, gint width, gint height) gst_gl_display_resizeWindow (GstGLDisplay* display, gint width, gint height)
{ {
gst_gl_display_lock (display); gst_gl_display_lock (display);
display->glcontext_width = width; display->resize_width = width;
display->glcontext_height = height; display->resize_height = height;
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_RESHAPE, display); gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_RESHAPE, display);
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
} }
@ -1500,8 +1445,8 @@ void
gst_gl_display_initDonwloadFBO (GstGLDisplay* display, gint width, gint height) gst_gl_display_initDonwloadFBO (GstGLDisplay* display, gint width, gint height)
{ {
gst_gl_display_lock (display); gst_gl_display_lock (display);
display->glcontext_width = width; display->outputWidth = width;
display->glcontext_height = height; display->outputHeight = height;
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_OVFBO, display); gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_OVFBO, display);
g_cond_wait (display->cond_download, display->mutex); g_cond_wait (display->cond_download, display->mutex);
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
@ -1537,7 +1482,7 @@ gst_gl_display_destroyShader (GstGLDisplay* display, GLhandleARB shader)
void void
gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId) gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId)
{ {
static gint glheight = 0; static gint y_pos = 0;
gst_gl_display_lock (display); gst_gl_display_lock (display);
gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_DESTROY, display); gst_gl_display_postMessage (GST_GL_DISPLAY_ACTION_DESTROY, display);
@ -1555,9 +1500,8 @@ gst_gl_display_set_windowId (GstGLDisplay* display, gulong winId)
} }
//init opengl context //init opengl context
gst_gl_display_initGLContext (display, gst_gl_display_init_gl_context (display,
50, glheight++ * (display->glcontext_height+50) + 50, 50, y_pos++ * (display->textureFBOHeight+50) + 50,
display->glcontext_width, display->glcontext_height,
display->textureFBOWidth, display->textureFBOHeight, display->textureFBOWidth, display->textureFBOHeight,
winId, winId,
TRUE); TRUE);
@ -2048,80 +1992,10 @@ gst_gl_display_draw_texture (GstGLDisplay* display)
} }
/* called by gst_gl_display_glutUpdateTexture (in the glut thread) */
void
gst_gl_display_draw_graphic (GstGLDisplay* display)
{
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, display->graphicFBO);
glPushAttrib(GL_VIEWPORT_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPerspective(45, (gfloat)display->glcontext_width/(gfloat)display->glcontext_height, 0.1, 100);
//gluOrtho2D(0.0, display->glcontext_width, 0.0, display->glcontext_height);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glViewport(0, 0, display->glcontext_width, display->glcontext_height);
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//check if a client draw callback is registered
if (display->clientDrawCallback)
{
display->clientDrawCallback(display->recordedTexture,
display->recordedTextureWidth, display->recordedTextureHeight);
}
else
{
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->recordedTexture);
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glBegin (GL_QUADS);
glTexCoord2i (display->recordedTextureWidth, 0);
glVertex2f (1.0f, 1.0f);
glTexCoord2i (0, 0);
glVertex2f (-1.0f, 1.0f);
glTexCoord2i (0, display->recordedTextureHeight);
glVertex2f (-1.0f, -1.0f);
glTexCoord2i (display->recordedTextureWidth, display->recordedTextureHeight);
glVertex2f (1.0f, -1.0f);
glEnd ();
}
glDrawBuffer(GL_NONE);
glUseProgramObjectARB (0);
glDisable(GL_TEXTURE_RECTANGLE_ARB);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
checkFramebufferStatus();
}
/* called by gst_gl_display_glutUpdateVideo (in the glut thread) */ /* called by gst_gl_display_glutUpdateVideo (in the glut thread) */
void void
gst_gl_display_fill_video (GstGLDisplay* display) gst_gl_display_fill_video (GstGLDisplay* display)
{ {
gint width = display->outputWidth; gint width = display->outputWidth;
gint height = display->outputHeight; gint height = display->outputHeight;
GstVideoFormat outputVideo_format = display->outputVideo_format; GstVideoFormat outputVideo_format = display->outputVideo_format;
@ -2134,7 +2008,8 @@ gst_gl_display_fill_video (GstGLDisplay* display)
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
glLoadIdentity(); glLoadIdentity();
gluOrtho2D(0.0, width, 0.0, height); //gluOrtho2D(0.0, width, 0.0, height);
gluPerspective(45, (gfloat)width/(gfloat)height, 0.1, 100);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
@ -2157,7 +2032,7 @@ gst_gl_display_fill_video (GstGLDisplay* display)
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->graphicTexture); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->recordedTexture);
glEnable(GL_TEXTURE_RECTANGLE_ARB); glEnable(GL_TEXTURE_RECTANGLE_ARB);
} }
break; break;
@ -2193,7 +2068,7 @@ gst_gl_display_fill_video (GstGLDisplay* display)
glActiveTextureARB(GL_TEXTURE0_ARB); glActiveTextureARB(GL_TEXTURE0_ARB);
i = glGetUniformLocationARB (GLSLProgram_to_YUY2_UYVY, "tex"); i = glGetUniformLocationARB (GLSLProgram_to_YUY2_UYVY, "tex");
glUniform1iARB (i, 0); glUniform1iARB (i, 0);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->graphicTexture); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->recordedTexture);
} }
break; break;
@ -2216,10 +2091,10 @@ gst_gl_display_fill_video (GstGLDisplay* display)
i = glGetUniformLocationARB (display->GLSLProgram_to_I420_YV12, "tex"); i = glGetUniformLocationARB (display->GLSLProgram_to_I420_YV12, "tex");
glUniform1iARB (i, 0); glUniform1iARB (i, 0);
i = glGetUniformLocationARB (display->GLSLProgram_to_I420_YV12, "w"); i = glGetUniformLocationARB (display->GLSLProgram_to_I420_YV12, "w");
glUniform1fARB (i, (gfloat)width); glUniform1fARB (i, (gfloat)display->recordedTextureWidth);
i = glGetUniformLocationARB (display->GLSLProgram_to_I420_YV12, "h"); i = glGetUniformLocationARB (display->GLSLProgram_to_I420_YV12, "h");
glUniform1fARB (i, (gfloat)height); glUniform1fARB (i, (gfloat)display->recordedTextureHeight);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->graphicTexture); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->recordedTexture);
} }
break; break;
@ -2240,7 +2115,7 @@ gst_gl_display_fill_video (GstGLDisplay* display)
glActiveTextureARB(GL_TEXTURE0_ARB); glActiveTextureARB(GL_TEXTURE0_ARB);
i = glGetUniformLocationARB (display->GLSLProgram_to_AYUV, "tex"); i = glGetUniformLocationARB (display->GLSLProgram_to_AYUV, "tex");
glUniform1iARB (i, 0); glUniform1iARB (i, 0);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->graphicTexture); glBindTexture (GL_TEXTURE_RECTANGLE_ARB, display->recordedTexture);
} }
break; break;
@ -2250,14 +2125,14 @@ gst_gl_display_fill_video (GstGLDisplay* display)
}//end switch display->currentVideo_format }//end switch display->currentVideo_format
glBegin (GL_QUADS); glBegin (GL_QUADS);
glTexCoord2i (width, 0);
glVertex2f (1.0f, 1.0f);
glTexCoord2i (0, 0); glTexCoord2i (0, 0);
glVertex2f (-1.0f, 1.0f);
glTexCoord2i (0, height);
glVertex2f (-1.0f, -1.0f); glVertex2f (-1.0f, -1.0f);
glTexCoord2i (width, height); glTexCoord2i (width, 0);
glVertex2f (1.0f, -1.0f); glVertex2f (1.0f, -1.0f);
glTexCoord2i (width, height);
glVertex2f (1.0f, 1.0f);
glTexCoord2i (0, height);
glVertex2f (-1.0f, 1.0f);
glEnd (); glEnd ();
glDrawBuffer(GL_NONE); glDrawBuffer(GL_NONE);

View file

@ -111,8 +111,6 @@ struct _GstGLDisplay {
GString* title; GString* title;
gint win_xpos; gint win_xpos;
gint win_ypos; gint win_ypos;
gint glcontext_width;
gint glcontext_height;
gboolean visible; gboolean visible;
gboolean isAlive; gboolean isAlive;
@ -123,11 +121,6 @@ struct _GstGLDisplay {
GLuint textureFBOWidth; GLuint textureFBOWidth;
GLuint textureFBOHeight; GLuint textureFBOHeight;
//graphic frame buffer object (GL texture -> GL scene)
GLuint graphicFBO;
GLuint graphicDepthBuffer;
GLuint graphicTexture;
//filter frame buffer object (GL -> GL) //filter frame buffer object (GL -> GL)
GLuint requestedFBO; GLuint requestedFBO;
GLuint requestedDepthBuffer; GLuint requestedDepthBuffer;
@ -154,6 +147,9 @@ struct _GstGLDisplay {
GLuint displayedTextureWidth; GLuint displayedTextureWidth;
GLuint displayedTextureHeight; GLuint displayedTextureHeight;
gint resize_width;
gint resize_height;
GLuint preparedTexture; GLuint preparedTexture;
GLuint currentTexture; GLuint currentTexture;
@ -230,12 +226,11 @@ GType gst_gl_display_get_type (void);
//-------------------- Public declarations ------------------ //-------------------- Public declarations ------------------
//------------------------------------------------------------ //------------------------------------------------------------
GstGLDisplay *gst_gl_display_new (void); GstGLDisplay *gst_gl_display_new (void);
void gst_gl_display_initGLContext (GstGLDisplay* display, void gst_gl_display_init_gl_context (GstGLDisplay* display,
GLint x, GLint y, GLint x, GLint y,
GLint graphic_width, GLint graphic_height, GLint width, GLint height,
GLint video_width, GLint video_height, gulong winId,
gulong winId, gboolean visible);
gboolean visible);
void gst_gl_display_setClientReshapeCallback (GstGLDisplay* display, CRCB cb); void gst_gl_display_setClientReshapeCallback (GstGLDisplay* display, CRCB cb);
void gst_gl_display_setClientDrawCallback (GstGLDisplay* display, CDCB cb); void gst_gl_display_setClientDrawCallback (GstGLDisplay* display, CDCB cb);
void gst_gl_display_setVisibleWindow (GstGLDisplay* display, gboolean visible); void gst_gl_display_setVisibleWindow (GstGLDisplay* display, gboolean visible);