2 * common OpenGL routines
4 * copyleft (C) 2005-2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
5 * Special thanks go to the xine team and Matthias Hopf, whose video_out_opengl.c
6 * gave me lots of good ideas.
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * You can alternatively redistribute this file and/or
25 * modify it under the terms of the GNU Lesser General Public
26 * License as published by the Free Software Foundation; either
27 * version 2.1 of the License, or (at your option) any later version.
32 * \brief OpenGL helper functions used by vo_gl.c and vo_gl2.c
40 #include "old_vo_defines.h"
41 #include "gl_common.h"
45 void (GLAPIENTRY
*mpglBegin
)(GLenum
);
46 void (GLAPIENTRY
*mpglEnd
)(void);
47 void (GLAPIENTRY
*mpglViewport
)(GLint
, GLint
, GLsizei
, GLsizei
);
48 void (GLAPIENTRY
*mpglMatrixMode
)(GLenum
);
49 void (GLAPIENTRY
*mpglLoadIdentity
)(void);
50 void (GLAPIENTRY
*mpglTranslated
)(double, double, double);
51 void (GLAPIENTRY
*mpglScaled
)(double, double, double);
52 void (GLAPIENTRY
*mpglOrtho
)(double, double, double, double, double, double);
53 void (GLAPIENTRY
*mpglFrustum
)(double, double, double, double, double, double);
54 void (GLAPIENTRY
*mpglPushMatrix
)(void);
55 void (GLAPIENTRY
*mpglPopMatrix
)(void);
56 void (GLAPIENTRY
*mpglClear
)(GLbitfield
);
57 GLuint (GLAPIENTRY
*mpglGenLists
)(GLsizei
);
58 void (GLAPIENTRY
*mpglDeleteLists
)(GLuint
, GLsizei
);
59 void (GLAPIENTRY
*mpglNewList
)(GLuint
, GLenum
);
60 void (GLAPIENTRY
*mpglEndList
)(void);
61 void (GLAPIENTRY
*mpglCallList
)(GLuint
);
62 void (GLAPIENTRY
*mpglCallLists
)(GLsizei
, GLenum
, const GLvoid
*);
63 void (GLAPIENTRY
*mpglGenTextures
)(GLsizei
, GLuint
*);
64 void (GLAPIENTRY
*mpglDeleteTextures
)(GLsizei
, const GLuint
*);
65 void (GLAPIENTRY
*mpglTexEnvf
)(GLenum
, GLenum
, GLfloat
);
66 void (GLAPIENTRY
*mpglTexEnvi
)(GLenum
, GLenum
, GLint
);
67 void (GLAPIENTRY
*mpglColor4ub
)(GLubyte
, GLubyte
, GLubyte
, GLubyte
);
68 void (GLAPIENTRY
*mpglColor3f
)(GLfloat
, GLfloat
, GLfloat
);
69 void (GLAPIENTRY
*mpglColor4f
)(GLfloat
, GLfloat
, GLfloat
, GLfloat
);
70 void (GLAPIENTRY
*mpglClearColor
)(GLclampf
, GLclampf
, GLclampf
, GLclampf
);
71 void (GLAPIENTRY
*mpglClearDepth
)(GLclampd
);
72 void (GLAPIENTRY
*mpglDepthFunc
)(GLenum
);
73 void (GLAPIENTRY
*mpglEnable
)(GLenum
);
74 void (GLAPIENTRY
*mpglDisable
)(GLenum
);
75 const GLubyte
*(GLAPIENTRY
*mpglGetString
)(GLenum
);
76 void (GLAPIENTRY
*mpglDrawBuffer
)(GLenum
);
77 void (GLAPIENTRY
*mpglDepthMask
)(GLboolean
);
78 void (GLAPIENTRY
*mpglBlendFunc
)(GLenum
, GLenum
);
79 void (GLAPIENTRY
*mpglFlush
)(void);
80 void (GLAPIENTRY
*mpglFinish
)(void);
81 void (GLAPIENTRY
*mpglPixelStorei
)(GLenum
, GLint
);
82 void (GLAPIENTRY
*mpglTexImage1D
)(GLenum
, GLint
, GLint
, GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
83 void (GLAPIENTRY
*mpglTexImage2D
)(GLenum
, GLint
, GLint
, GLsizei
, GLsizei
, GLint
, GLenum
, GLenum
, const GLvoid
*);
84 void (GLAPIENTRY
*mpglTexSubImage2D
)(GLenum
, GLint
, GLint
, GLint
, GLsizei
, GLsizei
, GLenum
, GLenum
, const GLvoid
*);
85 void (GLAPIENTRY
*mpglTexParameteri
)(GLenum
, GLenum
, GLint
);
86 void (GLAPIENTRY
*mpglTexParameterf
)(GLenum
, GLenum
, GLfloat
);
87 void (GLAPIENTRY
*mpglTexParameterfv
)(GLenum
, GLenum
, const GLfloat
*);
88 void (GLAPIENTRY
*mpglTexCoord2f
)(GLfloat
, GLfloat
);
89 void (GLAPIENTRY
*mpglVertex2f
)(GLfloat
, GLfloat
);
90 void (GLAPIENTRY
*mpglVertex3f
)(GLfloat
, GLfloat
, GLfloat
);
91 void (GLAPIENTRY
*mpglNormal3f
)(GLfloat
, GLfloat
, GLfloat
);
92 void (GLAPIENTRY
*mpglLightfv
)(GLenum
, GLenum
, const GLfloat
*);
93 void (GLAPIENTRY
*mpglColorMaterial
)(GLenum
, GLenum
);
94 void (GLAPIENTRY
*mpglShadeModel
)(GLenum
);
95 void (GLAPIENTRY
*mpglGetIntegerv
)(GLenum
, GLint
*);
96 void (GLAPIENTRY
*mpglColorMask
)(GLboolean
, GLboolean
, GLboolean
, GLboolean
);
99 * \defgroup glextfunctions OpenGL extension functions
101 * the pointers to these functions are acquired when the OpenGL
105 void (GLAPIENTRY
*mpglGenBuffers
)(GLsizei
, GLuint
*);
106 void (GLAPIENTRY
*mpglDeleteBuffers
)(GLsizei
, const GLuint
*);
107 void (GLAPIENTRY
*mpglBindBuffer
)(GLenum
, GLuint
);
108 GLvoid
* (GLAPIENTRY
*mpglMapBuffer
)(GLenum
, GLenum
);
109 GLboolean (GLAPIENTRY
*mpglUnmapBuffer
)(GLenum
);
110 void (GLAPIENTRY
*mpglBufferData
)(GLenum
, intptr_t, const GLvoid
*, GLenum
);
111 void (GLAPIENTRY
*mpglCombinerParameterfv
)(GLenum
, const GLfloat
*);
112 void (GLAPIENTRY
*mpglCombinerParameteri
)(GLenum
, GLint
);
113 void (GLAPIENTRY
*mpglCombinerInput
)(GLenum
, GLenum
, GLenum
, GLenum
, GLenum
,
115 void (GLAPIENTRY
*mpglCombinerOutput
)(GLenum
, GLenum
, GLenum
, GLenum
, GLenum
,
116 GLenum
, GLenum
, GLboolean
, GLboolean
,
118 void (GLAPIENTRY
*mpglBeginFragmentShader
)(void);
119 void (GLAPIENTRY
*mpglEndFragmentShader
)(void);
120 void (GLAPIENTRY
*mpglSampleMap
)(GLuint
, GLuint
, GLenum
);
121 void (GLAPIENTRY
*mpglColorFragmentOp2
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
122 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
);
123 void (GLAPIENTRY
*mpglColorFragmentOp3
)(GLenum
, GLuint
, GLuint
, GLuint
, GLuint
,
124 GLuint
, GLuint
, GLuint
, GLuint
, GLuint
,
125 GLuint
, GLuint
, GLuint
);
126 void (GLAPIENTRY
*mpglSetFragmentShaderConstant
)(GLuint
, const GLfloat
*);
127 void (GLAPIENTRY
*mpglActiveTexture
)(GLenum
);
128 void (GLAPIENTRY
*mpglBindTexture
)(GLenum
, GLuint
);
129 void (GLAPIENTRY
*mpglMultiTexCoord2f
)(GLenum
, GLfloat
, GLfloat
);
130 void (GLAPIENTRY
*mpglGenPrograms
)(GLsizei
, GLuint
*);
131 void (GLAPIENTRY
*mpglDeletePrograms
)(GLsizei
, const GLuint
*);
132 void (GLAPIENTRY
*mpglBindProgram
)(GLenum
, GLuint
);
133 void (GLAPIENTRY
*mpglProgramString
)(GLenum
, GLenum
, GLsizei
, const GLvoid
*);
134 void (GLAPIENTRY
*mpglGetProgramiv
)(GLenum
, GLenum
, GLint
*);
135 void (GLAPIENTRY
*mpglProgramEnvParameter4f
)(GLenum
, GLuint
, GLfloat
, GLfloat
,
137 int (GLAPIENTRY
*mpglSwapInterval
)(int);
138 void (GLAPIENTRY
*mpglTexImage3D
)(GLenum
, GLint
, GLenum
, GLsizei
, GLsizei
, GLsizei
,
139 GLint
, GLenum
, GLenum
, const GLvoid
*);
140 void* (GLAPIENTRY
*mpglAllocateMemoryMESA
)(void *, int, size_t, float, float, float);
141 void (GLAPIENTRY
*mpglFreeMemoryMESA
)(void *, int, void *);
142 /** \} */ // end of glextfunctions group
144 //! \defgroup glgeneral OpenGL general helper functions
146 //! \defgroup glcontext OpenGL context management helper functions
148 //! \defgroup gltexture OpenGL texture handling helper functions
150 //! \defgroup glconversion OpenGL conversion helper functions
152 static GLint hqtexfmt
;
155 * \brief adjusts the GL_UNPACK_ALIGNMENT to fit the stride.
156 * \param stride number of bytes per line for which alignment should fit.
159 void glAdjustAlignment(int stride
) {
163 else if (stride
% 4 == 0)
165 else if (stride
% 2 == 0)
169 mpglPixelStorei(GL_UNPACK_ALIGNMENT
, gl_alignment
);
172 struct gl_name_map_struct
{
178 #define MAP(a) {a, #a}
179 //! mapping table for the glValName function
180 static const struct gl_name_map_struct gl_name_map
[] = {
182 MAP(GL_R3_G3_B2
), MAP(GL_RGB4
), MAP(GL_RGB5
), MAP(GL_RGB8
),
183 MAP(GL_RGB10
), MAP(GL_RGB12
), MAP(GL_RGB16
), MAP(GL_RGBA2
),
184 MAP(GL_RGBA4
), MAP(GL_RGB5_A1
), MAP(GL_RGBA8
), MAP(GL_RGB10_A2
),
185 MAP(GL_RGBA12
), MAP(GL_RGBA16
), MAP(GL_LUMINANCE8
),
188 MAP(GL_RGB
), MAP(GL_RGBA
), MAP(GL_RED
), MAP(GL_GREEN
), MAP(GL_BLUE
),
189 MAP(GL_ALPHA
), MAP(GL_LUMINANCE
), MAP(GL_LUMINANCE_ALPHA
),
192 MAP(GL_BGR
), MAP(GL_BGRA
),
195 MAP(GL_BYTE
), MAP(GL_UNSIGNED_BYTE
), MAP(GL_SHORT
), MAP(GL_UNSIGNED_SHORT
),
196 MAP(GL_INT
), MAP(GL_UNSIGNED_INT
), MAP(GL_FLOAT
), MAP(GL_DOUBLE
),
197 MAP(GL_2_BYTES
), MAP(GL_3_BYTES
), MAP(GL_4_BYTES
),
199 MAP(GL_UNSIGNED_BYTE_3_3_2
), MAP(GL_UNSIGNED_BYTE_2_3_3_REV
),
200 MAP(GL_UNSIGNED_SHORT_5_6_5
), MAP(GL_UNSIGNED_SHORT_5_6_5_REV
),
201 MAP(GL_UNSIGNED_SHORT_4_4_4_4
), MAP(GL_UNSIGNED_SHORT_4_4_4_4_REV
),
202 MAP(GL_UNSIGNED_SHORT_5_5_5_1
), MAP(GL_UNSIGNED_SHORT_1_5_5_5_REV
),
203 MAP(GL_UNSIGNED_INT_8_8_8_8
), MAP(GL_UNSIGNED_INT_8_8_8_8_REV
),
204 MAP(GL_UNSIGNED_INT_10_10_10_2
), MAP(GL_UNSIGNED_INT_2_10_10_10_REV
),
210 * \brief return the name of an OpenGL constant
211 * \param value the constant
212 * \return name of the constant or "Unknown format!"
215 const char *glValName(GLint value
)
219 while (gl_name_map
[i
].name
) {
220 if (gl_name_map
[i
].value
== value
)
221 return gl_name_map
[i
].name
;
224 return "Unknown format!";
227 //! always return this format as internal texture format in glFindFormat
228 #define TEXTUREFORMAT_ALWAYS GL_RGB8
229 #undef TEXTUREFORMAT_ALWAYS
232 * \brief find the OpenGL settings coresponding to format.
234 * All parameters may be NULL.
235 * \param fmt MPlayer format to analyze.
236 * \param bpp [OUT] bits per pixel of that format.
237 * \param gl_texfmt [OUT] internal texture format that fits the
238 * image format, not necessarily the best for performance.
239 * \param gl_format [OUT] OpenGL format for this image format.
240 * \param gl_type [OUT] OpenGL type for this image format.
241 * \return 1 if format is supported by OpenGL, 0 if not.
244 int glFindFormat(uint32_t fmt
, int *bpp
, GLint
*gl_texfmt
,
245 GLenum
*gl_format
, GLenum
*gl_type
)
251 if (!bpp
) bpp
= &dummy1
;
252 if (!gl_texfmt
) gl_texfmt
= &dummy3
;
253 if (!gl_format
) gl_format
= &dummy2
;
254 if (!gl_type
) gl_type
= &dummy2
;
256 if (mp_get_chroma_shift(fmt
, NULL
, NULL
)) {
257 // reduce the possible cases a bit
258 if (IMGFMT_IS_YUVP16_LE(fmt
))
259 fmt
= IMGFMT_420P16_LE
;
260 else if (IMGFMT_IS_YUVP16_BE(fmt
))
261 fmt
= IMGFMT_420P16_BE
;
266 *bpp
= IMGFMT_IS_BGR(fmt
)?IMGFMT_BGR_DEPTH(fmt
):IMGFMT_RGB_DEPTH(fmt
);
271 *gl_type
= GL_UNSIGNED_SHORT
;
275 *gl_type
= GL_UNSIGNED_BYTE
;
279 *gl_format
= GL_RGBA
;
280 *gl_type
= GL_UNSIGNED_BYTE
;
283 supported
= 0; // no native YUV support
286 *gl_format
= GL_LUMINANCE
;
287 *gl_type
= GL_UNSIGNED_SHORT
;
290 supported
= 0; // no native YV12 support
295 *gl_format
= GL_LUMINANCE
;
296 *gl_type
= GL_UNSIGNED_BYTE
;
300 *gl_texfmt
= GL_YCBCR_MESA
;
302 *gl_format
= GL_YCBCR_MESA
;
303 *gl_type
= fmt
== IMGFMT_UYVY
? GL_UNSIGNED_SHORT_8_8
: GL_UNSIGNED_SHORT_8_8_REV
;
306 // we do not support palettized formats, although the format the
307 // swscale produces works
310 gl_type
= GL_UNSIGNED_BYTE_2_3_3_REV
;
314 *gl_format
= GL_RGBA
;
315 *gl_type
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
319 *gl_type
= GL_UNSIGNED_SHORT_5_6_5_REV
;
323 // special case as red and blue have a differen number of bits.
324 // GL_BGR and GL_UNSIGNED_BYTE_3_3_2 isn't supported at least
325 // by nVidia drivers, and in addition would give more bits to
326 // blue than to red, which isn't wanted
328 gl_type
= GL_UNSIGNED_BYTE_3_3_2
;
332 *gl_format
= GL_BGRA
;
333 *gl_type
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
337 *gl_type
= GL_UNSIGNED_SHORT_5_6_5
;
341 *gl_type
= GL_UNSIGNED_BYTE
;
345 *gl_format
= GL_BGRA
;
346 *gl_type
= GL_UNSIGNED_BYTE
;
350 *gl_format
= GL_RGBA
;
351 *gl_type
= GL_UNSIGNED_BYTE
;
354 #ifdef TEXTUREFORMAT_ALWAYS
355 *gl_texfmt
= TEXTUREFORMAT_ALWAYS
;
364 * \brief find address of a linked function
365 * \param s name of function to find
366 * \return address of function or NULL if not found
368 static void *getdladdr(const char *s
) {
371 void *handle
= dlopen(NULL
, RTLD_LAZY
);
374 ret
= dlsym(handle
, s
);
383 const char *funcnames
[7];
387 #define DEF_FUNC_DESC(name) {&mpgl##name, NULL, {"gl"#name, NULL}, gl ##name}
388 static const extfunc_desc_t extfuncs
[] = {
389 // these aren't extension functions but we query them anyway to allow
390 // different "backends" with one binary
391 DEF_FUNC_DESC(Begin
),
393 DEF_FUNC_DESC(Viewport
),
394 DEF_FUNC_DESC(MatrixMode
),
395 DEF_FUNC_DESC(LoadIdentity
),
396 DEF_FUNC_DESC(Translated
),
397 DEF_FUNC_DESC(Scaled
),
398 DEF_FUNC_DESC(Ortho
),
399 DEF_FUNC_DESC(Frustum
),
400 DEF_FUNC_DESC(PushMatrix
),
401 DEF_FUNC_DESC(PopMatrix
),
402 DEF_FUNC_DESC(Clear
),
403 DEF_FUNC_DESC(GenLists
),
404 DEF_FUNC_DESC(DeleteLists
),
405 DEF_FUNC_DESC(NewList
),
406 DEF_FUNC_DESC(EndList
),
407 DEF_FUNC_DESC(CallList
),
408 DEF_FUNC_DESC(CallLists
),
409 DEF_FUNC_DESC(GenTextures
),
410 DEF_FUNC_DESC(DeleteTextures
),
411 DEF_FUNC_DESC(TexEnvf
),
412 DEF_FUNC_DESC(TexEnvi
),
413 DEF_FUNC_DESC(Color4ub
),
414 DEF_FUNC_DESC(Color3f
),
415 DEF_FUNC_DESC(Color4f
),
416 DEF_FUNC_DESC(ClearColor
),
417 DEF_FUNC_DESC(ClearDepth
),
418 DEF_FUNC_DESC(DepthFunc
),
419 DEF_FUNC_DESC(Enable
),
420 DEF_FUNC_DESC(Disable
),
421 DEF_FUNC_DESC(DrawBuffer
),
422 DEF_FUNC_DESC(DepthMask
),
423 DEF_FUNC_DESC(BlendFunc
),
424 DEF_FUNC_DESC(Flush
),
425 DEF_FUNC_DESC(Finish
),
426 DEF_FUNC_DESC(PixelStorei
),
427 DEF_FUNC_DESC(TexImage1D
),
428 DEF_FUNC_DESC(TexImage2D
),
429 DEF_FUNC_DESC(TexSubImage2D
),
430 DEF_FUNC_DESC(TexParameteri
),
431 DEF_FUNC_DESC(TexParameterf
),
432 DEF_FUNC_DESC(TexParameterfv
),
433 DEF_FUNC_DESC(TexCoord2f
),
434 DEF_FUNC_DESC(Vertex2f
),
435 DEF_FUNC_DESC(Vertex3f
),
436 DEF_FUNC_DESC(Normal3f
),
437 DEF_FUNC_DESC(Lightfv
),
438 DEF_FUNC_DESC(ColorMaterial
),
439 DEF_FUNC_DESC(ShadeModel
),
440 DEF_FUNC_DESC(GetIntegerv
),
441 DEF_FUNC_DESC(ColorMask
),
443 // here start the real extensions
444 {&mpglGenBuffers
, NULL
, {"glGenBuffers", "glGenBuffersARB", NULL
}},
445 {&mpglDeleteBuffers
, NULL
, {"glDeleteBuffers", "glDeleteBuffersARB", NULL
}},
446 {&mpglBindBuffer
, NULL
, {"glBindBuffer", "glBindBufferARB", NULL
}},
447 {&mpglMapBuffer
, NULL
, {"glMapBuffer", "glMapBufferARB", NULL
}},
448 {&mpglUnmapBuffer
, NULL
, {"glUnmapBuffer", "glUnmapBufferARB", NULL
}},
449 {&mpglBufferData
, NULL
, {"glBufferData", "glBufferDataARB", NULL
}},
450 {&mpglCombinerParameterfv
, "NV_register_combiners", {"glCombinerParameterfv", "glCombinerParameterfvNV", NULL
}},
451 {&mpglCombinerParameteri
, "NV_register_combiners", {"glCombinerParameteri", "glCombinerParameteriNV", NULL
}},
452 {&mpglCombinerInput
, "NV_register_combiners", {"glCombinerInput", "glCombinerInputNV", NULL
}},
453 {&mpglCombinerOutput
, "NV_register_combiners", {"glCombinerOutput", "glCombinerOutputNV", NULL
}},
454 {&mpglBeginFragmentShader
, "ATI_fragment_shader", {"glBeginFragmentShaderATI", NULL
}},
455 {&mpglEndFragmentShader
, "ATI_fragment_shader", {"glEndFragmentShaderATI", NULL
}},
456 {&mpglSampleMap
, "ATI_fragment_shader", {"glSampleMapATI", NULL
}},
457 {&mpglColorFragmentOp2
, "ATI_fragment_shader", {"glColorFragmentOp2ATI", NULL
}},
458 {&mpglColorFragmentOp3
, "ATI_fragment_shader", {"glColorFragmentOp3ATI", NULL
}},
459 {&mpglSetFragmentShaderConstant
, "ATI_fragment_shader", {"glSetFragmentShaderConstantATI", NULL
}},
460 {&mpglActiveTexture
, NULL
, {"glActiveTexture", "glActiveTextureARB", NULL
}},
461 {&mpglBindTexture
, NULL
, {"glBindTexture", "glBindTextureARB", "glBindTextureEXT", NULL
}},
462 {&mpglMultiTexCoord2f
, NULL
, {"glMultiTexCoord2f", "glMultiTexCoord2fARB", NULL
}},
463 {&mpglGenPrograms
, "_program", {"glGenProgramsARB", NULL
}},
464 {&mpglDeletePrograms
, "_program", {"glDeleteProgramsARB", NULL
}},
465 {&mpglBindProgram
, "_program", {"glBindProgramARB", NULL
}},
466 {&mpglProgramString
, "_program", {"glProgramStringARB", NULL
}},
467 {&mpglGetProgramiv
, "_program", {"glGetProgramivARB", NULL
}},
468 {&mpglProgramEnvParameter4f
, "_program", {"glProgramEnvParameter4fARB", NULL
}},
469 {&mpglSwapInterval
, "_swap_control", {"glXSwapIntervalSGI", "glXSwapInterval", "wglSwapIntervalSGI", "wglSwapInterval", "wglSwapIntervalEXT", NULL
}},
470 {&mpglTexImage3D
, NULL
, {"glTexImage3D", NULL
}},
471 {&mpglAllocateMemoryMESA
, "GLX_MESA_allocate_memory", {"glXAllocateMemoryMESA", NULL
}},
472 {&mpglFreeMemoryMESA
, "GLX_MESA_allocate_memory", {"glXFreeMemoryMESA", NULL
}},
477 * \brief find the function pointers of some useful OpenGL extensions
478 * \param getProcAddress function to resolve function names, may be NULL
479 * \param ext2 an extra extension string
481 static void getFunctions(void *(*getProcAddress
)(const GLubyte
*),
483 const extfunc_desc_t
*dsc
;
484 const char *extensions
;
488 getProcAddress
= (void *)getdladdr
;
490 // special case, we need glGetString before starting to find the other functions
491 mpglGetString
= getProcAddress("glGetString");
493 mpglGetString
= glGetString
;
495 extensions
= (const char *)mpglGetString(GL_EXTENSIONS
);
496 if (!extensions
) extensions
= "";
497 if (!ext2
) ext2
= "";
498 allexts
= malloc(strlen(extensions
) + strlen(ext2
) + 2);
499 strcpy(allexts
, extensions
);
500 strcat(allexts
, " ");
501 strcat(allexts
, ext2
);
502 mp_msg(MSGT_VO
, MSGL_DBG2
, "OpenGL extensions string:\n%s\n", allexts
);
503 for (dsc
= extfuncs
; dsc
->funcptr
; dsc
++) {
506 if (!dsc
->extstr
|| strstr(allexts
, dsc
->extstr
)) {
507 for (i
= 0; !ptr
&& dsc
->funcnames
[i
]; i
++)
508 ptr
= getProcAddress((const GLubyte
*)dsc
->funcnames
[i
]);
512 *(void **)dsc
->funcptr
= ptr
;
514 if (strstr(allexts
, "_texture_float"))
515 hqtexfmt
= GL_RGB32F
;
516 else if (strstr(allexts
, "NV_float_buffer"))
517 hqtexfmt
= GL_FLOAT_RGB32_NV
;
524 * \brief create a texture and set some defaults
525 * \param target texture taget, usually GL_TEXTURE_2D
526 * \param fmt internal texture format
527 * \param format texture host data format
528 * \param type texture host data type
529 * \param filter filter used for scaling, e.g. GL_LINEAR
530 * \param w texture width
531 * \param h texture height
532 * \param val luminance value to fill texture with
535 void glCreateClearTex(GLenum target
, GLenum fmt
, GLenum format
, GLenum type
, GLint filter
,
536 int w
, int h
, unsigned char val
) {
537 GLfloat fval
= (GLfloat
)val
/ 255.0;
538 GLfloat border
[4] = {fval
, fval
, fval
, fval
};
543 stride
= w
* glFmt2bpp(format
, type
);
545 init
= malloc(stride
* h
);
546 memset(init
, val
, stride
* h
);
547 glAdjustAlignment(stride
);
548 mpglPixelStorei(GL_UNPACK_ROW_LENGTH
, w
);
549 mpglTexImage2D(target
, 0, fmt
, w
, h
, 0, format
, type
, init
);
550 mpglTexParameterf(target
, GL_TEXTURE_PRIORITY
, 1.0);
551 mpglTexParameteri(target
, GL_TEXTURE_MIN_FILTER
, filter
);
552 mpglTexParameteri(target
, GL_TEXTURE_MAG_FILTER
, filter
);
553 mpglTexParameteri(target
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
554 mpglTexParameteri(target
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
555 // Border texels should not be used with CLAMP_TO_EDGE
556 // We set a sane default anyway.
557 mpglTexParameterfv(target
, GL_TEXTURE_BORDER_COLOR
, border
);
562 * \brief skips whitespace and comments
563 * \param f file to read from
565 static void ppm_skip(FILE *f
) {
573 } while (c
!= EOF
&& (isspace(c
) || comment
));
578 #define MAXDIM (16 * 1024)
580 static uint8_t *read_pnm(FILE *f
, int *width
, int *height
,
581 int *bytes_per_pixel
, int *maxval
) {
584 unsigned w
, h
, m
, val
, bpp
;
585 *width
= *height
= *bytes_per_pixel
= *maxval
= 0;
590 if (type
!= '5' && type
!= '6')
593 if (fscanf(f
, "%u", &w
) != 1)
596 if (fscanf(f
, "%u", &h
) != 1)
599 if (fscanf(f
, "%u", &m
) != 1)
604 if (w
> MAXDIM
|| h
> MAXDIM
)
606 bpp
= (m
> 255) ? 2 : 1;
609 data
= malloc(w
* h
* bpp
);
610 if (fread(data
, w
* bpp
, h
, f
) != h
) {
616 *bytes_per_pixel
= bpp
;
622 * \brief creates a texture from a PPM file
623 * \param target texture taget, usually GL_TEXTURE_2D
624 * \param fmt internal texture format, 0 for default
625 * \param filter filter used for scaling, e.g. GL_LINEAR
626 * \param f file to read PPM from
627 * \param width [out] width of texture
628 * \param height [out] height of texture
629 * \param maxval [out] maxval value from PPM file
630 * \return 0 on error, 1 otherwise
633 int glCreatePPMTex(GLenum target
, GLenum fmt
, GLint filter
,
634 FILE *f
, int *width
, int *height
, int *maxval
) {
637 uint8_t *data
= read_pnm(f
, &w
, &h
, &bpp
, &m
);
638 if (!data
|| (bpp
!= 3 && bpp
!= 6)) {
643 fmt
= bpp
== 6 ? hqtexfmt
: 3;
644 if (fmt
== GL_FLOAT_RGB32_NV
&& target
!= GL_TEXTURE_RECTANGLE
)
647 type
= bpp
== 6 ? GL_UNSIGNED_SHORT
: GL_UNSIGNED_BYTE
;
648 glCreateClearTex(target
, fmt
, GL_RGB
, type
, filter
, w
, h
, 0);
649 glUploadTex(target
, GL_RGB
, type
,
650 data
, w
* bpp
, 0, 0, w
, h
, 0);
652 if (width
) *width
= w
;
653 if (height
) *height
= h
;
654 if (maxval
) *maxval
= m
;
659 * \brief return the number of bytes per pixel for the given format
660 * \param format OpenGL format
661 * \param type OpenGL type
662 * \return bytes per pixel
665 * Does not handle all possible variants, just those used by MPlayer
667 int glFmt2bpp(GLenum format
, GLenum type
) {
668 int component_size
= 0;
670 case GL_UNSIGNED_BYTE_3_3_2
:
671 case GL_UNSIGNED_BYTE_2_3_3_REV
:
673 case GL_UNSIGNED_SHORT_5_5_5_1
:
674 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
675 case GL_UNSIGNED_SHORT_5_6_5
:
676 case GL_UNSIGNED_SHORT_5_6_5_REV
:
678 case GL_UNSIGNED_BYTE
:
681 case GL_UNSIGNED_SHORT
:
688 return component_size
;
693 return 3 * component_size
;
696 return 4 * component_size
;
702 * \brief upload a texture, handling things like stride and slices
703 * \param target texture target, usually GL_TEXTURE_2D
704 * \param format OpenGL format of data
705 * \param type OpenGL type of data
706 * \param dataptr data to upload
707 * \param stride data stride
708 * \param x x offset in texture
709 * \param y y offset in texture
710 * \param w width of the texture part to upload
711 * \param h height of the texture part to upload
712 * \param slice height of an upload slice, 0 for all at once
715 void glUploadTex(GLenum target
, GLenum format
, GLenum type
,
716 const void *dataptr
, int stride
,
717 int x
, int y
, int w
, int h
, int slice
) {
718 const uint8_t *data
= dataptr
;
720 if (w
<= 0 || h
<= 0) return;
724 data
+= (h
- 1) * stride
;
727 // this is not always correct, but should work for MPlayer
728 glAdjustAlignment(stride
);
729 mpglPixelStorei(GL_UNPACK_ROW_LENGTH
, stride
/ glFmt2bpp(format
, type
));
730 for (; y
+ slice
<= y_max
; y
+= slice
) {
731 mpglTexSubImage2D(target
, 0, x
, y
, w
, slice
, format
, type
, data
);
732 data
+= stride
* slice
;
735 mpglTexSubImage2D(target
, 0, x
, y
, w
, y_max
- y
, format
, type
, data
);
738 static void fillUVcoeff(GLfloat
*ucoef
, GLfloat
*vcoef
,
739 float uvcos
, float uvsin
) {
741 ucoef
[0] = 0 * uvcos
+ 1.403 * uvsin
;
742 vcoef
[0] = 0 * uvsin
+ 1.403 * uvcos
;
743 ucoef
[1] = -0.344 * uvcos
+ -0.714 * uvsin
;
744 vcoef
[1] = -0.344 * uvsin
+ -0.714 * uvcos
;
745 ucoef
[2] = 1.770 * uvcos
+ 0 * uvsin
;
746 vcoef
[2] = 1.770 * uvsin
+ 0 * uvcos
;
749 // Coefficients (probably) must be in [0, 1] range, whereas they originally
750 // are in [-2, 2] range, so here comes the trick:
751 // First put them in the [-0.5, 0.5] range, then add 0.5.
752 // This can be undone with the HALF_BIAS and SCALE_BY_FOUR arguments
753 // for CombinerInput and CombinerOutput (or the respective ATI variants)
754 for (i
= 0; i
< 4; i
++) {
755 ucoef
[i
] = ucoef
[i
] * 0.25 + 0.5;
756 vcoef
[i
] = vcoef
[i
] * 0.25 + 0.5;
761 * \brief Setup register combiners for YUV to RGB conversion.
762 * \param uvcos used for saturation and hue adjustment
763 * \param uvsin used for saturation and hue adjustment
765 static void glSetupYUVCombiners(float uvcos
, float uvsin
) {
769 if (!mpglCombinerInput
|| !mpglCombinerOutput
||
770 !mpglCombinerParameterfv
|| !mpglCombinerParameteri
) {
771 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] Combiner functions missing!\n");
774 mpglGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV
, &i
);
776 mp_msg(MSGT_VO
, MSGL_ERR
,
777 "[gl] 2 general combiners needed for YUV combiner support (found %i)\n", i
);
778 mpglGetIntegerv(GL_MAX_TEXTURE_UNITS
, &i
);
780 mp_msg(MSGT_VO
, MSGL_ERR
,
781 "[gl] 3 texture units needed for YUV combiner support (found %i)\n", i
);
782 fillUVcoeff(ucoef
, vcoef
, uvcos
, uvsin
);
783 mpglCombinerParameterfv(GL_CONSTANT_COLOR0_NV
, ucoef
);
784 mpglCombinerParameterfv(GL_CONSTANT_COLOR1_NV
, vcoef
);
786 // UV first, like this green component cannot overflow
787 mpglCombinerInput(GL_COMBINER0_NV
, GL_RGB
, GL_VARIABLE_A_NV
,
788 GL_TEXTURE1
, GL_HALF_BIAS_NORMAL_NV
, GL_RGB
);
789 mpglCombinerInput(GL_COMBINER0_NV
, GL_RGB
, GL_VARIABLE_B_NV
,
790 GL_CONSTANT_COLOR0_NV
, GL_HALF_BIAS_NORMAL_NV
, GL_RGB
);
791 mpglCombinerInput(GL_COMBINER0_NV
, GL_RGB
, GL_VARIABLE_C_NV
,
792 GL_TEXTURE2
, GL_HALF_BIAS_NORMAL_NV
, GL_RGB
);
793 mpglCombinerInput(GL_COMBINER0_NV
, GL_RGB
, GL_VARIABLE_D_NV
,
794 GL_CONSTANT_COLOR1_NV
, GL_HALF_BIAS_NORMAL_NV
, GL_RGB
);
795 mpglCombinerOutput(GL_COMBINER0_NV
, GL_RGB
, GL_DISCARD_NV
, GL_DISCARD_NV
,
796 GL_SPARE0_NV
, GL_SCALE_BY_FOUR_NV
, GL_NONE
, GL_FALSE
,
800 mpglCombinerInput(GL_COMBINER1_NV
, GL_RGB
, GL_VARIABLE_A_NV
, GL_SPARE0_NV
,
801 GL_SIGNED_IDENTITY_NV
, GL_RGB
);
802 mpglCombinerInput(GL_COMBINER1_NV
, GL_RGB
, GL_VARIABLE_B_NV
, GL_ZERO
,
803 GL_UNSIGNED_INVERT_NV
, GL_RGB
);
804 mpglCombinerInput(GL_COMBINER1_NV
, GL_RGB
, GL_VARIABLE_C_NV
,
805 GL_TEXTURE0
, GL_SIGNED_IDENTITY_NV
, GL_RGB
);
806 mpglCombinerInput(GL_COMBINER1_NV
, GL_RGB
, GL_VARIABLE_D_NV
, GL_ZERO
,
807 GL_UNSIGNED_INVERT_NV
, GL_RGB
);
808 mpglCombinerOutput(GL_COMBINER1_NV
, GL_RGB
, GL_DISCARD_NV
, GL_DISCARD_NV
,
809 GL_SPARE0_NV
, GL_NONE
, GL_NONE
, GL_FALSE
,
812 // leave final combiner stage in default mode
813 mpglCombinerParameteri(GL_NUM_GENERAL_COMBINERS_NV
, 2);
817 * \brief Setup ATI version of register combiners for YUV to RGB conversion.
818 * \param csp_params parameters used for colorspace conversion
819 * \param text if set use the GL_ATI_text_fragment_shader API as
822 static void glSetupYUVFragmentATI(struct mp_csp_params
*csp_params
,
827 mpglGetIntegerv (GL_MAX_TEXTURE_UNITS
, &i
);
829 mp_msg(MSGT_VO
, MSGL_ERR
,
830 "[gl] 3 texture units needed for YUV combiner (ATI) support (found %i)\n", i
);
832 mp_get_yuv2rgb_coeffs(csp_params
, yuv2rgb
);
833 for (i
= 0; i
< 3; i
++) {
835 yuv2rgb
[i
][3] -= -0.5 * (yuv2rgb
[i
][1] + yuv2rgb
[i
][2]);
836 for (j
= 0; j
< 4; j
++) {
837 yuv2rgb
[i
][j
] *= 0.125;
838 yuv2rgb
[i
][j
] += 0.5;
839 if (yuv2rgb
[i
][j
] > 1)
841 if (yuv2rgb
[i
][j
] < 0)
846 GLfloat c0
[4] = {yuv2rgb
[0][0], yuv2rgb
[1][0], yuv2rgb
[2][0]};
847 GLfloat c1
[4] = {yuv2rgb
[0][1], yuv2rgb
[1][1], yuv2rgb
[2][1]};
848 GLfloat c2
[4] = {yuv2rgb
[0][2], yuv2rgb
[1][2], yuv2rgb
[2][2]};
849 GLfloat c3
[4] = {yuv2rgb
[0][3], yuv2rgb
[1][3], yuv2rgb
[2][3]};
850 if (!mpglBeginFragmentShader
|| !mpglEndFragmentShader
||
851 !mpglSetFragmentShaderConstant
|| !mpglSampleMap
||
852 !mpglColorFragmentOp2
|| !mpglColorFragmentOp3
) {
853 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] Combiner (ATI) functions missing!\n");
856 mpglGetIntegerv(GL_NUM_FRAGMENT_REGISTERS_ATI
, &i
);
858 mp_msg(MSGT_VO
, MSGL_ERR
,
859 "[gl] 3 registers needed for YUV combiner (ATI) support (found %i)\n", i
);
860 mpglBeginFragmentShader();
861 mpglSetFragmentShaderConstant(GL_CON_0_ATI
, c0
);
862 mpglSetFragmentShaderConstant(GL_CON_1_ATI
, c1
);
863 mpglSetFragmentShaderConstant(GL_CON_2_ATI
, c2
);
864 mpglSetFragmentShaderConstant(GL_CON_3_ATI
, c3
);
865 mpglSampleMap(GL_REG_0_ATI
, GL_TEXTURE0
, GL_SWIZZLE_STR_ATI
);
866 mpglSampleMap(GL_REG_1_ATI
, GL_TEXTURE1
, GL_SWIZZLE_STR_ATI
);
867 mpglSampleMap(GL_REG_2_ATI
, GL_TEXTURE2
, GL_SWIZZLE_STR_ATI
);
868 mpglColorFragmentOp2(GL_MUL_ATI
, GL_REG_1_ATI
, GL_NONE
, GL_NONE
,
869 GL_REG_1_ATI
, GL_NONE
, GL_BIAS_BIT_ATI
,
870 GL_CON_1_ATI
, GL_NONE
, GL_BIAS_BIT_ATI
);
871 mpglColorFragmentOp3(GL_MAD_ATI
, GL_REG_2_ATI
, GL_NONE
, GL_NONE
,
872 GL_REG_2_ATI
, GL_NONE
, GL_BIAS_BIT_ATI
,
873 GL_CON_2_ATI
, GL_NONE
, GL_BIAS_BIT_ATI
,
874 GL_REG_1_ATI
, GL_NONE
, GL_NONE
);
875 mpglColorFragmentOp3(GL_MAD_ATI
, GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
876 GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
877 GL_CON_0_ATI
, GL_NONE
, GL_BIAS_BIT_ATI
,
878 GL_REG_2_ATI
, GL_NONE
, GL_NONE
);
879 mpglColorFragmentOp2(GL_ADD_ATI
, GL_REG_0_ATI
, GL_NONE
, GL_8X_BIT_ATI
,
880 GL_REG_0_ATI
, GL_NONE
, GL_NONE
,
881 GL_CON_3_ATI
, GL_NONE
, GL_BIAS_BIT_ATI
);
882 mpglEndFragmentShader();
884 static const char template[] =
887 " CONSTANT c0 = {%e, %e, %e};\n"
888 " CONSTANT c1 = {%e, %e, %e};\n"
889 " CONSTANT c2 = {%e, %e, %e};\n"
890 " CONSTANT c3 = {%e, %e, %e};\n"
893 " SampleMap r0, t0.str;\n"
894 " SampleMap r1, t1.str;\n"
895 " SampleMap r2, t2.str;\n"
896 " MUL r1.rgb, r1.bias, c1.bias;\n"
897 " MAD r2.rgb, r2.bias, c2.bias, r1;\n"
898 " MAD r0.rgb, r0, c0.bias, r2;\n"
899 " ADD r0.rgb.8x, r0, c3.bias;\n"
902 snprintf(buffer
, sizeof(buffer
), template,
903 yuv2rgb
[0][0], yuv2rgb
[1][0], yuv2rgb
[2][0],
904 yuv2rgb
[0][1], yuv2rgb
[1][1], yuv2rgb
[2][1],
905 yuv2rgb
[0][2], yuv2rgb
[1][2], yuv2rgb
[2][2],
906 yuv2rgb
[0][3], yuv2rgb
[1][3], yuv2rgb
[2][3]);
907 mp_msg(MSGT_VO
, MSGL_DBG2
, "[gl] generated fragment program:\n%s\n", buffer
);
908 loadGPUProgram(GL_TEXT_FRAGMENT_SHADER_ATI
, buffer
);
913 * \brief helper function for gen_spline_lookup_tex
914 * \param x subpixel-position ((0,1) range) to calculate weights for
915 * \param dst where to store transformed weights, must provide space for 4 GLfloats
917 * calculates the weights and stores them after appropriate transformation
918 * for the scaler fragment program.
920 static void store_weights(float x
, GLfloat
*dst
) {
921 float w0
= (((-1 * x
+ 3) * x
- 3) * x
+ 1) / 6;
922 float w1
= ((( 3 * x
- 6) * x
+ 0) * x
+ 4) / 6;
923 float w2
= (((-3 * x
+ 3) * x
+ 3) * x
+ 1) / 6;
924 float w3
= ((( 1 * x
+ 0) * x
+ 0) * x
+ 0) / 6;
925 *dst
++ = 1 + x
- w1
/ (w0
+ w1
);
926 *dst
++ = 1 - x
+ w3
/ (w2
+ w3
);
931 //! to avoid artefacts this should be rather large
932 #define LOOKUP_BSPLINE_RES (2 * 1024)
934 * \brief creates the 1D lookup texture needed for fast higher-order filtering
935 * \param unit texture unit to attach texture to
937 static void gen_spline_lookup_tex(GLenum unit
) {
938 GLfloat
*tex
= calloc(4 * LOOKUP_BSPLINE_RES
, sizeof(*tex
));
941 for (i
= 0; i
< LOOKUP_BSPLINE_RES
; i
++) {
942 float x
= (float)(i
+ 0.5) / LOOKUP_BSPLINE_RES
;
943 store_weights(x
, tp
);
946 store_weights(0, tex
);
947 store_weights(1, &tex
[4 * (LOOKUP_BSPLINE_RES
- 1)]);
948 mpglActiveTexture(unit
);
949 mpglTexImage1D(GL_TEXTURE_1D
, 0, GL_RGBA16
, LOOKUP_BSPLINE_RES
, 0, GL_RGBA
, GL_FLOAT
, tex
);
950 mpglTexParameterf(GL_TEXTURE_1D
, GL_TEXTURE_PRIORITY
, 1.0);
951 mpglTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
952 mpglTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
953 mpglTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
954 mpglActiveTexture(GL_TEXTURE0
);
958 static const char *bilin_filt_template
=
959 "TEX yuv.%c, fragment.texcoord[%c], texture[%c], %s;\n";
961 #define BICUB_FILT_MAIN(textype) \
962 /* first y-interpolation */ \
963 "ADD coord, fragment.texcoord[%c].xyxy, cdelta.xyxw;\n" \
964 "ADD coord2, fragment.texcoord[%c].xyxy, cdelta.zyzw;\n" \
965 "TEX a.r, coord.xyxy, texture[%c], "textype";\n" \
966 "TEX a.g, coord.zwzw, texture[%c], "textype";\n" \
967 /* second y-interpolation */ \
968 "TEX b.r, coord2.xyxy, texture[%c], "textype";\n" \
969 "TEX b.g, coord2.zwzw, texture[%c], "textype";\n" \
970 "LRP a.b, parmy.b, a.rrrr, a.gggg;\n" \
971 "LRP a.a, parmy.b, b.rrrr, b.gggg;\n" \
972 /* x-interpolation */ \
973 "LRP yuv.%c, parmx.b, a.bbbb, a.aaaa;\n"
975 static const char *bicub_filt_template_2D
=
976 "MAD coord.xy, fragment.texcoord[%c], {%e, %e}, {0.5, 0.5};\n"
977 "TEX parmx, coord.x, texture[%c], 1D;\n"
978 "MUL cdelta.xz, parmx.rrgg, {-%e, 0, %e, 0};\n"
979 "TEX parmy, coord.y, texture[%c], 1D;\n"
980 "MUL cdelta.yw, parmy.rrgg, {0, -%e, 0, %e};\n"
981 BICUB_FILT_MAIN("2D");
983 static const char *bicub_filt_template_RECT
=
984 "ADD coord, fragment.texcoord[%c], {0.5, 0.5};\n"
985 "TEX parmx, coord.x, texture[%c], 1D;\n"
986 "MUL cdelta.xz, parmx.rrgg, {-1, 0, 1, 0};\n"
987 "TEX parmy, coord.y, texture[%c], 1D;\n"
988 "MUL cdelta.yw, parmy.rrgg, {0, -1, 0, 1};\n"
989 BICUB_FILT_MAIN("RECT");
991 #define CALCWEIGHTS(t, s) \
992 "MAD "t", {-0.5, 0.1666, 0.3333, -0.3333}, "s", {1, 0, -0.5, 0.5};\n" \
993 "MAD "t", "t", "s", {0, 0, -0.5, 0.5};\n" \
994 "MAD "t", "t", "s", {-0.6666, 0, 0.8333, 0.1666};\n" \
995 "RCP a.x, "t".z;\n" \
996 "RCP a.y, "t".w;\n" \
997 "MAD "t".xy, "t".xyxy, a.xyxy, {1, 1, 0, 0};\n" \
998 "ADD "t".x, "t".xxxx, "s";\n" \
999 "SUB "t".y, "t".yyyy, "s";\n"
1001 static const char *bicub_notex_filt_template_2D
=
1002 "MAD coord.xy, fragment.texcoord[%c], {%e, %e}, {0.5, 0.5};\n"
1003 "FRC coord.xy, coord.xyxy;\n"
1004 CALCWEIGHTS("parmx", "coord.xxxx")
1005 "MUL cdelta.xz, parmx.rrgg, {-%e, 0, %e, 0};\n"
1006 CALCWEIGHTS("parmy", "coord.yyyy")
1007 "MUL cdelta.yw, parmy.rrgg, {0, -%e, 0, %e};\n"
1008 BICUB_FILT_MAIN("2D");
1010 static const char *bicub_notex_filt_template_RECT
=
1011 "ADD coord, fragment.texcoord[%c], {0.5, 0.5};\n"
1012 "FRC coord.xy, coord.xyxy;\n"
1013 CALCWEIGHTS("parmx", "coord.xxxx")
1014 "MUL cdelta.xz, parmx.rrgg, {-1, 0, 1, 0};\n"
1015 CALCWEIGHTS("parmy", "coord.yyyy")
1016 "MUL cdelta.yw, parmy.rrgg, {0, -1, 0, 1};\n"
1017 BICUB_FILT_MAIN("RECT");
1019 #define BICUB_X_FILT_MAIN(textype) \
1020 "ADD coord.xy, fragment.texcoord[%c].xyxy, cdelta.xyxy;\n" \
1021 "ADD coord2.xy, fragment.texcoord[%c].xyxy, cdelta.zyzy;\n" \
1022 "TEX a.r, coord, texture[%c], "textype";\n" \
1023 "TEX b.r, coord2, texture[%c], "textype";\n" \
1024 /* x-interpolation */ \
1025 "LRP yuv.%c, parmx.b, a.rrrr, b.rrrr;\n"
1027 static const char *bicub_x_filt_template_2D
=
1028 "MAD coord.x, fragment.texcoord[%c], {%e}, {0.5};\n"
1029 "TEX parmx, coord, texture[%c], 1D;\n"
1030 "MUL cdelta.xyz, parmx.rrgg, {-%e, 0, %e};\n"
1031 BICUB_X_FILT_MAIN("2D");
1033 static const char *bicub_x_filt_template_RECT
=
1034 "ADD coord.x, fragment.texcoord[%c], {0.5};\n"
1035 "TEX parmx, coord, texture[%c], 1D;\n"
1036 "MUL cdelta.xyz, parmx.rrgg, {-1, 0, 1};\n"
1037 BICUB_X_FILT_MAIN("RECT");
1039 static const char *unsharp_filt_template
=
1040 "PARAM dcoord%c = {%e, %e, %e, %e};\n"
1041 "ADD coord, fragment.texcoord[%c].xyxy, dcoord%c;\n"
1042 "SUB coord2, fragment.texcoord[%c].xyxy, dcoord%c;\n"
1043 "TEX a.r, fragment.texcoord[%c], texture[%c], %s;\n"
1044 "TEX b.r, coord.xyxy, texture[%c], %s;\n"
1045 "TEX b.g, coord.zwzw, texture[%c], %s;\n"
1046 "ADD b.r, b.r, b.g;\n"
1047 "TEX b.b, coord2.xyxy, texture[%c], %s;\n"
1048 "TEX b.g, coord2.zwzw, texture[%c], %s;\n"
1049 "DP3 b, b, {0.25, 0.25, 0.25};\n"
1050 "SUB b.r, a.r, b.r;\n"
1051 "MAD yuv.%c, b.r, {%e}, a.r;\n";
1053 static const char *unsharp_filt_template2
=
1054 "PARAM dcoord%c = {%e, %e, %e, %e};\n"
1055 "PARAM dcoord2%c = {%e, 0, 0, %e};\n"
1056 "ADD coord, fragment.texcoord[%c].xyxy, dcoord%c;\n"
1057 "SUB coord2, fragment.texcoord[%c].xyxy, dcoord%c;\n"
1058 "TEX a.r, fragment.texcoord[%c], texture[%c], %s;\n"
1059 "TEX b.r, coord.xyxy, texture[%c], %s;\n"
1060 "TEX b.g, coord.zwzw, texture[%c], %s;\n"
1061 "ADD b.r, b.r, b.g;\n"
1062 "TEX b.b, coord2.xyxy, texture[%c], %s;\n"
1063 "TEX b.g, coord2.zwzw, texture[%c], %s;\n"
1064 "ADD b.r, b.r, b.b;\n"
1065 "ADD b.a, b.r, b.g;\n"
1066 "ADD coord, fragment.texcoord[%c].xyxy, dcoord2%c;\n"
1067 "SUB coord2, fragment.texcoord[%c].xyxy, dcoord2%c;\n"
1068 "TEX b.r, coord.xyxy, texture[%c], %s;\n"
1069 "TEX b.g, coord.zwzw, texture[%c], %s;\n"
1070 "ADD b.r, b.r, b.g;\n"
1071 "TEX b.b, coord2.xyxy, texture[%c], %s;\n"
1072 "TEX b.g, coord2.zwzw, texture[%c], %s;\n"
1073 "DP4 b.r, b, {-0.1171875, -0.1171875, -0.1171875, -0.09765625};\n"
1074 "MAD b.r, a.r, {0.859375}, b.r;\n"
1075 "MAD yuv.%c, b.r, {%e}, a.r;\n";
1077 static const char *yuv_prog_template
=
1078 "PARAM ycoef = {%e, %e, %e};\n"
1079 "PARAM ucoef = {%e, %e, %e};\n"
1080 "PARAM vcoef = {%e, %e, %e};\n"
1081 "PARAM offsets = {%e, %e, %e};\n"
1083 "MAD res.rgb, yuv.rrrr, ycoef, offsets;\n"
1084 "MAD res.rgb, yuv.gggg, ucoef, res;\n"
1085 "MAD result.color.rgb, yuv.bbbb, vcoef, res;\n"
1088 static const char *yuv_pow_prog_template
=
1089 "PARAM ycoef = {%e, %e, %e};\n"
1090 "PARAM ucoef = {%e, %e, %e};\n"
1091 "PARAM vcoef = {%e, %e, %e};\n"
1092 "PARAM offsets = {%e, %e, %e};\n"
1093 "PARAM gamma = {%e, %e, %e};\n"
1095 "MAD res.rgb, yuv.rrrr, ycoef, offsets;\n"
1096 "MAD res.rgb, yuv.gggg, ucoef, res;\n"
1097 "MAD_SAT res.rgb, yuv.bbbb, vcoef, res;\n"
1098 "POW result.color.r, res.r, gamma.r;\n"
1099 "POW result.color.g, res.g, gamma.g;\n"
1100 "POW result.color.b, res.b, gamma.b;\n"
1103 static const char *yuv_lookup_prog_template
=
1104 "PARAM ycoef = {%e, %e, %e, 0};\n"
1105 "PARAM ucoef = {%e, %e, %e, 0};\n"
1106 "PARAM vcoef = {%e, %e, %e, 0};\n"
1107 "PARAM offsets = {%e, %e, %e, 0.125};\n"
1109 "MAD res, yuv.rrrr, ycoef, offsets;\n"
1110 "MAD res.rgb, yuv.gggg, ucoef, res;\n"
1111 "MAD res.rgb, yuv.bbbb, vcoef, res;\n"
1112 "TEX result.color.r, res.raaa, texture[%c], 2D;\n"
1113 "ADD res.a, res.a, 0.25;\n"
1114 "TEX result.color.g, res.gaaa, texture[%c], 2D;\n"
1115 "ADD res.a, res.a, 0.25;\n"
1116 "TEX result.color.b, res.baaa, texture[%c], 2D;\n"
1119 static const char *yuv_lookup3d_prog_template
=
1120 "TEX result.color, yuv, texture[%c], 3D;\n"
1124 * \brief creates and initializes helper textures needed for scaling texture read
1125 * \param scaler scaler type to create texture for
1126 * \param texu contains next free texture unit number
1127 * \param texs texture unit ids for the scaler are stored in this array
1129 static void create_scaler_textures(int scaler
, int *texu
, char *texs
) {
1131 case YUV_SCALER_BILIN
:
1132 case YUV_SCALER_BICUB_NOTEX
:
1133 case YUV_SCALER_UNSHARP
:
1134 case YUV_SCALER_UNSHARP2
:
1136 case YUV_SCALER_BICUB
:
1137 case YUV_SCALER_BICUB_X
:
1138 texs
[0] = (*texu
)++;
1139 gen_spline_lookup_tex(GL_TEXTURE0
+ texs
[0]);
1143 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] unknown scaler type %i\n", scaler
);
1147 //! resolution of texture for gamma lookup table
1148 #define LOOKUP_RES 512
1149 //! resolution for 3D yuv->rgb conversion lookup table
1150 #define LOOKUP_3DRES 32
1152 * \brief creates and initializes helper textures needed for yuv conversion
1153 * \param params struct containing parameters like brightness, gamma, ...
1154 * \param texu contains next free texture unit number
1155 * \param texs texture unit ids for the conversion are stored in this array
1157 static void create_conv_textures(gl_conversion_params_t
*params
, int *texu
, char *texs
) {
1158 unsigned char *lookup_data
= NULL
;
1159 int conv
= YUV_CONVERSION(params
->type
);
1161 case YUV_CONVERSION_FRAGMENT
:
1162 case YUV_CONVERSION_FRAGMENT_POW
:
1164 case YUV_CONVERSION_FRAGMENT_LOOKUP
:
1165 texs
[0] = (*texu
)++;
1166 mpglActiveTexture(GL_TEXTURE0
+ texs
[0]);
1167 lookup_data
= malloc(4 * LOOKUP_RES
);
1168 mp_gen_gamma_map(lookup_data
, LOOKUP_RES
, params
->csp_params
.rgamma
);
1169 mp_gen_gamma_map(&lookup_data
[LOOKUP_RES
], LOOKUP_RES
, params
->csp_params
.ggamma
);
1170 mp_gen_gamma_map(&lookup_data
[2 * LOOKUP_RES
], LOOKUP_RES
, params
->csp_params
.bgamma
);
1171 glCreateClearTex(GL_TEXTURE_2D
, GL_LUMINANCE8
, GL_LUMINANCE
, GL_UNSIGNED_BYTE
, GL_LINEAR
,
1173 glUploadTex(GL_TEXTURE_2D
, GL_LUMINANCE
, GL_UNSIGNED_BYTE
, lookup_data
,
1174 LOOKUP_RES
, 0, 0, LOOKUP_RES
, 4, 0);
1175 mpglActiveTexture(GL_TEXTURE0
);
1178 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
1180 int sz
= LOOKUP_3DRES
+ 2; // texture size including borders
1181 if (!mpglTexImage3D
) {
1182 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] Missing 3D texture function!\n");
1185 texs
[0] = (*texu
)++;
1186 mpglActiveTexture(GL_TEXTURE0
+ texs
[0]);
1187 lookup_data
= malloc(3 * sz
* sz
* sz
);
1188 mp_gen_yuv2rgb_map(¶ms
->csp_params
, lookup_data
, LOOKUP_3DRES
);
1189 glAdjustAlignment(sz
);
1190 mpglPixelStorei(GL_UNPACK_ROW_LENGTH
, 0);
1191 mpglTexImage3D(GL_TEXTURE_3D
, 0, 3, sz
, sz
, sz
, 1,
1192 GL_RGB
, GL_UNSIGNED_BYTE
, lookup_data
);
1193 mpglTexParameterf(GL_TEXTURE_3D
, GL_TEXTURE_PRIORITY
, 1.0);
1194 mpglTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1195 mpglTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
1196 mpglTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_S
, GL_CLAMP
);
1197 mpglTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_T
, GL_CLAMP
);
1198 mpglTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_WRAP_R
, GL_CLAMP
);
1199 mpglActiveTexture(GL_TEXTURE0
);
1204 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] unknown conversion type %i\n", conv
);
1211 * \brief adds a scaling texture read at the current fragment program position
1212 * \param scaler type of scaler to insert
1213 * \param prog_pos current position in fragment program
1214 * \param remain how many bytes remain in the buffer given by prog_pos
1215 * \param texs array containing the texture unit identifiers for this scaler
1216 * \param in_tex texture unit the scaler should read from
1217 * \param out_comp component of the yuv variable the scaler stores the result in
1218 * \param rect if rectangular (pixel) adressing should be used for in_tex
1219 * \param texw width of the in_tex texture
1220 * \param texh height of the in_tex texture
1221 * \param strength strength of filter effect if the scaler does some kind of filtering
1223 static void add_scaler(int scaler
, char **prog_pos
, int *remain
, char *texs
,
1224 char in_tex
, char out_comp
, int rect
, int texw
, int texh
,
1226 const char *ttype
= rect
? "RECT" : "2D";
1227 const float ptw
= rect
? 1.0 : 1.0 / texw
;
1228 const float pth
= rect
? 1.0 : 1.0 / texh
;
1230 case YUV_SCALER_BILIN
:
1231 snprintf(*prog_pos
, *remain
, bilin_filt_template
, out_comp
, in_tex
,
1234 case YUV_SCALER_BICUB
:
1236 snprintf(*prog_pos
, *remain
, bicub_filt_template_RECT
,
1237 in_tex
, texs
[0], texs
[0],
1238 in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, out_comp
);
1240 snprintf(*prog_pos
, *remain
, bicub_filt_template_2D
,
1241 in_tex
, (float)texw
, (float)texh
,
1242 texs
[0], ptw
, ptw
, texs
[0], pth
, pth
,
1243 in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, out_comp
);
1245 case YUV_SCALER_BICUB_X
:
1247 snprintf(*prog_pos
, *remain
, bicub_x_filt_template_RECT
,
1249 in_tex
, in_tex
, in_tex
, in_tex
, out_comp
);
1251 snprintf(*prog_pos
, *remain
, bicub_x_filt_template_2D
,
1252 in_tex
, (float)texw
,
1254 in_tex
, in_tex
, in_tex
, in_tex
, out_comp
);
1256 case YUV_SCALER_BICUB_NOTEX
:
1258 snprintf(*prog_pos
, *remain
, bicub_notex_filt_template_RECT
,
1260 in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, out_comp
);
1262 snprintf(*prog_pos
, *remain
, bicub_notex_filt_template_2D
,
1263 in_tex
, (float)texw
, (float)texh
, ptw
, ptw
, pth
, pth
,
1264 in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, in_tex
, out_comp
);
1266 case YUV_SCALER_UNSHARP
:
1267 snprintf(*prog_pos
, *remain
, unsharp_filt_template
,
1268 out_comp
, 0.5 * ptw
, 0.5 * pth
, 0.5 * ptw
, -0.5 * pth
,
1269 in_tex
, out_comp
, in_tex
, out_comp
, in_tex
,
1270 in_tex
, ttype
, in_tex
, ttype
, in_tex
, ttype
, in_tex
, ttype
,
1271 in_tex
, ttype
, out_comp
, strength
);
1273 case YUV_SCALER_UNSHARP2
:
1274 snprintf(*prog_pos
, *remain
, unsharp_filt_template2
,
1275 out_comp
, 1.2 * ptw
, 1.2 * pth
, 1.2 * ptw
, -1.2 * pth
,
1276 out_comp
, 1.5 * ptw
, 1.5 * pth
,
1277 in_tex
, out_comp
, in_tex
, out_comp
, in_tex
,
1278 in_tex
, ttype
, in_tex
, ttype
, in_tex
, ttype
, in_tex
, ttype
,
1279 in_tex
, ttype
, in_tex
, out_comp
, in_tex
, out_comp
,
1280 in_tex
, ttype
, in_tex
, ttype
, in_tex
, ttype
,
1281 in_tex
, ttype
, out_comp
, strength
);
1284 *remain
-= strlen(*prog_pos
);
1285 *prog_pos
+= strlen(*prog_pos
);
1288 static const struct {
1293 {"instructions", 0x88A0, 0x88A1},
1294 {"native instructions", 0x88A2, 0x88A3},
1295 {"temporaries", 0x88A4, 0x88A5},
1296 {"native temporaries", 0x88A6, 0x88A7},
1297 {"parameters", 0x88A8, 0x88A9},
1298 {"native parameters", 0x88AA, 0x88AB},
1299 {"attribs", 0x88AC, 0x88AD},
1300 {"native attribs", 0x88AE, 0x88AF},
1301 {"ALU instructions", 0x8805, 0x880B},
1302 {"TEX instructions", 0x8806, 0x880C},
1303 {"TEX indirections", 0x8807, 0x880D},
1304 {"native ALU instructions", 0x8808, 0x880E},
1305 {"native TEX instructions", 0x8809, 0x880F},
1306 {"native TEX indirections", 0x880A, 0x8810},
1311 * \brief load the specified GPU Program
1312 * \param target program target to load into, only GL_FRAGMENT_PROGRAM is tested
1313 * \param prog program string
1314 * \return 1 on success, 0 otherwise
1316 int loadGPUProgram(GLenum target
, char *prog
) {
1318 GLint cur
= 0, max
= 0, err
= 0;
1319 if (!mpglProgramString
) {
1320 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] Missing GPU program function\n");
1323 mpglProgramString(target
, GL_PROGRAM_FORMAT_ASCII
, strlen(prog
), prog
);
1324 mpglGetIntegerv(GL_PROGRAM_ERROR_POSITION
, &err
);
1326 mp_msg(MSGT_VO
, MSGL_ERR
,
1327 "[gl] Error compiling fragment program, make sure your card supports\n"
1328 "[gl] GL_ARB_fragment_program (use glxinfo to check).\n"
1329 "[gl] Error message:\n %s at %.10s\n",
1330 mpglGetString(GL_PROGRAM_ERROR_STRING
), &prog
[err
]);
1333 if (!mpglGetProgramiv
|| !mp_msg_test(MSGT_VO
, MSGL_DBG2
))
1335 mp_msg(MSGT_VO
, MSGL_V
, "[gl] Program statistics:\n");
1336 for (i
= 0; progstats
[i
].name
; i
++) {
1337 mpglGetProgramiv(target
, progstats
[i
].cur
, &cur
);
1338 mpglGetProgramiv(target
, progstats
[i
].max
, &max
);
1339 mp_msg(MSGT_VO
, MSGL_V
, "[gl] %s: %i/%i\n", progstats
[i
].name
, cur
, max
);
1344 #define MAX_PROGSZ (1024*1024)
1347 * \brief setup a fragment program that will do YUV->RGB conversion
1348 * \param parms struct containing parameters like conversion and scaler type,
1351 static void glSetupYUVFragprog(gl_conversion_params_t
*params
) {
1352 int type
= params
->type
;
1353 int texw
= params
->texw
;
1354 int texh
= params
->texh
;
1355 int rect
= params
->target
== GL_TEXTURE_RECTANGLE
;
1356 static const char prog_hdr
[] =
1358 "OPTION ARB_precision_hint_fastest;\n"
1359 // all scaler variables must go here so they aren't defined
1360 // multiple times when the same scaler is used more than once
1361 "TEMP coord, coord2, cdelta, parmx, parmy, a, b, yuv;\n";
1363 char *yuv_prog
, *prog_pos
;
1365 char lum_scale_texs
[1];
1366 char chrom_scale_texs
[1];
1369 // this is the conversion matrix, with y, u, v factors
1370 // for red, green, blue and the constant offsets
1371 float yuv2rgb
[3][4];
1372 create_conv_textures(params
, &cur_texu
, conv_texs
);
1373 create_scaler_textures(YUV_LUM_SCALER(type
), &cur_texu
, lum_scale_texs
);
1374 if (YUV_CHROM_SCALER(type
) == YUV_LUM_SCALER(type
))
1375 memcpy(chrom_scale_texs
, lum_scale_texs
, sizeof(chrom_scale_texs
));
1377 create_scaler_textures(YUV_CHROM_SCALER(type
), &cur_texu
, chrom_scale_texs
);
1378 mpglGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS
, &i
);
1380 mp_msg(MSGT_VO
, MSGL_ERR
,
1381 "[gl] %i texture units needed for this type of YUV fragment support (found %i)\n",
1383 if (!mpglProgramString
) {
1384 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] ProgramString function missing!\n");
1387 yuv_prog
= malloc(MAX_PROGSZ
);
1388 strcpy(yuv_prog
, prog_hdr
);
1389 prog_pos
= yuv_prog
+ sizeof(prog_hdr
) - 1;
1390 prog_remain
= MAX_PROGSZ
- sizeof(prog_hdr
);
1391 add_scaler(YUV_LUM_SCALER(type
), &prog_pos
, &prog_remain
, lum_scale_texs
,
1392 '0', 'r', rect
, texw
, texh
, params
->filter_strength
);
1393 add_scaler(YUV_CHROM_SCALER(type
), &prog_pos
, &prog_remain
, chrom_scale_texs
,
1394 '1', 'g', rect
, params
->chrom_texw
, params
->chrom_texh
, params
->filter_strength
);
1395 add_scaler(YUV_CHROM_SCALER(type
), &prog_pos
, &prog_remain
, chrom_scale_texs
,
1396 '2', 'b', rect
, params
->chrom_texw
, params
->chrom_texh
, params
->filter_strength
);
1397 mp_get_yuv2rgb_coeffs(¶ms
->csp_params
, yuv2rgb
);
1398 switch (YUV_CONVERSION(type
)) {
1399 case YUV_CONVERSION_FRAGMENT
:
1400 snprintf(prog_pos
, prog_remain
, yuv_prog_template
,
1401 yuv2rgb
[ROW_R
][COL_Y
], yuv2rgb
[ROW_G
][COL_Y
], yuv2rgb
[ROW_B
][COL_Y
],
1402 yuv2rgb
[ROW_R
][COL_U
], yuv2rgb
[ROW_G
][COL_U
], yuv2rgb
[ROW_B
][COL_U
],
1403 yuv2rgb
[ROW_R
][COL_V
], yuv2rgb
[ROW_G
][COL_V
], yuv2rgb
[ROW_B
][COL_V
],
1404 yuv2rgb
[ROW_R
][COL_C
], yuv2rgb
[ROW_G
][COL_C
], yuv2rgb
[ROW_B
][COL_C
]);
1406 case YUV_CONVERSION_FRAGMENT_POW
:
1407 snprintf(prog_pos
, prog_remain
, yuv_pow_prog_template
,
1408 yuv2rgb
[ROW_R
][COL_Y
], yuv2rgb
[ROW_G
][COL_Y
], yuv2rgb
[ROW_B
][COL_Y
],
1409 yuv2rgb
[ROW_R
][COL_U
], yuv2rgb
[ROW_G
][COL_U
], yuv2rgb
[ROW_B
][COL_U
],
1410 yuv2rgb
[ROW_R
][COL_V
], yuv2rgb
[ROW_G
][COL_V
], yuv2rgb
[ROW_B
][COL_V
],
1411 yuv2rgb
[ROW_R
][COL_C
], yuv2rgb
[ROW_G
][COL_C
], yuv2rgb
[ROW_B
][COL_C
],
1412 (float)1.0 / params
->csp_params
.rgamma
, (float)1.0 / params
->csp_params
.bgamma
, (float)1.0 / params
->csp_params
.bgamma
);
1414 case YUV_CONVERSION_FRAGMENT_LOOKUP
:
1415 snprintf(prog_pos
, prog_remain
, yuv_lookup_prog_template
,
1416 yuv2rgb
[ROW_R
][COL_Y
], yuv2rgb
[ROW_G
][COL_Y
], yuv2rgb
[ROW_B
][COL_Y
],
1417 yuv2rgb
[ROW_R
][COL_U
], yuv2rgb
[ROW_G
][COL_U
], yuv2rgb
[ROW_B
][COL_U
],
1418 yuv2rgb
[ROW_R
][COL_V
], yuv2rgb
[ROW_G
][COL_V
], yuv2rgb
[ROW_B
][COL_V
],
1419 yuv2rgb
[ROW_R
][COL_C
], yuv2rgb
[ROW_G
][COL_C
], yuv2rgb
[ROW_B
][COL_C
],
1420 conv_texs
[0], conv_texs
[0], conv_texs
[0]);
1422 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
1423 snprintf(prog_pos
, prog_remain
, yuv_lookup3d_prog_template
, conv_texs
[0]);
1426 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] unknown conversion type %i\n", YUV_CONVERSION(type
));
1429 mp_msg(MSGT_VO
, MSGL_DBG2
, "[gl] generated fragment program:\n%s\n", yuv_prog
);
1430 loadGPUProgram(GL_FRAGMENT_PROGRAM
, yuv_prog
);
1435 * \brief detect the best YUV->RGB conversion method available
1437 int glAutodetectYUVConversion(void) {
1438 const char *extensions
= mpglGetString(GL_EXTENSIONS
);
1439 if (!extensions
|| !mpglMultiTexCoord2f
)
1440 return YUV_CONVERSION_NONE
;
1441 if (strstr(extensions
, "GL_ARB_fragment_program"))
1442 return YUV_CONVERSION_FRAGMENT
;
1443 if (strstr(extensions
, "GL_ATI_text_fragment_shader"))
1444 return YUV_CONVERSION_TEXT_FRAGMENT
;
1445 if (strstr(extensions
, "GL_ATI_fragment_shader"))
1446 return YUV_CONVERSION_COMBINERS_ATI
;
1447 return YUV_CONVERSION_NONE
;
1451 * \brief setup YUV->RGB conversion
1452 * \param parms struct containing parameters like conversion and scaler type,
1454 * \ingroup glconversion
1456 void glSetupYUVConversion(gl_conversion_params_t
*params
) {
1457 float uvcos
= params
->csp_params
.saturation
* cos(params
->csp_params
.hue
);
1458 float uvsin
= params
->csp_params
.saturation
* sin(params
->csp_params
.hue
);
1459 if (params
->chrom_texw
== 0) params
->chrom_texw
= 1;
1460 if (params
->chrom_texh
== 0) params
->chrom_texh
= 1;
1461 switch (YUV_CONVERSION(params
->type
)) {
1462 case YUV_CONVERSION_COMBINERS
:
1463 glSetupYUVCombiners(uvcos
, uvsin
);
1465 case YUV_CONVERSION_COMBINERS_ATI
:
1466 glSetupYUVFragmentATI(¶ms
->csp_params
, 0);
1468 case YUV_CONVERSION_TEXT_FRAGMENT
:
1469 glSetupYUVFragmentATI(¶ms
->csp_params
, 1);
1471 case YUV_CONVERSION_FRAGMENT_LOOKUP
:
1472 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
1473 case YUV_CONVERSION_FRAGMENT
:
1474 case YUV_CONVERSION_FRAGMENT_POW
:
1475 glSetupYUVFragprog(params
);
1477 case YUV_CONVERSION_NONE
:
1480 mp_msg(MSGT_VO
, MSGL_ERR
, "[gl] unknown conversion type %i\n", YUV_CONVERSION(params
->type
));
1485 * \brief enable the specified YUV conversion
1486 * \param target texture target for Y, U and V textures (e.g. GL_TEXTURE_2D)
1487 * \param type type of YUV conversion
1488 * \ingroup glconversion
1490 void glEnableYUVConversion(GLenum target
, int type
) {
1491 switch (YUV_CONVERSION(type
)) {
1492 case YUV_CONVERSION_COMBINERS
:
1493 mpglActiveTexture(GL_TEXTURE1
);
1495 mpglActiveTexture(GL_TEXTURE2
);
1497 mpglActiveTexture(GL_TEXTURE0
);
1498 mpglEnable(GL_REGISTER_COMBINERS_NV
);
1500 case YUV_CONVERSION_COMBINERS_ATI
:
1501 mpglActiveTexture(GL_TEXTURE1
);
1503 mpglActiveTexture(GL_TEXTURE2
);
1505 mpglActiveTexture(GL_TEXTURE0
);
1506 mpglEnable(GL_FRAGMENT_SHADER_ATI
);
1508 case YUV_CONVERSION_TEXT_FRAGMENT
:
1509 mpglActiveTexture(GL_TEXTURE1
);
1511 mpglActiveTexture(GL_TEXTURE2
);
1513 mpglActiveTexture(GL_TEXTURE0
);
1514 mpglEnable(GL_TEXT_FRAGMENT_SHADER_ATI
);
1516 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
1517 case YUV_CONVERSION_FRAGMENT_LOOKUP
:
1518 case YUV_CONVERSION_FRAGMENT_POW
:
1519 case YUV_CONVERSION_FRAGMENT
:
1520 case YUV_CONVERSION_NONE
:
1521 mpglEnable(GL_FRAGMENT_PROGRAM
);
1527 * \brief disable the specified YUV conversion
1528 * \param target texture target for Y, U and V textures (e.g. GL_TEXTURE_2D)
1529 * \param type type of YUV conversion
1530 * \ingroup glconversion
1532 void glDisableYUVConversion(GLenum target
, int type
) {
1533 switch (YUV_CONVERSION(type
)) {
1534 case YUV_CONVERSION_COMBINERS
:
1535 mpglActiveTexture(GL_TEXTURE1
);
1536 mpglDisable(target
);
1537 mpglActiveTexture(GL_TEXTURE2
);
1538 mpglDisable(target
);
1539 mpglActiveTexture(GL_TEXTURE0
);
1540 mpglDisable(GL_REGISTER_COMBINERS_NV
);
1542 case YUV_CONVERSION_COMBINERS_ATI
:
1543 mpglActiveTexture(GL_TEXTURE1
);
1544 mpglDisable(target
);
1545 mpglActiveTexture(GL_TEXTURE2
);
1546 mpglDisable(target
);
1547 mpglActiveTexture(GL_TEXTURE0
);
1548 mpglDisable(GL_FRAGMENT_SHADER_ATI
);
1550 case YUV_CONVERSION_TEXT_FRAGMENT
:
1551 mpglDisable(GL_TEXT_FRAGMENT_SHADER_ATI
);
1552 // HACK: at least the Mac OS X 10.5 PPC Radeon drivers are broken and
1553 // without this disable the texture units while the program is still
1554 // running (10.4 PPC seems to work without this though).
1556 mpglActiveTexture(GL_TEXTURE1
);
1557 mpglDisable(target
);
1558 mpglActiveTexture(GL_TEXTURE2
);
1559 mpglDisable(target
);
1560 mpglActiveTexture(GL_TEXTURE0
);
1562 case YUV_CONVERSION_FRAGMENT_LOOKUP3D
:
1563 case YUV_CONVERSION_FRAGMENT_LOOKUP
:
1564 case YUV_CONVERSION_FRAGMENT_POW
:
1565 case YUV_CONVERSION_FRAGMENT
:
1566 case YUV_CONVERSION_NONE
:
1567 mpglDisable(GL_FRAGMENT_PROGRAM
);
1572 void glEnable3DLeft(int type
) {
1575 case GL_3D_RED_CYAN
:
1576 mpglColorMask(GL_TRUE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1578 case GL_3D_GREEN_MAGENTA
:
1579 mpglColorMask(GL_FALSE
, GL_TRUE
, GL_FALSE
, GL_FALSE
);
1581 case GL_3D_QUADBUFFER
:
1582 mpglGetIntegerv(GL_DRAW_BUFFER
, &buffer
);
1586 case GL_FRONT_RIGHT
:
1587 buffer
= GL_FRONT_LEFT
;
1592 buffer
= GL_BACK_LEFT
;
1595 mpglDrawBuffer(buffer
);
1600 void glEnable3DRight(int type
) {
1603 case GL_3D_RED_CYAN
:
1604 mpglColorMask(GL_FALSE
, GL_TRUE
, GL_TRUE
, GL_FALSE
);
1606 case GL_3D_GREEN_MAGENTA
:
1607 mpglColorMask(GL_TRUE
, GL_FALSE
, GL_TRUE
, GL_FALSE
);
1609 case GL_3D_QUADBUFFER
:
1610 mpglGetIntegerv(GL_DRAW_BUFFER
, &buffer
);
1614 case GL_FRONT_RIGHT
:
1615 buffer
= GL_FRONT_RIGHT
;
1620 buffer
= GL_BACK_RIGHT
;
1623 mpglDrawBuffer(buffer
);
1628 void glDisable3D(int type
) {
1631 case GL_3D_RED_CYAN
:
1632 case GL_3D_GREEN_MAGENTA
:
1633 mpglColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
1635 case GL_3D_QUADBUFFER
:
1636 mpglDrawBuffer(vo_doublebuffering
? GL_BACK
: GL_FRONT
);
1637 mpglGetIntegerv(GL_DRAW_BUFFER
, &buffer
);
1641 case GL_FRONT_RIGHT
:
1650 mpglDrawBuffer(buffer
);
1656 * \brief draw a texture part at given 2D coordinates
1657 * \param x screen top coordinate
1658 * \param y screen left coordinate
1659 * \param w screen width coordinate
1660 * \param h screen height coordinate
1661 * \param tx texture top coordinate in pixels
1662 * \param ty texture left coordinate in pixels
1663 * \param tw texture part width in pixels
1664 * \param th texture part height in pixels
1665 * \param sx width of texture in pixels
1666 * \param sy height of texture in pixels
1667 * \param rect_tex whether this texture uses texture_rectangle extension
1668 * \param is_yv12 if != 0, also draw the textures from units 1 and 2,
1669 * bits 8 - 15 and 16 - 23 specify the x and y scaling of those textures
1670 * \param flip flip the texture upside down
1671 * \ingroup gltexture
1673 void glDrawTex(GLfloat x
, GLfloat y
, GLfloat w
, GLfloat h
,
1674 GLfloat tx
, GLfloat ty
, GLfloat tw
, GLfloat th
,
1675 int sx
, int sy
, int rect_tex
, int is_yv12
, int flip
) {
1676 int chroma_x_shift
= (is_yv12
>> 8) & 31;
1677 int chroma_y_shift
= (is_yv12
>> 16) & 31;
1678 GLfloat xscale
= 1 << chroma_x_shift
;
1679 GLfloat yscale
= 1 << chroma_y_shift
;
1680 GLfloat tx2
= tx
/ xscale
, ty2
= ty
/ yscale
, tw2
= tw
/ xscale
, th2
= th
/ yscale
;
1682 tx
/= sx
; ty
/= sy
; tw
/= sx
; th
/= sy
;
1683 tx2
= tx
, ty2
= ty
, tw2
= tw
, th2
= th
;
1689 mpglBegin(GL_QUADS
);
1690 mpglTexCoord2f(tx
, ty
);
1692 mpglMultiTexCoord2f(GL_TEXTURE1
, tx2
, ty2
);
1693 mpglMultiTexCoord2f(GL_TEXTURE2
, tx2
, ty2
);
1696 mpglTexCoord2f(tx
, ty
+ th
);
1698 mpglMultiTexCoord2f(GL_TEXTURE1
, tx2
, ty2
+ th2
);
1699 mpglMultiTexCoord2f(GL_TEXTURE2
, tx2
, ty2
+ th2
);
1701 mpglVertex2f(x
, y
+ h
);
1702 mpglTexCoord2f(tx
+ tw
, ty
+ th
);
1704 mpglMultiTexCoord2f(GL_TEXTURE1
, tx2
+ tw2
, ty2
+ th2
);
1705 mpglMultiTexCoord2f(GL_TEXTURE2
, tx2
+ tw2
, ty2
+ th2
);
1707 mpglVertex2f(x
+ w
, y
+ h
);
1708 mpglTexCoord2f(tx
+ tw
, ty
);
1710 mpglMultiTexCoord2f(GL_TEXTURE1
, tx2
+ tw2
, ty2
);
1711 mpglMultiTexCoord2f(GL_TEXTURE2
, tx2
+ tw2
, ty2
);
1713 mpglVertex2f(x
+ w
, y
);
1717 #ifdef CONFIG_GL_WIN32
1718 #include "w32_common.h"
1720 * \brief little helper since wglGetProcAddress definition does not fit our
1722 * \param procName name of function to look up
1723 * \return function pointer returned by wglGetProcAddress
1725 static void *w32gpa(const GLubyte
*procName
) {
1727 void *res
= wglGetProcAddress(procName
);
1728 if (res
) return res
;
1729 oglmod
= GetModuleHandle("opengl32.dll");
1730 return GetProcAddress(oglmod
, procName
);
1733 static int setGlWindow_w32(MPGLContext
*ctx
)
1735 HWND win
= vo_w32_window
;
1736 int *vinfo
= &ctx
->vinfo
.w32
;
1737 HGLRC
*context
= &ctx
->context
.w32
;
1739 HDC windc
= vo_w32_get_dc(win
);
1740 HGLRC new_context
= 0;
1741 int keep_context
= 0;
1742 int res
= SET_WINDOW_FAILED
;
1744 // should only be needed when keeping context, but not doing glFinish
1745 // can cause flickering even when we do not keep it.
1748 new_vinfo
= GetPixelFormat(windc
);
1749 if (*context
&& *vinfo
&& new_vinfo
&& *vinfo
== new_vinfo
) {
1750 // we can keep the wglContext
1751 new_context
= *context
;
1755 new_context
= wglCreateContext(windc
);
1757 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] Could not create GL context!\n");
1763 if (!wglMakeCurrent(windc
, new_context
)) {
1764 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] Could not set GL context!\n");
1765 if (!keep_context
) {
1766 wglDeleteContext(new_context
);
1772 vo_w32_window
= win
;
1775 GetClientRect(win
, &rect
);
1776 vo_dwidth
= rect
.right
;
1777 vo_dheight
= rect
.bottom
;
1779 if (!keep_context
) {
1781 wglDeleteContext(*context
);
1782 *context
= new_context
;
1784 getFunctions(w32gpa
, NULL
);
1786 // and inform that reinit is neccessary
1787 res
= SET_WINDOW_REINIT
;
1789 res
= SET_WINDOW_OK
;
1792 vo_w32_release_dc(win
, windc
);
1796 static void releaseGlContext_w32(MPGLContext
*ctx
) {
1797 int *vinfo
= &ctx
->vinfo
.w32
;
1798 HGLRC
*context
= &ctx
->context
.w32
;
1801 wglMakeCurrent(0, 0);
1802 wglDeleteContext(*context
);
1807 static void swapGlBuffers_w32(MPGLContext
*ctx
) {
1808 HDC vo_hdc
= vo_w32_get_dc(vo_w32_window
);
1809 SwapBuffers(vo_hdc
);
1810 vo_w32_release_dc(vo_w32_window
, vo_hdc
);
1813 #ifdef CONFIG_GL_X11
1814 #include "x11_common.h"
1817 * \brief Returns the XVisualInfo associated with Window win.
1818 * \param win Window whose XVisualInfo is returne.
1819 * \return XVisualInfo of the window. Caller must use XFree to free it.
1821 static XVisualInfo
*getWindowVisualInfo(Window win
) {
1822 XWindowAttributes xw_attr
;
1823 XVisualInfo vinfo_template
;
1825 XGetWindowAttributes(mDisplay
, win
, &xw_attr
);
1826 vinfo_template
.visualid
= XVisualIDFromVisual(xw_attr
.visual
);
1827 return XGetVisualInfo(mDisplay
, VisualIDMask
, &vinfo_template
, &tmp
);
1830 static void appendstr(char **dst
, const char *str
)
1836 newsize
= strlen(*dst
) + 1 + strlen(str
) + 1;
1837 newstr
= realloc(*dst
, newsize
);
1846 * \brief Changes the window in which video is displayed.
1847 * If possible only transfers the context to the new window, otherwise
1848 * creates a new one, which must be initialized by the caller.
1849 * \param vinfo Currently used visual.
1850 * \param context Currently used context.
1851 * \param win window that should be used for drawing.
1852 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT.
1853 * In case of SET_WINDOW_REINIT the context could not be transfered
1854 * and the caller must initialize it correctly.
1855 * \ingroup glcontext
1857 static int setGlWindow_x11(MPGLContext
*ctx
)
1859 XVisualInfo
**vinfo
= &ctx
->vinfo
.x11
;
1860 GLXContext
*context
= &ctx
->context
.x11
;
1861 Window win
= vo_window
;
1862 XVisualInfo
*new_vinfo
;
1863 GLXContext new_context
= NULL
;
1864 int keep_context
= 0;
1866 // should only be needed when keeping context, but not doing glFinish
1867 // can cause flickering even when we do not keep it.
1870 new_vinfo
= getWindowVisualInfo(win
);
1871 if (*context
&& *vinfo
&& new_vinfo
&&
1872 (*vinfo
)->visualid
== new_vinfo
->visualid
) {
1873 // we can keep the GLXContext
1874 new_context
= *context
;
1880 new_context
= glXCreateContext(mDisplay
, new_vinfo
, NULL
, True
);
1882 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] Could not create GLX context!\n");
1884 return SET_WINDOW_FAILED
;
1889 if (!glXMakeCurrent(mDisplay
, vo_window
, new_context
)) {
1890 mp_msg(MSGT_VO
, MSGL_FATAL
, "[gl] Could not set GLX context!\n");
1891 if (!keep_context
) {
1892 glXDestroyContext(mDisplay
, new_context
);
1895 return SET_WINDOW_FAILED
;
1900 vo_x11_update_geometry();
1901 if (!keep_context
) {
1902 void *(*getProcAddress
)(const GLubyte
*);
1903 const char *(*glXExtStr
)(Display
*, int);
1904 char *glxstr
= strdup("");
1906 glXDestroyContext(mDisplay
, *context
);
1907 *context
= new_context
;
1911 getProcAddress
= getdladdr("glXGetProcAddress");
1912 if (!getProcAddress
)
1913 getProcAddress
= getdladdr("glXGetProcAddressARB");
1914 glXExtStr
= getdladdr("glXQueryExtensionsString");
1916 appendstr(&glxstr
, glXExtStr(mDisplay
, DefaultScreen(mDisplay
)));
1917 glXExtStr
= getdladdr("glXGetClientString");
1919 appendstr(&glxstr
, glXExtStr(mDisplay
, GLX_EXTENSIONS
));
1920 glXExtStr
= getdladdr("glXGetServerString");
1922 appendstr(&glxstr
, glXExtStr(mDisplay
, GLX_EXTENSIONS
));
1924 getFunctions(getProcAddress
, glxstr
);
1925 if (!mpglGenPrograms
&& mpglGetString
&&
1927 strstr(mpglGetString(GL_EXTENSIONS
), "GL_ARB_vertex_program")) {
1928 mp_msg(MSGT_VO
, MSGL_WARN
, "Broken glXGetProcAddress detected, trying workaround\n");
1929 getFunctions(NULL
, glxstr
);
1933 // and inform that reinit is neccessary
1934 return SET_WINDOW_REINIT
;
1936 return SET_WINDOW_OK
;
1940 * \brief free the VisualInfo and GLXContext of an OpenGL context.
1941 * \ingroup glcontext
1943 static void releaseGlContext_x11(MPGLContext
*ctx
) {
1944 XVisualInfo
**vinfo
= &ctx
->vinfo
.x11
;
1945 GLXContext
*context
= &ctx
->context
.x11
;
1952 glXMakeCurrent(mDisplay
, None
, NULL
);
1953 glXDestroyContext(mDisplay
, *context
);
1958 static void swapGlBuffers_x11(MPGLContext
*ctx
) {
1959 glXSwapBuffers(mDisplay
, vo_window
);
1962 static int x11_check_events(void) {
1963 return vo_x11_check_events(mDisplay
);
1966 static void gl_update_xinerama_info(void)
1968 update_xinerama_info(global_vo
);
1971 static void gl_border(void)
1976 static void gl_fullscreen(void)
1978 vo_x11_fullscreen();
1981 static void gl_ontop(void)
1987 #ifdef CONFIG_GL_SDL
1988 #include "sdl_common.h"
1990 static void swapGlBuffers_sdl(MPGLContext
*ctx
) {
1991 SDL_GL_SwapBuffers();
1994 static void *sdlgpa(const GLubyte
*name
) {
1995 return SDL_GL_GetProcAddress(name
);
1998 static int setGlWindow_sdl(MPGLContext
*ctx
) {
1999 if (sdl_set_mode(0, SDL_OPENGL
| SDL_RESIZABLE
) < 0)
2000 return SET_WINDOW_FAILED
;
2001 SDL_GL_LoadLibrary(NULL
);
2002 getFunctions(sdlgpa
, NULL
);
2003 return SET_WINDOW_OK
;
2006 static int sdl_check_events(void) {
2009 while (SDL_PollEvent(&event
)) {
2010 res
|= sdl_default_handle_event(&event
);
2012 // poll "events" from within MPlayer code
2013 res
|= sdl_default_handle_event(NULL
);
2014 if (res
& VO_EVENT_RESIZE
)
2015 sdl_set_mode(0, SDL_OPENGL
| SDL_RESIZABLE
);
2021 static int setGlWindow_dummy(MPGLContext
*ctx
) {
2022 getFunctions(NULL
, NULL
);
2023 return SET_WINDOW_OK
;
2026 static void releaseGlContext_dummy(MPGLContext
*ctx
) {
2029 static int dummy_check_events(void) {
2033 static void dummy_update_xinerama_info(void) {
2034 if (vo_screenwidth
<= 0 || vo_screenheight
<= 0) {
2035 mp_msg(MSGT_VO
, MSGL_ERR
, "You must specify the screen dimensions "
2036 "with -screenw and -screenh\n");
2037 vo_screenwidth
= 1280;
2038 vo_screenheight
= 768;
2040 aspect_save_screenres(vo_screenwidth
, vo_screenheight
);
2043 int init_mpglcontext(MPGLContext
*ctx
, enum MPGLType type
) {
2044 if (type
== GLTYPE_AUTO
) {
2045 int res
= init_mpglcontext(ctx
, GLTYPE_W32
);
2046 if (res
) return res
;
2047 res
= init_mpglcontext(ctx
, GLTYPE_X11
);
2048 if (res
) return res
;
2049 res
= init_mpglcontext(ctx
, GLTYPE_SDL
);
2052 memset(ctx
, 0, sizeof(*ctx
));
2053 ctx
->setGlWindow
= setGlWindow_dummy
;
2054 ctx
->releaseGlContext
= releaseGlContext_dummy
;
2055 ctx
->update_xinerama_info
= dummy_update_xinerama_info
;
2056 ctx
->check_events
= dummy_check_events
;
2058 switch (ctx
->type
) {
2059 #ifdef CONFIG_GL_WIN32
2061 ctx
->setGlWindow
= setGlWindow_w32
;
2062 ctx
->releaseGlContext
= releaseGlContext_w32
;
2063 ctx
->swapGlBuffers
= swapGlBuffers_w32
;
2064 ctx
->update_xinerama_info
= w32_update_xinerama_info
;
2065 ctx
->border
= vo_w32_border
;
2066 ctx
->check_events
= vo_w32_check_events
;
2067 ctx
->fullscreen
= vo_w32_fullscreen
;
2068 ctx
->ontop
= vo_w32_ontop
;
2069 return vo_w32_init();
2071 #ifdef CONFIG_GL_X11
2073 ctx
->setGlWindow
= setGlWindow_x11
;
2074 ctx
->releaseGlContext
= releaseGlContext_x11
;
2075 ctx
->swapGlBuffers
= swapGlBuffers_x11
;
2076 ctx
->update_xinerama_info
= gl_update_xinerama_info
;
2077 ctx
->border
= gl_border
;
2078 ctx
->check_events
= x11_check_events
;
2079 ctx
->fullscreen
= gl_fullscreen
;
2080 ctx
->ontop
= gl_ontop
;
2083 #ifdef CONFIG_GL_SDL
2085 SDL_Init(SDL_INIT_VIDEO
);
2086 ctx
->setGlWindow
= setGlWindow_sdl
;
2087 ctx
->swapGlBuffers
= swapGlBuffers_sdl
;
2088 ctx
->check_events
= sdl_check_events
;
2089 ctx
->fullscreen
= vo_sdl_fullscreen
;
2090 return vo_sdl_init();
2097 void uninit_mpglcontext(MPGLContext
*ctx
) {
2098 ctx
->releaseGlContext(ctx
);
2099 switch (ctx
->type
) {
2100 #ifdef CONFIG_GL_WIN32
2105 #ifdef CONFIG_GL_X11
2110 #ifdef CONFIG_GL_SDL
2116 memset(ctx
, 0, sizeof(*ctx
));