gl_common: move header hacks into gl_header_fixes.h
[mplayer.git] / libvo / gl_common.h
blob285cb20243ea4e7902c04f3eeb8a936e3e6f94da
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 * You can alternatively redistribute this file and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
24 #ifndef MPLAYER_GL_COMMON_H
25 #define MPLAYER_GL_COMMON_H
27 #include <stdio.h>
28 #include <stdint.h>
30 #include "config.h"
31 #include "mp_msg.h"
33 #include "video_out.h"
34 #include "csputils.h"
36 #ifdef CONFIG_GL_WIN32
37 #include <windows.h>
38 #include "w32_common.h"
39 #endif
40 #ifdef CONFIG_GL_X11
41 #include <X11/Xlib.h>
42 #include <GL/glx.h>
43 #include "x11_common.h"
44 // This old-vo wrapper macro would conflict with the struct member
45 #undef update_xinerama_info
46 #endif
48 #if defined(CONFIG_GL_COCOA) && !defined(CONFIG_GL_X11)
49 #include <OpenGL/gl.h>
50 #else
51 #include <GL/gl.h>
52 #endif
54 #ifdef CONFIG_GL_WIN32
55 #include <GL/glext.h>
56 #endif
58 #include "libvo/gl_header_fixes.h"
60 struct GL;
61 typedef struct GL GL;
63 void glAdjustAlignment(GL *gl, int stride);
65 const char *glValName(GLint value);
67 int glFindFormat(uint32_t format, int have_texture_rg, int *bpp,
68 GLint *gl_texfmt, GLenum *gl_format, GLenum *gl_type);
69 int glFmt2bpp(GLenum format, GLenum type);
70 void glCreateClearTex(GL *gl, GLenum target, GLenum fmt, GLenum format,
71 GLenum type, GLint filter, int w, int h,
72 unsigned char val);
73 int glCreatePPMTex(GL *gl, GLenum target, GLenum fmt, GLint filter,
74 FILE *f, int *width, int *height, int *maxval);
75 void glUploadTex(GL *gl, GLenum target, GLenum format, GLenum type,
76 const void *dataptr, int stride,
77 int x, int y, int w, int h, int slice);
78 void glDownloadTex(GL *gl, GLenum target, GLenum format, GLenum type,
79 void *dataptr, int stride);
80 void glDrawTex(GL *gl, GLfloat x, GLfloat y, GLfloat w, GLfloat h,
81 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
82 int sx, int sy, int rect_tex, int is_yv12, int flip);
83 int loadGPUProgram(GL *gl, GLenum target, char *prog);
84 void glCheckError(GL *gl, const char *info);
86 /** \addtogroup glconversion
87 * \{ */
88 //! do not use YUV conversion, this should always stay 0
89 #define YUV_CONVERSION_NONE 0
90 //! use nVidia specific register combiners for YUV conversion
91 //! implementation has been removed
92 #define YUV_CONVERSION_COMBINERS 1
93 //! use a fragment program for YUV conversion
94 #define YUV_CONVERSION_FRAGMENT 2
95 //! use a fragment program for YUV conversion with gamma using POW
96 #define YUV_CONVERSION_FRAGMENT_POW 3
97 //! use a fragment program with additional table lookup for YUV conversion
98 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
99 //! use ATI specific register combiners ("fragment program")
100 #define YUV_CONVERSION_COMBINERS_ATI 5
101 //! use a fragment program with 3D table lookup for YUV conversion
102 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
103 //! use ATI specific "text" register combiners ("fragment program")
104 #define YUV_CONVERSION_TEXT_FRAGMENT 7
105 //! use normal bilinear scaling for textures
106 #define YUV_SCALER_BILIN 0
107 //! use higher quality bicubic scaling for textures
108 #define YUV_SCALER_BICUB 1
109 //! use cubic scaling in X and normal linear scaling in Y direction
110 #define YUV_SCALER_BICUB_X 2
111 //! use cubic scaling without additional lookup texture
112 #define YUV_SCALER_BICUB_NOTEX 3
113 #define YUV_SCALER_UNSHARP 4
114 #define YUV_SCALER_UNSHARP2 5
115 //! mask for conversion type
116 #define YUV_CONVERSION_MASK 0xF
117 //! mask for scaler type
118 #define YUV_SCALER_MASK 0xF
119 //! shift value for luminance scaler type
120 #define YUV_LUM_SCALER_SHIFT 8
121 //! shift value for chrominance scaler type
122 #define YUV_CHROM_SCALER_SHIFT 12
123 //! extract conversion out of type
124 #define YUV_CONVERSION(t) ((t) & YUV_CONVERSION_MASK)
125 //! extract luminance scaler out of type
126 #define YUV_LUM_SCALER(t) (((t) >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
127 //! extract chrominance scaler out of type
128 #define YUV_CHROM_SCALER(t) (((t) >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
129 #define SET_YUV_CONVERSION(c) ((c) & YUV_CONVERSION_MASK)
130 #define SET_YUV_LUM_SCALER(s) (((s) & YUV_SCALER_MASK) << YUV_LUM_SCALER_SHIFT)
131 #define SET_YUV_CHROM_SCALER(s) (((s) & YUV_SCALER_MASK) << YUV_CHROM_SCALER_SHIFT)
132 //! returns whether the yuv conversion supports large brightness range etc.
133 static inline int glYUVLargeRange(int conv)
135 switch (conv) {
136 case YUV_CONVERSION_NONE:
137 case YUV_CONVERSION_COMBINERS_ATI:
138 case YUV_CONVERSION_FRAGMENT_LOOKUP3D:
139 case YUV_CONVERSION_TEXT_FRAGMENT:
140 return 0;
142 return 1;
144 /** \} */
146 typedef struct {
147 GLenum target;
148 int type;
149 struct mp_csp_params csp_params;
150 int texw;
151 int texh;
152 int chrom_texw;
153 int chrom_texh;
154 float filter_strength;
155 float noise_strength;
156 } gl_conversion_params_t;
158 int glAutodetectYUVConversion(GL *gl);
159 void glSetupYUVConversion(GL *gl, gl_conversion_params_t *params);
160 void glEnableYUVConversion(GL *gl, GLenum target, int type);
161 void glDisableYUVConversion(GL *gl, GLenum target, int type);
163 #define GL_3D_RED_CYAN 1
164 #define GL_3D_GREEN_MAGENTA 2
165 #define GL_3D_QUADBUFFER 3
167 void glEnable3DLeft(GL *gl, int type);
168 void glEnable3DRight(GL *gl, int type);
169 void glDisable3D(GL *gl, int type);
171 /** \addtogroup glcontext
172 * \{ */
173 //! could not set new window, will continue drawing into the old one.
174 #define SET_WINDOW_FAILED -1
175 //! new window is set, could even transfer the OpenGL context.
176 #define SET_WINDOW_OK 0
177 //! new window is set, but the OpenGL context needs to be reinitialized.
178 #define SET_WINDOW_REINIT 1
179 /** \} */
181 enum MPGLType {
182 GLTYPE_AUTO,
183 GLTYPE_COCOA,
184 GLTYPE_W32,
185 GLTYPE_X11,
186 GLTYPE_SDL,
189 enum {
190 MPGLFLAG_DEBUG = 1,
193 #define MPGL_VER(major, minor) (((major) << 16) | (minor))
194 #define MPGL_VER_GET_MAJOR(ver) ((ver) >> 16)
195 #define MPGL_VER_GET_MINOR(ver) ((ver) & ((1 << 16) - 1))
197 typedef struct MPGLContext {
198 GL *gl;
199 enum MPGLType type;
200 struct vo *vo;
201 // Bit size of each component in the created framebuffer. 0 if unknown.
202 int depth_r, depth_g, depth_b;
203 union {
204 int w32;
205 #ifdef CONFIG_GL_X11
206 XVisualInfo *x11;
207 #endif
208 } vinfo;
209 union {
210 #ifdef CONFIG_GL_WIN32
211 HGLRC w32;
212 #endif
213 #ifdef CONFIG_GL_X11
214 GLXContext x11;
215 #endif
216 } context;
217 int (*create_window)(struct MPGLContext *ctx, uint32_t d_width,
218 uint32_t d_height, uint32_t flags);
219 int (*setGlWindow)(struct MPGLContext *);
220 void (*releaseGlContext)(struct MPGLContext *);
221 void (*swapGlBuffers)(struct MPGLContext *);
222 int (*check_events)(struct vo *vo);
223 void (*fullscreen)(struct vo *vo);
224 // only available if GL3 context creation is supported
225 // gl_flags: bitfield of MPGLFLAG_* constants
226 // gl_version: requested OpenGL version number (use MPGL_VER())
227 // return value is one of the SET_WINDOW_* constants
228 int (*create_window_gl3)(struct MPGLContext *ctx, int gl_flags,
229 int gl_version, uint32_t d_width,
230 uint32_t d_height, uint32_t flags);
231 // optional
232 void (*ontop)(struct vo *vo);
233 void (*border)(struct vo *vo);
234 void (*update_xinerama_info)(struct vo *vo);
235 } MPGLContext;
237 int mpgl_find_backend(const char *name);
239 MPGLContext *init_mpglcontext(enum MPGLType type, struct vo *vo);
240 void uninit_mpglcontext(MPGLContext *ctx);
242 // calls create_window_gl3 or create_window+setGlWindow
243 int create_mpglcontext(struct MPGLContext *ctx, int gl_flags, int gl_version,
244 uint32_t d_width, uint32_t d_height, uint32_t flags);
246 // print a multi line string with line numbers (e.g. for shader sources)
247 // mod, lev: module and log level, as in mp_msg()
248 void mp_log_source(int mod, int lev, const char *src);
250 //function pointers loaded from the OpenGL library
251 struct GL {
252 void (GLAPIENTRY *Begin)(GLenum);
253 void (GLAPIENTRY *End)(void);
254 void (GLAPIENTRY *Viewport)(GLint, GLint, GLsizei, GLsizei);
255 void (GLAPIENTRY *MatrixMode)(GLenum);
256 void (GLAPIENTRY *LoadIdentity)(void);
257 void (GLAPIENTRY *Translated)(double, double, double);
258 void (GLAPIENTRY *Scaled)(double, double, double);
259 void (GLAPIENTRY *Ortho)(double, double, double, double, double,double);
260 void (GLAPIENTRY *PushMatrix)(void);
261 void (GLAPIENTRY *PopMatrix)(void);
262 void (GLAPIENTRY *Clear)(GLbitfield);
263 GLuint (GLAPIENTRY *GenLists)(GLsizei);
264 void (GLAPIENTRY *DeleteLists)(GLuint, GLsizei);
265 void (GLAPIENTRY *NewList)(GLuint, GLenum);
266 void (GLAPIENTRY *EndList)(void);
267 void (GLAPIENTRY *CallList)(GLuint);
268 void (GLAPIENTRY *CallLists)(GLsizei, GLenum, const GLvoid *);
269 void (GLAPIENTRY *GenTextures)(GLsizei, GLuint *);
270 void (GLAPIENTRY *DeleteTextures)(GLsizei, const GLuint *);
271 void (GLAPIENTRY *TexEnvi)(GLenum, GLenum, GLint);
272 void (GLAPIENTRY *Color4ub)(GLubyte, GLubyte, GLubyte, GLubyte);
273 void (GLAPIENTRY *Color4f)(GLfloat, GLfloat, GLfloat, GLfloat);
274 void (GLAPIENTRY *ClearColor)(GLclampf, GLclampf, GLclampf, GLclampf);
275 void (GLAPIENTRY *Enable)(GLenum);
276 void (GLAPIENTRY *Disable)(GLenum);
277 const GLubyte *(GLAPIENTRY * GetString)(GLenum);
278 void (GLAPIENTRY *DrawBuffer)(GLenum);
279 void (GLAPIENTRY *DepthMask)(GLboolean);
280 void (GLAPIENTRY *BlendFunc)(GLenum, GLenum);
281 void (GLAPIENTRY *Flush)(void);
282 void (GLAPIENTRY *Finish)(void);
283 void (GLAPIENTRY *PixelStorei)(GLenum, GLint);
284 void (GLAPIENTRY *TexImage1D)(GLenum, GLint, GLint, GLsizei, GLint,
285 GLenum, GLenum, const GLvoid *);
286 void (GLAPIENTRY *TexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei,
287 GLint, GLenum, GLenum, const GLvoid *);
288 void (GLAPIENTRY *TexSubImage2D)(GLenum, GLint, GLint, GLint,
289 GLsizei, GLsizei, GLenum, GLenum,
290 const GLvoid *);
291 void (GLAPIENTRY *GetTexImage)(GLenum, GLint, GLenum, GLenum, GLvoid *);
292 void (GLAPIENTRY *TexParameteri)(GLenum, GLenum, GLint);
293 void (GLAPIENTRY *TexParameterf)(GLenum, GLenum, GLfloat);
294 void (GLAPIENTRY *TexParameterfv)(GLenum, GLenum, const GLfloat *);
295 void (GLAPIENTRY *TexCoord2f)(GLfloat, GLfloat);
296 void (GLAPIENTRY *TexCoord2fv)(const GLfloat *);
297 void (GLAPIENTRY *Vertex2f)(GLfloat, GLfloat);
298 void (GLAPIENTRY *GetIntegerv)(GLenum, GLint *);
299 void (GLAPIENTRY *GetBooleanv)(GLenum, GLboolean *);
300 void (GLAPIENTRY *ColorMask)(GLboolean, GLboolean, GLboolean, GLboolean);
301 void (GLAPIENTRY *ReadPixels)(GLint, GLint, GLsizei, GLsizei, GLenum,
302 GLenum, GLvoid *);
303 void (GLAPIENTRY *ReadBuffer)(GLenum);
304 void (GLAPIENTRY *VertexPointer)(GLint, GLenum, GLsizei, const GLvoid *);
305 void (GLAPIENTRY *ColorPointer)(GLint, GLenum, GLsizei, const GLvoid *);
306 void (GLAPIENTRY *TexCoordPointer)(GLint, GLenum, GLsizei, const GLvoid *);
307 void (GLAPIENTRY *DrawArrays)(GLenum, GLint, GLsizei);
308 void (GLAPIENTRY *EnableClientState)(GLenum);
309 void (GLAPIENTRY *DisableClientState)(GLenum);
310 GLenum (GLAPIENTRY *GetError)(void);
313 // OpenGL extension functions
314 void (GLAPIENTRY *GenBuffers)(GLsizei, GLuint *);
315 void (GLAPIENTRY *DeleteBuffers)(GLsizei, const GLuint *);
316 void (GLAPIENTRY *BindBuffer)(GLenum, GLuint);
317 GLvoid * (GLAPIENTRY * MapBuffer)(GLenum, GLenum);
318 GLboolean (GLAPIENTRY *UnmapBuffer)(GLenum);
319 void (GLAPIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
320 void (GLAPIENTRY *ActiveTexture)(GLenum);
321 void (GLAPIENTRY *BindTexture)(GLenum, GLuint);
322 void (GLAPIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
323 void (GLAPIENTRY *GenPrograms)(GLsizei, GLuint *);
324 void (GLAPIENTRY *DeletePrograms)(GLsizei, const GLuint *);
325 void (GLAPIENTRY *BindProgram)(GLenum, GLuint);
326 void (GLAPIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
327 void (GLAPIENTRY *GetProgramivARB)(GLenum, GLenum, GLint *);
328 void (GLAPIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
329 GLfloat, GLfloat);
330 int (GLAPIENTRY *SwapInterval)(int);
331 void (GLAPIENTRY *TexImage3D)(GLenum, GLint, GLenum, GLsizei, GLsizei,
332 GLsizei, GLint, GLenum, GLenum,
333 const GLvoid *);
335 // ancient ATI extensions
336 void (GLAPIENTRY *BeginFragmentShader)(void);
337 void (GLAPIENTRY *EndFragmentShader)(void);
338 void (GLAPIENTRY *SampleMap)(GLuint, GLuint, GLenum);
339 void (GLAPIENTRY *ColorFragmentOp2)(GLenum, GLuint, GLuint, GLuint, GLuint,
340 GLuint, GLuint, GLuint, GLuint, GLuint);
341 void (GLAPIENTRY *ColorFragmentOp3)(GLenum, GLuint, GLuint, GLuint, GLuint,
342 GLuint, GLuint, GLuint, GLuint, GLuint,
343 GLuint, GLuint, GLuint);
344 void (GLAPIENTRY *SetFragmentShaderConstant)(GLuint, const GLfloat *);
347 // GL 3, possibly in GL 2.x as well in form of extensions
348 void (GLAPIENTRY *GenVertexArrays)(GLsizei, GLuint *);
349 void (GLAPIENTRY *BindVertexArray)(GLuint);
350 GLint (GLAPIENTRY *GetAttribLocation)(GLuint, const GLchar *);
351 void (GLAPIENTRY *EnableVertexAttribArray)(GLuint);
352 void (GLAPIENTRY *DisableVertexAttribArray)(GLuint);
353 void (GLAPIENTRY *VertexAttribPointer)(GLuint, GLint, GLenum, GLboolean,
354 GLsizei, const GLvoid *);
355 void (GLAPIENTRY *DeleteVertexArrays)(GLsizei, const GLuint *);
356 void (GLAPIENTRY *UseProgram)(GLuint);
357 GLint (GLAPIENTRY *GetUniformLocation)(GLuint, const GLchar *);
358 void (GLAPIENTRY *CompileShader)(GLuint);
359 GLuint (GLAPIENTRY *CreateProgram)(void);
360 GLuint (GLAPIENTRY *CreateShader)(GLenum);
361 void (GLAPIENTRY *ShaderSource)(GLuint, GLsizei, const GLchar **,
362 const GLint *);
363 void (GLAPIENTRY *LinkProgram)(GLuint);
364 void (GLAPIENTRY *AttachShader)(GLuint, GLuint);
365 void (GLAPIENTRY *DeleteShader)(GLuint);
366 void (GLAPIENTRY *DeleteProgram)(GLuint);
367 void (GLAPIENTRY *GetShaderInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
368 void (GLAPIENTRY *GetShaderiv)(GLuint, GLenum, GLint *);
369 void (GLAPIENTRY *GetProgramInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
370 void (GLAPIENTRY *GetProgramiv)(GLenum, GLenum, GLint *);
371 const GLubyte* (GLAPIENTRY *GetStringi)(GLenum, GLuint);
372 void (GLAPIENTRY *BindAttribLocation)(GLuint, GLuint, const GLchar *);
373 void (GLAPIENTRY *BindFramebuffer)(GLenum, GLuint);
374 void (GLAPIENTRY *GenFramebuffers)(GLsizei, GLuint *);
375 void (GLAPIENTRY *DeleteFramebuffers)(GLsizei, const GLuint *);
376 GLenum (GLAPIENTRY *CheckFramebufferStatus)(GLenum);
377 void (GLAPIENTRY *FramebufferTexture2D)(GLenum, GLenum, GLenum, GLuint,
378 GLint);
380 void (GLAPIENTRY *Uniform1f)(GLint, GLfloat);
381 void (GLAPIENTRY *Uniform3f)(GLint, GLfloat, GLfloat, GLfloat);
382 void (GLAPIENTRY *Uniform1i)(GLint, GLint);
383 void (GLAPIENTRY *UniformMatrix3fv)(GLint, GLsizei, GLboolean,
384 const GLfloat *);
385 void (GLAPIENTRY *UniformMatrix4x3fv)(GLint, GLsizei, GLboolean,
386 const GLfloat *);
389 #endif /* MPLAYER_GL_COMMON_H */