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 #if defined(CONFIG_GL_COCOA) && !defined(CONFIG_GL_X11)
37 #include <OpenGL/gl.h>
38 #include <OpenGL/gl3.h>
39 #include <OpenGL/glext.h>
45 #include "libvo/gl_header_fixes.h"
50 void glAdjustAlignment(GL
*gl
, int stride
);
52 int glFindFormat(uint32_t format
, int have_texture_rg
, int *bpp
,
53 GLint
*gl_texfmt
, GLenum
*gl_format
, GLenum
*gl_type
);
54 int glFmt2bpp(GLenum format
, GLenum type
);
55 void glCreateClearTex(GL
*gl
, GLenum target
, GLenum fmt
, GLenum format
,
56 GLenum type
, GLint filter
, int w
, int h
,
58 int glCreatePPMTex(GL
*gl
, GLenum target
, GLenum fmt
, GLint filter
,
59 FILE *f
, int *width
, int *height
, int *maxval
);
60 void glUploadTex(GL
*gl
, GLenum target
, GLenum format
, GLenum type
,
61 const void *dataptr
, int stride
,
62 int x
, int y
, int w
, int h
, int slice
);
63 void glDownloadTex(GL
*gl
, GLenum target
, GLenum format
, GLenum type
,
64 void *dataptr
, int stride
);
65 void glDrawTex(GL
*gl
, GLfloat x
, GLfloat y
, GLfloat w
, GLfloat h
,
66 GLfloat tx
, GLfloat ty
, GLfloat tw
, GLfloat th
,
67 int sx
, int sy
, int rect_tex
, int is_yv12
, int flip
);
68 int loadGPUProgram(GL
*gl
, GLenum target
, char *prog
);
69 void glCheckError(GL
*gl
, const char *info
);
71 /** \addtogroup glconversion
73 //! do not use YUV conversion, this should always stay 0
74 #define YUV_CONVERSION_NONE 0
75 //! use nVidia specific register combiners for YUV conversion
76 //! implementation has been removed
77 #define YUV_CONVERSION_COMBINERS 1
78 //! use a fragment program for YUV conversion
79 #define YUV_CONVERSION_FRAGMENT 2
80 //! use a fragment program for YUV conversion with gamma using POW
81 #define YUV_CONVERSION_FRAGMENT_POW 3
82 //! use a fragment program with additional table lookup for YUV conversion
83 #define YUV_CONVERSION_FRAGMENT_LOOKUP 4
84 //! use ATI specific register combiners ("fragment program")
85 #define YUV_CONVERSION_COMBINERS_ATI 5
86 //! use a fragment program with 3D table lookup for YUV conversion
87 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
88 //! use ATI specific "text" register combiners ("fragment program")
89 #define YUV_CONVERSION_TEXT_FRAGMENT 7
90 //! use normal bilinear scaling for textures
91 #define YUV_SCALER_BILIN 0
92 //! use higher quality bicubic scaling for textures
93 #define YUV_SCALER_BICUB 1
94 //! use cubic scaling in X and normal linear scaling in Y direction
95 #define YUV_SCALER_BICUB_X 2
96 //! use cubic scaling without additional lookup texture
97 #define YUV_SCALER_BICUB_NOTEX 3
98 #define YUV_SCALER_UNSHARP 4
99 #define YUV_SCALER_UNSHARP2 5
100 //! mask for conversion type
101 #define YUV_CONVERSION_MASK 0xF
102 //! mask for scaler type
103 #define YUV_SCALER_MASK 0xF
104 //! shift value for luminance scaler type
105 #define YUV_LUM_SCALER_SHIFT 8
106 //! shift value for chrominance scaler type
107 #define YUV_CHROM_SCALER_SHIFT 12
108 //! extract conversion out of type
109 #define YUV_CONVERSION(t) ((t) & YUV_CONVERSION_MASK)
110 //! extract luminance scaler out of type
111 #define YUV_LUM_SCALER(t) (((t) >> YUV_LUM_SCALER_SHIFT) & YUV_SCALER_MASK)
112 //! extract chrominance scaler out of type
113 #define YUV_CHROM_SCALER(t) (((t) >> YUV_CHROM_SCALER_SHIFT) & YUV_SCALER_MASK)
114 #define SET_YUV_CONVERSION(c) ((c) & YUV_CONVERSION_MASK)
115 #define SET_YUV_LUM_SCALER(s) (((s) & YUV_SCALER_MASK) << YUV_LUM_SCALER_SHIFT)
116 #define SET_YUV_CHROM_SCALER(s) (((s) & YUV_SCALER_MASK) << YUV_CHROM_SCALER_SHIFT)
117 //! returns whether the yuv conversion supports large brightness range etc.
118 static inline int glYUVLargeRange(int conv
)
121 case YUV_CONVERSION_NONE
:
122 case YUV_CONVERSION_COMBINERS_ATI
:
123 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
124 case YUV_CONVERSION_TEXT_FRAGMENT
:
134 struct mp_csp_params csp_params
;
139 float filter_strength
;
140 float noise_strength
;
141 } gl_conversion_params_t
;
143 int glAutodetectYUVConversion(GL
*gl
);
144 void glSetupYUVConversion(GL
*gl
, gl_conversion_params_t
*params
);
145 void glEnableYUVConversion(GL
*gl
, GLenum target
, int type
);
146 void glDisableYUVConversion(GL
*gl
, GLenum target
, int type
);
148 #define GL_3D_RED_CYAN 1
149 #define GL_3D_GREEN_MAGENTA 2
150 #define GL_3D_QUADBUFFER 3
152 void glEnable3DLeft(GL
*gl
, int type
);
153 void glEnable3DRight(GL
*gl
, int type
);
154 void glDisable3D(GL
*gl
, int type
);
156 /** \addtogroup glcontext
158 //! could not set new window, will continue drawing into the old one.
159 #define SET_WINDOW_FAILED -1
160 //! new window is set, could even transfer the OpenGL context.
161 #define SET_WINDOW_OK 0
162 //! new window is set, but the OpenGL context needs to be reinitialized.
163 #define SET_WINDOW_REINIT 1
178 #define MPGL_VER(major, minor) (((major) << 16) | (minor))
179 #define MPGL_VER_GET_MAJOR(ver) ((ver) >> 16)
180 #define MPGL_VER_GET_MINOR(ver) ((ver) & ((1 << 16) - 1))
182 typedef struct MPGLContext
{
187 // Bit size of each component in the created framebuffer. 0 if unknown.
188 int depth_r
, depth_g
, depth_b
;
189 int (*create_window
)(struct MPGLContext
*ctx
, uint32_t d_width
,
190 uint32_t d_height
, uint32_t flags
);
191 int (*setGlWindow
)(struct MPGLContext
*);
192 void (*releaseGlContext
)(struct MPGLContext
*);
193 void (*swapGlBuffers
)(struct MPGLContext
*);
194 int (*check_events
)(struct vo
*vo
);
195 void (*fullscreen
)(struct vo
*vo
);
196 void (*vo_uninit
)(struct vo
*vo
);
197 // only available if GL3 context creation is supported
198 // gl_flags: bitfield of MPGLFLAG_* constants
199 // gl_version: requested OpenGL version number (use MPGL_VER())
200 // return value is one of the SET_WINDOW_* constants
201 int (*create_window_gl3
)(struct MPGLContext
*ctx
, int gl_flags
,
202 int gl_version
, uint32_t d_width
,
203 uint32_t d_height
, uint32_t flags
);
205 void (*ontop
)(struct vo
*vo
);
206 void (*border
)(struct vo
*vo
);
207 void (*update_xinerama_info
)(struct vo
*vo
);
210 int mpgl_find_backend(const char *name
);
212 MPGLContext
*init_mpglcontext(enum MPGLType type
, struct vo
*vo
);
213 void uninit_mpglcontext(MPGLContext
*ctx
);
215 // calls create_window_gl3 or create_window+setGlWindow
216 int create_mpglcontext(struct MPGLContext
*ctx
, int gl_flags
, int gl_version
,
217 uint32_t d_width
, uint32_t d_height
, uint32_t flags
);
219 // print a multi line string with line numbers (e.g. for shader sources)
220 // mod, lev: module and log level, as in mp_msg()
221 void mp_log_source(int mod
, int lev
, const char *src
);
223 //function pointers loaded from the OpenGL library
225 void (GLAPIENTRY
*Begin
)(GLenum
);
226 void (GLAPIENTRY
*End
)(void);
227 void (GLAPIENTRY
*Viewport
)(GLint
, GLint
, GLsizei
, GLsizei
);
228 void (GLAPIENTRY
*MatrixMode
)(GLenum
);
229 void (GLAPIENTRY
*LoadIdentity
)(void);
230 void (GLAPIENTRY
*Translated
)(double, double, double);
231 void (GLAPIENTRY
*Scaled
)(double, double, double);
232 void (GLAPIENTRY
*Ortho
)(double, double, double, double, double,double);
233 void (GLAPIENTRY
*PushMatrix
)(void);
234 void (GLAPIENTRY
*PopMatrix
)(void);
235 void (GLAPIENTRY
*Clear
)(GLbitfield
);
236 GLuint (GLAPIENTRY
*GenLists
)(GLsizei
);
237 void (GLAPIENTRY
*DeleteLists
)(GLuint
, GLsizei
);
238 void (GLAPIENTRY
*NewList
)(GLuint
, GLenum
);
239 void (GLAPIENTRY
*EndList
)(void);
240 void (GLAPIENTRY
*CallList
)(GLuint
);
241 void (GLAPIENTRY
*CallLists
)(GLsizei
, GLenum
, const GLvoid
*);
242 void (GLAPIENTRY
*GenTextures
)(GLsizei
, GLuint
*);
243 void (GLAPIENTRY
*DeleteTextures
)(GLsizei
, const GLuint
*);
244 void (GLAPIENTRY
*TexEnvi
)(GLenum
, GLenum
, GLint
);
245 void (GLAPIENTRY
*Color4ub
)(GLubyte
, GLubyte
, GLubyte
, GLubyte
);
246 void (GLAPIENTRY
*Color4f
)(GLfloat
, GLfloat
, GLfloat
, GLfloat
);
247 void (GLAPIENTRY
*ClearColor
)(GLclampf
, GLclampf
, GLclampf
, GLclampf
);
248 void (GLAPIENTRY
*Enable
)(GLenum
);
249 void (GLAPIENTRY
*Disable
)(GLenum
);
250 const GLubyte
*(GLAPIENTRY
* GetString
)(GLenum
);
251 void (GLAPIENTRY
*DrawBuffer
)(GLenum
);
252 void (GLAPIENTRY
*DepthMask
)(GLboolean
);
253 void (GLAPIENTRY
*BlendFunc
)(GLenum
, GLenum
);
254 void (GLAPIENTRY
*Flush
)(void);
255 void (GLAPIENTRY
*Finish
)(void);
256 void (GLAPIENTRY
*PixelStorei
)(GLenum
, GLint
);
257 void (GLAPIENTRY
*TexImage1D
)(GLenum
, GLint
, GLint
, GLsizei
, GLint
,
258 GLenum
, GLenum
, const GLvoid
*);
259 void (GLAPIENTRY
*TexImage2D
)(GLenum
, GLint
, GLint
, GLsizei
, GLsizei
,
260 GLint
, GLenum
, GLenum
, const GLvoid
*);
261 void (GLAPIENTRY
*TexSubImage2D
)(GLenum
, GLint
, GLint
, GLint
,
262 GLsizei
, GLsizei
, GLenum
, GLenum
,
264 void (GLAPIENTRY
*GetTexImage
)(GLenum
, GLint
, GLenum
, GLenum
, GLvoid
*);
265 void (GLAPIENTRY
*TexParameteri
)(GLenum
, GLenum
, GLint
);
266 void (GLAPIENTRY
*TexParameterf
)(GLenum
, GLenum
, GLfloat
);
267 void (GLAPIENTRY
*TexParameterfv
)(GLenum
, GLenum
, const GLfloat
*);
268 void (GLAPIENTRY
*TexCoord2f
)(GLfloat
, GLfloat
);
269 void (GLAPIENTRY
*TexCoord2fv
)(const GLfloat
*);
270 void (GLAPIENTRY
*Vertex2f
)(GLfloat
, GLfloat
);
271 void (GLAPIENTRY
*GetIntegerv
)(GLenum
, GLint
*);
272 void (GLAPIENTRY
*GetBooleanv
)(GLenum
, GLboolean
*);
273 void (GLAPIENTRY
*ColorMask
)(GLboolean
, GLboolean
, GLboolean
, GLboolean
);
274 void (GLAPIENTRY
*ReadPixels
)(GLint
, GLint
, GLsizei
, GLsizei
, GLenum
,
276 void (GLAPIENTRY
*ReadBuffer
)(GLenum
);
277 void (GLAPIENTRY
*VertexPointer
)(GLint
, GLenum
, GLsizei
, const GLvoid
*);
278 void (GLAPIENTRY
*ColorPointer
)(GLint
, GLenum
, GLsizei
, const GLvoid
*);
279 void (GLAPIENTRY
*TexCoordPointer
)(GLint
, GLenum
, GLsizei
, const GLvoid
*);
280 void (GLAPIENTRY
*DrawArrays
)(GLenum
, GLint
, GLsizei
);
281 void (GLAPIENTRY
*EnableClientState
)(GLenum
);
282 void (GLAPIENTRY
*DisableClientState
)(GLenum
);
283 GLenum (GLAPIENTRY
*GetError
)(void);
286 // OpenGL extension functions
287 void (GLAPIENTRY
*GenBuffers
)(GLsizei
, GLuint
*);
288 void (GLAPIENTRY
*DeleteBuffers
)(GLsizei
, const GLuint
*);
289 void (GLAPIENTRY
*BindBuffer
)(GLenum
, GLuint
);
290 GLvoid
* (GLAPIENTRY
* MapBuffer
)(GLenum
, GLenum
);
291 GLboolean (GLAPIENTRY
*UnmapBuffer
)(GLenum
);
292 void (GLAPIENTRY
*BufferData
)(GLenum
, intptr_t, const GLvoid
*, GLenum
);
293 void (GLAPIENTRY
*ActiveTexture
)(GLenum
);
294 void (GLAPIENTRY
*BindTexture
)(GLenum
, GLuint
);
295 void (GLAPIENTRY
*MultiTexCoord2f
)(GLenum
, GLfloat
, GLfloat
);
296 void (GLAPIENTRY
*GenPrograms
)(GLsizei
, GLuint
*);
297 void (GLAPIENTRY
*DeletePrograms
)(GLsizei
, const GLuint
*);
298 void (GLAPIENTRY
*BindProgram
)(GLenum
, GLuint
);
299 void (GLAPIENTRY
*ProgramString
)(GLenum
, GLenum
, GLsizei
, const GLvoid
*);
300 void (GLAPIENTRY
*GetProgramivARB
)(GLenum
, GLenum
, GLint
*);
301 void (GLAPIENTRY
*ProgramEnvParameter4f
)(GLenum
, GLuint
, GLfloat
, GLfloat
,
303 int (GLAPIENTRY
*SwapInterval
)(int);
304 void (GLAPIENTRY
*TexImage3D
)(GLenum
, GLint
, GLenum
, GLsizei
, GLsizei
,
305 GLsizei
, GLint
, GLenum
, GLenum
,
308 // ancient ATI extensions
309 void (GLAPIENTRY
*BeginFragmentShader
)(void);
310 void (GLAPIENTRY
*EndFragmentShader
)(void);
311 void (GLAPIENTRY
*SampleMap
)(GLuint
, GLuint
, GLenum
);
312 void (GLAPIENTRY
*ColorFragmentOp2
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
313 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
);
314 void (GLAPIENTRY
*ColorFragmentOp3
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
315 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
,
316 GLuint
, GLuint
, GLuint
);
317 void (GLAPIENTRY
*SetFragmentShaderConstant
)(GLuint
, const GLfloat
*);
320 // GL 3, possibly in GL 2.x as well in form of extensions
321 void (GLAPIENTRY
*GenVertexArrays
)(GLsizei
, GLuint
*);
322 void (GLAPIENTRY
*BindVertexArray
)(GLuint
);
323 GLint (GLAPIENTRY
*GetAttribLocation
)(GLuint
, const GLchar
*);
324 void (GLAPIENTRY
*EnableVertexAttribArray
)(GLuint
);
325 void (GLAPIENTRY
*DisableVertexAttribArray
)(GLuint
);
326 void (GLAPIENTRY
*VertexAttribPointer
)(GLuint
, GLint
, GLenum
, GLboolean
,
327 GLsizei
, const GLvoid
*);
328 void (GLAPIENTRY
*DeleteVertexArrays
)(GLsizei
, const GLuint
*);
329 void (GLAPIENTRY
*UseProgram
)(GLuint
);
330 GLint (GLAPIENTRY
*GetUniformLocation
)(GLuint
, const GLchar
*);
331 void (GLAPIENTRY
*CompileShader
)(GLuint
);
332 GLuint (GLAPIENTRY
*CreateProgram
)(void);
333 GLuint (GLAPIENTRY
*CreateShader
)(GLenum
);
334 void (GLAPIENTRY
*ShaderSource
)(GLuint
, GLsizei
, const GLchar
**,
336 void (GLAPIENTRY
*LinkProgram
)(GLuint
);
337 void (GLAPIENTRY
*AttachShader
)(GLuint
, GLuint
);
338 void (GLAPIENTRY
*DeleteShader
)(GLuint
);
339 void (GLAPIENTRY
*DeleteProgram
)(GLuint
);
340 void (GLAPIENTRY
*GetShaderInfoLog
)(GLuint
, GLsizei
, GLsizei
*, GLchar
*);
341 void (GLAPIENTRY
*GetShaderiv
)(GLuint
, GLenum
, GLint
*);
342 void (GLAPIENTRY
*GetProgramInfoLog
)(GLuint
, GLsizei
, GLsizei
*, GLchar
*);
343 void (GLAPIENTRY
*GetProgramiv
)(GLenum
, GLenum
, GLint
*);
344 const GLubyte
* (GLAPIENTRY
*GetStringi
)(GLenum
, GLuint
);
345 void (GLAPIENTRY
*BindAttribLocation
)(GLuint
, GLuint
, const GLchar
*);
346 void (GLAPIENTRY
*BindFramebuffer
)(GLenum
, GLuint
);
347 void (GLAPIENTRY
*GenFramebuffers
)(GLsizei
, GLuint
*);
348 void (GLAPIENTRY
*DeleteFramebuffers
)(GLsizei
, const GLuint
*);
349 GLenum (GLAPIENTRY
*CheckFramebufferStatus
)(GLenum
);
350 void (GLAPIENTRY
*FramebufferTexture2D
)(GLenum
, GLenum
, GLenum
, GLuint
,
353 void (GLAPIENTRY
*Uniform1f
)(GLint
, GLfloat
);
354 void (GLAPIENTRY
*Uniform3f
)(GLint
, GLfloat
, GLfloat
, GLfloat
);
355 void (GLAPIENTRY
*Uniform1i
)(GLint
, GLint
);
356 void (GLAPIENTRY
*UniformMatrix3fv
)(GLint
, GLsizei
, GLboolean
,
358 void (GLAPIENTRY
*UniformMatrix4x3fv
)(GLint
, GLsizei
, GLboolean
,
362 #endif /* MPLAYER_GL_COMMON_H */