01478794cb9754266195a716ccb3984deb05bc24
[platform/upstream/gstreamer.git] / gst-libs / gst / gl / gstglfilter.h
1 /*
2  * GStreamer
3  * Copyright (C) 2007 David Schleef <ds@schleef.org>
4  * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
5  * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef _GST_GL_FILTER_H_
24 #define _GST_GL_FILTER_H_
25
26 #include <gst/gst.h>
27 #include <gst/base/gstbasetransform.h>
28 #include <gst/video/video.h>
29
30 #include <gst/gl/gl.h>
31
32 G_BEGIN_DECLS
33
34 GType gst_gl_filter_get_type(void);
35 #define GST_TYPE_GL_FILTER            (gst_gl_filter_get_type())
36 #define GST_GL_FILTER(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_FILTER,GstGLFilter))
37 #define GST_IS_GL_FILTER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_FILTER))
38 #define GST_GL_FILTER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_GL_FILTER,GstGLFilterClass))
39 #define GST_IS_GL_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_GL_FILTER))
40 #define GST_GL_FILTER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_GL_FILTER,GstGLFilterClass))
41
42 typedef struct _GstGLFilter GstGLFilter;
43 typedef struct _GstGLFilterClass GstGLFilterClass;
44
45 /**
46  * GstGLFilter:
47  * @base_transform: parent #GstBaseTransform
48  * @pool: the currently configured #GstBufferPool
49  * @display: the currently configured #GstGLDisplay
50  * @in_info: the video info for input buffers
51  * @out_info: the video info for output buffers
52  * @fbo: GL Framebuffer object used for transformations
53  * @depthbuffer: GL renderbuffer attached to @fbo
54  * @upload: the object used for uploading data, if needed
55  * @download: the object used for downloading data, if needed
56  *
57  * #GstGLFilter is a base class that provides the logic of getting the GL context
58  * from downstream and automatic upload/download for non-#GstGLMemory
59  * #GstBuffer<!--  -->s.
60  */
61 struct _GstGLFilter
62 {
63   GstBaseTransform   base_transform;
64
65   GstBufferPool     *pool;
66
67   GstGLDisplay      *display;
68
69   GstVideoInfo       in_info;
70   GstVideoInfo       out_info;
71   GLuint             fbo;
72   GLuint             depthbuffer;
73
74   GstGLUpload       *upload;
75   GstGLDownload     *download;
76
77   /* <private> */
78   GLuint             in_tex_id;
79   GLuint             out_tex_id;
80
81   GstGLShader       *default_shader;
82
83   GstGLContext      *other_context;
84 };
85
86 /**
87  * GstGLFilterClass:
88  * @base_transform_class: parent class
89  * @set_caps: mirror from #GstBaseTransform
90  * @filter: perform operations on the input and output buffers.  In general,
91  *          you should avoid using this method if at all possible. One valid
92  *          use-case for using this is keeping previous buffers for future calculations.
93  *          Note: If @filter exists, then @filter_texture is not run
94  * @filter_texture: given @in_tex, transform it into @out_tex.  Not used
95  *                  if @filter exists
96  * @onInitFBO: perform initialization when the Framebuffer object is created
97  * @onStart: called when element activates see also #GstBaseTransform
98  * @onStop: called when the element deactivates e also #GstBaseTransform
99  * @onReset: called on inizialation and after @onStop
100  * @display_init_cb: execute arbitrary gl code on start
101  * @display_reset_cb: execute arbitrary gl code at stop
102  */
103 struct _GstGLFilterClass
104 {
105   GstBaseTransformClass base_transform_class;
106
107   gboolean (*set_caps)          (GstGLFilter* filter, GstCaps* incaps, GstCaps* outcaps);
108   gboolean (*filter)            (GstGLFilter *filter, GstBuffer *inbuf, GstBuffer *outbuf);
109   gboolean (*filter_texture)    (GstGLFilter *filter, guint in_tex, guint out_tex);
110   gboolean (*onInitFBO)         (GstGLFilter *filter);
111
112   void (*onStart)               (GstGLFilter *filter);
113   void (*onStop)                (GstGLFilter *filter);
114   void (*onReset)               (GstGLFilter *filter);
115
116   /* useful to init and cleanup custom gl resources */
117   void (*display_init_cb)       (GstGLFilter *filter);
118   void (*display_reset_cb)      (GstGLFilter *filter);
119 };
120
121 gboolean gst_gl_filter_filter_texture (GstGLFilter * filter, GstBuffer * inbuf,
122                                        GstBuffer * outbuf);
123
124 void gst_gl_filter_render_to_target (GstGLFilter *filter, gboolean resize, GLuint input,
125                                      GLuint target, GLCB func, gpointer data);
126
127 #if GST_GL_HAVE_OPENGL
128 void gst_gl_filter_render_to_target_with_shader (GstGLFilter * filter, gboolean resize,
129                                                  GLuint input, GLuint target, GstGLShader *shader);
130
131 void gst_gl_filter_draw_texture (GstGLFilter *filter, GLuint texture, guint width, guint height);
132 #endif /* GST_GL_HAVE_OPENGL */
133
134 G_END_DECLS
135
136 #endif /* _GST_GL_FILTER_H_ */