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