Fix vf_tcdump's compilation
[mplayer/kovensky.git] / libvo / gl_common.h
blob0be98cf6ed4b58381376f05617b3121e28afd55e
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.
19 #ifndef MPLAYER_GL_COMMON_H
20 #define MPLAYER_GL_COMMON_H
22 #include <stdio.h>
23 #include <stdint.h>
25 #include "config.h"
26 #include "mp_msg.h"
28 #include "video_out.h"
29 #include "csputils.h"
31 #ifdef CONFIG_GL_WIN32
32 #include <windows.h>
33 #include <GL/gl.h>
34 #include "w32_common.h"
35 #endif
36 #ifdef CONFIG_GL_X11
37 #include <GL/gl.h>
38 #include <X11/Xlib.h>
39 #include <GL/glx.h>
40 #include "x11_common.h"
41 // This old-vo wrapper macro would conflict with the struct member
42 #undef update_xinerama_info
43 #endif
45 // workaround for some gl.h headers
46 #ifndef GLAPIENTRY
47 #ifdef APIENTRY
48 #define GLAPIENTRY APIENTRY
49 #elif defined(CONFIG_GL_WIN32)
50 #define GLAPIENTRY __stdcall
51 #else
52 #define GLAPIENTRY
53 #endif
54 #endif
56 /**
57 * \defgroup glextdefines OpenGL extension defines
59 * conditionally define all extension defines used.
60 * vendor specific extensions should be marked as such
61 * (e.g. _NV), _ARB is not used to ease readability.
62 * \{
64 #ifndef GL_TEXTURE_3D
65 #define GL_TEXTURE_3D 0x806F
66 #endif
67 #ifndef GL_TEXTURE_WRAP_R
68 #define GL_TEXTURE_WRAP_R 0x8072
69 #endif
70 #ifndef GL_CLAMP_TO_EDGE
71 #define GL_CLAMP_TO_EDGE 0x812F
72 #endif
73 #ifndef GL_GENERATE_MIPMAP
74 #define GL_GENERATE_MIPMAP 0x8191
75 #endif
76 #ifndef GL_REGISTER_COMBINERS_NV
77 #define GL_REGISTER_COMBINERS_NV 0x8522
78 #endif
79 #ifndef GL_MAX_GENERAL_COMBINERS_NV
80 #define GL_MAX_GENERAL_COMBINERS_NV 0x854D
81 #endif
82 #ifndef GL_NUM_GENERAL_COMBINERS_NV
83 #define GL_NUM_GENERAL_COMBINERS_NV 0x854E
84 #endif
85 #ifndef GL_CONSTANT_COLOR0_NV
86 #define GL_CONSTANT_COLOR0_NV 0x852A
87 #endif
88 #ifndef GL_CONSTANT_COLOR1_NV
89 #define GL_CONSTANT_COLOR1_NV 0x852B
90 #endif
91 #ifndef GL_COMBINER0_NV
92 #define GL_COMBINER0_NV 0x8550
93 #endif
94 #ifndef GL_COMBINER1_NV
95 #define GL_COMBINER1_NV 0x8551
96 #endif
97 #ifndef GL_VARIABLE_A_NV
98 #define GL_VARIABLE_A_NV 0x8523
99 #endif
100 #ifndef GL_VARIABLE_B_NV
101 #define GL_VARIABLE_B_NV 0x8524
102 #endif
103 #ifndef GL_VARIABLE_C_NV
104 #define GL_VARIABLE_C_NV 0x8525
105 #endif
106 #ifndef GL_VARIABLE_D_NV
107 #define GL_VARIABLE_D_NV 0x8526
108 #endif
109 #ifndef GL_UNSIGNED_INVERT_NV
110 #define GL_UNSIGNED_INVERT_NV 0x8537
111 #endif
112 #ifndef GL_HALF_BIAS_NORMAL_NV
113 #define GL_HALF_BIAS_NORMAL_NV 0x853A
114 #endif
115 #ifndef GL_SIGNED_IDENTITY_NV
116 #define GL_SIGNED_IDENTITY_NV 0x853C
117 #endif
118 #ifndef GL_SCALE_BY_FOUR_NV
119 #define GL_SCALE_BY_FOUR_NV 0x853F
120 #endif
121 #ifndef GL_DISCARD_NV
122 #define GL_DISCARD_NV 0x8530
123 #endif
124 #ifndef GL_SPARE0_NV
125 #define GL_SPARE0_NV 0x852E
126 #endif
127 #ifndef GL_FRAGMENT_SHADER_ATI
128 #define GL_FRAGMENT_SHADER_ATI 0x8920
129 #endif
130 #ifndef GL_NUM_FRAGMENT_REGISTERS_ATI
131 #define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
132 #endif
133 #ifndef GL_REG_0_ATI
134 #define GL_REG_0_ATI 0x8921
135 #endif
136 #ifndef GL_REG_1_ATI
137 #define GL_REG_1_ATI 0x8922
138 #endif
139 #ifndef GL_REG_2_ATI
140 #define GL_REG_2_ATI 0x8923
141 #endif
142 #ifndef GL_CON_0_ATI
143 #define GL_CON_0_ATI 0x8941
144 #endif
145 #ifndef GL_CON_1_ATI
146 #define GL_CON_1_ATI 0x8942
147 #endif
148 #ifndef GL_ADD_ATI
149 #define GL_ADD_ATI 0x8963
150 #endif
151 #ifndef GL_MUL_ATI
152 #define GL_MUL_ATI 0x8964
153 #endif
154 #ifndef GL_MAD_ATI
155 #define GL_MAD_ATI 0x8968
156 #endif
157 #ifndef GL_SWIZZLE_STR_ATI
158 #define GL_SWIZZLE_STR_ATI 0x8976
159 #endif
160 #ifndef GL_4X_BIT_ATI
161 #define GL_4X_BIT_ATI 2
162 #endif
163 #ifndef GL_BIAS_BIT_ATI
164 #define GL_BIAS_BIT_ATI 8
165 #endif
166 #ifndef GL_MAX_TEXTURE_UNITS
167 #define GL_MAX_TEXTURE_UNITS 0x84E2
168 #endif
169 #ifndef GL_TEXTURE0
170 #define GL_TEXTURE0 0x84C0
171 #endif
172 #ifndef GL_TEXTURE1
173 #define GL_TEXTURE1 0x84C1
174 #endif
175 #ifndef GL_TEXTURE2
176 #define GL_TEXTURE2 0x84C2
177 #endif
178 #ifndef GL_TEXTURE3
179 #define GL_TEXTURE3 0x84C3
180 #endif
181 #ifndef GL_TEXTURE_RECTANGLE
182 #define GL_TEXTURE_RECTANGLE 0x84F5
183 #endif
184 #ifndef GL_PIXEL_UNPACK_BUFFER
185 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
186 #endif
187 #ifndef GL_STREAM_DRAW
188 #define GL_STREAM_DRAW 0x88E0
189 #endif
190 #ifndef GL_DYNAMIC_DRAW
191 #define GL_DYNAMIC_DRAW 0x88E8
192 #endif
193 #ifndef GL_WRITE_ONLY
194 #define GL_WRITE_ONLY 0x88B9
195 #endif
196 #ifndef GL_BGR
197 #define GL_BGR 0x80E0
198 #endif
199 #ifndef GL_BGRA
200 #define GL_BGRA 0x80E1
201 #endif
202 #ifndef GL_UNSIGNED_BYTE_3_3_2
203 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
204 #endif
205 #ifndef GL_UNSIGNED_BYTE_2_3_3_REV
206 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
207 #endif
208 #ifndef GL_UNSIGNED_SHORT_4_4_4_4
209 #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
210 #endif
211 #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
212 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
213 #endif
214 #ifndef GL_UNSIGNED_SHORT_5_6_5
215 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
216 #endif
217 #ifndef GL_UNSIGNED_INT_8_8_8_8
218 #define GL_UNSIGNED_INT_8_8_8_8 0x8035
219 #endif
220 #ifndef GL_UNSIGNED_INT_8_8_8_8_REV
221 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
222 #endif
223 #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
224 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
225 #endif
226 #ifndef GL_UNSIGNED_INT_10_10_10_2
227 #define GL_UNSIGNED_INT_10_10_10_2 0x8036
228 #endif
229 #ifndef GL_UNSIGNED_INT_2_10_10_10_REV
230 #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
231 #endif
232 #ifndef GL_UNSIGNED_SHORT_5_5_5_1
233 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
234 #endif
235 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
236 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
237 #endif
238 #ifndef GL_UNSIGNED_SHORT_8_8
239 #define GL_UNSIGNED_SHORT_8_8 0x85BA
240 #endif
241 #ifndef GL_UNSIGNED_SHORT_8_8_REV
242 #define GL_UNSIGNED_SHORT_8_8_REV 0x85BB
243 #endif
244 #ifndef GL_YCBCR_MESA
245 #define GL_YCBCR_MESA 0x8757
246 #endif
247 #ifndef GL_RGB32F
248 #define GL_RGB32F 0x8815
249 #endif
250 #ifndef GL_FLOAT_RGB32_NV
251 #define GL_FLOAT_RGB32_NV 0x8889
252 #endif
253 #ifndef GL_UNPACK_CLIENT_STORAGE_APPLE
254 #define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
255 #endif
256 #ifndef GL_FRAGMENT_PROGRAM
257 #define GL_FRAGMENT_PROGRAM 0x8804
258 #endif
259 #ifndef GL_PROGRAM_FORMAT_ASCII
260 #define GL_PROGRAM_FORMAT_ASCII 0x8875
261 #endif
262 #ifndef GL_PROGRAM_ERROR_POSITION
263 #define GL_PROGRAM_ERROR_POSITION 0x864B
264 #endif
265 #ifndef GL_MAX_TEXTURE_IMAGE_UNITS
266 #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
267 #endif
268 #ifndef GL_PROGRAM_ERROR_STRING
269 #define GL_PROGRAM_ERROR_STRING 0x8874
270 #endif
271 /** \} */ // end of glextdefines group
273 void glAdjustAlignment(int stride);
275 const char *glValName(GLint value);
277 int glFindFormat(uint32_t format, int *bpp, GLint *gl_texfmt,
278 GLenum *gl_format, GLenum *gl_type);
279 int glFmt2bpp(GLenum format, GLenum type);
280 void glCreateClearTex(GLenum target, GLenum fmt, GLenum format, GLenum type, GLint filter,
281 int w, int h, unsigned char val);
282 int glCreatePPMTex(GLenum target, GLenum fmt, GLint filter,
283 FILE *f, int *width, int *height, int *maxval);
284 void glUploadTex(GLenum target, GLenum format, GLenum type,
285 const void *dataptr, int stride,
286 int x, int y, int w, int h, int slice);
287 void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
288 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
289 int sx, int sy, int rect_tex, int is_yv12, int flip);
290 int loadGPUProgram(GLenum target, char *prog);
292 /** \addtogroup glconversion
293 * \{ */
294 //! do not use YUV conversion, this should always stay 0
295 #define YUV_CONVERSION_NONE 0
296 //! use nVidia specific register combiners for YUV conversion
297 #define YUV_CONVERSION_COMBINERS 1
298 //! use a fragment program for YUV conversion
299 #define YUV_CONVERSION_FRAGMENT 2
300 //! use a fragment program for YUV conversion with gamma using POW
301 #define YUV_CONVERSION_FRAGMENT_POW 3
302 //! use a fragment program with additional table lookup for YUV conversion
303 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
304 //! use ATI specific register combiners ("fragment program")
305 #define YUV_CONVERSION_COMBINERS_ATI 5
306 //! use a fragment program with 3D table lookup for YUV conversion
307 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
308 //! use normal bilinear scaling for textures
309 #define YUV_SCALER_BILIN 0
310 //! use higher quality bicubic scaling for textures
311 #define YUV_SCALER_BICUB 1
312 //! use cubic scaling in X and normal linear scaling in Y direction
313 #define YUV_SCALER_BICUB_X 2
314 //! use cubic scaling without additional lookup texture
315 #define YUV_SCALER_BICUB_NOTEX 3
316 #define YUV_SCALER_UNSHARP 4
317 #define YUV_SCALER_UNSHARP2 5
318 //! mask for conversion type
319 #define YUV_CONVERSION_MASK 0xF
320 //! mask for scaler type
321 #define YUV_SCALER_MASK 0xF
322 //! shift value for luminance scaler type
323 #define YUV_LUM_SCALER_SHIFT 8
324 //! shift value for chrominance scaler type
325 #define YUV_CHROM_SCALER_SHIFT 12
326 //! extract conversion out of type
327 #define YUV_CONVERSION(t) (t & YUV_CONVERSION_MASK)
328 //! extract luminance scaler out of type
329 #define YUV_LUM_SCALER(t) ((t >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
330 //! extract chrominance scaler out of type
331 #define YUV_CHROM_SCALER(t) ((t >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
332 /** \} */
334 typedef struct {
335 GLenum target;
336 int type;
337 struct mp_csp_params csp_params;
338 int texw;
339 int texh;
340 int chrom_texw;
341 int chrom_texh;
342 float filter_strength;
343 } gl_conversion_params_t;
345 void glSetupYUVConversion(gl_conversion_params_t *params);
346 void glEnableYUVConversion(GLenum target, int type);
347 void glDisableYUVConversion(GLenum target, int type);
349 /** \addtogroup glcontext
350 * \{ */
351 //! could not set new window, will continue drawing into the old one.
352 #define SET_WINDOW_FAILED -1
353 //! new window is set, could even transfer the OpenGL context.
354 #define SET_WINDOW_OK 0
355 //! new window is set, but the OpenGL context needs to be reinitialized.
356 #define SET_WINDOW_REINIT 1
357 /** \} */
359 enum MPGLType {
360 GLTYPE_W32,
361 GLTYPE_X11,
364 typedef struct MPGLContext {
365 enum MPGLType type;
366 union {
367 int w32;
368 #ifdef CONFIG_GL_X11
369 XVisualInfo *x11;
370 #endif
371 } vinfo;
372 union {
373 #ifdef CONFIG_GL_WIN32
374 HGLRC w32;
375 #endif
376 #ifdef CONFIG_GL_X11
377 GLXContext x11;
378 #endif
379 } context;
380 int (*setGlWindow)(struct MPGLContext *);
381 void (*releaseGlContext)(struct MPGLContext *);
382 void (*swapGlBuffers)(struct MPGLContext *);
383 void (*update_xinerama_info)(void);
384 void (*border)(void);
385 int (*check_events)(void);
386 void (*fullscreen)(void);
387 void (*ontop)(void);
388 } MPGLContext;
390 int init_mpglcontext(MPGLContext *ctx, enum MPGLType type);
391 void uninit_mpglcontext(MPGLContext *ctx);
393 extern void (GLAPIENTRY *Begin)(GLenum);
394 extern void (GLAPIENTRY *End)(void);
395 extern void (GLAPIENTRY *Viewport)(GLint, GLint, GLsizei, GLsizei);
396 extern void (GLAPIENTRY *MatrixMode)(GLenum);
397 extern void (GLAPIENTRY *LoadIdentity)(void);
398 extern void (GLAPIENTRY *Translated)(double, double, double);
399 extern void (GLAPIENTRY *Scaled)(double, double, double);
400 extern void (GLAPIENTRY *Ortho)(double, double, double, double, double, double);
401 extern void (GLAPIENTRY *Frustum)(double, double, double, double, double, double);
402 extern void (GLAPIENTRY *PushMatrix)(void);
403 extern void (GLAPIENTRY *PopMatrix)(void);
404 extern void (GLAPIENTRY *Clear)(GLbitfield);
405 extern GLuint (GLAPIENTRY *GenLists)(GLsizei);
406 extern void (GLAPIENTRY *DeleteLists)(GLuint, GLsizei);
407 extern void (GLAPIENTRY *NewList)(GLuint, GLenum);
408 extern void (GLAPIENTRY *EndList)(void);
409 extern void (GLAPIENTRY *CallList)(GLuint);
410 extern void (GLAPIENTRY *CallLists)(GLsizei, GLenum, const GLvoid *);
411 extern void (GLAPIENTRY *GenTextures)(GLsizei, GLuint *);
412 extern void (GLAPIENTRY *DeleteTextures)(GLsizei, const GLuint *);
413 extern void (GLAPIENTRY *TexEnvf)(GLenum, GLenum, GLfloat);
414 extern void (GLAPIENTRY *TexEnvi)(GLenum, GLenum, GLint);
415 extern void (GLAPIENTRY *Color4ub)(GLubyte, GLubyte, GLubyte, GLubyte);
416 extern void (GLAPIENTRY *Color3f)(GLfloat, GLfloat, GLfloat);
417 extern void (GLAPIENTRY *Color4f)(GLfloat, GLfloat, GLfloat, GLfloat);
418 extern void (GLAPIENTRY *ClearColor)(GLclampf, GLclampf, GLclampf, GLclampf);
419 extern void (GLAPIENTRY *ClearDepth)(GLclampd);
420 extern void (GLAPIENTRY *DepthFunc)(GLenum);
421 extern void (GLAPIENTRY *Enable)(GLenum);
422 extern void (GLAPIENTRY *Disable)(GLenum);
423 extern const GLubyte *(GLAPIENTRY *GetString)(GLenum);
424 extern void (GLAPIENTRY *DrawBuffer)(GLenum);
425 extern void (GLAPIENTRY *DepthMask)(GLboolean);
426 extern void (GLAPIENTRY *BlendFunc)(GLenum, GLenum);
427 extern void (GLAPIENTRY *Flush)(void);
428 extern void (GLAPIENTRY *Finish)(void);
429 extern void (GLAPIENTRY *PixelStorei)(GLenum, GLint);
430 extern void (GLAPIENTRY *TexImage1D)(GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, const GLvoid *);
431 extern void (GLAPIENTRY *TexImage2D)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *);
432 extern void (GLAPIENTRY *TexSubImage2D)(GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *);
433 extern void (GLAPIENTRY *TexParameteri)(GLenum, GLenum, GLint);
434 extern void (GLAPIENTRY *TexParameterf)(GLenum, GLenum, GLfloat);
435 extern void (GLAPIENTRY *TexParameterfv)(GLenum, GLenum, const GLfloat *);
436 extern void (GLAPIENTRY *TexCoord2f)(GLfloat, GLfloat);
437 extern void (GLAPIENTRY *Vertex2f)(GLfloat, GLfloat);
438 extern void (GLAPIENTRY *Vertex3f)(GLfloat, GLfloat, GLfloat);
439 extern void (GLAPIENTRY *Normal3f)(GLfloat, GLfloat, GLfloat);
440 extern void (GLAPIENTRY *Lightfv)(GLenum, GLenum, const GLfloat *);
441 extern void (GLAPIENTRY *ColorMaterial)(GLenum, GLenum);
442 extern void (GLAPIENTRY *ShadeModel)(GLenum);
443 extern void (GLAPIENTRY *GetIntegerv)(GLenum, GLint *);
445 extern void (GLAPIENTRY *GenBuffers)(GLsizei, GLuint *);
446 extern void (GLAPIENTRY *DeleteBuffers)(GLsizei, const GLuint *);
447 extern void (GLAPIENTRY *BindBuffer)(GLenum, GLuint);
448 extern GLvoid* (GLAPIENTRY *MapBuffer)(GLenum, GLenum);
449 extern GLboolean (GLAPIENTRY *UnmapBuffer)(GLenum);
450 extern void (GLAPIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
451 extern void (GLAPIENTRY *CombinerParameterfv)(GLenum, const GLfloat *);
452 extern void (GLAPIENTRY *CombinerParameteri)(GLenum, GLint);
453 extern void (GLAPIENTRY *CombinerInput)(GLenum, GLenum, GLenum, GLenum, GLenum,
454 GLenum);
455 extern void (GLAPIENTRY *CombinerOutput)(GLenum, GLenum, GLenum, GLenum, GLenum,
456 GLenum, GLenum, GLboolean, GLboolean,
457 GLboolean);
458 extern void (GLAPIENTRY *BeginFragmentShader)(void);
459 extern void (GLAPIENTRY *EndFragmentShader)(void);
460 extern void (GLAPIENTRY *SampleMap)(GLuint, GLuint, GLenum);
461 extern void (GLAPIENTRY *ColorFragmentOp2)(GLenum, GLuint, GLuint, GLuint, GLuint,
462 GLuint, GLuint, GLuint, GLuint, GLuint);
463 extern void (GLAPIENTRY *ColorFragmentOp3)(GLenum, GLuint, GLuint, GLuint, GLuint,
464 GLuint, GLuint, GLuint, GLuint, GLuint,
465 GLuint, GLuint, GLuint);
466 extern void (GLAPIENTRY *SetFragmentShaderConstant)(GLuint, const GLfloat *);
467 extern void (GLAPIENTRY *ActiveTexture)(GLenum);
468 extern void (GLAPIENTRY *BindTexture)(GLenum, GLuint);
469 extern void (GLAPIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
470 extern void (GLAPIENTRY *GenPrograms)(GLsizei, GLuint *);
471 extern void (GLAPIENTRY *DeletePrograms)(GLsizei, const GLuint *);
472 extern void (GLAPIENTRY *BindProgram)(GLenum, GLuint);
473 extern void (GLAPIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
474 extern void (GLAPIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
475 GLfloat, GLfloat);
476 extern int (GLAPIENTRY *SwapInterval)(int);
477 extern void (GLAPIENTRY *TexImage3D)(GLenum, GLint, GLenum, GLsizei, GLsizei,
478 GLsizei, GLint, GLenum, GLenum, const GLvoid *);
479 extern void* (GLAPIENTRY *AllocateMemoryMESA)(void *, int, size_t, float, float, float);
480 extern void (GLAPIENTRY *FreeMemoryMESA)(void *, int, void *);
482 #endif /* MPLAYER_GL_COMMON_H */