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
33 #include "video_out.h"
36 #ifdef CONFIG_GL_WIN32
38 #include "w32_common.h"
43 #include "x11_common.h"
44 // This old-vo wrapper macro would conflict with the struct member
45 #undef update_xinerama_info
48 #if defined(CONFIG_GL_COCOA) && !defined(CONFIG_GL_X11)
49 #include <OpenGL/gl.h>
54 // workaround for some gl.h headers
57 #define GLAPIENTRY APIENTRY
58 #elif defined(CONFIG_GL_WIN32)
59 #define GLAPIENTRY __stdcall
66 * \defgroup glextdefines OpenGL extension defines
68 * conditionally define all extension defines used.
69 * vendor specific extensions should be marked as such
70 * (e.g. _NV), _ARB is not used to ease readability.
74 #define GL_TEXTURE_3D 0x806F
76 #ifndef GL_TEXTURE_WRAP_R
77 #define GL_TEXTURE_WRAP_R 0x8072
79 #ifndef GL_CLAMP_TO_EDGE
80 #define GL_CLAMP_TO_EDGE 0x812F
82 #ifndef GL_GENERATE_MIPMAP
83 #define GL_GENERATE_MIPMAP 0x8191
85 #ifndef GL_TEXT_FRAGMENT_SHADER_ATI
86 #define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200
88 #ifndef GL_FRAGMENT_SHADER_ATI
89 #define GL_FRAGMENT_SHADER_ATI 0x8920
91 #ifndef GL_NUM_FRAGMENT_REGISTERS_ATI
92 #define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
95 #define GL_REG_0_ATI 0x8921
98 #define GL_REG_1_ATI 0x8922
101 #define GL_REG_2_ATI 0x8923
104 #define GL_CON_0_ATI 0x8941
107 #define GL_CON_1_ATI 0x8942
110 #define GL_CON_2_ATI 0x8943
113 #define GL_CON_3_ATI 0x8944
116 #define GL_ADD_ATI 0x8963
119 #define GL_MUL_ATI 0x8964
122 #define GL_MAD_ATI 0x8968
124 #ifndef GL_SWIZZLE_STR_ATI
125 #define GL_SWIZZLE_STR_ATI 0x8976
127 #ifndef GL_4X_BIT_ATI
128 #define GL_4X_BIT_ATI 2
130 #ifndef GL_8X_BIT_ATI
131 #define GL_8X_BIT_ATI 4
133 #ifndef GL_BIAS_BIT_ATI
134 #define GL_BIAS_BIT_ATI 8
136 #ifndef GL_MAX_TEXTURE_UNITS
137 #define GL_MAX_TEXTURE_UNITS 0x84E2
140 #define GL_TEXTURE0 0x84C0
143 #define GL_TEXTURE1 0x84C1
146 #define GL_TEXTURE2 0x84C2
149 #define GL_TEXTURE3 0x84C3
151 #ifndef GL_TEXTURE_RECTANGLE
152 #define GL_TEXTURE_RECTANGLE 0x84F5
154 #ifndef GL_PIXEL_UNPACK_BUFFER
155 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
157 #ifndef GL_STREAM_DRAW
158 #define GL_STREAM_DRAW 0x88E0
160 #ifndef GL_DYNAMIC_DRAW
161 #define GL_DYNAMIC_DRAW 0x88E8
163 #ifndef GL_WRITE_ONLY
164 #define GL_WRITE_ONLY 0x88B9
167 #define GL_BGR 0x80E0
170 #define GL_BGRA 0x80E1
172 #ifndef GL_UNSIGNED_BYTE_3_3_2
173 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
175 #ifndef GL_UNSIGNED_BYTE_2_3_3_REV
176 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
178 #ifndef GL_UNSIGNED_SHORT_4_4_4_4
179 #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
181 #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
182 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
184 #ifndef GL_UNSIGNED_SHORT_5_6_5
185 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
187 #ifndef GL_UNSIGNED_INT_8_8_8_8
188 #define GL_UNSIGNED_INT_8_8_8_8 0x8035
190 #ifndef GL_UNSIGNED_INT_8_8_8_8_REV
191 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
193 #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
194 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
196 #ifndef GL_UNSIGNED_INT_10_10_10_2
197 #define GL_UNSIGNED_INT_10_10_10_2 0x8036
199 #ifndef GL_UNSIGNED_INT_2_10_10_10_REV
200 #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
202 #ifndef GL_UNSIGNED_SHORT_5_5_5_1
203 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
205 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
206 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
208 #ifndef GL_UNSIGNED_SHORT_8_8
209 #define GL_UNSIGNED_SHORT_8_8 0x85BA
211 #ifndef GL_UNSIGNED_SHORT_8_8_REV
212 #define GL_UNSIGNED_SHORT_8_8_REV 0x85BB
214 #ifndef GL_YCBCR_MESA
215 #define GL_YCBCR_MESA 0x8757
218 #define GL_RGB32F 0x8815
220 #ifndef GL_FLOAT_RGB32_NV
221 #define GL_FLOAT_RGB32_NV 0x8889
223 #ifndef GL_LUMINANCE16
224 #define GL_LUMINANCE16 0x8042
227 #define GL_R16 0x822A
229 #ifndef GL_UNPACK_CLIENT_STORAGE_APPLE
230 #define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
232 #ifndef GL_FRAGMENT_PROGRAM
233 #define GL_FRAGMENT_PROGRAM 0x8804
235 #ifndef GL_PROGRAM_FORMAT_ASCII
236 #define GL_PROGRAM_FORMAT_ASCII 0x8875
238 #ifndef GL_PROGRAM_ERROR_POSITION
239 #define GL_PROGRAM_ERROR_POSITION 0x864B
241 #ifndef GL_MAX_TEXTURE_IMAGE_UNITS
242 #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
244 #ifndef GL_PROGRAM_ERROR_STRING
245 #define GL_PROGRAM_ERROR_STRING 0x8874
247 /** \} */ // end of glextdefines group
250 typedef struct GL GL
;
252 void glAdjustAlignment(GL
*gl
, int stride
);
254 const char *glValName(GLint value
);
256 int glFindFormat(uint32_t format
, int have_texture_rg
, int *bpp
,
257 GLint
*gl_texfmt
, GLenum
*gl_format
, GLenum
*gl_type
);
258 int glFmt2bpp(GLenum format
, GLenum type
);
259 void glCreateClearTex(GL
*gl
, GLenum target
, GLenum fmt
, GLenum format
,
260 GLenum type
, GLint filter
, int w
, int h
,
262 int glCreatePPMTex(GL
*gl
, GLenum target
, GLenum fmt
, GLint filter
,
263 FILE *f
, int *width
, int *height
, int *maxval
);
264 void glUploadTex(GL
*gl
, GLenum target
, GLenum format
, GLenum type
,
265 const void *dataptr
, int stride
,
266 int x
, int y
, int w
, int h
, int slice
);
267 void glDownloadTex(GL
*gl
, GLenum target
, GLenum format
, GLenum type
,
268 void *dataptr
, int stride
);
269 void glDrawTex(GL
*gl
, GLfloat x
, GLfloat y
, GLfloat w
, GLfloat h
,
270 GLfloat tx
, GLfloat ty
, GLfloat tw
, GLfloat th
,
271 int sx
, int sy
, int rect_tex
, int is_yv12
, int flip
);
272 int loadGPUProgram(GL
*gl
, GLenum target
, char *prog
);
274 /** \addtogroup glconversion
276 //! do not use YUV conversion, this should always stay 0
277 #define YUV_CONVERSION_NONE 0
278 //! use nVidia specific register combiners for YUV conversion
279 //! implementation has been removed
280 #define YUV_CONVERSION_COMBINERS 1
281 //! use a fragment program for YUV conversion
282 #define YUV_CONVERSION_FRAGMENT 2
283 //! use a fragment program for YUV conversion with gamma using POW
284 #define YUV_CONVERSION_FRAGMENT_POW 3
285 //! use a fragment program with additional table lookup for YUV conversion
286 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
287 //! use ATI specific register combiners ("fragment program")
288 #define YUV_CONVERSION_COMBINERS_ATI 5
289 //! use a fragment program with 3D table lookup for YUV conversion
290 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
291 //! use ATI specific "text" register combiners ("fragment program")
292 #define YUV_CONVERSION_TEXT_FRAGMENT 7
293 //! use normal bilinear scaling for textures
294 #define YUV_SCALER_BILIN 0
295 //! use higher quality bicubic scaling for textures
296 #define YUV_SCALER_BICUB 1
297 //! use cubic scaling in X and normal linear scaling in Y direction
298 #define YUV_SCALER_BICUB_X 2
299 //! use cubic scaling without additional lookup texture
300 #define YUV_SCALER_BICUB_NOTEX 3
301 #define YUV_SCALER_UNSHARP 4
302 #define YUV_SCALER_UNSHARP2 5
303 //! mask for conversion type
304 #define YUV_CONVERSION_MASK 0xF
305 //! mask for scaler type
306 #define YUV_SCALER_MASK 0xF
307 //! shift value for luminance scaler type
308 #define YUV_LUM_SCALER_SHIFT 8
309 //! shift value for chrominance scaler type
310 #define YUV_CHROM_SCALER_SHIFT 12
311 //! extract conversion out of type
312 #define YUV_CONVERSION(t) ((t) & YUV_CONVERSION_MASK)
313 //! extract luminance scaler out of type
314 #define YUV_LUM_SCALER(t) (((t) >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
315 //! extract chrominance scaler out of type
316 #define YUV_CHROM_SCALER(t) (((t) >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
317 #define SET_YUV_CONVERSION(c) ((c) & YUV_CONVERSION_MASK)
318 #define SET_YUV_LUM_SCALER(s) (((s) & YUV_SCALER_MASK) << YUV_LUM_SCALER_SHIFT)
319 #define SET_YUV_CHROM_SCALER(s) (((s) & YUV_SCALER_MASK) << YUV_CHROM_SCALER_SHIFT)
320 //! returns whether the yuv conversion supports large brightness range etc.
321 static inline int glYUVLargeRange(int conv
)
324 case YUV_CONVERSION_NONE
:
325 case YUV_CONVERSION_COMBINERS_ATI
:
326 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
327 case YUV_CONVERSION_TEXT_FRAGMENT
:
337 struct mp_csp_params csp_params
;
342 float filter_strength
;
343 } gl_conversion_params_t
;
345 int glAutodetectYUVConversion(GL
*gl
);
346 void glSetupYUVConversion(GL
*gl
, gl_conversion_params_t
*params
);
347 void glEnableYUVConversion(GL
*gl
, GLenum target
, int type
);
348 void glDisableYUVConversion(GL
*gl
, GLenum target
, int type
);
350 #define GL_3D_RED_CYAN 1
351 #define GL_3D_GREEN_MAGENTA 2
352 #define GL_3D_QUADBUFFER 3
354 void glEnable3DLeft(GL
*gl
, int type
);
355 void glEnable3DRight(GL
*gl
, int type
);
356 void glDisable3D(GL
*gl
, int type
);
358 /** \addtogroup glcontext
360 //! could not set new window, will continue drawing into the old one.
361 #define SET_WINDOW_FAILED -1
362 //! new window is set, could even transfer the OpenGL context.
363 #define SET_WINDOW_OK 0
364 //! new window is set, but the OpenGL context needs to be reinitialized.
365 #define SET_WINDOW_REINIT 1
376 typedef struct MPGLContext
{
387 #ifdef CONFIG_GL_WIN32
394 int (*create_window
)(struct MPGLContext
*ctx
, uint32_t d_width
,
395 uint32_t d_height
, uint32_t flags
);
396 int (*setGlWindow
)(struct MPGLContext
*);
397 void (*releaseGlContext
)(struct MPGLContext
*);
398 void (*swapGlBuffers
)(struct MPGLContext
*);
399 void (*update_xinerama_info
)(struct vo
*vo
);
400 void (*border
)(struct vo
*vo
);
401 int (*check_events
)(struct vo
*vo
);
402 void (*fullscreen
)(struct vo
*vo
);
403 void (*ontop
)(struct vo
*vo
);
406 MPGLContext
*init_mpglcontext(enum MPGLType type
, struct vo
*vo
);
407 void uninit_mpglcontext(MPGLContext
*ctx
);
409 //function pointers loaded from the OpenGL library
411 void (GLAPIENTRY
*Begin
)(GLenum
);
412 void (GLAPIENTRY
*End
)(void);
413 void (GLAPIENTRY
*Viewport
)(GLint
, GLint
, GLsizei
, GLsizei
);
414 void (GLAPIENTRY
*MatrixMode
)(GLenum
);
415 void (GLAPIENTRY
*LoadIdentity
)(void);
416 void (GLAPIENTRY
*Translated
)(double, double, double);
417 void (GLAPIENTRY
*Scaled
)(double, double, double);
418 void (GLAPIENTRY
*Ortho
)(double, double, double, double, double,double);
419 void (GLAPIENTRY
*Frustum
)(double, double, double, double, double, double);
420 void (GLAPIENTRY
*PushMatrix
)(void);
421 void (GLAPIENTRY
*PopMatrix
)(void);
422 void (GLAPIENTRY
*Clear
)(GLbitfield
);
423 GLuint (GLAPIENTRY
*GenLists
)(GLsizei
);
424 void (GLAPIENTRY
*DeleteLists
)(GLuint
, GLsizei
);
425 void (GLAPIENTRY
*NewList
)(GLuint
, GLenum
);
426 void (GLAPIENTRY
*EndList
)(void);
427 void (GLAPIENTRY
*CallList
)(GLuint
);
428 void (GLAPIENTRY
*CallLists
)(GLsizei
, GLenum
, const GLvoid
*);
429 void (GLAPIENTRY
*GenTextures
)(GLsizei
, GLuint
*);
430 void (GLAPIENTRY
*DeleteTextures
)(GLsizei
, const GLuint
*);
431 void (GLAPIENTRY
*TexEnvf
)(GLenum
, GLenum
, GLfloat
);
432 void (GLAPIENTRY
*TexEnvi
)(GLenum
, GLenum
, GLint
);
433 void (GLAPIENTRY
*Color4ub
)(GLubyte
, GLubyte
, GLubyte
, GLubyte
);
434 void (GLAPIENTRY
*Color3f
)(GLfloat
, GLfloat
, GLfloat
);
435 void (GLAPIENTRY
*Color4f
)(GLfloat
, GLfloat
, GLfloat
, GLfloat
);
436 void (GLAPIENTRY
*ClearColor
)(GLclampf
, GLclampf
, GLclampf
, GLclampf
);
437 void (GLAPIENTRY
*ClearDepth
)(GLclampd
);
438 void (GLAPIENTRY
*DepthFunc
)(GLenum
);
439 void (GLAPIENTRY
*Enable
)(GLenum
);
440 void (GLAPIENTRY
*Disable
)(GLenum
);
441 const GLubyte
*(GLAPIENTRY
* GetString
)(GLenum
);
442 void (GLAPIENTRY
*DrawBuffer
)(GLenum
);
443 void (GLAPIENTRY
*DepthMask
)(GLboolean
);
444 void (GLAPIENTRY
*BlendFunc
)(GLenum
, GLenum
);
445 void (GLAPIENTRY
*Flush
)(void);
446 void (GLAPIENTRY
*Finish
)(void);
447 void (GLAPIENTRY
*PixelStorei
)(GLenum
, GLint
);
448 void (GLAPIENTRY
*TexImage1D
)(GLenum
, GLint
, GLint
, GLsizei
, GLint
,
449 GLenum
, GLenum
, const GLvoid
*);
450 void (GLAPIENTRY
*TexImage2D
)(GLenum
, GLint
, GLint
, GLsizei
, GLsizei
,
451 GLint
, GLenum
, GLenum
, const GLvoid
*);
452 void (GLAPIENTRY
*TexSubImage2D
)(GLenum
, GLint
, GLint
, GLint
,
453 GLsizei
, GLsizei
, GLenum
, GLenum
,
455 void (GLAPIENTRY
*GetTexImage
)(GLenum
, GLint
, GLenum
, GLenum
, GLvoid
*);
456 void (GLAPIENTRY
*TexParameteri
)(GLenum
, GLenum
, GLint
);
457 void (GLAPIENTRY
*TexParameterf
)(GLenum
, GLenum
, GLfloat
);
458 void (GLAPIENTRY
*TexParameterfv
)(GLenum
, GLenum
, const GLfloat
*);
459 void (GLAPIENTRY
*TexCoord2f
)(GLfloat
, GLfloat
);
460 void (GLAPIENTRY
*TexCoord2fv
)(const GLfloat
*);
461 void (GLAPIENTRY
*Vertex2f
)(GLfloat
, GLfloat
);
462 void (GLAPIENTRY
*Vertex3f
)(GLfloat
, GLfloat
, GLfloat
);
463 void (GLAPIENTRY
*Normal3f
)(GLfloat
, GLfloat
, GLfloat
);
464 void (GLAPIENTRY
*Lightfv
)(GLenum
, GLenum
, const GLfloat
*);
465 void (GLAPIENTRY
*ColorMaterial
)(GLenum
, GLenum
);
466 void (GLAPIENTRY
*ShadeModel
)(GLenum
);
467 void (GLAPIENTRY
*GetIntegerv
)(GLenum
, GLint
*);
468 void (GLAPIENTRY
*ColorMask
)(GLboolean
, GLboolean
, GLboolean
, GLboolean
);
469 void (GLAPIENTRY
*ReadPixels
)(GLint
, GLint
, GLsizei
, GLsizei
, GLenum
,
471 void (GLAPIENTRY
*ReadBuffer
)(GLenum
);
473 // OpenGL extension functions
474 void (GLAPIENTRY
*GenBuffers
)(GLsizei
, GLuint
*);
475 void (GLAPIENTRY
*DeleteBuffers
)(GLsizei
, const GLuint
*);
476 void (GLAPIENTRY
*BindBuffer
)(GLenum
, GLuint
);
477 GLvoid
* (GLAPIENTRY
* MapBuffer
)(GLenum
, GLenum
);
478 GLboolean (GLAPIENTRY
*UnmapBuffer
)(GLenum
);
479 void (GLAPIENTRY
*BufferData
)(GLenum
, intptr_t, const GLvoid
*, GLenum
);
480 void (GLAPIENTRY
*BeginFragmentShader
)(void);
481 void (GLAPIENTRY
*EndFragmentShader
)(void);
482 void (GLAPIENTRY
*SampleMap
)(GLuint
, GLuint
, GLenum
);
483 void (GLAPIENTRY
*ColorFragmentOp2
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
484 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
);
485 void (GLAPIENTRY
*ColorFragmentOp3
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
486 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
,
487 GLuint
, GLuint
, GLuint
);
488 void (GLAPIENTRY
*SetFragmentShaderConstant
)(GLuint
, const GLfloat
*);
489 void (GLAPIENTRY
*ActiveTexture
)(GLenum
);
490 void (GLAPIENTRY
*BindTexture
)(GLenum
, GLuint
);
491 void (GLAPIENTRY
*MultiTexCoord2f
)(GLenum
, GLfloat
, GLfloat
);
492 void (GLAPIENTRY
*GenPrograms
)(GLsizei
, GLuint
*);
493 void (GLAPIENTRY
*DeletePrograms
)(GLsizei
, const GLuint
*);
494 void (GLAPIENTRY
*BindProgram
)(GLenum
, GLuint
);
495 void (GLAPIENTRY
*ProgramString
)(GLenum
, GLenum
, GLsizei
, const GLvoid
*);
496 void (GLAPIENTRY
*GetProgramiv
)(GLenum
, GLenum
, GLint
*);
497 void (GLAPIENTRY
*ProgramEnvParameter4f
)(GLenum
, GLuint
, GLfloat
, GLfloat
,
499 int (GLAPIENTRY
*SwapInterval
)(int);
500 void (GLAPIENTRY
*TexImage3D
)(GLenum
, GLint
, GLenum
, GLsizei
, GLsizei
,
501 GLsizei
, GLint
, GLenum
, GLenum
,
505 #endif /* MPLAYER_GL_COMMON_H */