summaryrefslogtreecommitdiff
path: root/gst-libs/gst/vaapi/gstvaapiutils_glx.h
blob: 912d0723b3ea61c837ca1404e4e179a3310636cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 *  gstvaapiutils_glx.h - GLX utilties
 *
 *  Copyright (C) 2010-2011 Splitted-Desktop Systems
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2.1
 *  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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301 USA
 */

#ifndef GST_VAAPI_UTILS_GLX_H
#define GST_VAAPI_UTILS_GLX_H

#include "config.h"
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glx.h>
#include <GL/glxext.h>
#include <glib.h>

#if GLX_GLXEXT_VERSION < 18
typedef void (*PFNGLXBINDTEXIMAGEEXTPROC)(Display *, GLXDrawable, int, const int *);
typedef void (*PFNGLXRELEASETEXIMAGEEXTPROC)(Display *, GLXDrawable, int);
#endif

#if GLX_GLXEXT_VERSION < 27
/* XXX: this is not exactly that version but this is the only means to
   make sure we have the correct <GL/glx.h> with those signatures */
typedef GLXPixmap (*PFNGLXCREATEPIXMAPPROC)(Display *, GLXFBConfig, Pixmap, const int *);
typedef void (*PFNGLXDESTROYPIXMAPPROC)(Display *, GLXPixmap);
#endif

#ifndef GL_FRAMEBUFFER_BINDING
#define GL_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING_EXT
#endif

G_GNUC_INTERNAL
const char *
gl_get_error_string(GLenum error);

G_GNUC_INTERNAL
void
gl_purge_errors(void);

G_GNUC_INTERNAL
gboolean
gl_check_error(void);

G_GNUC_INTERNAL
gboolean
gl_get_param(GLenum param, guint *pval);

G_GNUC_INTERNAL
gboolean
gl_get_texture_param(GLenum target, GLenum param, guint *pval);

G_GNUC_INTERNAL
void
gl_set_bgcolor(guint32 color);

G_GNUC_INTERNAL
void
gl_resize(guint width, guint height);

typedef struct _GLContextState GLContextState;
struct _GLContextState {
    Display     *display;
    Window       window;
    XVisualInfo *visual;
    GLXContext   context;
    guint        swapped_buffers : 1;
};

G_GNUC_INTERNAL
GLContextState *
gl_create_context(Display *dpy, int screen, GLContextState *parent);

G_GNUC_INTERNAL
void
gl_destroy_context(GLContextState *cs);

G_GNUC_INTERNAL
void
gl_get_current_context(GLContextState *cs);

G_GNUC_INTERNAL
gboolean
gl_set_current_context(GLContextState *new_cs, GLContextState *old_cs);

G_GNUC_INTERNAL
void
gl_swap_buffers(GLContextState *cs);

typedef struct _GLTextureState GLTextureState;
struct _GLTextureState {
    GLenum      target;
    GLuint      old_texture;
    guint       was_enabled     : 1;
    guint       was_bound       : 1;
};

G_GNUC_INTERNAL
gboolean
gl_bind_texture(GLTextureState *ts, GLenum target, GLuint texture);

G_GNUC_INTERNAL
void
gl_unbind_texture(GLTextureState *ts);

G_GNUC_INTERNAL
GLuint
gl_create_texture(GLenum target, GLenum format, guint width, guint height);

typedef struct _GLVTable GLVTable;
struct _GLVTable {
    PFNGLXCREATEPIXMAPPROC              glx_create_pixmap;
    PFNGLXDESTROYPIXMAPPROC             glx_destroy_pixmap;
    PFNGLXBINDTEXIMAGEEXTPROC           glx_bind_tex_image;
    PFNGLXRELEASETEXIMAGEEXTPROC        glx_release_tex_image;
    PFNGLGENFRAMEBUFFERSEXTPROC         gl_gen_framebuffers;
    PFNGLDELETEFRAMEBUFFERSEXTPROC      gl_delete_framebuffers;
    PFNGLBINDFRAMEBUFFEREXTPROC         gl_bind_framebuffer;
    PFNGLGENRENDERBUFFERSEXTPROC        gl_gen_renderbuffers;
    PFNGLDELETERENDERBUFFERSEXTPROC     gl_delete_renderbuffers;
    PFNGLBINDRENDERBUFFEREXTPROC        gl_bind_renderbuffer;
    PFNGLRENDERBUFFERSTORAGEEXTPROC     gl_renderbuffer_storage;
    PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC gl_framebuffer_renderbuffer;
    PFNGLFRAMEBUFFERTEXTURE2DEXTPROC    gl_framebuffer_texture_2d;
    PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC  gl_check_framebuffer_status;
    guint                               has_texture_from_pixmap : 1;
    guint                               has_framebuffer_object  : 1;
};

G_GNUC_INTERNAL
GLVTable *
gl_get_vtable(void);

typedef struct _GLPixmapObject GLPixmapObject;
struct _GLPixmapObject {
    Display        *dpy;
    GLenum          target;
    GLuint          texture;
    GLTextureState  old_texture;
    guint           width;
    guint           height;
    Pixmap          pixmap;
    GLXPixmap       glx_pixmap;
    guint           is_bound    : 1;
};

G_GNUC_INTERNAL
GLPixmapObject *
gl_create_pixmap_object(Display *dpy, guint width, guint height);

G_GNUC_INTERNAL
void
gl_destroy_pixmap_object(GLPixmapObject *pixo);

G_GNUC_INTERNAL
gboolean
gl_bind_pixmap_object(GLPixmapObject *pixo);

G_GNUC_INTERNAL
gboolean
gl_unbind_pixmap_object(GLPixmapObject *pixo);

typedef struct _GLFramebufferObject GLFramebufferObject;
struct _GLFramebufferObject {
    guint           width;
    guint           height;
    GLuint          fbo;
    GLuint          old_fbo;
    guint           is_bound    : 1;
};

G_GNUC_INTERNAL
GLFramebufferObject *
gl_create_framebuffer_object(
    GLenum target,
    GLuint texture,
    guint  width,
    guint  height
);

G_GNUC_INTERNAL
void
gl_destroy_framebuffer_object(GLFramebufferObject *fbo);

G_GNUC_INTERNAL
gboolean
gl_bind_framebuffer_object(GLFramebufferObject *fbo);

G_GNUC_INTERNAL
gboolean
gl_unbind_framebuffer_object(GLFramebufferObject *fbo);

#endif /* GST_VAAPI_UTILS_GLX_H */