mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 09:40:37 +00:00
gltransformation: fix issues and expose mvp matrix
* aspect should not be 0 on init * rename fovy to fov * add mvp to properties as boxed graphene type * fix transformation order. scale first * clear color with 1.0 alpha https://bugzilla.gnome.org/show_bug.cgi?id=734223
This commit is contained in:
parent
eca4eaf183
commit
f1b026c480
2 changed files with 35 additions and 16 deletions
|
@ -46,6 +46,7 @@
|
||||||
|
|
||||||
#include <gst/gl/gstglapi.h>
|
#include <gst/gl/gstglapi.h>
|
||||||
#include "gstgltransformation.h"
|
#include "gstgltransformation.h"
|
||||||
|
#include <graphene-1.0/graphene-gobject.h>
|
||||||
|
|
||||||
#define GST_CAT_DEFAULT gst_gl_transformation_debug
|
#define GST_CAT_DEFAULT gst_gl_transformation_debug
|
||||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||||
|
@ -53,7 +54,7 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_FOVY,
|
PROP_FOV,
|
||||||
PROP_ORTHO,
|
PROP_ORTHO,
|
||||||
PROP_TRANSLATION_X,
|
PROP_TRANSLATION_X,
|
||||||
PROP_TRANSLATION_Y,
|
PROP_TRANSLATION_Y,
|
||||||
|
@ -62,7 +63,8 @@ enum
|
||||||
PROP_ROTATION_Y,
|
PROP_ROTATION_Y,
|
||||||
PROP_ROTATION_Z,
|
PROP_ROTATION_Z,
|
||||||
PROP_SCALE_X,
|
PROP_SCALE_X,
|
||||||
PROP_SCALE_Y
|
PROP_SCALE_Y,
|
||||||
|
PROP_MVP
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DEBUG_INIT \
|
#define DEBUG_INIT \
|
||||||
|
@ -130,8 +132,8 @@ gst_gl_transformation_class_init (GstGLTransformationClass * klass)
|
||||||
GST_GL_FILTER_CLASS (klass)->filter_texture =
|
GST_GL_FILTER_CLASS (klass)->filter_texture =
|
||||||
gst_gl_transformation_filter_texture;
|
gst_gl_transformation_filter_texture;
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_FOVY,
|
g_object_class_install_property (gobject_class, PROP_FOV,
|
||||||
g_param_spec_float ("fovy", "Fovy", "Field of view angle in degrees",
|
g_param_spec_float ("fov", "Fov", "Field of view angle in degrees",
|
||||||
0.0, G_MAXFLOAT, 90.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
0.0, G_MAXFLOAT, 90.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_ORTHO,
|
g_object_class_install_property (gobject_class, PROP_ORTHO,
|
||||||
|
@ -188,6 +190,13 @@ gst_gl_transformation_class_init (GstGLTransformationClass * klass)
|
||||||
"Scale multiplierer for the Y-Axis.",
|
"Scale multiplierer for the Y-Axis.",
|
||||||
0.0, G_MAXFLOAT, 1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
0.0, G_MAXFLOAT, 1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
/* MVP */
|
||||||
|
g_object_class_install_property (gobject_class, PROP_MVP,
|
||||||
|
g_param_spec_boxed ("mvp-matrix",
|
||||||
|
"Modelview Projection Matrix",
|
||||||
|
"The final Graphene 4x4 Matrix for transformation",
|
||||||
|
GRAPHENE_TYPE_MATRIX, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
gst_element_class_set_metadata (element_class, "OpenGL transformation filter",
|
gst_element_class_set_metadata (element_class, "OpenGL transformation filter",
|
||||||
"Filter/Effect/Video", "Transform video on the GPU",
|
"Filter/Effect/Video", "Transform video on the GPU",
|
||||||
"Lubosz Sarnecki <lubosz@gmail.com>");
|
"Lubosz Sarnecki <lubosz@gmail.com>");
|
||||||
|
@ -197,8 +206,8 @@ static void
|
||||||
gst_gl_transformation_init (GstGLTransformation * filter)
|
gst_gl_transformation_init (GstGLTransformation * filter)
|
||||||
{
|
{
|
||||||
filter->shader = NULL;
|
filter->shader = NULL;
|
||||||
filter->fovy = 90;
|
filter->fov = 90;
|
||||||
filter->aspect = 0;
|
filter->aspect = 1.0;
|
||||||
filter->znear = 0.1;
|
filter->znear = 0.1;
|
||||||
filter->zfar = 100;
|
filter->zfar = 100;
|
||||||
|
|
||||||
|
@ -231,14 +240,16 @@ gst_gl_transformation_build_mvp (GstGLTransformation * transformation)
|
||||||
graphene_vec3_init (¢er, 0.f, 0.f, 0.f);
|
graphene_vec3_init (¢er, 0.f, 0.f, 0.f);
|
||||||
graphene_vec3_init (&up, 0.f, 1.f, 0.f);
|
graphene_vec3_init (&up, 0.f, 1.f, 0.f);
|
||||||
|
|
||||||
graphene_matrix_init_rotate (&model_matrix,
|
graphene_matrix_init_scale (&model_matrix,
|
||||||
|
transformation->xscale, transformation->yscale, 1.0f);
|
||||||
|
|
||||||
|
graphene_matrix_rotate (&model_matrix,
|
||||||
transformation->xrotation, graphene_vec3_x_axis ());
|
transformation->xrotation, graphene_vec3_x_axis ());
|
||||||
graphene_matrix_rotate (&model_matrix,
|
graphene_matrix_rotate (&model_matrix,
|
||||||
transformation->yrotation, graphene_vec3_y_axis ());
|
transformation->yrotation, graphene_vec3_y_axis ());
|
||||||
graphene_matrix_rotate (&model_matrix,
|
graphene_matrix_rotate (&model_matrix,
|
||||||
transformation->zrotation, graphene_vec3_z_axis ());
|
transformation->zrotation, graphene_vec3_z_axis ());
|
||||||
graphene_matrix_scale (&model_matrix,
|
|
||||||
transformation->xscale, transformation->yscale, 1.0f);
|
|
||||||
graphene_matrix_translate (&model_matrix, &translation_vector);
|
graphene_matrix_translate (&model_matrix, &translation_vector);
|
||||||
|
|
||||||
if (transformation->ortho) {
|
if (transformation->ortho) {
|
||||||
|
@ -247,7 +258,7 @@ gst_gl_transformation_build_mvp (GstGLTransformation * transformation)
|
||||||
-1, 1, transformation->znear, transformation->zfar);
|
-1, 1, transformation->znear, transformation->zfar);
|
||||||
} else {
|
} else {
|
||||||
graphene_matrix_init_perspective (&projection_matrix,
|
graphene_matrix_init_perspective (&projection_matrix,
|
||||||
transformation->fovy,
|
transformation->fov,
|
||||||
transformation->aspect, transformation->znear, transformation->zfar);
|
transformation->aspect, transformation->znear, transformation->zfar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,8 +276,8 @@ gst_gl_transformation_set_property (GObject * object, guint prop_id,
|
||||||
GstGLTransformation *filter = GST_GL_TRANSFORMATION (object);
|
GstGLTransformation *filter = GST_GL_TRANSFORMATION (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_FOVY:
|
case PROP_FOV:
|
||||||
filter->fovy = g_value_get_float (value);
|
filter->fov = g_value_get_float (value);
|
||||||
break;
|
break;
|
||||||
case PROP_ORTHO:
|
case PROP_ORTHO:
|
||||||
filter->ortho = g_value_get_boolean (value);
|
filter->ortho = g_value_get_boolean (value);
|
||||||
|
@ -295,6 +306,11 @@ gst_gl_transformation_set_property (GObject * object, guint prop_id,
|
||||||
case PROP_SCALE_Y:
|
case PROP_SCALE_Y:
|
||||||
filter->yscale = g_value_get_float (value);
|
filter->yscale = g_value_get_float (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_MVP:
|
||||||
|
if (g_value_get_boxed (value) != NULL)
|
||||||
|
filter->mvp_matrix = *((graphene_matrix_t *) g_value_get_boxed (value));
|
||||||
|
return;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -309,8 +325,8 @@ gst_gl_transformation_get_property (GObject * object, guint prop_id,
|
||||||
GstGLTransformation *filter = GST_GL_TRANSFORMATION (object);
|
GstGLTransformation *filter = GST_GL_TRANSFORMATION (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
case PROP_FOVY:
|
case PROP_FOV:
|
||||||
g_value_set_float (value, filter->fovy);
|
g_value_set_float (value, filter->fov);
|
||||||
break;
|
break;
|
||||||
case PROP_ORTHO:
|
case PROP_ORTHO:
|
||||||
g_value_set_boolean (value, filter->ortho);
|
g_value_set_boolean (value, filter->ortho);
|
||||||
|
@ -339,6 +355,9 @@ gst_gl_transformation_get_property (GObject * object, guint prop_id,
|
||||||
case PROP_SCALE_Y:
|
case PROP_SCALE_Y:
|
||||||
g_value_set_float (value, filter->yscale);
|
g_value_set_float (value, filter->yscale);
|
||||||
break;
|
break;
|
||||||
|
case PROP_MVP:
|
||||||
|
g_value_set_boxed (value, (gconstpointer) & filter->mvp_matrix);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
|
@ -437,7 +456,7 @@ gst_gl_transformation_callback (gpointer stuff)
|
||||||
gst_gl_context_clear_shader (filter->context);
|
gst_gl_context_clear_shader (filter->context);
|
||||||
gl->BindTexture (GL_TEXTURE_2D, 0);
|
gl->BindTexture (GL_TEXTURE_2D, 0);
|
||||||
|
|
||||||
gl->ClearColor (0.f, 0.f, 0.f, 0.f);
|
gl->ClearColor (0.f, 0.f, 0.f, 1.f);
|
||||||
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
gl->Clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
gst_gl_shader_use (transformation->shader);
|
gst_gl_shader_use (transformation->shader);
|
||||||
|
|
|
@ -56,7 +56,7 @@ struct _GstGLTransformation
|
||||||
gfloat ztranslation;
|
gfloat ztranslation;
|
||||||
|
|
||||||
/* perspective */
|
/* perspective */
|
||||||
gfloat fovy;
|
gfloat fov;
|
||||||
gfloat aspect;
|
gfloat aspect;
|
||||||
gfloat znear;
|
gfloat znear;
|
||||||
gfloat zfar;
|
gfloat zfar;
|
||||||
|
|
Loading…
Reference in a new issue