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"
43 // workaround for some gl.h headers
46 #define GLAPIENTRY APIENTRY
47 #elif defined(CONFIG_GL_WIN32)
48 #define GLAPIENTRY __stdcall
55 * \defgroup glextdefines OpenGL extension defines
57 * conditionally define all extension defines used.
58 * vendor specific extensions should be marked as such
59 * (e.g. _NV), _ARB is not used to ease readability.
63 #define GL_TEXTURE_3D 0x806F
65 #ifndef GL_TEXTURE_WRAP_R
66 #define GL_TEXTURE_WRAP_R 0x8072
68 #ifndef GL_CLAMP_TO_EDGE
69 #define GL_CLAMP_TO_EDGE 0x812F
71 #ifndef GL_GENERATE_MIPMAP
72 #define GL_GENERATE_MIPMAP 0x8191
74 #ifndef GL_REGISTER_COMBINERS_NV
75 #define GL_REGISTER_COMBINERS_NV 0x8522
77 #ifndef GL_MAX_GENERAL_COMBINERS_NV
78 #define GL_MAX_GENERAL_COMBINERS_NV 0x854D
80 #ifndef GL_NUM_GENERAL_COMBINERS_NV
81 #define GL_NUM_GENERAL_COMBINERS_NV 0x854E
83 #ifndef GL_CONSTANT_COLOR0_NV
84 #define GL_CONSTANT_COLOR0_NV 0x852A
86 #ifndef GL_CONSTANT_COLOR1_NV
87 #define GL_CONSTANT_COLOR1_NV 0x852B
89 #ifndef GL_COMBINER0_NV
90 #define GL_COMBINER0_NV 0x8550
92 #ifndef GL_COMBINER1_NV
93 #define GL_COMBINER1_NV 0x8551
95 #ifndef GL_VARIABLE_A_NV
96 #define GL_VARIABLE_A_NV 0x8523
98 #ifndef GL_VARIABLE_B_NV
99 #define GL_VARIABLE_B_NV 0x8524
101 #ifndef GL_VARIABLE_C_NV
102 #define GL_VARIABLE_C_NV 0x8525
104 #ifndef GL_VARIABLE_D_NV
105 #define GL_VARIABLE_D_NV 0x8526
107 #ifndef GL_UNSIGNED_INVERT_NV
108 #define GL_UNSIGNED_INVERT_NV 0x8537
110 #ifndef GL_HALF_BIAS_NORMAL_NV
111 #define GL_HALF_BIAS_NORMAL_NV 0x853A
113 #ifndef GL_SIGNED_IDENTITY_NV
114 #define GL_SIGNED_IDENTITY_NV 0x853C
116 #ifndef GL_SCALE_BY_FOUR_NV
117 #define GL_SCALE_BY_FOUR_NV 0x853F
119 #ifndef GL_DISCARD_NV
120 #define GL_DISCARD_NV 0x8530
123 #define GL_SPARE0_NV 0x852E
125 #ifndef GL_FRAGMENT_SHADER_ATI
126 #define GL_FRAGMENT_SHADER_ATI 0x8920
128 #ifndef GL_NUM_FRAGMENT_REGISTERS_ATI
129 #define GL_NUM_FRAGMENT_REGISTERS_ATI 0x896E
132 #define GL_REG_0_ATI 0x8921
135 #define GL_REG_1_ATI 0x8922
138 #define GL_REG_2_ATI 0x8923
141 #define GL_CON_0_ATI 0x8941
144 #define GL_CON_1_ATI 0x8942
147 #define GL_ADD_ATI 0x8963
150 #define GL_MUL_ATI 0x8964
153 #define GL_MAD_ATI 0x8968
155 #ifndef GL_SWIZZLE_STR_ATI
156 #define GL_SWIZZLE_STR_ATI 0x8976
158 #ifndef GL_4X_BIT_ATI
159 #define GL_4X_BIT_ATI 2
161 #ifndef GL_BIAS_BIT_ATI
162 #define GL_BIAS_BIT_ATI 8
164 #ifndef GL_MAX_TEXTURE_UNITS
165 #define GL_MAX_TEXTURE_UNITS 0x84E2
168 #define GL_TEXTURE0 0x84C0
171 #define GL_TEXTURE1 0x84C1
174 #define GL_TEXTURE2 0x84C2
177 #define GL_TEXTURE3 0x84C3
179 #ifndef GL_TEXTURE_RECTANGLE
180 #define GL_TEXTURE_RECTANGLE 0x84F5
182 #ifndef GL_PIXEL_UNPACK_BUFFER
183 #define GL_PIXEL_UNPACK_BUFFER 0x88EC
185 #ifndef GL_STREAM_DRAW
186 #define GL_STREAM_DRAW 0x88E0
188 #ifndef GL_DYNAMIC_DRAW
189 #define GL_DYNAMIC_DRAW 0x88E8
191 #ifndef GL_WRITE_ONLY
192 #define GL_WRITE_ONLY 0x88B9
195 #define GL_BGR 0x80E0
198 #define GL_BGRA 0x80E1
200 #ifndef GL_UNSIGNED_BYTE_3_3_2
201 #define GL_UNSIGNED_BYTE_3_3_2 0x8032
203 #ifndef GL_UNSIGNED_BYTE_2_3_3_REV
204 #define GL_UNSIGNED_BYTE_2_3_3_REV 0x8362
206 #ifndef GL_UNSIGNED_SHORT_4_4_4_4
207 #define GL_UNSIGNED_SHORT_4_4_4_4 0x8033
209 #ifndef GL_UNSIGNED_SHORT_4_4_4_4_REV
210 #define GL_UNSIGNED_SHORT_4_4_4_4_REV 0x8365
212 #ifndef GL_UNSIGNED_SHORT_5_6_5
213 #define GL_UNSIGNED_SHORT_5_6_5 0x8363
215 #ifndef GL_UNSIGNED_INT_8_8_8_8
216 #define GL_UNSIGNED_INT_8_8_8_8 0x8035
218 #ifndef GL_UNSIGNED_INT_8_8_8_8_REV
219 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367
221 #ifndef GL_UNSIGNED_SHORT_5_6_5_REV
222 #define GL_UNSIGNED_SHORT_5_6_5_REV 0x8364
224 #ifndef GL_UNSIGNED_INT_10_10_10_2
225 #define GL_UNSIGNED_INT_10_10_10_2 0x8036
227 #ifndef GL_UNSIGNED_INT_2_10_10_10_REV
228 #define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368
230 #ifndef GL_UNSIGNED_SHORT_5_5_5_1
231 #define GL_UNSIGNED_SHORT_5_5_5_1 0x8034
233 #ifndef GL_UNSIGNED_SHORT_1_5_5_5_REV
234 #define GL_UNSIGNED_SHORT_1_5_5_5_REV 0x8366
236 #ifndef GL_UNSIGNED_SHORT_8_8
237 #define GL_UNSIGNED_SHORT_8_8 0x85BA
239 #ifndef GL_UNSIGNED_SHORT_8_8_REV
240 #define GL_UNSIGNED_SHORT_8_8_REV 0x85BB
242 #ifndef GL_YCBCR_MESA
243 #define GL_YCBCR_MESA 0x8757
246 #define GL_RGB32F 0x8815
248 #ifndef GL_FLOAT_RGB32_NV
249 #define GL_FLOAT_RGB32_NV 0x8889
251 #ifndef GL_UNPACK_CLIENT_STORAGE_APPLE
252 #define GL_UNPACK_CLIENT_STORAGE_APPLE 0x85B2
254 #ifndef GL_FRAGMENT_PROGRAM
255 #define GL_FRAGMENT_PROGRAM 0x8804
257 #ifndef GL_PROGRAM_FORMAT_ASCII
258 #define GL_PROGRAM_FORMAT_ASCII 0x8875
260 #ifndef GL_PROGRAM_ERROR_POSITION
261 #define GL_PROGRAM_ERROR_POSITION 0x864B
263 #ifndef GL_MAX_TEXTURE_IMAGE_UNITS
264 #define GL_MAX_TEXTURE_IMAGE_UNITS 0x8872
266 #ifndef GL_PROGRAM_ERROR_STRING
267 #define GL_PROGRAM_ERROR_STRING 0x8874
269 /** \} */ // end of glextdefines group
271 void glAdjustAlignment(int stride
);
273 const char *glValName(GLint value
);
275 int glFindFormat(uint32_t format
, int *bpp
, GLint
*gl_texfmt
,
276 GLenum
*gl_format
, GLenum
*gl_type
);
277 int glFmt2bpp(GLenum format
, GLenum type
);
278 void glCreateClearTex(GLenum target
, GLenum fmt
, GLenum format
, GLenum type
, GLint filter
,
279 int w
, int h
, unsigned char val
);
280 int glCreatePPMTex(GLenum target
, GLenum fmt
, GLint filter
,
281 FILE *f
, int *width
, int *height
, int *maxval
);
282 void glUploadTex(GLenum target
, GLenum format
, GLenum type
,
283 const void *dataptr
, int stride
,
284 int x
, int y
, int w
, int h
, int slice
);
285 void glDrawTex(GLfloat x
, GLfloat y
, GLfloat w
, GLfloat h
,
286 GLfloat tx
, GLfloat ty
, GLfloat tw
, GLfloat th
,
287 int sx
, int sy
, int rect_tex
, int is_yv12
, int flip
);
288 int loadGPUProgram(GLenum target
, char *prog
);
290 /** \addtogroup glconversion
292 //! do not use YUV conversion, this should always stay 0
293 #define YUV_CONVERSION_NONE 0
294 //! use nVidia specific register combiners for YUV conversion
295 #define YUV_CONVERSION_COMBINERS 1
296 //! use a fragment program for YUV conversion
297 #define YUV_CONVERSION_FRAGMENT 2
298 //! use a fragment program for YUV conversion with gamma using POW
299 #define YUV_CONVERSION_FRAGMENT_POW 3
300 //! use a fragment program with additional table lookup for YUV conversion
301 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
302 //! use ATI specific register combiners ("fragment program")
303 #define YUV_CONVERSION_COMBINERS_ATI 5
304 //! use a fragment program with 3D table lookup for YUV conversion
305 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
306 //! use normal bilinear scaling for textures
307 #define YUV_SCALER_BILIN 0
308 //! use higher quality bicubic scaling for textures
309 #define YUV_SCALER_BICUB 1
310 //! use cubic scaling in X and normal linear scaling in Y direction
311 #define YUV_SCALER_BICUB_X 2
312 //! use cubic scaling without additional lookup texture
313 #define YUV_SCALER_BICUB_NOTEX 3
314 #define YUV_SCALER_UNSHARP 4
315 #define YUV_SCALER_UNSHARP2 5
316 //! mask for conversion type
317 #define YUV_CONVERSION_MASK 0xF
318 //! mask for scaler type
319 #define YUV_SCALER_MASK 0xF
320 //! shift value for luminance scaler type
321 #define YUV_LUM_SCALER_SHIFT 8
322 //! shift value for chrominance scaler type
323 #define YUV_CHROM_SCALER_SHIFT 12
324 //! extract conversion out of type
325 #define YUV_CONVERSION(t) (t & YUV_CONVERSION_MASK)
326 //! extract luminance scaler out of type
327 #define YUV_LUM_SCALER(t) ((t >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
328 //! extract chrominance scaler out of type
329 #define YUV_CHROM_SCALER(t) ((t >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
335 struct mp_csp_params csp_params
;
340 float filter_strength
;
341 } gl_conversion_params_t
;
343 void glSetupYUVConversion(gl_conversion_params_t
*params
);
344 void glEnableYUVConversion(GLenum target
, int type
);
345 void glDisableYUVConversion(GLenum target
, int type
);
347 /** \addtogroup glcontext
349 //! could not set new window, will continue drawing into the old one.
350 #define SET_WINDOW_FAILED -1
351 //! new window is set, could even transfer the OpenGL context.
352 #define SET_WINDOW_OK 0
353 //! new window is set, but the OpenGL context needs to be reinitialized.
354 #define SET_WINDOW_REINIT 1
362 typedef struct MPGLContext
{
371 #ifdef CONFIG_GL_WIN32
378 int (*setGlWindow
)(struct MPGLContext
*);
379 void (*releaseGlContext
)(struct MPGLContext
*);
380 void (*swapGlBuffers
)(struct MPGLContext
*);
381 void (*update_xinerama_info
)(void);
382 void (*border
)(void);
383 int (*check_events
)(void);
384 void (*fullscreen
)(void);
388 int init_mpglcontext(MPGLContext
*ctx
, enum MPGLType type
);
389 void uninit_mpglcontext(MPGLContext
*ctx
);
391 extern void (GLAPIENTRY
*Begin
)(GLenum
);
392 extern void (GLAPIENTRY
*End
)(void);
393 extern void (GLAPIENTRY
*Viewport
)(GLint
, GLint
, GLsizei
, GLsizei
);
394 extern void (GLAPIENTRY
*MatrixMode
)(GLenum
);
395 extern void (GLAPIENTRY
*LoadIdentity
)(void);
396 extern void (GLAPIENTRY
*Translated
)(double, double, double);
397 extern void (GLAPIENTRY
*Scaled
)(double, double, double);
398 extern void (GLAPIENTRY
*Ortho
)(double, double, double, double, double, double);
399 extern void (GLAPIENTRY
*Frustum
)(double, double, double, double, double, double);
400 extern void (GLAPIENTRY
*PushMatrix
)(void);
401 extern void (GLAPIENTRY
*PopMatrix
)(void);
402 extern void (GLAPIENTRY
*Clear
)(GLbitfield
);
403 extern GLuint (GLAPIENTRY
*GenLists
)(GLsizei
);
404 extern void (GLAPIENTRY
*DeleteLists
)(GLuint
, GLsizei
);
405 extern void (GLAPIENTRY
*NewList
)(GLuint
, GLenum
);
406 extern void (GLAPIENTRY
*EndList
)(void);
407 extern void (GLAPIENTRY
*CallList
)(GLuint
);
408 extern void (GLAPIENTRY
*CallLists
)(GLsizei
, GLenum
, const GLvoid
*);
409 extern void (GLAPIENTRY
*GenTextures
)(GLsizei
, GLuint
*);
410 extern void (GLAPIENTRY
*DeleteTextures
)(GLsizei
, const GLuint
*);
411 extern void (GLAPIENTRY
*TexEnvf
)(GLenum
, GLenum
, GLfloat
);
412 extern void (GLAPIENTRY
*TexEnvi
)(GLenum
, GLenum
, GLint
);
413 extern void (GLAPIENTRY
*Color4ub
)(GLubyte
, GLubyte
, GLubyte
, GLubyte
);
414 extern void (GLAPIENTRY
*Color3f
)(GLfloat
, GLfloat
, GLfloat
);
415 extern void (GLAPIENTRY
*Color4f
)(GLfloat
, GLfloat
, GLfloat
, GLfloat
);
416 extern void (GLAPIENTRY
*ClearColor
)(GLclampf
, GLclampf
, GLclampf
, GLclampf
);
417 extern void (GLAPIENTRY
*ClearDepth
)(GLclampd
);
418 extern void (GLAPIENTRY
*DepthFunc
)(GLenum
);
419 extern void (GLAPIENTRY
*Enable
)(GLenum
);
420 extern void (GLAPIENTRY
*Disable
)(GLenum
);
421 extern const GLubyte
*(GLAPIENTRY
*GetString
)(GLenum
);
422 extern void (GLAPIENTRY
*DrawBuffer
)(GLenum
);
423 extern void (GLAPIENTRY
*DepthMask
)(GLboolean
);
424 extern void (GLAPIENTRY
*BlendFunc
)(GLenum
, GLenum
);
425 extern void (GLAPIENTRY
*Flush
)(void);
426 extern void (GLAPIENTRY
*Finish
)(void);
427 extern void (GLAPIENTRY
*PixelStorei
)(GLenum
, GLint
);
428 extern void (GLAPIENTRY
*TexImage1D
)(GLenum
, GLint
, GLint
, GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
429 extern void (GLAPIENTRY
*TexImage2D
)(GLenum
, GLint
, GLint
, GLsizei
, GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
430 extern void (GLAPIENTRY
*TexSubImage2D
)(GLenum
, GLint
, GLint
, GLint
, GLsizei
, GLsizei
, GLenum
, GLenum
, const GLvoid
*);
431 extern void (GLAPIENTRY
*TexParameteri
)(GLenum
, GLenum
, GLint
);
432 extern void (GLAPIENTRY
*TexParameterf
)(GLenum
, GLenum
, GLfloat
);
433 extern void (GLAPIENTRY
*TexParameterfv
)(GLenum
, GLenum
, const GLfloat
*);
434 extern void (GLAPIENTRY
*TexCoord2f
)(GLfloat
, GLfloat
);
435 extern void (GLAPIENTRY
*Vertex2f
)(GLfloat
, GLfloat
);
436 extern void (GLAPIENTRY
*Vertex3f
)(GLfloat
, GLfloat
, GLfloat
);
437 extern void (GLAPIENTRY
*Normal3f
)(GLfloat
, GLfloat
, GLfloat
);
438 extern void (GLAPIENTRY
*Lightfv
)(GLenum
, GLenum
, const GLfloat
*);
439 extern void (GLAPIENTRY
*ColorMaterial
)(GLenum
, GLenum
);
440 extern void (GLAPIENTRY
*ShadeModel
)(GLenum
);
441 extern void (GLAPIENTRY
*GetIntegerv
)(GLenum
, GLint
*);
443 extern void (GLAPIENTRY
*GenBuffers
)(GLsizei
, GLuint
*);
444 extern void (GLAPIENTRY
*DeleteBuffers
)(GLsizei
, const GLuint
*);
445 extern void (GLAPIENTRY
*BindBuffer
)(GLenum
, GLuint
);
446 extern GLvoid
* (GLAPIENTRY
*MapBuffer
)(GLenum
, GLenum
);
447 extern GLboolean (GLAPIENTRY
*UnmapBuffer
)(GLenum
);
448 extern void (GLAPIENTRY
*BufferData
)(GLenum
, intptr_t, const GLvoid
*, GLenum
);
449 extern void (GLAPIENTRY
*CombinerParameterfv
)(GLenum
, const GLfloat
*);
450 extern void (GLAPIENTRY
*CombinerParameteri
)(GLenum
, GLint
);
451 extern void (GLAPIENTRY
*CombinerInput
)(GLenum
, GLenum
, GLenum
, GLenum
, GLenum
,
453 extern void (GLAPIENTRY
*CombinerOutput
)(GLenum
, GLenum
, GLenum
, GLenum
, GLenum
,
454 GLenum
, GLenum
, GLboolean
, GLboolean
,
456 extern void (GLAPIENTRY
*BeginFragmentShader
)(void);
457 extern void (GLAPIENTRY
*EndFragmentShader
)(void);
458 extern void (GLAPIENTRY
*SampleMap
)(GLuint
, GLuint
, GLenum
);
459 extern void (GLAPIENTRY
*ColorFragmentOp2
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
460 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
);
461 extern void (GLAPIENTRY
*ColorFragmentOp3
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
462 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
,
463 GLuint
, GLuint
, GLuint
);
464 extern void (GLAPIENTRY
*SetFragmentShaderConstant
)(GLuint
, const GLfloat
*);
465 extern void (GLAPIENTRY
*ActiveTexture
)(GLenum
);
466 extern void (GLAPIENTRY
*BindTexture
)(GLenum
, GLuint
);
467 extern void (GLAPIENTRY
*MultiTexCoord2f
)(GLenum
, GLfloat
, GLfloat
);
468 extern void (GLAPIENTRY
*GenPrograms
)(GLsizei
, GLuint
*);
469 extern void (GLAPIENTRY
*DeletePrograms
)(GLsizei
, const GLuint
*);
470 extern void (GLAPIENTRY
*BindProgram
)(GLenum
, GLuint
);
471 extern void (GLAPIENTRY
*ProgramString
)(GLenum
, GLenum
, GLsizei
, const GLvoid
*);
472 extern void (GLAPIENTRY
*ProgramEnvParameter4f
)(GLenum
, GLuint
, GLfloat
, GLfloat
,
474 extern int (GLAPIENTRY
*SwapInterval
)(int);
475 extern void (GLAPIENTRY
*TexImage3D
)(GLenum
, GLint
, GLenum
, GLsizei
, GLsizei
,
476 GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
477 extern void* (GLAPIENTRY
*AllocateMemoryMESA
)(void *, int, size_t, float, float, float);
478 extern void (GLAPIENTRY
*FreeMemoryMESA
)(void *, int, void *);
480 #endif /* MPLAYER_GL_COMMON_H */