annotate libvo/gl_common.c @ 16268:d7856c2232d0

automatic vsync enabling for vo_gl.
author reimar
date Fri, 19 Aug 2005 09:31:02 +0000
parents f00a2826ee11
children d5374d07492a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
1 #include <stdlib.h>
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
2 #include <string.h>
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
3 #include "gl_common.h"
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
4
16233
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
5 void (APIENTRY *GenBuffers)(GLsizei, GLuint *);
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
6 void (APIENTRY *DeleteBuffers)(GLsizei, const GLuint *);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
7 void (APIENTRY *BindBuffer)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
8 GLvoid* (APIENTRY *MapBuffer)(GLenum, GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
9 GLboolean (APIENTRY *UnmapBuffer)(GLenum);
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
10 void (APIENTRY *BufferData)(GLenum, intptr_t, const GLvoid *, GLenum);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
11 void (APIENTRY *CombinerParameterfv)(GLenum, const GLfloat *);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
12 void (APIENTRY *CombinerParameteri)(GLenum, GLint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
13 void (APIENTRY *CombinerInput)(GLenum, GLenum, GLenum, GLenum, GLenum,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
14 GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
15 void (APIENTRY *CombinerOutput)(GLenum, GLenum, GLenum, GLenum, GLenum,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
16 GLenum, GLenum, GLboolean, GLboolean,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
17 GLboolean);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
18 void (APIENTRY *ActiveTexture)(GLenum);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
19 void (APIENTRY *BindTexture)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
20 void (APIENTRY *MultiTexCoord2f)(GLenum, GLfloat, GLfloat);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
21 void (APIENTRY *BindProgram)(GLenum, GLuint);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
22 void (APIENTRY *ProgramString)(GLenum, GLenum, GLsizei, const GLvoid *);
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
23 void (APIENTRY *ProgramEnvParameter4f)(GLenum, GLuint, GLfloat, GLfloat,
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
24 GLfloat, GLfloat);
16268
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
25 int (*SwapInterval)(int);
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
26
13653
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
27 /**
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
28 * \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
29 * \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
30 */
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
31 void glAdjustAlignment(int stride) {
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
32 GLint gl_alignment;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
33 if (stride % 8 == 0)
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
34 gl_alignment=8;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
35 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
36 gl_alignment=4;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
37 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
38 gl_alignment=2;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
39 else
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
40 gl_alignment=1;
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
41 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
42 }
799f81d3cb19 added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff changeset
43
14078
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
44 struct gl_name_map_struct {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
45 GLint value;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
46 char *name;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
47 };
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
48
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
49 #undef MAP
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
50 #define MAP(a) {a, #a}
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
51 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
52 // internal format
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
53 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
54 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
55 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
56 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
57
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
58 // format
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
59 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
60 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
61 MAP(GL_COLOR_INDEX),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
62 // rest 1.2 only
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
63 MAP(GL_BGR), MAP(GL_BGRA),
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
64
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
65 //type
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
66 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
67 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
68 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
69 // rest 1.2 only
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 {0, 0}
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
77 };
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
78 #undef MAP
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
79
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 * \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
82 * \param value the constant
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
83 * \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
84 */
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
85 const char *glValName(GLint value)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
86 {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
87 int i = 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 while (gl_name_map[i].name) {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
90 if (gl_name_map[i].value == value)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
91 return gl_name_map[i].name;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
92 i++;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
93 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
94 return "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
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
97 #undef TEXTUREFORMAT_ALWAYS
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
98 //! 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
99 #define TEXTUREFORMAT_ALWAYS GL_RGB8
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
100
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 * \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
103 *
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
104 * All parameters may be NULL.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
105 * \param fmt MPlayer format to analyze.
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
106 * \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
107 * \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
108 * 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
109 * \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
110 * \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
111 * \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
112 */
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
113 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
114 GLenum *gl_format, GLenum *gl_type)
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
115 {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
116 int dummy1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
117 GLenum dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
118 if (bpp == NULL) bpp = &dummy1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
119 if (gl_texfmt == NULL) gl_texfmt = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
120 if (gl_format == NULL) gl_format = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
121 if (gl_type == NULL) gl_type = &dummy2;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
122
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
123 *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
124 *gl_texfmt = 3;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
125 switch (fmt) {
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
126 case IMGFMT_RGB24:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
127 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
128 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
129 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
130 case IMGFMT_RGBA:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
131 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
132 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
133 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
134 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
135 case IMGFMT_Y800:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
136 case IMGFMT_Y8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
137 *gl_texfmt = 1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
138 *bpp = 8;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
139 *gl_format = GL_LUMINANCE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
140 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
141 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
142 #if 0
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
143 // 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
144 // swscale produces works
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
145 case IMGFMT_RGB8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
146 gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
147 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
148 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
149 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
150 case IMGFMT_RGB15:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
151 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
152 *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
153 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
154 case IMGFMT_RGB16:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
155 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
156 *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
157 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
158 #if 0
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
159 case IMGFMT_BGR8:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
160 // 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
161 // 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
162 // 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
163 // 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
164 gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
165 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
166 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
167 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
168 case IMGFMT_BGR15:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
169 *gl_format = GL_BGRA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
170 *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
171 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
172 case IMGFMT_BGR16:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
173 *gl_format = GL_RGB;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
174 *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
175 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
176 case IMGFMT_BGR24:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
177 *gl_format = GL_BGR;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
178 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
179 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
180 case IMGFMT_BGRA:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
181 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
182 *gl_format = GL_BGRA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
183 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
184 break;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
185 default:
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
186 *gl_texfmt = 4;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
187 *gl_format = GL_RGBA;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
188 *gl_type = GL_UNSIGNED_BYTE;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
189 return 0;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
190 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
191 #ifdef TEXTUREFORMAT_ALWAYS
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
192 *gl_texfmt = TEXTUREFORMAT_ALWAYS;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
193 #endif
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
194 return 1;
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
195 }
c4033dcb986f More similar code from gl and gl2 moved to gl_common
reimar
parents: 13843
diff changeset
196
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
197 static void *setNull(const GLubyte *s) {
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
198 return NULL;
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
199 }
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
200
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
201 static void *(*getProcAddress)(const GLubyte *procName) = NULL;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
202
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
203 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
204 * \brief find the function pointers of some useful OpenGL extensions
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
205 */
16099
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;
16233
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
209 GenBuffers = getProcAddress("glGenBuffers");
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
210 if (!GenBuffers)
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
211 GenBuffers = getProcAddress("glGenBuffersARB");
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
212 DeleteBuffers = getProcAddress("glDeleteBuffers");
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
213 if (!DeleteBuffers)
f00a2826ee11 use GenBuffers to get a buffer number instead of hardcoding 1.
reimar
parents: 16223
diff changeset
214 DeleteBuffers = getProcAddress("glDeleteBuffersARB");
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
215 BindBuffer = getProcAddress("glBindBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
216 if (!BindBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
217 BindBuffer = getProcAddress("glBindBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
218 MapBuffer = getProcAddress("glMapBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
219 if (!MapBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
220 MapBuffer = getProcAddress("glMapBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
221 UnmapBuffer = getProcAddress("glUnmapBuffer");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
222 if (!UnmapBuffer)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
223 UnmapBuffer = getProcAddress("glUnmapBufferARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
224 BufferData = getProcAddress("glBufferData");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
225 if (!BufferData)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
226 BufferData = getProcAddress("glBufferDataARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
227 CombinerParameterfv = getProcAddress("glCombinerParameterfv");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
228 if (!CombinerParameterfv)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
229 CombinerParameterfv = getProcAddress("glCombinerParameterfvNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
230 CombinerParameteri = getProcAddress("glCombinerParameteri");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
231 if (!CombinerParameteri)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
232 CombinerParameteri = getProcAddress("glCombinerParameteriNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
233 CombinerInput = getProcAddress("glCombinerInput");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
234 if (!CombinerInput)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
235 CombinerInput = getProcAddress("glCombinerInputNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
236 CombinerOutput = getProcAddress("glCombinerOutput");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
237 if (!CombinerOutput)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
238 CombinerOutput = getProcAddress("glCombinerOutputNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
239 ActiveTexture = getProcAddress("glActiveTexture");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
240 if (!ActiveTexture)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
241 ActiveTexture = getProcAddress("glActiveTextureARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
242 BindTexture = getProcAddress("glBindTexture");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
243 if (!BindTexture)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
244 BindTexture = getProcAddress("glBindTextureARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
245 MultiTexCoord2f = getProcAddress("glMultiTexCoord2f");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
246 if (!MultiTexCoord2f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
247 MultiTexCoord2f = getProcAddress("glMultiTexCoord2fARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
248 BindProgram = getProcAddress("glBindProgram");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
249 if (!BindProgram)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
250 BindProgram = getProcAddress("glBindProgramARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
251 if (!BindProgram)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
252 BindProgram = getProcAddress("glBindProgramNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
253 ProgramString = getProcAddress("glProgramString");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
254 if (!ProgramString)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
255 ProgramString = getProcAddress("glProgramStringARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
256 if (!ProgramString)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
257 ProgramString = getProcAddress("glProgramStringNV");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
258 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4f");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
259 if (!ProgramEnvParameter4f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
260 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4fARB");
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
261 if (!ProgramEnvParameter4f)
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
262 ProgramEnvParameter4f = getProcAddress("glProgramEnvParameter4fNV");
16268
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
263 SwapInterval = getProcAddress("glXSwapInterval");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
264 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
265 SwapInterval = getProcAddress("glXSwapIntervalEXT");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
266 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
267 SwapInterval = getProcAddress("glXSwapIntervalSGI");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
268 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
269 SwapInterval = getProcAddress("wglSwapInterval");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
270 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
271 SwapInterval = getProcAddress("wglSwapIntervalEXT");
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
272 if (!SwapInterval)
d7856c2232d0 automatic vsync enabling for vo_gl.
reimar
parents: 16233
diff changeset
273 SwapInterval = getProcAddress("wglSwapIntervalSGI");
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
274 }
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
275
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
276 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
277 * \brief create a texture and set some defaults
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
278 * \param target texture taget, usually GL_TEXTURE_2D
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
279 * \param fmt internal texture format
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
280 * \param filter filter used for scaling, e.g. GL_LINEAR
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
281 * \param w texture width
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
282 * \param h texture height
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
283 * \param val luminance value to fill texture with
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
284 */
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
285 void glCreateClearTex(GLenum target, GLenum fmt, GLint filter,
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
286 int w, int h, char val) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
287 GLenum clrfmt = (fmt == GL_ALPHA) ? GL_ALPHA : GL_LUMINANCE;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
288 char *init = (char *)malloc(w * h);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
289 memset(init, val, w * h);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
290 glAdjustAlignment(w);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
291 glPixelStorei(GL_UNPACK_ROW_LENGTH, w);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
292 glTexImage2D(target, 0, fmt, w, h, 0, clrfmt, GL_UNSIGNED_BYTE, init);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
293 glTexParameterf(target, GL_TEXTURE_PRIORITY, 1.0);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
294 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
295 glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
296 glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
297 glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
298 free(init);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
299 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
300
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 return the number of bytes oer pixel for the given format
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
303 * \param format OpenGL format
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
304 * \param type OpenGL type
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
305 * \return bytes per pixel
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
306 *
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
307 * Does not handle all possible variants, just those use by MPlayer
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
308 */
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
309 int glFmt2bpp(GLenum format, GLenum type) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
310 switch (type) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
311 case GL_UNSIGNED_BYTE_3_3_2:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
312 case GL_UNSIGNED_BYTE_2_3_3_REV:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
313 return 1;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
314 case GL_UNSIGNED_SHORT_5_5_5_1:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
315 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
316 case GL_UNSIGNED_SHORT_5_6_5:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
317 case GL_UNSIGNED_SHORT_5_6_5_REV:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
318 return 2;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
319 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
320 if (type != GL_UNSIGNED_BYTE)
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
321 return 0; //not implemented
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
322 switch (format) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
323 case GL_LUMINANCE:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
324 case GL_ALPHA:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
325 return 1;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
326 case GL_RGB:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
327 case GL_BGR:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
328 return 3;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
329 case GL_RGBA:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
330 case GL_BGRA:
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
331 return 4;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
332 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
333 return 0; // unkown
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
334 }
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
335
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
336 /**
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
337 * \brief upload a texture, handling things like stride and slices
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
338 * \param target texture target, usually GL_TEXTURE_2D
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
339 * \param format OpenGL format of data
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
340 * \param type OpenGL type of data
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
341 * \param data data to upload
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
342 * \param stride data stride
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
343 * \param x x offset in texture
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
344 * \param y y offset in texture
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
345 * \param w width of the texture part to upload
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
346 * \param h height of the texture part to upload
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
347 * \param slice height of an upload slice, 0 for all at once
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
348 */
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
349 void glUploadTex(GLenum target, GLenum format, GLenum type,
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
350 const char *data, int stride,
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
351 int x, int y, int w, int h, int slice) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
352 int y_max = y + h;
16223
f540609340ac extra check for glUploadTex to avoid a possible hang.
reimar
parents: 16221
diff changeset
353 if (w <= 0 || h <= 0) return;
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
354 if (slice <= 0)
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
355 slice = h;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
356 // this is not always correct, but should work for MPlayer
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
357 glAdjustAlignment(stride);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
358 glPixelStorei(GL_UNPACK_ROW_LENGTH, stride / glFmt2bpp(format, type));
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
359 for (; y + slice <= y_max; y += slice) {
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
360 glTexSubImage2D(target, 0, x, y, w, slice, format, type, data);
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
361 data += stride * slice;
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 if (y < y_max)
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
364 glTexSubImage2D(target, 0, x, y, w, y_max - y, format, type, data);
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
16214
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
367 /**
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
368 * \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
369 * \param x screen top coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
370 * \param y screen left coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
371 * \param w screen width coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
372 * \param h screen height coordinate
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
373 * \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
374 * \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
375 * \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
376 * \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
377 * \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
378 * \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
379 * \param rect_tex whether this texture uses texture_rectangle extension
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
380 */
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
381 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
382 GLfloat tx, GLfloat ty, GLfloat tw, GLfloat th,
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
383 int sx, int sy, int rect_tex) {
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
384 if (!rect_tex) {
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
385 tx /= sx; ty /= sy; tw /= sx; th /= sy;
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
386 }
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
387 glBegin(GL_QUADS);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
388 glTexCoord2f(tx, ty);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
389 glVertex2f(x, y);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
390 glTexCoord2f(tx, ty + th);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
391 glVertex2f(x, y + h);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
392 glTexCoord2f(tx + tw, ty + th);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
393 glVertex2f(x + w, y + h);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
394 glTexCoord2f(tx + tw, ty);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
395 glVertex2f(x + w, y);
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
396 glEnd();
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
397 }
ede5b4afd262 Helper function for drawing texture and general cleanup of vo_gl2.c
reimar
parents: 16117
diff changeset
398
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
399 #ifdef GL_WIN32
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
400 static void *w32gpa(const GLubyte *procName) {
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
401 return wglGetProcAddress(procName);
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
402 }
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
403
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
404 int setGlWindow(int *vinfo, HGLRC *context, HWND win)
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
405 {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
406 int new_vinfo;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
407 HDC windc = GetDC(win);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
408 HGLRC new_context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
409 int keep_context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
410
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
411 // 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
412 // 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
413 glFinish();
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
414 new_vinfo = GetPixelFormat(windc);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
415 if (*context && *vinfo && new_vinfo && *vinfo == new_vinfo) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
416 // we can keep the wglContext
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
417 new_context = *context;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
418 keep_context = 1;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
419 } else {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
420 // create a context
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
421 new_context = wglCreateContext(windc);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
422 if (!new_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
423 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
424 return SET_WINDOW_FAILED;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
425 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
426 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
427
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
428 // set context
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
429 if (!wglMakeCurrent(windc, new_context)) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
430 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
431 if (!keep_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
432 wglDeleteContext(new_context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
433 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
434 return SET_WINDOW_FAILED;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
435 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
436
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
437 // set new values
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
438 vo_window = win;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
439 vo_hdc = windc;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
440 {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
441 RECT rect;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
442 GetClientRect(win, &rect);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
443 vo_dwidth = rect.right;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
444 vo_dheight = rect.bottom;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
445 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
446 if (!keep_context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
447 if (*context)
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
448 wglDeleteContext(*context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
449 *context = new_context;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
450 *vinfo = new_vinfo;
16109
519a307e3ccf OpenGL fixes for windows and vo_gl.c ported to windows.
reimar
parents: 16099
diff changeset
451 getProcAddress = w32gpa;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
452 getFunctions();
14142
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
453
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
454 // and inform that reinit is neccessary
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
455 return SET_WINDOW_REINIT;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
456 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
457 return SET_WINDOW_OK;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
458 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
459
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
460 void releaseGlContext(int *vinfo, HGLRC *context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
461 *vinfo = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
462 if (*context) {
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
463 wglMakeCurrent(0, 0);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
464 wglDeleteContext(*context);
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
465 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
466 *context = 0;
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
467 }
f0c1ee83b216 Improving gl2 under windows, moving some functionality to gl_common
reimar
parents: 14089
diff changeset
468 #else
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
469 #ifdef HAVE_LIBDL
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
470 #include <dlfcn.h>
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
471 #endif
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
472 /**
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
473 * \brief find address of a linked function
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
474 * \param s name of function to find
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
475 * \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
476 *
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
477 * Copied from xine
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
478 */
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
479 static void *getdladdr(const GLubyte *s) {
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
480 #ifdef HAVE_LIBDL
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
481 #if defined(__sun) || defined(__sgi)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
482 static void *handle = dlopen(NULL, RTLD_LAZY);
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
483 return dlsym(handle, s);
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
484 #else
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
485 return dlsym(0, s);
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
486 #endif
16117
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
487 #else
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
488 return NULL;
d280ec2b9e63 More helper functions/defines and bugfixes
reimar
parents: 16111
diff changeset
489 #endif
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
490 }
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
491
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
492 /**
14269
718ec28220d6 Doxygen comments improved
reimar
parents: 14142
diff changeset
493 * \brief Returns the XVisualInfo associated with Window win.
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
494 * \param win Window whose XVisualInfo is returne.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
495 * \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
496 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
497 static XVisualInfo *getWindowVisualInfo(Window win) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
498 XWindowAttributes xw_attr;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
499 XVisualInfo vinfo_template;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
500 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
501 XGetWindowAttributes(mDisplay, win, &xw_attr);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
502 vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
503 return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
504 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
505
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
506 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
507 * \brief Changes the window in which video is displayed.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
508 * 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
509 * 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
510 * \param vinfo Currently used visual.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
511 * \param context Currently used context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
512 * \param win window that should be used for drawing.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
513 * \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
514 * 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
515 * and the caller must initialize it correctly.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
516 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
517 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
518 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
519 XVisualInfo *new_vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
520 GLXContext new_context = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
521 int keep_context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
522
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
523 // 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
524 // can cause flickering even when we do not keep it.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
525 glFinish();
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
526 new_vinfo = getWindowVisualInfo(win);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
527 if (*context && *vinfo && new_vinfo &&
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
528 (*vinfo)->visualid == new_vinfo->visualid) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
529 // we can keep the GLXContext
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
530 new_context = *context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
531 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
532 new_vinfo = *vinfo;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
533 keep_context = 1;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
534 } else {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
535 // create a context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
536 new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
537 if (!new_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
538 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
539 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
540 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
541 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
542 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
543
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
544 // set context
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
545 if (!glXMakeCurrent(mDisplay, vo_window, new_context)) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
546 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
547 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
548 glXDestroyContext (mDisplay, new_context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
549 XFree(new_vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
550 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
551 return SET_WINDOW_FAILED;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
552 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
553
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
554 // set new values
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
555 vo_window = win;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
556 {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
557 Window root;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
558 int tmp;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
559 XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp,
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
560 &vo_dwidth, &vo_dheight, &tmp, &tmp);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
561 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
562 if (!keep_context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
563 if (*context)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
564 glXDestroyContext(mDisplay, *context);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
565 *context = new_context;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
566 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
567 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
568 *vinfo = new_vinfo;
16111
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
569 if (!getProcAddress)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
570 getProcAddress = getdladdr("glXGetProcAddress");
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
571 if (!getProcAddress)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
572 getProcAddress = getdladdr("glXGetProcAddressARB");
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
573 if (!getProcAddress)
5683110fce0a Use dlsym to get glXGetProcAddress, only way to (hopefully) make it
reimar
parents: 16109
diff changeset
574 getProcAddress = getdladdr;
16099
629c54dc7e0d support for rectangular and streaming textures.
reimar
parents: 14269
diff changeset
575 getFunctions();
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
576
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
577 // and inform that reinit is neccessary
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
578 return SET_WINDOW_REINIT;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
579 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
580 return SET_WINDOW_OK;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
581 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
582
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
583 /**
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
584 * \brief free the VisualInfo and GLXContext of an OpenGL context.
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
585 */
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
586 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) {
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
587 if (*vinfo)
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
588 XFree(*vinfo);
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
589 *vinfo = NULL;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
590 if (*context)
14089
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
591 {
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
592 glFinish();
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
593 glXMakeCurrent(mDisplay, None, NULL);
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
594 glXDestroyContext(mDisplay, *context);
14089
00283cb37fd0 Make the context not current before destroying it.
reimar
parents: 14078
diff changeset
595 }
13843
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
596 *context = 0;
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
597 }
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
598 #endif
3f28d2a56758 fullscreen fixes and GUI support for vo_gl
reimar
parents: 13653
diff changeset
599