annotate libvo/gl_common.c @ 16582:cbd0ee58633b

texture units do not need to be explicitly enabled when using a fragment program.
author reimar
date Sun, 25 Sep 2005 13:56:42 +0000
parents 3191dcb27a12
children 26b156d7a68d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
1 /**
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
2 * Common OpenGL routines.
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
3 * Copyleft (C) Reimar Döffinger <Reimar.Doeffinger@stud.uni-karlsruhe.de>, 2005
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
4 * Licensend under the GNU GPL v2.
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
5 * Special thanks go to the xine team and Matthias Hopf, whose video_out_opengl.c
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
6 * gave me lots of good ideas.
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
7 */
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
8 #include <stdlib.h>
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
9 #include <stdio.h>
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
10 #include <string.h>
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
11 #include <math.h>
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
12 #include "gl_common.h"
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
13
16233
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
14 void (APIENTRY *GenBuffers)(GLsizei, GLuint *);
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
15 void (APIENTRY *DeleteBuffers)(GLsizei, const GLuint *);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
16 void (APIENTRY *BindBuffer)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
17 GLvoid* (APIENTRY *MapBuffer)(GLenum, GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
18 GLboolean (APIENTRY *UnmapBuffer)(GLenum);
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
19 void (APIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
20 void (APIENTRY *CombinerParameterfv)(GLenum, const GLfloat *);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
21 void (APIENTRY *CombinerParameteri)(GLenum, GLint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
22 void (APIENTRY *CombinerInput)(GLenum, GLenum, GLenum, GLenum, GLenum,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
23 GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
24 void (APIENTRY *CombinerOutput)(GLenum, GLenum, GLenum, GLenum, GLenum,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
25 GLenum, GLenum, GLboolean, GLboolean,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
26 GLboolean);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
27 void (APIENTRY *ActiveTexture)(GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
28 void (APIENTRY *BindTexture)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
29 void (APIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
30 void (APIENTRY *GenPrograms)(GLsizei, GLuint *);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
31 void (APIENTRY *DeletePrograms)(GLsizei, const GLuint *);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
32 void (APIENTRY *BindProgram)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
33 void (APIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
34 void (APIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
35 GLfloat, GLfloat);
16270
d5374d07492a Fix crash in windows
reimar
parents: 16268
diff changeset
36 int (APIENTRY *SwapInterval)(int);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
37
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
38 /**
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
39 * \brief adjusts the GL_UNPACK_ALGNMENT to fit the stride.
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
40 * \param stride number of bytes per line for which alignment should fit.
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
41 */
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
42 void glAdjustAlignment(int stride) {
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
43 GLint gl_alignment;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
44 if (stride % 8 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
45 gl_alignment=8;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
46 else if (stride % 4 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
47 gl_alignment=4;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
48 else if (stride % 2 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
49 gl_alignment=2;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
50 else
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
51 gl_alignment=1;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
52 glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment);
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
53 }
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
54
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
55 struct gl_name_map_struct {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
56 GLint value;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
57 char *name;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
58 };
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
59
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
60 #undef MAP
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
61 #define MAP(a) {a, #a}
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
62 static const struct gl_name_map_struct gl_name_map[] = {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
63 // internal format
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
64 MAP(GL_R3_G3_B2), MAP(GL_RGB4), MAP(GL_RGB5), MAP(GL_RGB8),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
65 MAP(GL_RGB10), MAP(GL_RGB12), MAP(GL_RGB16), MAP(GL_RGBA2),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
66 MAP(GL_RGBA4), MAP(GL_RGB5_A1), MAP(GL_RGBA8), MAP(GL_RGB10_A2),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
67 MAP(GL_RGBA12), MAP(GL_RGBA16), MAP(GL_LUMINANCE8),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
68
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
69 // format
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
70 MAP(GL_RGB), MAP(GL_RGBA), MAP(GL_RED), MAP(GL_GREEN), MAP(GL_BLUE),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
71 MAP(GL_ALPHA), MAP(GL_LUMINANCE), MAP(GL_LUMINANCE_ALPHA),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
72 MAP(GL_COLOR_INDEX),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
73 // rest 1.2 only
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
74 MAP(GL_BGR), MAP(GL_BGRA),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
75
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
76 //type
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
77 MAP(GL_BYTE), MAP(GL_UNSIGNED_BYTE), MAP(GL_SHORT), MAP(GL_UNSIGNED_SHORT),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
78 MAP(GL_INT), MAP(GL_UNSIGNED_INT), MAP(GL_FLOAT), MAP(GL_DOUBLE),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
79 MAP(GL_2_BYTES), MAP(GL_3_BYTES), MAP(GL_4_BYTES),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
80 // rest 1.2 only
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
81 MAP(GL_UNSIGNED_BYTE_3_3_2), MAP(GL_UNSIGNED_BYTE_2_3_3_REV),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
82 MAP(GL_UNSIGNED_SHORT_5_6_5), MAP(GL_UNSIGNED_SHORT_5_6_5_REV),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
83 MAP(GL_UNSIGNED_SHORT_4_4_4_4), MAP(GL_UNSIGNED_SHORT_4_4_4_4_REV),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
84 MAP(GL_UNSIGNED_SHORT_5_5_5_1), MAP(GL_UNSIGNED_SHORT_1_5_5_5_REV),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
85 MAP(GL_UNSIGNED_INT_8_8_8_8), MAP(GL_UNSIGNED_INT_8_8_8_8_REV),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
86 MAP(GL_UNSIGNED_INT_10_10_10_2), MAP(GL_UNSIGNED_INT_2_10_10_10_REV),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
87 {0, 0}
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
88 };
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
89 #undef MAP
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
90
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
91 /**
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
92 * \brief return the name of an OpenGL constant
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
93 * \param value the constant
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
94 * \return name of the constant or "Unknown format!"
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
95 */
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
96 const char *glValName(GLint value)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
97 {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
98 int i = 0;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
99
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
100 while (gl_name_map[i].name) {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
101 if (gl_name_map[i].value == value)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
102 return gl_name_map[i].name;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
103 i++;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
104 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
105 return "Unknown format!";
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
106 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
107
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
108 //! always return this format as internal texture format in glFindFormat
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
109 #define TEXTUREFORMAT_ALWAYS GL_RGB8
16474
01d27e023ae4 Improved glFindFormat
reimar
parents: 16461
diff changeset
110 #undef TEXTUREFORMAT_ALWAYS
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
111
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
112 /**
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
113 * \brief find the OpenGL settings coresponding to format.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
114 *
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
115 * All parameters may be NULL.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
116 * \param fmt MPlayer format to analyze.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
117 * \param bpp [OUT] bits per pixel of that format.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
118 * \param gl_texfmt [OUT] internal texture format that fits the
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
119 * image format, not necessarily the best for performance.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
120 * \param gl_format [OUT] OpenGL format for this image format.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
121 * \param gl_type [OUT] OpenGL type for this image format.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
122 * \return 1 if format is supported by OpenGL, 0 if not.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
123 */
16303
a87c6cf3fe52 Fix texture format variable types. Internal format is GLint, others are GLenum
reimar
parents: 16270
diff changeset
124 int glFindFormat(uint32_t fmt, uint32_t *bpp, GLint *gl_texfmt,
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
125 GLenum *gl_format, GLenum *gl_type)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
126 {
16474
01d27e023ae4 Improved glFindFormat
reimar
parents: 16461
diff changeset
127 int supported = 1;
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
128 int dummy1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
129 GLenum dummy2;
16303
a87c6cf3fe52 Fix texture format variable types. Internal format is GLint, others are GLenum
reimar
parents: 16270
diff changeset
130 GLint dummy3;
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
131 if (bpp == NULL) bpp = &dummy1;
16303
a87c6cf3fe52 Fix texture format variable types. Internal format is GLint, others are GLenum
reimar
parents: 16270
diff changeset
132 if (gl_texfmt == NULL) gl_texfmt = &dummy3;
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
133 if (gl_format == NULL) gl_format = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
134 if (gl_type == NULL) gl_type = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
135
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
136 *bpp = IMGFMT_IS_BGR(fmt)?IMGFMT_BGR_DEPTH(fmt):IMGFMT_RGB_DEPTH(fmt);
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
137 *gl_texfmt = 3;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
138 switch (fmt) {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
139 case IMGFMT_RGB24:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
140 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
141 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
142 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
143 case IMGFMT_RGBA:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
144 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
145 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
146 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
147 break;
16474
01d27e023ae4 Improved glFindFormat
reimar
parents: 16461
diff changeset
148 case IMGFMT_YV12:
01d27e023ae4 Improved glFindFormat
reimar
parents: 16461
diff changeset
149 supported = 0; // no native YV12 support
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
150 case IMGFMT_Y800:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
151 case IMGFMT_Y8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
152 *gl_texfmt = 1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
153 *bpp = 8;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
154 *gl_format = GL_LUMINANCE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
155 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
156 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
157 #if 0
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
158 // we do not support palettized formats, although the format the
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
159 // swscale produces works
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
160 case IMGFMT_RGB8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
161 gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
162 gl_type = GL_UNSIGNED_BYTE_2_3_3_REV;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
163 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
164 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
165 case IMGFMT_RGB15:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
166 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
167 *gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
168 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
169 case IMGFMT_RGB16:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
170 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
171 *gl_type = GL_UNSIGNED_SHORT_5_6_5_REV;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
172 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
173 #if 0
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
174 case IMGFMT_BGR8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
175 // special case as red and blue have a differen number of bits.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
176 // GL_BGR and GL_UNSIGNED_BYTE_3_3_2 isn't supported at least
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
177 // by nVidia drivers, and in addition would give more bits to
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
178 // blue than to red, which isn't wanted
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
179 gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
180 gl_type = GL_UNSIGNED_BYTE_3_3_2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
181 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
182 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
183 case IMGFMT_BGR15:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
184 *gl_format = GL_BGRA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
185 *gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
186 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
187 case IMGFMT_BGR16:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
188 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
189 *gl_type = GL_UNSIGNED_SHORT_5_6_5;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
190 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
191 case IMGFMT_BGR24:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
192 *gl_format = GL_BGR;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
193 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
194 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
195 case IMGFMT_BGRA:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
196 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
197 *gl_format = GL_BGRA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
198 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
199 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
200 default:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
201 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
202 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
203 *gl_type = GL_UNSIGNED_BYTE;
16474
01d27e023ae4 Improved glFindFormat
reimar
parents: 16461
diff changeset
204 supported = 0;
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
205 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
206 #ifdef TEXTUREFORMAT_ALWAYS
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
207 *gl_texfmt = TEXTUREFORMAT_ALWAYS;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
208 #endif
16474
01d27e023ae4 Improved glFindFormat
reimar
parents: 16461
diff changeset
209 return supported;
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
210 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
211
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
212 static void *setNull(const GLubyte *s) {
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
213 return NULL;
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
214 }
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
215
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
216 static void *(*getProcAddress)(const GLubyte *procName) = NULL;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
217
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
218 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
219 * \brief find the function pointers of some useful OpenGL extensions
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
220 */
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
221 static void getFunctions() {
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
222 if (!getProcAddress)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
223 getProcAddress = setNull;
16233
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
224 GenBuffers = getProcAddress("glGenBuffers");
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
225 if (!GenBuffers)
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
226 GenBuffers = getProcAddress("glGenBuffersARB");
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
227 DeleteBuffers = getProcAddress("glDeleteBuffers");
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
228 if (!DeleteBuffers)
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
229 DeleteBuffers = getProcAddress("glDeleteBuffersARB");
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
230 BindBuffer = getProcAddress("glBindBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
231 if (!BindBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
232 BindBuffer = getProcAddress("glBindBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
233 MapBuffer = getProcAddress("glMapBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
234 if (!MapBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
235 MapBuffer = getProcAddress("glMapBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
236 UnmapBuffer = getProcAddress("glUnmapBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
237 if (!UnmapBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
238 UnmapBuffer = getProcAddress("glUnmapBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
239 BufferData = getProcAddress("glBufferData");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
240 if (!BufferData)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
241 BufferData = getProcAddress("glBufferDataARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
242 CombinerParameterfv = getProcAddress("glCombinerParameterfv");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
243 if (!CombinerParameterfv)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
244 CombinerParameterfv = getProcAddress("glCombinerParameterfvNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
245 CombinerParameteri = getProcAddress("glCombinerParameteri");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
246 if (!CombinerParameteri)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
247 CombinerParameteri = getProcAddress("glCombinerParameteriNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
248 CombinerInput = getProcAddress("glCombinerInput");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
249 if (!CombinerInput)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
250 CombinerInput = getProcAddress("glCombinerInputNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
251 CombinerOutput = getProcAddress("glCombinerOutput");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
252 if (!CombinerOutput)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
253 CombinerOutput = getProcAddress("glCombinerOutputNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
254 ActiveTexture = getProcAddress("glActiveTexture");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
255 if (!ActiveTexture)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
256 ActiveTexture = getProcAddress("glActiveTextureARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
257 BindTexture = getProcAddress("glBindTexture");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
258 if (!BindTexture)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
259 BindTexture = getProcAddress("glBindTextureARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
260 MultiTexCoord2f = getProcAddress("glMultiTexCoord2f");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
261 if (!MultiTexCoord2f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
262 MultiTexCoord2f = getProcAddress("glMultiTexCoord2fARB");
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
263 GenPrograms = getProcAddress("glGenPrograms");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
264 if (!GenPrograms)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
265 GenPrograms = getProcAddress("glGenProgramsARB");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
266 if (!GenPrograms)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
267 GenPrograms = getProcAddress("glGenProgramsNV");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
268 DeletePrograms = getProcAddress("glDeletePrograms");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
269 if (!DeletePrograms)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
270 DeletePrograms = getProcAddress("glDeleteProgramsARB");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
271 if (!DeletePrograms)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
272 DeletePrograms = getProcAddress("glDeleteProgramsNV");
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
273 BindProgram = getProcAddress("glBindProgram");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
274 if (!BindProgram)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
275 BindProgram = getProcAddress("glBindProgramARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
276 if (!BindProgram)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
277 BindProgram = getProcAddress("glBindProgramNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
278 ProgramString = getProcAddress("glProgramString");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
279 if (!ProgramString)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
280 ProgramString = getProcAddress("glProgramStringARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
281 if (!ProgramString)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
282 ProgramString = getProcAddress("glProgramStringNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
283 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4f");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
284 if (!ProgramEnvParameter4f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
285 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4fARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
286 if (!ProgramEnvParameter4f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
287 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4fNV");
16268
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
288 SwapInterval = getProcAddress("glXSwapInterval");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
289 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
290 SwapInterval = getProcAddress("glXSwapIntervalEXT");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
291 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
292 SwapInterval = getProcAddress("glXSwapIntervalSGI");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
293 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
294 SwapInterval = getProcAddress("wglSwapInterval");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
295 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
296 SwapInterval = getProcAddress("wglSwapIntervalEXT");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
297 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
298 SwapInterval = getProcAddress("wglSwapIntervalSGI");
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
299 }
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
300
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
301 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
302 * \brief create a texture and set some defaults
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
303 * \param target texture taget, usually GL_TEXTURE_2D
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
304 * \param fmt internal texture format
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
305 * \param filter filter used for scaling, e.g. GL_LINEAR
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
306 * \param w texture width
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
307 * \param h texture height
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
308 * \param val luminance value to fill texture with
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
309 */
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
310 void glCreateClearTex(GLenum target, GLenum fmt, GLint filter,
16460
ec7036dedee4 Fix border color (forgot to divide by 255.0).
reimar
parents: 16437
diff changeset
311 int w, int h, unsigned char val) {
ec7036dedee4 Fix border color (forgot to divide by 255.0).
reimar
parents: 16437
diff changeset
312 GLfloat fval = (GLfloat)val / 255.0;
ec7036dedee4 Fix border color (forgot to divide by 255.0).
reimar
parents: 16437
diff changeset
313 GLfloat border[4] = {fval, fval, fval, fval};
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
314 GLenum clrfmt = (fmt == GL_ALPHA) ? GL_ALPHA : GL_LUMINANCE;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
315 char *init = (char *)malloc(w * h);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
316 memset(init, val, w * h);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
317 glAdjustAlignment(w);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
318 glPixelStorei(GL_UNPACK_ROW_LENGTH, w);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
319 glTexImage2D(target, 0, fmt, w, h, 0, clrfmt, GL_UNSIGNED_BYTE, init);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
320 glTexParameterf(target, GL_TEXTURE_PRIORITY, 1.0);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
321 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
322 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
16461
f93eaa5ad64d Use GL_CLAMP_TO_EDGE instead of GL_CLAMP to avoid border texels being sampled.
reimar
parents: 16460
diff changeset
323 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
f93eaa5ad64d Use GL_CLAMP_TO_EDGE instead of GL_CLAMP to avoid border texels being sampled.
reimar
parents: 16460
diff changeset
324 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
f93eaa5ad64d Use GL_CLAMP_TO_EDGE instead of GL_CLAMP to avoid border texels being sampled.
reimar
parents: 16460
diff changeset
325 // Border texels should not be used with CLAMP_TO_EDGE
f93eaa5ad64d Use GL_CLAMP_TO_EDGE instead of GL_CLAMP to avoid border texels being sampled.
reimar
parents: 16460
diff changeset
326 // We set a sane default anyway.
16437
9dda08ef3e7c Set texture border color to avoid weird border colors in some rare cases.
reimar
parents: 16435
diff changeset
327 glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, border);
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
328 free(init);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
329 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
330
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
331 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
332 * \brief return the number of bytes oer pixel for the given format
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
333 * \param format OpenGL format
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
334 * \param type OpenGL type
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
335 * \return bytes per pixel
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
336 *
16435
b5ca0e5760d0 Fix a typo in a comment
reimar
parents: 16303
diff changeset
337 * Does not handle all possible variants, just those used by MPlayer
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
338 */
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
339 int glFmt2bpp(GLenum format, GLenum type) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
340 switch (type) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
341 case GL_UNSIGNED_BYTE_3_3_2:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
342 case GL_UNSIGNED_BYTE_2_3_3_REV:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
343 return 1;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
344 case GL_UNSIGNED_SHORT_5_5_5_1:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
345 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
346 case GL_UNSIGNED_SHORT_5_6_5:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
347 case GL_UNSIGNED_SHORT_5_6_5_REV:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
348 return 2;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
349 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
350 if (type != GL_UNSIGNED_BYTE)
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
351 return 0; //not implemented
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
352 switch (format) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
353 case GL_LUMINANCE:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
354 case GL_ALPHA:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
355 return 1;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
356 case GL_RGB:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
357 case GL_BGR:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
358 return 3;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
359 case GL_RGBA:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
360 case GL_BGRA:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
361 return 4;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
362 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
363 return 0; // unkown
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
364 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
365
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
366 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
367 * \brief upload a texture, handling things like stride and slices
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
368 * \param target texture target, usually GL_TEXTURE_2D
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
369 * \param format OpenGL format of data
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
370 * \param type OpenGL type of data
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
371 * \param data data to upload
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
372 * \param stride data stride
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
373 * \param x x offset in texture
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
374 * \param y y offset in texture
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
375 * \param w width of the texture part to upload
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
376 * \param h height of the texture part to upload
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
377 * \param slice height of an upload slice, 0 for all at once
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
378 */
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
379 void glUploadTex(GLenum target, GLenum format, GLenum type,
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
380 const char *data, int stride,
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
381 int x, int y, int w, int h, int slice) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
382 int y_max = y + h;
16223
f540609340ac extra check for glUploadTex to avoid a possible hang.
reimar
parents: 16221
diff changeset
383 if (w <= 0 || h <= 0) return;
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
384 if (slice <= 0)
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
385 slice = h;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
386 // this is not always correct, but should work for MPlayer
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
387 glAdjustAlignment(stride);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
388 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / glFmt2bpp(format, type));
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
389 for (; y + slice <= y_max; y += slice) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
390 glTexSubImage2D(target, 0, x, y, w, slice, format, type, data);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
391 data += stride * slice;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
392 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
393 if (y < y_max)
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
394 glTexSubImage2D(target, 0, x, y, w, y_max - y, format, type, data);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
395 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
396
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
397 /**
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
398 * \brief Setup register combiners for YUV to RGB conversion.
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
399 * \param uvcos used for saturation and hue adjustment
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
400 * \param uvsin used for saturation and hue adjustment
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
401 */
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
402 static void glSetupYUVCombiners(float uvcos, float uvsin) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
403 GLfloat ucoef[4];
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
404 GLfloat vcoef[4];
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
405 GLint i;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
406 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
407 if (i < 2)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
408 mp_msg(MSGT_VO, MSGL_ERR,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
409 "[gl] 2 general combiners needed for YUV combiner support (found %i)\n", i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
410 glGetIntegerv (GL_MAX_TEXTURE_UNITS, &i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
411 if (i < 3)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
412 mp_msg(MSGT_VO, MSGL_ERR,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
413 "[gl] 3 texture units needed for YUV combiner support (found %i)\n", i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
414 if (!CombinerInput || !CombinerOutput ||
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
415 !CombinerParameterfv || !CombinerParameteri) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
416 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Combiner functions missing!\n");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
417 return;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
418 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
419 ucoef[0] = 0 * uvcos + 1.403 * uvsin;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
420 vcoef[0] = 0 * uvsin + 1.403 * uvcos;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
421 ucoef[1] = -0.344 * uvcos + -0.714 * uvsin;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
422 vcoef[1] = -0.344 * uvsin + -0.714 * uvcos;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
423 ucoef[2] = 1.770 * uvcos + 0 * uvsin;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
424 vcoef[2] = 1.770 * uvsin + 0 * uvcos;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
425 ucoef[3] = 0;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
426 vcoef[3] = 0;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
427 // Coefficients (probably) must be in [0, 1] range, whereas they originally
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
428 // are in [-2, 2] range, so here comes the trick:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
429 // First put them in the [-0.5, 0.5] range, then add 0.5.
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
430 // This can be undone with the HALF_BIAS and SCALE_BY_FOUR arguments
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
431 // for CombinerInput and CombinerOutput
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
432 for (i = 0; i < 4; i++) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
433 ucoef[i] = ucoef[i] * 0.25 + 0.5;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
434 vcoef[i] = vcoef[i] * 0.25 + 0.5;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
435 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
436 CombinerParameterfv(GL_CONSTANT_COLOR0_NV, ucoef);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
437 CombinerParameterfv(GL_CONSTANT_COLOR1_NV, vcoef);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
438
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
439 // UV first, like this green component cannot overflow
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
440 CombinerInput(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_A_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
441 GL_TEXTURE1, GL_HALF_BIAS_NORMAL_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
442 CombinerInput(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_B_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
443 GL_CONSTANT_COLOR0_NV, GL_HALF_BIAS_NORMAL_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
444 CombinerInput(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_C_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
445 GL_TEXTURE2, GL_HALF_BIAS_NORMAL_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
446 CombinerInput(GL_COMBINER0_NV, GL_RGB, GL_VARIABLE_D_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
447 GL_CONSTANT_COLOR1_NV, GL_HALF_BIAS_NORMAL_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
448 CombinerOutput(GL_COMBINER0_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
449 GL_SPARE0_NV, GL_SCALE_BY_FOUR_NV, GL_NONE, GL_FALSE,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
450 GL_FALSE, GL_FALSE);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
451
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
452 // stage 2
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
453 CombinerInput(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_A_NV, GL_SPARE0_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
454 GL_SIGNED_IDENTITY_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
455 CombinerInput(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_B_NV, GL_ZERO,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
456 GL_UNSIGNED_INVERT_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
457 CombinerInput(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_C_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
458 GL_TEXTURE0, GL_SIGNED_IDENTITY_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
459 CombinerInput(GL_COMBINER1_NV, GL_RGB, GL_VARIABLE_D_NV, GL_ZERO,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
460 GL_UNSIGNED_INVERT_NV, GL_RGB);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
461 CombinerOutput(GL_COMBINER1_NV, GL_RGB, GL_DISCARD_NV, GL_DISCARD_NV,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
462 GL_SPARE0_NV, GL_NONE, GL_NONE, GL_FALSE,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
463 GL_FALSE, GL_FALSE);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
464
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
465 // leave final combiner stage in default mode
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
466 CombinerParameteri(GL_NUM_GENERAL_COMBINERS_NV, 2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
467 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
468
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
469 static const char *yuv_prog_template =
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
470 "!!ARBfp1.0\n"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
471 "TEMP res, y, u, v;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
472 "TEX y, fragment.texcoord[0], texture[0], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
473 "MAD res, y, {%.4f, %.4f, %.4f}, {%.4f, %.4f, %.4f};"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
474 "TEX u, fragment.texcoord[1], texture[1], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
475 "MAD res, u, {%.4f, %.4f, %.4f}, res;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
476 "TEX v, fragment.texcoord[2], texture[2], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
477 "MAD result.color, v, {%.4f, %.4f, %.4f}, res;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
478 "END";
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
479
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
480 static const char *yuv_pow_prog_template =
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
481 "!!ARBfp1.0\n"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
482 "TEMP res, y, u, v;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
483 "TEX y, fragment.texcoord[0], texture[0], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
484 "MAD res, y, {%.4f, %.4f, %.4f}, {%.4f, %.4f, %.4f};"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
485 "TEX u, fragment.texcoord[1], texture[1], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
486 "MAD res, u, {%.4f, %.4f, %.4f}, res;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
487 "TEX v, fragment.texcoord[2], texture[2], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
488 "MAD_SAT res, v, {%.4f, %.4f, %.4f}, res;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
489 "POW result.color.r, res.r, %.4f.r;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
490 "POW result.color.g, res.g, %.4f.g;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
491 "POW result.color.b, res.b, %.4f.b;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
492 "END";
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
493
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
494 static const char *yuv_lookup_prog_template =
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
495 "!!ARBfp1.0\n"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
496 "TEMP res, y, u, v;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
497 "TEX y, fragment.texcoord[0], texture[0], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
498 "MAD res, y, {%.4f, %.4f, %.4f, 0}, {%.4f, %.4f, %.4f, 0};"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
499 "TEX u, fragment.texcoord[1], texture[1], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
500 "MAD res, u, {%.4f, %.4f, %.4f, 0}, res;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
501 "TEX v, fragment.texcoord[2], texture[2], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
502 "MAD res, v, {%.4f, %.4f, %.4f, 0}, res;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
503 "ADD res.a, res.a, 0.125;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
504 "TEX result.color.r, res.raaa, texture[3], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
505 "ADD res.a, res.a, 0.25;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
506 "TEX result.color.g, res.gaaa, texture[3], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
507 "ADD res.a, res.a, 0.25;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
508 "TEX result.color.b, res.baaa, texture[3], 2D;"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
509 "END";
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
510
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
511 /**
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
512 * \brief setup a fragment program that will do YUV->RGB conversion
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
513 * \param brightness brightness adjustment offset
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
514 * \param contrast contrast adjustment factor
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
515 * \param uvcos used for saturation and hue adjustment
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
516 * \param uvsin used for saturation and hue adjustment
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
517 * \param lookup use fragment program that uses texture unit 4 to
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
518 * do additional conversion via lookup.
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
519 */
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
520 static void glSetupYUVFragprog(float brightness, float contrast,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
521 float uvcos, float uvsin, float rgamma,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
522 float ggamma, float bgamma, int type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
523 char yuv_prog[1000];
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
524 const char *prog_template = yuv_prog_template;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
525 int lookup = 0;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
526 GLint i;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
527 // this is the conversion matrix, with y, u, v factors
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
528 // for red, green, blue and the constant offsets
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
529 float ry, ru, rv, rc;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
530 float gy, gu, gv, gc;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
531 float by, bu, bv, bc;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
532 switch (type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
533 case YUV_CONVERSION_FRAGMENT_POW:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
534 prog_template = yuv_pow_prog_template;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
535 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
536 case YUV_CONVERSION_FRAGMENT_LOOKUP:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
537 prog_template = yuv_lookup_prog_template;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
538 lookup = 1;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
539 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
540 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
541 glGetIntegerv (GL_MAX_TEXTURE_UNITS, &i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
542 if (i < 3)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
543 mp_msg(MSGT_VO, MSGL_ERR,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
544 "[gl] 3 texture units needed for YUV fragment support (found %i)\n", i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
545 if (lookup && i < 4)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
546 mp_msg(MSGT_VO, MSGL_ERR,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
547 "[gl] 4 texture units needed for YUV fragment support with lookup (found %i)\n", i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
548 if (!ProgramString) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
549 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] ProgramString function missing!\n");
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
550 return;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
551 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
552 ry = 1.164 * contrast;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
553 gy = 1.164 * contrast;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
554 by = 1.164 * contrast;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
555 ru = 0 * uvcos + 1.596 * uvsin;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
556 rv = 0 * uvsin + 1.596 * uvcos;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
557 gu = -0.391 * uvcos + -0.813 * uvsin;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
558 gv = -0.391 * uvsin + -0.813 * uvcos;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
559 bu = 2.018 * uvcos + 0 * uvsin;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
560 bv = 2.018 * uvsin + 0 * uvcos;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
561 rc = (-16 * ry + (-128) * ru + (-128) * rv) / 255.0 + brightness;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
562 gc = (-16 * gy + (-128) * gu + (-128) * gv) / 255.0 + brightness;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
563 bc = (-16 * by + (-128) * bu + (-128) * bv) / 255.0 + brightness;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
564 rgamma = 1.0 / rgamma;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
565 ggamma = 1.0 / ggamma;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
566 bgamma = 1.0 / bgamma;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
567 snprintf(yuv_prog, 1000, prog_template, ry, gy, by, rc, gc, bc, ru, gu, bu,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
568 rv, gv, bv, rgamma, bgamma, bgamma);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
569 ProgramString(GL_FRAGMENT_PROGRAM, GL_PROGRAM_FORMAT_ASCII,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
570 strlen(yuv_prog), yuv_prog);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
571 glGetIntegerv(GL_PROGRAM_ERROR_POSITION, &i);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
572 if (i != -1)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
573 mp_msg(MSGT_VO, MSGL_ERR,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
574 "[gl] Error compiling fragment program, make sure your card supports\n"
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
575 "GL_ARB_fragment_program (use glxinfo to check).%.10s\n", &yuv_prog[i]);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
576 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
577
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
578 /**
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
579 * \brief little helper function to create a lookup table for gamma
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
580 * \param map buffer to create map into
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
581 * \param size size of buffer
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
582 * \param gamma gamma value
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
583 */
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
584 static void gen_gamma_map(unsigned char *map, int size, float gamma) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
585 int i;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
586 gamma = 1.0 / gamma;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
587 for (i = 0; i < size; i++) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
588 float tmp = (float)i / (size - 1.0);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
589 tmp = pow(tmp, gamma);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
590 if (tmp > 1.0) tmp = 1.0;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
591 if (tmp < 0.0) tmp = 0.0;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
592 map[i] = 255 * tmp;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
593 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
594 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
595
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
596 //! resolution of texture for gamma lookup table
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
597 #define LOOKUP_RES 512
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
598
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
599 /**
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
600 * \brief setup YUV->RGB conversion
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
601 * \param brightness brightness adjustment offset
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
602 * \param contrast contrast adjustment factor
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
603 * \param hue hue adjustment angle
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
604 * \param saturation saturation adjustment factor
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
605 * \param rgamma gamma value for red channel
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
606 * \param ggamma gamma value for green channel
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
607 * \param bgamma gamma value for blue channel
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
608 * \param type YUV conversion type
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
609 */
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
610 void glSetupYUVConversion(int type, float brightness, float contrast,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
611 float hue, float saturation,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
612 float rgamma, float ggamma, float bgamma) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
613 float uvcos = saturation * cos(hue);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
614 float uvsin = saturation * sin(hue);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
615 switch (type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
616 case YUV_CONVERSION_COMBINERS:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
617 glSetupYUVCombiners(uvcos, uvsin);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
618 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
619 case YUV_CONVERSION_FRAGMENT_LOOKUP:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
620 {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
621 unsigned char lookup_data[4 * LOOKUP_RES];
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
622 gen_gamma_map(lookup_data, LOOKUP_RES, rgamma);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
623 gen_gamma_map(&lookup_data[LOOKUP_RES], LOOKUP_RES, ggamma);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
624 gen_gamma_map(&lookup_data[2 * LOOKUP_RES], LOOKUP_RES, bgamma);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
625 ActiveTexture(GL_TEXTURE3);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
626 glCreateClearTex(GL_TEXTURE_2D, GL_LUMINANCE8, GL_LINEAR,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
627 LOOKUP_RES, 4, 0);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
628 glUploadTex(GL_TEXTURE_2D, GL_LUMINANCE, GL_UNSIGNED_BYTE, lookup_data,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
629 LOOKUP_RES, 0, 0, LOOKUP_RES, 4, 0);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
630 ActiveTexture(GL_TEXTURE0);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
631 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
632 case YUV_CONVERSION_FRAGMENT:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
633 case YUV_CONVERSION_FRAGMENT_POW:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
634 glSetupYUVFragprog(brightness, contrast, uvcos, uvsin,
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
635 rgamma, ggamma, bgamma, type);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
636 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
637 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
638 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
639
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
640 /**
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
641 * \brief enable the specified YUV conversion
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
642 * \param target texture target for Y, U and V textures (e.g. GL_TEXTURE_2D)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
643 * \param type type of YUV conversion
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
644 */
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
645 void inline glEnableYUVConversion(GLenum target, int type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
646 if (type <= 0) return;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
647 switch (type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
648 case YUV_CONVERSION_COMBINERS:
16582
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
649 ActiveTexture(GL_TEXTURE1);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
650 glEnable(target);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
651 ActiveTexture(GL_TEXTURE2);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
652 glEnable(target);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
653 ActiveTexture(GL_TEXTURE0);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
654 glEnable(GL_REGISTER_COMBINERS_NV);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
655 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
656 case YUV_CONVERSION_FRAGMENT_LOOKUP:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
657 case YUV_CONVERSION_FRAGMENT_POW:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
658 case YUV_CONVERSION_FRAGMENT:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
659 glEnable(GL_FRAGMENT_PROGRAM);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
660 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
661 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
662 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
663
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
664 /**
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
665 * \brief disable the specified YUV conversion
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
666 * \param target texture target for Y, U and V textures (e.g. GL_TEXTURE_2D)
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
667 * \param type type of YUV conversion
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
668 */
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
669 void inline glDisableYUVConversion(GLenum target, int type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
670 if (type <= 0) return;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
671 switch (type) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
672 case YUV_CONVERSION_COMBINERS:
16582
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
673 ActiveTexture(GL_TEXTURE1);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
674 glDisable(target);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
675 ActiveTexture(GL_TEXTURE2);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
676 glDisable(target);
cbd0ee58633b texture units do not need to be explicitly enabled when using a fragment
reimar
parents: 16488
diff changeset
677 ActiveTexture(GL_TEXTURE0);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
678 glDisable(GL_REGISTER_COMBINERS_NV);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
679 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
680 case YUV_CONVERSION_FRAGMENT_LOOKUP:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
681 case YUV_CONVERSION_FRAGMENT_POW:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
682 case YUV_CONVERSION_FRAGMENT:
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
683 glDisable(GL_FRAGMENT_PROGRAM);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
684 break;
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
685 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
686 }
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
687
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
688 /**
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
689 * \brief draw a texture part at given 2D coordinates
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
690 * \param x screen top coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
691 * \param y screen left coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
692 * \param w screen width coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
693 * \param h screen height coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
694 * \param tx texture top coordinate in pixels
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
695 * \param ty texture left coordinate in pixels
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
696 * \param tw texture part width in pixels
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
697 * \param th texture part height in pixels
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
698 * \param sx width of texture in pixels
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
699 * \param sy height of texture in pixels
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
700 * \param rect_tex whether this texture uses texture_rectangle extension
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
701 * \param is_yv12 if set, also draw the textures from units 1 and 2
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
702 */
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
703 void glDrawTex(GLfloat x, GLfloat y, GLfloat w, GLfloat h,
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
704 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
705 int sx, int sy, int rect_tex, int is_yv12) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
706 GLfloat tx2 = tx / 2, ty2 = ty / 2, tw2 = tw / 2, th2 = th / 2;
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
707 if (!rect_tex) {
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
708 tx /= sx; ty /= sy; tw /= sx; th /= sy;
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
709 tx2 = tx, ty2 = ty, tw2 = tw, th2 = th;
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
710 }
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
711 glBegin(GL_QUADS);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
712 glTexCoord2f(tx, ty);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
713 if (is_yv12) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
714 MultiTexCoord2f(GL_TEXTURE1, tx2, ty2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
715 MultiTexCoord2f(GL_TEXTURE2, tx2, ty2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
716 }
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
717 glVertex2f(x, y);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
718 glTexCoord2f(tx, ty + th);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
719 if (is_yv12) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
720 MultiTexCoord2f(GL_TEXTURE1, tx2, ty2 + th2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
721 MultiTexCoord2f(GL_TEXTURE2, tx2, ty2 + th2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
722 }
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
723 glVertex2f(x, y + h);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
724 glTexCoord2f(tx + tw, ty + th);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
725 if (is_yv12) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
726 MultiTexCoord2f(GL_TEXTURE1, tx2 + tw2, ty2 + th2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
727 MultiTexCoord2f(GL_TEXTURE2, tx2 + tw2, ty2 + th2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
728 }
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
729 glVertex2f(x + w, y + h);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
730 glTexCoord2f(tx + tw, ty);
16488
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
731 if (is_yv12) {
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
732 MultiTexCoord2f(GL_TEXTURE1, tx2 + tw2, ty2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
733 MultiTexCoord2f(GL_TEXTURE2, tx2 + tw2, ty2);
3191dcb27a12 hardware color-space conversion for vo_gl and vo_gl2
reimar
parents: 16474
diff changeset
734 }
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
735 glVertex2f(x + w, y);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
736 glEnd();
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
737 }
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
738
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
739 #ifdef GL_WIN32
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
740 static void *w32gpa(const GLubyte *procName) {
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
741 return wglGetProcAddress(procName);
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
742 }
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
743
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
744 int setGlWindow(int *vinfo, HGLRC *context, HWND win)
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
745 {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
746 int new_vinfo;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
747 HDC windc = GetDC(win);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
748 HGLRC new_context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
749 int keep_context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
750
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
751 // should only be needed when keeping context, but not doing glFinish
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
752 // can cause flickering even when we do not keep it.
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
753 glFinish();
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
754 new_vinfo = GetPixelFormat(windc);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
755 if (*context && *vinfo && new_vinfo && *vinfo == new_vinfo) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
756 // we can keep the wglContext
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
757 new_context = *context;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
758 keep_context = 1;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
759 } else {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
760 // create a context
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
761 new_context = wglCreateContext(windc);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
762 if (!new_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
763 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GL context!\n");
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
764 return SET_WINDOW_FAILED;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
765 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
766 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
767
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
768 // set context
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
769 if (!wglMakeCurrent(windc, new_context)) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
770 mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GL context!\n");
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
771 if (!keep_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
772 wglDeleteContext(new_context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
773 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
774 return SET_WINDOW_FAILED;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
775 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
776
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
777 // set new values
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
778 vo_window = win;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
779 vo_hdc = windc;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
780 {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
781 RECT rect;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
782 GetClientRect(win, &rect);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
783 vo_dwidth = rect.right;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
784 vo_dheight = rect.bottom;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
785 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
786 if (!keep_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
787 if (*context)
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
788 wglDeleteContext(*context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
789 *context = new_context;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
790 *vinfo = new_vinfo;
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
791 getProcAddress = w32gpa;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
792 getFunctions();
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
793
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
794 // and inform that reinit is neccessary
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
795 return SET_WINDOW_REINIT;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
796 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
797 return SET_WINDOW_OK;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
798 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
799
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
800 void releaseGlContext(int *vinfo, HGLRC *context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
801 *vinfo = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
802 if (*context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
803 wglMakeCurrent(0, 0);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
804 wglDeleteContext(*context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
805 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
806 *context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
807 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
808 #else
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
809 #ifdef HAVE_LIBDL
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
810 #include <dlfcn.h>
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
811 #endif
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
812 /**
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
813 * \brief find address of a linked function
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
814 * \param s name of function to find
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
815 * \return address of function or NULL if not found
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
816 *
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
817 * Copied from xine
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
818 */
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
819 static void *getdladdr(const GLubyte *s) {
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
820 #ifdef HAVE_LIBDL
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
821 #if defined(__sun) || defined(__sgi)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
822 static void *handle = dlopen(NULL, RTLD_LAZY);
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
823 return dlsym(handle, s);
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
824 #else
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
825 return dlsym(0, s);
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
826 #endif
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
827 #else
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
828 return NULL;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
829 #endif
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
830 }
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
831
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
832 /**
14269
718ec28220d6 Doxygen comments improved
reimar
parents: 14142
diff changeset
833 * \brief Returns the XVisualInfo associated with Window win.
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
834 * \param win Window whose XVisualInfo is returne.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
835 * \return XVisualInfo of the window. Caller must use XFree to free it.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
836 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
837 static XVisualInfo *getWindowVisualInfo(Window win) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
838 XWindowAttributes xw_attr;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
839 XVisualInfo vinfo_template;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
840 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
841 XGetWindowAttributes(mDisplay, win, &xw_attr);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
842 vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
843 return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
844 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
845
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
846 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
847 * \brief Changes the window in which video is displayed.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
848 * If possible only transfers the context to the new window, otherwise
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
849 * creates a new one, which must be initialized by the caller.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
850 * \param vinfo Currently used visual.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
851 * \param context Currently used context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
852 * \param win window that should be used for drawing.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
853 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
854 * In case of SET_WINDOW_REINIT the context could not be transfered
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
855 * and the caller must initialize it correctly.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
856 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
857 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
858 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
859 XVisualInfo *new_vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
860 GLXContext new_context = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
861 int keep_context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
862
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
863 // should only be needed when keeping context, but not doing glFinish
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
864 // can cause flickering even when we do not keep it.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
865 glFinish();
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
866 new_vinfo = getWindowVisualInfo(win);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
867 if (*context && *vinfo && new_vinfo &&
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
868 (*vinfo)->visualid == new_vinfo->visualid) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
869 // we can keep the GLXContext
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
870 new_context = *context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
871 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
872 new_vinfo = *vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
873 keep_context = 1;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
874 } else {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
875 // create a context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
876 new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
877 if (!new_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
878 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GLX context!\n");
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
879 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
880 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
881 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
882 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
883
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
884 // set context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
885 if (!glXMakeCurrent(mDisplay, vo_window, new_context)) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
886 mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GLX context!\n");
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
887 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
888 glXDestroyContext (mDisplay, new_context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
889 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
890 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
891 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
892 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
893
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
894 // set new values
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
895 vo_window = win;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
896 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
897 Window root;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
898 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
899 XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp,
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
900 &vo_dwidth, &vo_dheight, &tmp, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
901 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
902 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
903 if (*context)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
904 glXDestroyContext(mDisplay, *context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
905 *context = new_context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
906 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
907 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
908 *vinfo = new_vinfo;
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
909 if (!getProcAddress)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
910 getProcAddress = getdladdr("glXGetProcAddress");
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
911 if (!getProcAddress)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
912 getProcAddress = getdladdr("glXGetProcAddressARB");
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
913 if (!getProcAddress)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
914 getProcAddress = getdladdr;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
915 getFunctions();
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
916
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
917 // and inform that reinit is neccessary
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
918 return SET_WINDOW_REINIT;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
919 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
920 return SET_WINDOW_OK;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
921 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
922
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
923 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
924 * \brief free the VisualInfo and GLXContext of an OpenGL context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
925 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
926 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
927 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
928 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
929 *vinfo = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
930 if (*context)
14089
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
931 {
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
932 glFinish();
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
933 glXMakeCurrent(mDisplay, None, NULL);
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
934 glXDestroyContext(mDisplay, *context);
14089
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
935 }
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
936 *context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
937 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
938 #endif
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
939