2008-06-07 00:01:18 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstglfiltercube.h"
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_filter_cube_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
|
|
|
static const GstElementDetails element_details =
|
|
|
|
GST_ELEMENT_DETAILS ("OpenGL cube filter",
|
|
|
|
"Filter/Effect",
|
2008-06-10 22:59:57 +00:00
|
|
|
"Map input texture on the 6 cube faces",
|
2008-06-07 00:01:18 +00:00
|
|
|
"Julien Isorce <julien.isorce@gmail.com>");
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2008-06-23 23:12:37 +00:00
|
|
|
PROP_0
|
2008-06-07 00:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DEBUG_INIT(bla) \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_filter_cube_debug, "glfiltercube", 0, "glfiltercube element");
|
|
|
|
|
|
|
|
GST_BOILERPLATE_FULL (GstGLFilterCube, gst_gl_filter_cube, GstGLFilter,
|
|
|
|
GST_TYPE_GL_FILTER, DEBUG_INIT);
|
|
|
|
|
2008-06-23 23:12:37 +00:00
|
|
|
static void gst_gl_filter_cube_set_property (GObject* object, guint prop_id,
|
|
|
|
const GValue* value, GParamSpec * pspec);
|
|
|
|
static void gst_gl_filter_cube_get_property (GObject* object, guint prop_id,
|
|
|
|
GValue* value, GParamSpec* pspec);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-23 23:12:37 +00:00
|
|
|
static gboolean gst_gl_filter_cube_filter (GstGLFilter* filter,
|
|
|
|
GstGLBuffer* inbuf, GstGLBuffer* outbuf);
|
2008-06-13 00:01:26 +00:00
|
|
|
static void gst_gl_filter_cube_callback (guint width, guint height, guint texture, GLhandleARB shader);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_cube_base_init (gpointer klass)
|
|
|
|
{
|
2008-06-23 23:12:37 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-23 23:12:37 +00:00
|
|
|
gst_element_class_set_details (element_class, &element_details);
|
2008-06-07 00:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_filter_cube_class_init (GstGLFilterCubeClass * klass)
|
|
|
|
{
|
2008-06-23 23:12:37 +00:00
|
|
|
GObjectClass* gobject_class;
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-23 23:12:37 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gobject_class->set_property = gst_gl_filter_cube_set_property;
|
|
|
|
gobject_class->get_property = gst_gl_filter_cube_get_property;
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-23 23:12:37 +00:00
|
|
|
GST_GL_FILTER_CLASS (klass)->filter = gst_gl_filter_cube_filter;
|
2008-06-07 00:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-07 15:27:12 +00:00
|
|
|
gst_gl_filter_cube_init (GstGLFilterCube* filter,
|
|
|
|
GstGLFilterCubeClass* klass)
|
2008-06-07 00:01:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-07 15:27:12 +00:00
|
|
|
gst_gl_filter_cube_set_property (GObject* object, guint prop_id,
|
|
|
|
const GValue* value, GParamSpec* pspec)
|
2008-06-07 00:01:18 +00:00
|
|
|
{
|
2008-06-07 15:27:12 +00:00
|
|
|
//GstGLFilterCube *filter = GST_GL_FILTER_CUBE (object);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-07 15:27:12 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-07 00:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-06-07 15:27:12 +00:00
|
|
|
gst_gl_filter_cube_get_property (GObject* object, guint prop_id,
|
|
|
|
GValue* value, GParamSpec* pspec)
|
2008-06-07 00:01:18 +00:00
|
|
|
{
|
2008-06-07 15:27:12 +00:00
|
|
|
//GstGLFilterCube *filter = GST_GL_FILTER_CUBE (object);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-07 15:27:12 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-07 00:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-06-07 15:27:12 +00:00
|
|
|
gst_gl_filter_cube_filter (GstGLFilter* filter, GstGLBuffer* inbuf,
|
|
|
|
GstGLBuffer* outbuf)
|
2008-06-07 00:01:18 +00:00
|
|
|
{
|
2008-06-11 23:40:01 +00:00
|
|
|
//GstGLFilterCube* cube_filter = GST_GL_FILTER_CUBE(filter);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-21 21:38:42 +00:00
|
|
|
//blocking call, use a FBO
|
2008-06-07 15:27:12 +00:00
|
|
|
gst_gl_display_useFBO (filter->display, filter->width, filter->height,
|
2008-06-21 21:38:42 +00:00
|
|
|
filter->fbo, filter->depthbuffer, outbuf->texture, gst_gl_filter_cube_callback,
|
|
|
|
inbuf->width, inbuf->height, inbuf->texture, 0);
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-07 15:27:12 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2008-06-07 00:01:18 +00:00
|
|
|
|
2008-06-07 15:27:12 +00:00
|
|
|
//opengl scene, params: input texture (not the output filter->texture)
|
|
|
|
static void
|
2008-06-13 00:01:26 +00:00
|
|
|
gst_gl_filter_cube_callback (guint width, guint height, guint texture, GLhandleARB shader)
|
2008-06-07 15:27:12 +00:00
|
|
|
{
|
|
|
|
static GLfloat xrot = 0;
|
|
|
|
static GLfloat yrot = 0;
|
|
|
|
static GLfloat zrot = 0;
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
|
|
|
glEnable (GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
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_TO_EDGE);
|
|
|
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
glTranslatef(0.0f,0.0f,-5.0f);
|
|
|
|
|
|
|
|
glRotatef(xrot,1.0f,0.0f,0.0f);
|
|
|
|
glRotatef(yrot,0.0f,1.0f,0.0f);
|
|
|
|
glRotatef(zrot,0.0f,0.0f,1.0f);
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
// Front Face
|
|
|
|
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
// Back Face
|
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f( 1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
|
|
|
|
// Top Face
|
|
|
|
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, 1.0f, -1.0f);
|
|
|
|
// Bottom Face
|
|
|
|
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f((gfloat)width,(gfloat)height); glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
// Right face
|
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, (gfloat)height); glVertex3f( 1.0f, 1.0f, -1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f( 1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
|
|
|
|
// Left Face
|
|
|
|
glTexCoord2f((gfloat)width, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
|
|
|
|
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
|
|
|
|
glTexCoord2f(0.0f, (gfloat)height); glVertex3f(-1.0f, 1.0f, 1.0f);
|
|
|
|
glTexCoord2f((gfloat)width, (gfloat)height); glVertex3f(-1.0f, 1.0f, -1.0f);
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
xrot+=0.3f;
|
|
|
|
yrot+=0.2f;
|
|
|
|
zrot+=0.4f;
|
2008-06-07 00:01:18 +00:00
|
|
|
}
|