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