annotate libvo/gl_common.c @ 16109:519a307e3ccf

OpenGL fixes for windows and vo_gl.c ported to windows.
author reimar
date Tue, 26 Jul 2005 13:47:18 +0000
parents 629c54dc7e0d
children 5683110fce0a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
1 #include "gl_common.h"
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
2
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
3 void (APIENTRY *BindBuffer)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
4 GLvoid* (APIENTRY *MapBuffer)(GLenum, GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
5 GLboolean (APIENTRY *UnmapBuffer)(GLenum);
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
6 void (APIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
7 void (APIENTRY *CombinerParameterfv)(GLenum, const GLfloat *);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
8 void (APIENTRY *CombinerParameteri)(GLenum, GLint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
9 void (APIENTRY *CombinerInput)(GLenum, GLenum, GLenum, GLenum, GLenum,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
10 GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
11 void (APIENTRY *CombinerOutput)(GLenum, GLenum, GLenum, GLenum, GLenum,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
12 GLenum, GLenum, GLboolean, GLboolean,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
13 GLboolean);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
14 void (APIENTRY *ActiveTexture)(GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
15 void (APIENTRY *BindTexture)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
16 void (APIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
17 void (APIENTRY *BindProgram)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
18 void (APIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
19 void (APIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
20 GLfloat, GLfloat);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
21
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
22 /**
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
23 * \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
24 * \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
25 */
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
26 void glAdjustAlignment(int stride) {
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
27 GLint gl_alignment;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
28 if (stride % 8 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
29 gl_alignment=8;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
30 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
31 gl_alignment=4;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
32 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
33 gl_alignment=2;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
34 else
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
35 gl_alignment=1;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
36 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
37 }
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
38
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
39 #include "img_format.h"
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
40
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
41 struct gl_name_map_struct {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
42 GLint value;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
43 char *name;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
44 };
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
45
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
46 #undef MAP
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
47 #define MAP(a) {a, #a}
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
48 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
49 // internal format
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
50 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
51 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
52 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
53 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
54
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
55 // format
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
56 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
57 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
58 MAP(GL_COLOR_INDEX),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
59 // rest 1.2 only
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
60 #ifdef GL_VERSION_1_2
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
61 MAP(GL_BGR), MAP(GL_BGRA),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
62 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
63
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
64 //type
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
65 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
66 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
67 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
68 // rest 1.2 only
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
69 #ifdef GL_VERSION_1_2
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
70 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
71 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
72 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
73 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
74 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
75 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
76 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
77 {0, 0}
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
78 };
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
79 #undef MAP
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
80
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
81 /**
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
82 * \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
83 * \param value the constant
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
84 * \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
85 */
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
86 const char *glValName(GLint value)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
87 {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
88 int i = 0;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
89
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
90 while (gl_name_map[i].name) {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
91 if (gl_name_map[i].value == value)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
92 return gl_name_map[i].name;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
93 i++;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
94 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
95 return "Unknown format!";
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
96 }
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 #undef TEXTUREFORMAT_ALWAYS
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
99 //! 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
100 #define TEXTUREFORMAT_ALWAYS GL_RGB8
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
101
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
102 /**
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
103 * \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
104 *
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
105 * All parameters may be NULL.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
106 * \param fmt MPlayer format to analyze.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
107 * \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
108 * \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
109 * 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
110 * \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
111 * \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
112 * \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
113 */
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
114 int glFindFormat(uint32_t fmt, uint32_t *bpp, GLenum *gl_texfmt,
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
115 GLenum *gl_format, GLenum *gl_type)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
116 {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
117 int dummy1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
118 GLenum dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
119 if (bpp == NULL) bpp = &dummy1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
120 if (gl_texfmt == NULL) gl_texfmt = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
121 if (gl_format == NULL) gl_format = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
122 if (gl_type == NULL) gl_type = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
123
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
124 *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
125 *gl_texfmt = 3;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
126 switch (fmt) {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
127 case IMGFMT_RGB24:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
128 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
129 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
130 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
131 case IMGFMT_RGBA:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
132 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
133 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
134 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
135 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
136 case IMGFMT_Y800:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
137 case IMGFMT_Y8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
138 *gl_texfmt = 1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
139 *bpp = 8;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
140 *gl_format = GL_LUMINANCE;
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 #ifdef GL_VERSION_1_2
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
144 #if 0
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
145 // 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
146 // swscale produces works
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
147 case IMGFMT_RGB8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
148 gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
149 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
150 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
151 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
152 case IMGFMT_RGB15:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
153 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
154 *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
155 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
156 case IMGFMT_RGB16:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
157 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
158 *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
159 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
160 #if 0
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
161 case IMGFMT_BGR8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
162 // 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
163 // 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
164 // 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
165 // 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
166 gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
167 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
168 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
169 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
170 case IMGFMT_BGR15:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
171 *gl_format = GL_BGRA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
172 *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
173 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
174 case IMGFMT_BGR16:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
175 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
176 *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
177 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
178 case IMGFMT_BGR24:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
179 *gl_format = GL_BGR;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
180 *gl_type = GL_UNSIGNED_BYTE;
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 case IMGFMT_BGRA:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
183 *gl_texfmt = 4;
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_BYTE;
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 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
188 default:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
189 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
190 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
191 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
192 return 0;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
193 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
194 #ifdef TEXTUREFORMAT_ALWAYS
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
195 *gl_texfmt = TEXTUREFORMAT_ALWAYS;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
196 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
197 return 1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
198 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
199
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
200 static void *setNull(const GLubyte *s) {
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
201 return NULL;
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
202 }
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
203
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
204 static void *(*getProcAddress)(const GLubyte *procName);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
205
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
206 static void getFunctions() {
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
207 if (!getProcAddress)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
208 getProcAddress = setNull;
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
209 BindBuffer = getProcAddress("glBindBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
210 if (!BindBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
211 BindBuffer = getProcAddress("glBindBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
212 MapBuffer = getProcAddress("glMapBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
213 if (!MapBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
214 MapBuffer = getProcAddress("glMapBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
215 UnmapBuffer = getProcAddress("glUnmapBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
216 if (!UnmapBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
217 UnmapBuffer = getProcAddress("glUnmapBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
218 BufferData = getProcAddress("glBufferData");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
219 if (!BufferData)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
220 BufferData = getProcAddress("glBufferDataARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
221 CombinerParameterfv = getProcAddress("glCombinerParameterfv");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
222 if (!CombinerParameterfv)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
223 CombinerParameterfv = getProcAddress("glCombinerParameterfvNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
224 CombinerParameteri = getProcAddress("glCombinerParameteri");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
225 if (!CombinerParameteri)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
226 CombinerParameteri = getProcAddress("glCombinerParameteriNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
227 CombinerInput = getProcAddress("glCombinerInput");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
228 if (!CombinerInput)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
229 CombinerInput = getProcAddress("glCombinerInputNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
230 CombinerOutput = getProcAddress("glCombinerOutput");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
231 if (!CombinerOutput)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
232 CombinerOutput = getProcAddress("glCombinerOutputNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
233 ActiveTexture = getProcAddress("glActiveTexture");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
234 if (!ActiveTexture)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
235 ActiveTexture = getProcAddress("glActiveTextureARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
236 BindTexture = getProcAddress("glBindTexture");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
237 if (!BindTexture)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
238 BindTexture = getProcAddress("glBindTextureARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
239 MultiTexCoord2f = getProcAddress("glMultiTexCoord2f");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
240 if (!MultiTexCoord2f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
241 MultiTexCoord2f = getProcAddress("glMultiTexCoord2fARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
242 BindProgram = getProcAddress("glBindProgram");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
243 if (!BindProgram)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
244 BindProgram = getProcAddress("glBindProgramARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
245 if (!BindProgram)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
246 BindProgram = getProcAddress("glBindProgramNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
247 ProgramString = getProcAddress("glProgramString");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
248 if (!ProgramString)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
249 ProgramString = getProcAddress("glProgramStringARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
250 if (!ProgramString)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
251 ProgramString = getProcAddress("glProgramStringNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
252 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4f");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
253 if (!ProgramEnvParameter4f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
254 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4fARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
255 if (!ProgramEnvParameter4f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
256 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4fNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
257 }
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
258
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
259 #ifdef GL_WIN32
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
260 static void *w32gpa(const GLubyte *procName) {
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
261 return wglGetProcAddress(procName);
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
262 }
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
263
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
264 int setGlWindow(int *vinfo, HGLRC *context, HWND win)
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
265 {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
266 int new_vinfo;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
267 HDC windc = GetDC(win);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
268 HGLRC new_context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
269 int keep_context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
270
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
271 // 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
272 // 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
273 glFinish();
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
274 new_vinfo = GetPixelFormat(windc);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
275 if (*context && *vinfo && new_vinfo && *vinfo == new_vinfo) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
276 // we can keep the wglContext
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
277 new_context = *context;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
278 keep_context = 1;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
279 } else {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
280 // create a context
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
281 new_context = wglCreateContext(windc);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
282 if (!new_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
283 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
284 return SET_WINDOW_FAILED;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
285 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
286 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
287
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
288 // set context
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
289 if (!wglMakeCurrent(windc, new_context)) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
290 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
291 if (!keep_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
292 wglDeleteContext(new_context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
293 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
294 return SET_WINDOW_FAILED;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
295 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
296
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
297 // set new values
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
298 vo_window = win;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
299 vo_hdc = windc;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
300 {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
301 RECT rect;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
302 GetClientRect(win, &rect);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
303 vo_dwidth = rect.right;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
304 vo_dheight = rect.bottom;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
305 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
306 if (!keep_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
307 if (*context)
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
308 wglDeleteContext(*context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
309 *context = new_context;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
310 *vinfo = new_vinfo;
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
311 getProcAddress = w32gpa;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
312 getFunctions();
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
313
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
314 // and inform that reinit is neccessary
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
315 return SET_WINDOW_REINIT;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
316 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
317 return SET_WINDOW_OK;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
318 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
319
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
320 void releaseGlContext(int *vinfo, HGLRC *context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
321 *vinfo = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
322 if (*context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
323 wglMakeCurrent(0, 0);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
324 wglDeleteContext(*context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
325 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
326 *context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
327 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
328 #else
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
329 /**
14269
718ec28220d6 Doxygen comments improved
reimar
parents: 14142
diff changeset
330 * \brief Returns the XVisualInfo associated with Window win.
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
331 * \param win Window whose XVisualInfo is returne.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
332 * \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
333 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
334 static XVisualInfo *getWindowVisualInfo(Window win) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
335 XWindowAttributes xw_attr;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
336 XVisualInfo vinfo_template;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
337 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
338 XGetWindowAttributes(mDisplay, win, &xw_attr);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
339 vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
340 return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
341 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
342
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
343 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
344 * \brief Changes the window in which video is displayed.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
345 * 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
346 * 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
347 * \param vinfo Currently used visual.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
348 * \param context Currently used context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
349 * \param win window that should be used for drawing.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
350 * \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
351 * 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
352 * and the caller must initialize it correctly.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
353 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
354 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
355 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
356 XVisualInfo *new_vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
357 GLXContext new_context = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
358 int keep_context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
359
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
360 // 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
361 // can cause flickering even when we do not keep it.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
362 glFinish();
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
363 new_vinfo = getWindowVisualInfo(win);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
364 if (*context && *vinfo && new_vinfo &&
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
365 (*vinfo)->visualid == new_vinfo->visualid) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
366 // we can keep the GLXContext
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
367 new_context = *context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
368 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
369 new_vinfo = *vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
370 keep_context = 1;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
371 } else {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
372 // create a context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
373 new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
374 if (!new_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
375 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
376 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
377 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
378 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
379 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
380
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
381 // set context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
382 if (!glXMakeCurrent(mDisplay, vo_window, new_context)) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
383 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
384 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
385 glXDestroyContext (mDisplay, new_context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
386 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
387 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
388 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
389 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
390
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
391 // set new values
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
392 vo_window = win;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
393 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
394 Window root;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
395 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
396 XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp,
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
397 &vo_dwidth, &vo_dheight, &tmp, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
398 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
399 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
400 if (*context)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
401 glXDestroyContext(mDisplay, *context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
402 *context = new_context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
403 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
404 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
405 *vinfo = new_vinfo;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
406 #ifdef GLX_ARB_get_proc_address
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
407 getProcAddress = (void *)glXGetProcAddressARB;
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
408 #else
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
409 getProcAddress = NULL;
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
410 #endif
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
411 getFunctions();
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
412
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
413 // and inform that reinit is neccessary
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
414 return SET_WINDOW_REINIT;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
415 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
416 return SET_WINDOW_OK;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
417 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
418
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
419 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
420 * \brief free the VisualInfo and GLXContext of an OpenGL context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
421 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
422 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
423 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
424 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
425 *vinfo = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
426 if (*context)
14089
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
427 {
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
428 glFinish();
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
429 glXMakeCurrent(mDisplay, None, NULL);
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
430 glXDestroyContext(mDisplay, *context);
14089
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
431 }
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
432 *context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
433 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
434 #endif
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
435