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
28 #include "video_out.h"
31 #ifdef CONFIG_GL_WIN32
34 #include "w32_common.h"
40 #include "x11_common.h"
41 // This old-vo wrapper macro would conflict with the struct member
42 #undef update_xinerama_info
45 // workaround for some gl.h headers
48 #define GLAPIENTRY APIENTRY
49 #elif defined(CONFIG_GL_WIN32)
50 #define GLAPIENTRY __stdcall
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.
65 #define GL_TEXTURE_3D 0x806F
67 #ifndef GL_TEXTURE_WRAP_R
68 #define GL_TEXTURE_WRAP_R 0x8072
70 #ifndef GL_CLAMP_TO_EDGE
71 #define GL_CLAMP_TO_EDGE 0x812F
73 #ifndef GL_GENERATE_MIPMAP
74 #define GL_GENERATE_MIPMAP 0x8191
76 #ifndef GL_TEXT_FRAGMENT_SHADER_ATI
77 #define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200
79 #ifndef GL_REGISTER_COMBINERS_NV
80 #define GL_REGISTER_COMBINERS_NV 0x8522
82 #ifndef GL_MAX_GENERAL_COMBINERS_NV
83 #define GL_MAX_GENERAL_COMBINERS_NV 0x854D
85 #ifndef GL_NUM_GENERAL_COMBINERS_NV
86 #define GL_NUM_GENERAL_COMBINERS_NV 0x854E
88 #ifndef GL_CONSTANT_COLOR0_NV
89 #define GL_CONSTANT_COLOR0_NV 0x852A
91 #ifndef GL_CONSTANT_COLOR1_NV
92 #define GL_CONSTANT_COLOR1_NV 0x852B
94 #ifndef GL_COMBINER0_NV
95 #define GL_COMBINER0_NV 0x8550
97 #ifndef GL_COMBINER1_NV
98 #define GL_COMBINER1_NV 0x8551
100 #ifndef GL_VARIABLE_A_NV
101 #define GL_VARIABLE_A_NV 0x8523
103 #ifndef GL_VARIABLE_B_NV
104 #define GL_VARIABLE_B_NV 0x8524
106 #ifndef GL_VARIABLE_C_NV
107 #define GL_VARIABLE_C_NV 0x8525
109 #ifndef GL_VARIABLE_D_NV
110 #define GL_VARIABLE_D_NV 0x8526
112 #ifndef GL_UNSIGNED_INVERT_NV
113 #define GL_UNSIGNED_INVERT_NV 0x8537
115 #ifndef GL_HALF_BIAS_NORMAL_NV
116 #define GL_HALF_BIAS_NORMAL_NV 0x853A
118 #ifndef GL_SIGNED_IDENTITY_NV
119 #define GL_SIGNED_IDENTITY_NV 0x853C
121 #ifndef GL_SCALE_BY_FOUR_NV
122 #define GL_SCALE_BY_FOUR_NV 0x853F
124 #ifndef GL_DISCARD_NV
125 #define GL_DISCARD_NV 0x8530
128 #define GL_SPARE0_NV 0x852E
130 #ifndef GL_FRAGMENT_SHADER_ATI
131 #define GL_FRAGMENT_SHADER_ATI 0x8920
133 #ifndef GL_NUM_FRAGMENT_REGISTERS_ATI
134 #define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
137 #define GL_REG_0_ATI 0x8921
140 #define GL_REG_1_ATI 0x8922
143 #define GL_REG_2_ATI 0x8923
146 #define GL_CON_0_ATI 0x8941
149 #define GL_CON_1_ATI 0x8942
152 #define GL_ADD_ATI 0x8963
155 #define GL_MUL_ATI 0x8964
158 #define GL_MAD_ATI 0x8968
160 #ifndef GL_SWIZZLE_STR_ATI
161 #define GL_SWIZZLE_STR_ATI 0x8976
163 #ifndef GL_4X_BIT_ATI
164 #define GL_4X_BIT_ATI 2
166 #ifndef GL_BIAS_BIT_ATI
167 #define GL_BIAS_BIT_ATI 8
169 #ifndef GL_MAX_TEXTURE_UNITS
170 #define GL_MAX_TEXTURE_UNITS 0x84E2
173 #define GL_TEXTURE0 0x84C0
176 #define GL_TEXTURE1 0x84C1
179 #define GL_TEXTURE2 0x84C2
182 #define GL_TEXTURE3 0x84C3
184 #ifndef GL_TEXTURE_RECTANGLE
185 #define GL_TEXTURE_RECTANGLE 0x84F5
187 #ifndef GL_PIXEL_UNPACK_BUFFER
188 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
190 #ifndef GL_STREAM_DRAW
191 #define GL_STREAM_DRAW 0x88E0
193 #ifndef GL_DYNAMIC_DRAW
194 #define GL_DYNAMIC_DRAW 0x88E8
196 #ifndef GL_WRITE_ONLY
197 #define GL_WRITE_ONLY 0x88B9
200 #define GL_BGR 0x80E0
203 #define GL_BGRA 0x80E1
205 #ifndef GL_UNSIGNED_BYTE_3_3_2
206 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
208 #ifndef GL_UNSIGNED_BYTE_2_3_3_REV
209 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
211 #ifndef GL_UNSIGNED_SHORT_4_4_4_4
212 #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
214 #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
215 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
217 #ifndef GL_UNSIGNED_SHORT_5_6_5
218 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
220 #ifndef GL_UNSIGNED_INT_8_8_8_8
221 #define GL_UNSIGNED_INT_8_8_8_8 0x8035
223 #ifndef GL_UNSIGNED_INT_8_8_8_8_REV
224 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
226 #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
227 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
229 #ifndef GL_UNSIGNED_INT_10_10_10_2
230 #define GL_UNSIGNED_INT_10_10_10_2 0x8036
232 #ifndef GL_UNSIGNED_INT_2_10_10_10_REV
233 #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
235 #ifndef GL_UNSIGNED_SHORT_5_5_5_1
236 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
238 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
239 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
241 #ifndef GL_UNSIGNED_SHORT_8_8
242 #define GL_UNSIGNED_SHORT_8_8 0x85BA
244 #ifndef GL_UNSIGNED_SHORT_8_8_REV
245 #define GL_UNSIGNED_SHORT_8_8_REV 0x85BB
247 #ifndef GL_YCBCR_MESA
248 #define GL_YCBCR_MESA 0x8757
251 #define GL_RGB32F 0x8815
253 #ifndef GL_FLOAT_RGB32_NV
254 #define GL_FLOAT_RGB32_NV 0x8889
256 #ifndef GL_UNPACK_CLIENT_STORAGE_APPLE
257 #define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
259 #ifndef GL_FRAGMENT_PROGRAM
260 #define GL_FRAGMENT_PROGRAM 0x8804
262 #ifndef GL_PROGRAM_FORMAT_ASCII
263 #define GL_PROGRAM_FORMAT_ASCII 0x8875
265 #ifndef GL_PROGRAM_ERROR_POSITION
266 #define GL_PROGRAM_ERROR_POSITION 0x864B
268 #ifndef GL_MAX_TEXTURE_IMAGE_UNITS
269 #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
271 #ifndef GL_PROGRAM_ERROR_STRING
272 #define GL_PROGRAM_ERROR_STRING 0x8874
274 /** \} */ // end of glextdefines group
276 void glAdjustAlignment(int stride
);
278 const char *glValName(GLint value
);
280 int glFindFormat(uint32_t format
, int *bpp
, GLint
*gl_texfmt
,
281 GLenum
*gl_format
, GLenum
*gl_type
);
282 int glFmt2bpp(GLenum format
, GLenum type
);
283 void glCreateClearTex(GLenum target
, GLenum fmt
, GLenum format
, GLenum type
, GLint filter
,
284 int w
, int h
, unsigned char val
);
285 int glCreatePPMTex(GLenum target
, GLenum fmt
, GLint filter
,
286 FILE *f
, int *width
, int *height
, int *maxval
);
287 void glUploadTex(GLenum target
, GLenum format
, GLenum type
,
288 const void *dataptr
, int stride
,
289 int x
, int y
, int w
, int h
, int slice
);
290 void glDrawTex(GLfloat x
, GLfloat y
, GLfloat w
, GLfloat h
,
291 GLfloat tx
, GLfloat ty
, GLfloat tw
, GLfloat th
,
292 int sx
, int sy
, int rect_tex
, int is_yv12
, int flip
);
293 int loadGPUProgram(GLenum target
, char *prog
);
295 /** \addtogroup glconversion
297 //! do not use YUV conversion, this should always stay 0
298 #define YUV_CONVERSION_NONE 0
299 //! use nVidia specific register combiners for YUV conversion
300 #define YUV_CONVERSION_COMBINERS 1
301 //! use a fragment program for YUV conversion
302 #define YUV_CONVERSION_FRAGMENT 2
303 //! use a fragment program for YUV conversion with gamma using POW
304 #define YUV_CONVERSION_FRAGMENT_POW 3
305 //! use a fragment program with additional table lookup for YUV conversion
306 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
307 //! use ATI specific register combiners ("fragment program")
308 #define YUV_CONVERSION_COMBINERS_ATI 5
309 //! use a fragment program with 3D table lookup for YUV conversion
310 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
311 //! use ATI specific "text" register combiners ("fragment program")
312 #define YUV_CONVERSION_TEXT_FRAGMENT 7
313 //! use normal bilinear scaling for textures
314 #define YUV_SCALER_BILIN 0
315 //! use higher quality bicubic scaling for textures
316 #define YUV_SCALER_BICUB 1
317 //! use cubic scaling in X and normal linear scaling in Y direction
318 #define YUV_SCALER_BICUB_X 2
319 //! use cubic scaling without additional lookup texture
320 #define YUV_SCALER_BICUB_NOTEX 3
321 #define YUV_SCALER_UNSHARP 4
322 #define YUV_SCALER_UNSHARP2 5
323 //! mask for conversion type
324 #define YUV_CONVERSION_MASK 0xF
325 //! mask for scaler type
326 #define YUV_SCALER_MASK 0xF
327 //! shift value for luminance scaler type
328 #define YUV_LUM_SCALER_SHIFT 8
329 //! shift value for chrominance scaler type
330 #define YUV_CHROM_SCALER_SHIFT 12
331 //! extract conversion out of type
332 #define YUV_CONVERSION(t) (t & YUV_CONVERSION_MASK)
333 //! extract luminance scaler out of type
334 #define YUV_LUM_SCALER(t) ((t >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
335 //! extract chrominance scaler out of type
336 #define YUV_CHROM_SCALER(t) ((t >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
342 struct mp_csp_params csp_params
;
347 float filter_strength
;
348 } gl_conversion_params_t
;
350 void glSetupYUVConversion(gl_conversion_params_t
*params
);
351 void glEnableYUVConversion(GLenum target
, int type
);
352 void glDisableYUVConversion(GLenum target
, int type
);
354 /** \addtogroup glcontext
356 //! could not set new window, will continue drawing into the old one.
357 #define SET_WINDOW_FAILED -1
358 //! new window is set, could even transfer the OpenGL context.
359 #define SET_WINDOW_OK 0
360 //! new window is set, but the OpenGL context needs to be reinitialized.
361 #define SET_WINDOW_REINIT 1
369 typedef struct MPGLContext
{
378 #ifdef CONFIG_GL_WIN32
385 int (*setGlWindow
)(struct MPGLContext
*);
386 void (*releaseGlContext
)(struct MPGLContext
*);
387 void (*swapGlBuffers
)(struct MPGLContext
*);
388 void (*update_xinerama_info
)(void);
389 void (*border
)(void);
390 int (*check_events
)(void);
391 void (*fullscreen
)(void);
395 int init_mpglcontext(MPGLContext
*ctx
, enum MPGLType type
);
396 void uninit_mpglcontext(MPGLContext
*ctx
);
398 extern void (GLAPIENTRY
*mpglBegin
)(GLenum
);
399 extern void (GLAPIENTRY
*mpglEnd
)(void);
400 extern void (GLAPIENTRY
*mpglViewport
)(GLint
, GLint
, GLsizei
, GLsizei
);
401 extern void (GLAPIENTRY
*mpglMatrixMode
)(GLenum
);
402 extern void (GLAPIENTRY
*mpglLoadIdentity
)(void);
403 extern void (GLAPIENTRY
*mpglTranslated
)(double, double, double);
404 extern void (GLAPIENTRY
*mpglScaled
)(double, double, double);
405 extern void (GLAPIENTRY
*mpglOrtho
)(double, double, double, double, double, double);
406 extern void (GLAPIENTRY
*mpglFrustum
)(double, double, double, double, double, double);
407 extern void (GLAPIENTRY
*mpglPushMatrix
)(void);
408 extern void (GLAPIENTRY
*mpglPopMatrix
)(void);
409 extern void (GLAPIENTRY
*mpglClear
)(GLbitfield
);
410 extern GLuint (GLAPIENTRY
*mpglGenLists
)(GLsizei
);
411 extern void (GLAPIENTRY
*mpglDeleteLists
)(GLuint
, GLsizei
);
412 extern void (GLAPIENTRY
*mpglNewList
)(GLuint
, GLenum
);
413 extern void (GLAPIENTRY
*mpglEndList
)(void);
414 extern void (GLAPIENTRY
*mpglCallList
)(GLuint
);
415 extern void (GLAPIENTRY
*mpglCallLists
)(GLsizei
, GLenum
, const GLvoid
*);
416 extern void (GLAPIENTRY
*mpglGenTextures
)(GLsizei
, GLuint
*);
417 extern void (GLAPIENTRY
*mpglDeleteTextures
)(GLsizei
, const GLuint
*);
418 extern void (GLAPIENTRY
*mpglTexEnvf
)(GLenum
, GLenum
, GLfloat
);
419 extern void (GLAPIENTRY
*mpglTexEnvi
)(GLenum
, GLenum
, GLint
);
420 extern void (GLAPIENTRY
*mpglColor4ub
)(GLubyte
, GLubyte
, GLubyte
, GLubyte
);
421 extern void (GLAPIENTRY
*mpglColor3f
)(GLfloat
, GLfloat
, GLfloat
);
422 extern void (GLAPIENTRY
*mpglColor4f
)(GLfloat
, GLfloat
, GLfloat
, GLfloat
);
423 extern void (GLAPIENTRY
*mpglClearColor
)(GLclampf
, GLclampf
, GLclampf
, GLclampf
);
424 extern void (GLAPIENTRY
*mpglClearDepth
)(GLclampd
);
425 extern void (GLAPIENTRY
*mpglDepthFunc
)(GLenum
);
426 extern void (GLAPIENTRY
*mpglEnable
)(GLenum
);
427 extern void (GLAPIENTRY
*mpglDisable
)(GLenum
);
428 extern const GLubyte
*(GLAPIENTRY
*mpglGetString
)(GLenum
);
429 extern void (GLAPIENTRY
*mpglDrawBuffer
)(GLenum
);
430 extern void (GLAPIENTRY
*mpglDepthMask
)(GLboolean
);
431 extern void (GLAPIENTRY
*mpglBlendFunc
)(GLenum
, GLenum
);
432 extern void (GLAPIENTRY
*mpglFlush
)(void);
433 extern void (GLAPIENTRY
*mpglFinish
)(void);
434 extern void (GLAPIENTRY
*mpglPixelStorei
)(GLenum
, GLint
);
435 extern void (GLAPIENTRY
*mpglTexImage1D
)(GLenum
, GLint
, GLint
, GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
436 extern void (GLAPIENTRY
*mpglTexImage2D
)(GLenum
, GLint
, GLint
, GLsizei
, GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
437 extern void (GLAPIENTRY
*mpglTexSubImage2D
)(GLenum
, GLint
, GLint
, GLint
, GLsizei
, GLsizei
, GLenum
, GLenum
, const GLvoid
*);
438 extern void (GLAPIENTRY
*mpglTexParameteri
)(GLenum
, GLenum
, GLint
);
439 extern void (GLAPIENTRY
*mpglTexParameterf
)(GLenum
, GLenum
, GLfloat
);
440 extern void (GLAPIENTRY
*mpglTexParameterfv
)(GLenum
, GLenum
, const GLfloat
*);
441 extern void (GLAPIENTRY
*mpglTexCoord2f
)(GLfloat
, GLfloat
);
442 extern void (GLAPIENTRY
*mpglVertex2f
)(GLfloat
, GLfloat
);
443 extern void (GLAPIENTRY
*mpglVertex3f
)(GLfloat
, GLfloat
, GLfloat
);
444 extern void (GLAPIENTRY
*mpglNormal3f
)(GLfloat
, GLfloat
, GLfloat
);
445 extern void (GLAPIENTRY
*mpglLightfv
)(GLenum
, GLenum
, const GLfloat
*);
446 extern void (GLAPIENTRY
*mpglColorMaterial
)(GLenum
, GLenum
);
447 extern void (GLAPIENTRY
*mpglShadeModel
)(GLenum
);
448 extern void (GLAPIENTRY
*mpglGetIntegerv
)(GLenum
, GLint
*);
450 extern void (GLAPIENTRY
*mpglGenBuffers
)(GLsizei
, GLuint
*);
451 extern void (GLAPIENTRY
*mpglDeleteBuffers
)(GLsizei
, const GLuint
*);
452 extern void (GLAPIENTRY
*mpglBindBuffer
)(GLenum
, GLuint
);
453 extern GLvoid
* (GLAPIENTRY
*mpglMapBuffer
)(GLenum
, GLenum
);
454 extern GLboolean (GLAPIENTRY
*mpglUnmapBuffer
)(GLenum
);
455 extern void (GLAPIENTRY
*mpglBufferData
)(GLenum
, intptr_t, const GLvoid
*, GLenum
);
456 extern void (GLAPIENTRY
*mpglCombinerParameterfv
)(GLenum
, const GLfloat
*);
457 extern void (GLAPIENTRY
*mpglCombinerParameteri
)(GLenum
, GLint
);
458 extern void (GLAPIENTRY
*mpglCombinerInput
)(GLenum
, GLenum
, GLenum
, GLenum
, GLenum
,
460 extern void (GLAPIENTRY
*mpglCombinerOutput
)(GLenum
, GLenum
, GLenum
, GLenum
, GLenum
,
461 GLenum
, GLenum
, GLboolean
, GLboolean
,
463 extern void (GLAPIENTRY
*mpglBeginFragmentShader
)(void);
464 extern void (GLAPIENTRY
*mpglEndFragmentShader
)(void);
465 extern void (GLAPIENTRY
*mpglSampleMap
)(GLuint
, GLuint
, GLenum
);
466 extern void (GLAPIENTRY
*mpglColorFragmentOp2
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
467 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
);
468 extern void (GLAPIENTRY
*mpglColorFragmentOp3
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
469 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
,
470 GLuint
, GLuint
, GLuint
);
471 extern void (GLAPIENTRY
*mpglSetFragmentShaderConstant
)(GLuint
, const GLfloat
*);
472 extern void (GLAPIENTRY
*mpglActiveTexture
)(GLenum
);
473 extern void (GLAPIENTRY
*mpglBindTexture
)(GLenum
, GLuint
);
474 extern void (GLAPIENTRY
*mpglMultiTexCoord2f
)(GLenum
, GLfloat
, GLfloat
);
475 extern void (GLAPIENTRY
*mpglGenPrograms
)(GLsizei
, GLuint
*);
476 extern void (GLAPIENTRY
*mpglDeletePrograms
)(GLsizei
, const GLuint
*);
477 extern void (GLAPIENTRY
*mpglBindProgram
)(GLenum
, GLuint
);
478 extern void (GLAPIENTRY
*mpglProgramString
)(GLenum
, GLenum
, GLsizei
, const GLvoid
*);
479 extern void (GLAPIENTRY
*mpglProgramEnvParameter4f
)(GLenum
, GLuint
, GLfloat
, GLfloat
,
481 extern int (GLAPIENTRY
*mpglSwapInterval
)(int);
482 extern void (GLAPIENTRY
*mpglTexImage3D
)(GLenum
, GLint
, GLenum
, GLsizei
, GLsizei
,
483 GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
484 extern void* (GLAPIENTRY
*mpglAllocateMemoryMESA
)(void *, int, size_t, float, float, float);
485 extern void (GLAPIENTRY
*mpglFreeMemoryMESA
)(void *, int, void *);
487 #endif /* MPLAYER_GL_COMMON_H */