mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-03-28 11:55:39 +00:00
sys/glsink/: Add vblank synchronization. Isn't really working on my driver. :(
Original commit message from CVS: * sys/glsink/Makefile.am: * sys/glsink/glextensions.c: * sys/glsink/glextensions.h: * sys/glsink/glvideo.c: Add vblank synchronization. Isn't really working on my driver. :(
This commit is contained in:
parent
601b1f640b
commit
1fab43e619
5 changed files with 219 additions and 5 deletions
|
@ -1,3 +1,12 @@
|
|||
2007-12-15 David Schleef <ds@schleef.org>
|
||||
|
||||
* sys/glsink/Makefile.am:
|
||||
* sys/glsink/glextensions.c:
|
||||
* sys/glsink/glextensions.h:
|
||||
* sys/glsink/glvideo.c:
|
||||
Add vblank synchronization. Isn't really working on my
|
||||
driver. :(
|
||||
|
||||
2007-12-15 David Schleef <ds@schleef.org>
|
||||
|
||||
* sys/glsink/Makefile.am:
|
||||
|
|
|
@ -5,7 +5,8 @@ libgstglimagesink_la_SOURCES = \
|
|||
glimagesink.c \
|
||||
glvideo.c \
|
||||
gstopengl.c \
|
||||
gstvideo-common.c
|
||||
gstvideo-common.c \
|
||||
glextensions.c
|
||||
libgstglimagesink_la_CFLAGS = $(GST_CFLAGS) $(X_CFLAGS) $(GST_BASE_CFLAGS) \
|
||||
$(GST_PLUGINS_BASE_CFLAGS)
|
||||
libgstglimagesink_la_LIBADD = $(X_LIBS) $(XSHM_LIBS) -lGL \
|
||||
|
@ -16,4 +17,5 @@ libgstglimagesink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
|||
noinst_HEADERS = \
|
||||
glimagesink.h \
|
||||
gstvideo-common.h \
|
||||
glvideo.h
|
||||
glvideo.h \
|
||||
glextensions.h
|
||||
|
|
124
sys/glsink/glextensions.c
Normal file
124
sys/glsink/glextensions.c
Normal file
|
@ -0,0 +1,124 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <GL/glx.h>
|
||||
#include <GL/glxext.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "glextensions.h"
|
||||
|
||||
int
|
||||
gl_have_extension (const char *name)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
s = (const char *) glGetString (GL_EXTENSIONS);
|
||||
if (s == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (strstr (s, name))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);
|
||||
|
||||
#define DEFINE_FUNC_RET(name,return_type,prototype,args) \
|
||||
return_type name prototype \
|
||||
{ \
|
||||
static return_type (*func) prototype; \
|
||||
if (func == NULL) { \
|
||||
func = (void *) glXGetProcAddressARB ((unsigned char *) #name); \
|
||||
} \
|
||||
return func args; \
|
||||
}
|
||||
|
||||
#define DEFINE_FUNC(name,prototype,args) \
|
||||
void name prototype \
|
||||
{ \
|
||||
static void (*func) prototype; \
|
||||
if (func == NULL) { \
|
||||
func = (void *) glXGetProcAddressARB ((unsigned char *) #name); \
|
||||
} \
|
||||
func args; \
|
||||
}
|
||||
|
||||
DEFINE_FUNC_RET (glCreateShaderObjectARB, GLhandleARB,
|
||||
(GLenum shaderType), (shaderType));
|
||||
#if 0
|
||||
typedef GLhandleARB type_glCreateShaderObjectARB (GLenum shaderType);
|
||||
GLhandleARB
|
||||
glCreateShaderObjectARB (GLenum shaderType)
|
||||
{
|
||||
type_glCreateShaderObjectARB *func;
|
||||
|
||||
if (func == NULL) {
|
||||
func = (type_glCreateShaderObjectARB *)
|
||||
glXGetProcAddress ((unsigned char *) "glCreateShaderObjectARB");
|
||||
}
|
||||
return (*func) (shaderType);
|
||||
}
|
||||
#endif
|
||||
|
||||
DEFINE_FUNC (glShaderSourceARB,
|
||||
(GLhandleARB shaderObj, GLsizei count, const GLcharARB ** string,
|
||||
const GLint * length), (shaderObj, count, string, length));
|
||||
|
||||
DEFINE_FUNC (glUniform2fARB,
|
||||
(GLint location, GLfloat val1, GLfloat val2), (location, val1, val2));
|
||||
|
||||
DEFINE_FUNC_RET (glGetUniformLocationARB, GLint,
|
||||
(GLhandleARB programObj, const GLcharARB * name), (programObj, name));
|
||||
|
||||
DEFINE_FUNC (glUniform1iARB, (GLint location, GLint val), (location, val));
|
||||
|
||||
DEFINE_FUNC (glGetObjectParameterivARB, (GLhandleARB object, GLenum pname,
|
||||
GLint * params), (object, pname, params));
|
||||
|
||||
DEFINE_FUNC (glCompileShaderARB, (GLhandleARB shader), (shader));
|
||||
|
||||
DEFINE_FUNC (glGetInfoLogARB, (GLhandleARB object, GLsizei maxLength,
|
||||
GLsizei * length, GLcharARB * infoLog), (object, maxLength, length,
|
||||
infoLog));
|
||||
|
||||
DEFINE_FUNC_RET (glCreateProgramObjectARB, GLhandleARB, (void), ());
|
||||
|
||||
DEFINE_FUNC (glAttachObjectARB, (GLhandleARB program, GLhandleARB shader),
|
||||
(program, shader));
|
||||
|
||||
DEFINE_FUNC (glLinkProgramARB, (GLhandleARB program), (program));
|
||||
|
||||
DEFINE_FUNC (glUseProgramObjectARB, (GLhandleARB program), (program));
|
||||
|
||||
DEFINE_FUNC (glPixelDataRangeNV, (GLenum target, GLsizei length, void *pointer),
|
||||
(target, length, pointer));
|
||||
|
||||
DEFINE_FUNC_RET (glXGetSyncValuesOML, Bool,
|
||||
(Display * display, GLXDrawable drawable, int64_t * ust, int64_t * msc,
|
||||
int64_t * sbc), (display, drawable, ust, msc, sbc));
|
||||
|
||||
DEFINE_FUNC_RET (glXGetMscRateOML, Bool,
|
||||
(Display * display, GLXDrawable drawable, int32_t * numerator,
|
||||
int32_t * denominator), (display, drawable, numerator, denominator));
|
||||
|
||||
DEFINE_FUNC_RET (glXSwapBuffersMscOML, int64_t,
|
||||
(Display * display, GLXDrawable drawable, int64_t target_msc,
|
||||
int64_t divisor, int64_t remainder), (display, drawable, target_msc,
|
||||
divisor, remainder));
|
||||
|
||||
DEFINE_FUNC_RET (glXWaitForMscOML, Bool,
|
||||
(Display * display, GLXDrawable drawable, int64_t target_msc,
|
||||
int64_t divisor, int64_t remainder, int64_t * ust, int64_t * msc,
|
||||
int64_t * sbc), (display, drawable, target_msc, divisor, remainder, ust,
|
||||
msc, sbc));
|
||||
|
||||
DEFINE_FUNC_RET (glXWaitForSbcOML, Bool,
|
||||
(Display * display, GLXDrawable drawable, int64_t target_sbc, int64_t * ust,
|
||||
int64_t * msc, int64_t * sbc), (display, drawable, target_sbc, ust, msc,
|
||||
sbc));
|
||||
|
||||
DEFINE_FUNC_RET (glXSwapIntervalSGI, int, (int interval), (interval));
|
||||
|
||||
DEFINE_FUNC_RET (glXSwapIntervalMESA, int, (unsigned int interval), (interval));
|
34
sys/glsink/glextensions.h
Normal file
34
sys/glsink/glextensions.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef __GST_GLEXTENSIONS_H__
|
||||
#define __GST_GLEXTENSIONS_H__
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <glib.h>
|
||||
|
||||
int gl_have_extension (const char *name);
|
||||
|
||||
GLhandleARB glCreateShaderObjectARB (GLenum shaderType);
|
||||
void glShaderSourceARB (GLhandleARB shaderObj, GLsizei count, const GLcharARB ** string, const GLint *length);
|
||||
void glUniform2fARB (GLint location, GLfloat val1, GLfloat val2);
|
||||
GLint glGetUniformLocationARB (GLhandleARB programObj, const GLcharARB *name);
|
||||
void glUniform1iARB (GLint location, GLint val);
|
||||
void glCompileShaderARB (GLhandleARB shader);
|
||||
void glGetObjectParameterivARB (GLhandleARB object, GLenum pname, GLint *params);
|
||||
void glGetInfoLogARB (GLhandleARB object, GLsizei maxLength, GLsizei *length,
|
||||
GLcharARB *infoLog);
|
||||
GLhandleARB glCreateProgramObjectARB (void);
|
||||
void glAttachObjectARB (GLhandleARB program, GLhandleARB shader);
|
||||
void glLinkProgramARB (GLhandleARB program);
|
||||
void glUseProgramObjectARB (GLhandleARB program);
|
||||
void glPixelDataRangeNV(GLenum target, GLsizei length, void *pointer);
|
||||
void glActiveTexture(GLenum target);
|
||||
Bool glXGetSyncValuesOML (Display *, GLXDrawable, int64_t *, int64_t *, int64_t *);
|
||||
Bool glXGetMscRateOML (Display *, GLXDrawable, int32_t *, int32_t *);
|
||||
int64_t glXSwapBuffersMscOML (Display *, GLXDrawable, int64_t, int64_t, int64_t);
|
||||
Bool glXWaitForMscOML (Display *, GLXDrawable, int64_t, int64_t, int64_t, int64_t *, int64_t *, int64_t *);
|
||||
Bool glXWaitForSbcOML (Display *, GLXDrawable, int64_t, int64_t *, int64_t *, int64_t *);
|
||||
int glXSwapIntervalSGI (int);
|
||||
int glXSwapIntervalMESA (unsigned int);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
#endif
|
||||
|
||||
#include "glvideo.h"
|
||||
#include "glextensions.h"
|
||||
/* only use gst for debugging */
|
||||
#include <gst/gst.h>
|
||||
|
||||
|
@ -327,11 +328,14 @@ static void
|
|||
draw_rect_texture (GLVideoDrawable * drawable, GLVideoImageType type,
|
||||
void *data, int width, int height)
|
||||
{
|
||||
GLuint texture;
|
||||
|
||||
GST_DEBUG ("using rectangular texture");
|
||||
|
||||
#ifdef GL_TEXTURE_RECTANGLE_ARB
|
||||
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, 1);
|
||||
glGenTextures (1, &texture);
|
||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, texture);
|
||||
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);
|
||||
|
@ -415,6 +419,7 @@ draw_rect_texture (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
glTexCoord2f (width, height);
|
||||
glVertex3f (1.0, -1.0, 0);
|
||||
glEnd ();
|
||||
glDeleteTextures (1, &texture);
|
||||
#else
|
||||
g_assert_not_reached ();
|
||||
#endif
|
||||
|
@ -427,6 +432,7 @@ draw_pow2_texture (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
int pow2_width;
|
||||
int pow2_height;
|
||||
double x, y;
|
||||
GLuint texture;
|
||||
|
||||
GST_DEBUG ("using power-of-2 texture");
|
||||
|
||||
|
@ -435,7 +441,8 @@ draw_pow2_texture (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
for (pow2_width = 64; pow2_width < width && pow2_width > 0; pow2_width <<= 1);
|
||||
|
||||
glEnable (GL_TEXTURE_2D);
|
||||
glBindTexture (GL_TEXTURE_2D, 1);
|
||||
glGenTextures (1, &texture);
|
||||
glBindTexture (GL_TEXTURE_2D, texture);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
|
@ -522,6 +529,7 @@ draw_pow2_texture (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
glTexCoord2f (x, y);
|
||||
glVertex3f (1.0, -1.0, 0);
|
||||
glEnd ();
|
||||
glDeleteTextures (1, &texture);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -534,8 +542,36 @@ glv_drawable_draw_image (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
|
||||
glv_drawable_lock (drawable);
|
||||
|
||||
#if 0
|
||||
/* Doesn't work */
|
||||
{
|
||||
int64_t ust = 1234;
|
||||
int64_t mst = 1234;
|
||||
int64_t sbc = 1234;
|
||||
gboolean ret;
|
||||
|
||||
ret = glXGetSyncValuesOML (drawable->display->display, drawable->window,
|
||||
&ust, &mst, &sbc);
|
||||
GST_ERROR ("sync values %d %lld %lld %lld", ret, ust, mst, sbc);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* Does work, but is not relevant */
|
||||
{
|
||||
int32_t num = 1234;
|
||||
int32_t den = 1234;
|
||||
gboolean ret;
|
||||
|
||||
ret = glXGetMscRateOML (drawable->display->display, drawable->window,
|
||||
&num, &den);
|
||||
GST_ERROR ("rate %d %d %d", ret, num, den);
|
||||
}
|
||||
#endif
|
||||
|
||||
glv_drawable_update_attributes (drawable);
|
||||
|
||||
glXSwapIntervalSGI (1);
|
||||
glViewport (0, 0, drawable->win_width, drawable->win_height);
|
||||
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -557,8 +593,17 @@ glv_drawable_draw_image (GLVideoDrawable * drawable, GLVideoImageType type,
|
|||
draw_pow2_texture (drawable, type, data, width, height);
|
||||
}
|
||||
|
||||
glFlush ();
|
||||
glXSwapBuffers (drawable->display->display, drawable->window);
|
||||
#if 0
|
||||
/* Doesn't work */
|
||||
{
|
||||
ret = glXSwapBuffersMscOML (drawable->display->display, drawable->window,
|
||||
0, 1, 0);
|
||||
if (ret == 0) {
|
||||
GST_ERROR ("glXSwapBuffersMscOML failed");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
glv_drawable_unlock (drawable);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue