[051/906] * sys/glsink/glextensions.c: * sys/glsink/glextensions.h: * sys/glsink/glimagesink.c: * sys/glsink/glimagesink.h: * sys/glsink/gstgldisplay.c: * sys/glsink/gstgldisplay.h: * sys/glsink/gstopengl.c: Reenable video/x-raw-rgb and x-raw-yuv for glimagesink. Enable vblank synchronization. Remove unused code.

This commit is contained in:
David Schleef 2008-01-06 01:19:48 +00:00 committed by Tim-Philipp Müller
parent 6fd801ba2a
commit 45d3247a68
4 changed files with 53 additions and 147 deletions

View file

@ -6,6 +6,7 @@
#include <GL/glx.h>
#include <GL/glxext.h>
#include <string.h>
#include <glib.h>
#include "glextensions.h"

View file

@ -2,7 +2,7 @@
#define __GST_GLEXTENSIONS_H__
#include <GL/gl.h>
#include <glib.h>
//#include <glib.h>
int gl_have_extension (const char *name);

View file

@ -85,7 +85,7 @@ gst_gl_display_new (void)
return g_object_new (GST_TYPE_GL_DISPLAY, NULL);
}
#define HANDLE_X_ERRORS
//#define HANDLE_X_ERRORS
#ifdef HANDLE_X_ERRORS
static int
x_error_handler (Display * display, XErrorEvent * event)
@ -167,29 +167,12 @@ gst_gl_display_check_features (GstGLDisplay * display)
GST_DEBUG ("No GLX extension");
return FALSE;
}
#if 0
{
int i;
int n;
visinfo = XGetVisualInfo (display->display, 0, NULL, &n);
for (i = 0; i < n; i++) {
GST_ERROR ("%d: %d %ld", i, visinfo[i].depth, visinfo[i].visualid);
if (visinfo[i].depth == 32)
break;
}
visinfo += i;
}
#endif
if (1) {
visinfo = glXChooseVisual (display->display, scrnum, attrib);
if (visinfo == NULL) {
GST_DEBUG ("No usable visual");
return FALSE;
}
}
display->visinfo = visinfo;
@ -204,7 +187,7 @@ gst_gl_display_check_features (GstGLDisplay * display)
mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect;
GST_ERROR ("creating window with visual %ld", visinfo->visualid);
GST_DEBUG ("creating window with visual %ld", visinfo->visualid);
window = XCreateWindow (display->display, root, 0, 0,
100, 100, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr);
@ -331,7 +314,9 @@ gst_gl_display_init_tmp_window (GstGLDisplay * display)
parent_window, 0, 0, width, height,
0, display->visinfo->depth, InputOutput,
display->visinfo->visual, mask, &attr);
if (display->visible) {
XMapWindow (display->display, display->window);
}
XSync (display->display, FALSE);
}
@ -341,35 +326,32 @@ gst_gl_display_destroy_tmp_window (GstGLDisplay * display)
XDestroyWindow (display->display, display->window);
}
void
gst_gl_display_set_visible (GstGLDisplay * display, gboolean visible)
{
if (display->visible == visible)
return;
display->visible = visible;
if (display->visible) {
XMapWindow (display->display, display->window);
} else {
XUnmapWindow (display->display, display->window);
}
XSync (display->display, FALSE);
}
void
gst_gl_display_set_window (GstGLDisplay * display, Window window)
{
g_mutex_lock (display->lock);
#if 0
if (window != display->assigned_window) {
if (display->assigned_window == None) {
gst_gl_display_destroy_tmp_window (display);
}
display->assigned_window = window;
if (display->assigned_window == None) {
gst_gl_display_init_tmp_window (display);
} else {
display->window = window;
}
}
#else
if (window != display->parent_window) {
gst_gl_display_destroy_tmp_window (display);
display->parent_window = window;
gst_gl_display_init_tmp_window (display);
//XReparentWindow (display->display, display->window,
// display->assigned_window, 0, 0);
}
#endif
g_mutex_unlock (display->lock);
}
@ -478,6 +460,7 @@ gst_gl_display_upload_texture_rectangle (GstGLDisplay * display,
}
#if 0
static void
draw_rect_texture (GstGLDisplay * display, GstVideoFormat type,
void *data, int width, int height)
@ -689,7 +672,9 @@ draw_pow2_texture (GstGLDisplay * display, GstVideoFormat type,
glEnd ();
glDeleteTextures (1, &texture);
}
#endif
#if 0
void
gst_gl_display_draw_image (GstGLDisplay * display, GstVideoFormat type,
void *data, int width, int height)
@ -710,7 +695,7 @@ gst_gl_display_draw_image (GstGLDisplay * display, GstVideoFormat type,
ret = glXGetSyncValuesOML (display->display, display->window,
&ust, &mst, &sbc);
GST_DEBUG ("sync values %d %lld %lld %lld", ret, ust, mst, sbc);
GST_ERROR ("sync values %d %lld %lld %lld", ret, ust, mst, sbc);
}
#endif
@ -763,107 +748,8 @@ gst_gl_display_draw_image (GstGLDisplay * display, GstVideoFormat type,
gst_gl_display_unlock (display);
}
void
gst_gl_display_draw_rbo (GstGLDisplay * display, GLuint rbo,
int width, int height)
{
GLuint texture;
GLuint fbo;
g_return_if_fail (width > 0);
g_return_if_fail (height > 0);
g_return_if_fail (rbo != None);
gst_gl_display_lock (display);
g_assert (display->window != None);
g_assert (display->context != NULL);
gst_gl_display_update_attributes (display);
glViewport (0, 0, display->win_width, display->win_height);
glClearColor (0.3, 0.3, 0.3, 1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glDisable (GL_CULL_FACE);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glColor4f (1, 1, 1, 1);
glGenFramebuffersEXT (1, &fbo);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, fbo);
glFramebufferRenderbufferEXT (GL_FRAMEBUFFER_EXT,
GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, rbo);
glDrawBuffer (GL_COLOR_ATTACHMENT0_EXT);
glReadBuffer (GL_COLOR_ATTACHMENT0_EXT);
g_assert (glCheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT) ==
GL_FRAMEBUFFER_COMPLETE_EXT);
#if 1
{
void *buffer;
buffer = malloc (320 * 240 * 4);
memset (buffer, random (), 320 * 240 * 4);
free (buffer);
}
#endif
glEnable (GL_TEXTURE_RECTANGLE_ARB);
glGenTextures (1, &texture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, width, height, 0,
GL_RGB, 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);
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glFramebufferTexture2DEXT (GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
GL_TEXTURE_RECTANGLE_ARB, texture, 0);
glDrawBuffer (0);
glReadBuffer (0);
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0);
glColor4f (1, 0, 1, 1);
gst_gl_display_check_error (display, __LINE__);
//glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 0);
glBegin (GL_QUADS);
glNormal3f (0, 0, -1);
glTexCoord2f (width, 0);
glVertex3f (0.9, 0.9, 0);
glTexCoord2f (0, 0);
glVertex3f (-0.9, 0.9, 0);
glTexCoord2f (0, height);
glVertex3f (-0.9, -0.9, 0);
glTexCoord2f (width, height);
glVertex3f (0.9, -0.9, 0);
glEnd ();
gst_gl_display_check_error (display, __LINE__);
glDeleteTextures (1, &texture);
glDeleteFramebuffersEXT (1, &fbo);
gst_gl_display_check_error (display, __LINE__);
glXSwapBuffers (display->display, display->window);
gst_gl_display_unlock (display);
}
void
gst_gl_display_draw_texture (GstGLDisplay * display, GLuint texture,
int width, int height)
@ -878,6 +764,24 @@ gst_gl_display_draw_texture (GstGLDisplay * display, GLuint texture,
g_assert (display->context != NULL);
gst_gl_display_update_attributes (display);
#if 0
/* Doesn't work */
{
int64_t ust = 1234;
int64_t mst = 1234;
int64_t sbc = 1234;
gboolean ret;
ret = glXGetSyncValuesOML (display->display, display->window,
&ust, &mst, &sbc);
GST_ERROR ("sync values %d %lld %lld %lld", ret, ust, mst, sbc);
}
#endif
#if 1
/* Doesn't work */
glXSwapIntervalSGI (1);
#endif
glViewport (0, 0, display->win_width, display->win_height);
@ -910,13 +814,13 @@ gst_gl_display_draw_texture (GstGLDisplay * display, GLuint texture,
glNormal3f (0, 0, -1);
glTexCoord2f (width, 0);
glVertex3f (0.9, 0.9, 0);
glVertex3f (1.0, 1.0, 0);
glTexCoord2f (0, 0);
glVertex3f (-0.9, 0.9, 0);
glVertex3f (-1.0, 1.0, 0);
glTexCoord2f (0, height);
glVertex3f (-0.9, -0.9, 0);
glVertex3f (-1.0, -1.0, 0);
glTexCoord2f (width, height);
glVertex3f (0.9, -0.9, 0);
glVertex3f (1.0, -1.0, 0);
glEnd ();
gst_gl_display_check_error (display, __LINE__);

View file

@ -46,7 +46,7 @@ struct _GstGLDisplay {
gboolean have_color_matrix;
Window window;
//Window assigned_window;
gboolean visible;
Window parent_window;
int win_width;
@ -80,6 +80,7 @@ void gst_gl_display_draw_texture (GstGLDisplay * display, GLuint texture,
void gst_gl_display_check_error (GstGLDisplay *display, int line);
GLuint gst_gl_display_upload_texture_rectangle (GstGLDisplay *display,
GstVideoFormat type, void *data, int width, int height);
void gst_gl_display_set_visible (GstGLDisplay *display, gboolean visible);
#endif