Mercurial > mplayer.hg
annotate libvo/gl_common.c @ 14116:7ee2ed4a08d5
synced to 1.57 (link updates)
author | gabrov |
---|---|
date | Mon, 06 Dec 2004 00:38:36 +0000 |
parents | 00283cb37fd0 |
children | f0c1ee83b216 |
rev | line source |
---|---|
13653
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
1 #include "gl_common.h" |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
2 |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
3 /** |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
4 * \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
|
5 * \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
|
6 */ |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
7 void glAdjustAlignment(int stride) { |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
8 GLint gl_alignment; |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
9 if (stride % 8 == 0) |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
10 gl_alignment=8; |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
11 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
|
12 gl_alignment=4; |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
13 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
|
14 gl_alignment=2; |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
15 else |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
16 gl_alignment=1; |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
17 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
|
18 } |
799f81d3cb19
added gl_common for code used by both vo_gl.c and vo_gl2.c.
reimar
parents:
diff
changeset
|
19 |
14078
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
20 #include "img_format.h" |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
21 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
22 struct gl_name_map_struct { |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
23 GLint value; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
24 char *name; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
25 }; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
26 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
27 #undef MAP |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
28 #define MAP(a) {a, #a} |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
29 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
|
30 // internal format |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 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
|
35 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
36 // format |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
37 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
|
38 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
|
39 MAP(GL_COLOR_INDEX), |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
40 // rest 1.2 only |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
41 #ifdef GL_VERSION_1_2 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
42 MAP(GL_BGR), MAP(GL_BGRA), |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
43 #endif |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
44 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
45 //type |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 // rest 1.2 only |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
50 #ifdef GL_VERSION_1_2 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 #endif |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
58 {0, 0} |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
59 }; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
60 #undef MAP |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
61 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
62 /** |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
63 * \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
|
64 * \param value the constant |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
65 * \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
|
66 */ |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
67 const char *glValName(GLint value) |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
68 { |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
69 int i = 0; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
70 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
71 while (gl_name_map[i].name) { |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
72 if (gl_name_map[i].value == value) |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
73 return gl_name_map[i].name; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
74 i++; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
75 } |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
76 return "Unknown format!"; |
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 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
79 #undef TEXTUREFORMAT_ALWAYS |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
80 //! 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
|
81 #define TEXTUREFORMAT_ALWAYS GL_RGB8 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
82 |
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 * \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
|
85 * |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
86 * All parameters may be NULL. |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
87 * \param fmt MPlayer format to analyze. |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
88 * \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
|
89 * \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
|
90 * 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
|
91 * \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
|
92 * \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
|
93 * \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
|
94 */ |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
95 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
|
96 GLenum *gl_format, GLenum *gl_type) |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
97 { |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
98 int dummy1; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
99 GLenum dummy2; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
100 if (bpp == NULL) bpp = &dummy1; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
101 if (gl_texfmt == NULL) gl_texfmt = &dummy2; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
102 if (gl_format == NULL) gl_format = &dummy2; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
103 if (gl_type == NULL) gl_type = &dummy2; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
104 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
105 *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
|
106 *gl_texfmt = 3; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
107 switch (fmt) { |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
108 case IMGFMT_RGB24: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
109 *gl_format = GL_RGB; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
110 *gl_type = GL_UNSIGNED_BYTE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
111 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
112 case IMGFMT_RGBA: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
113 *gl_texfmt = 4; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
114 *gl_format = GL_RGBA; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
115 *gl_type = GL_UNSIGNED_BYTE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
116 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
117 case IMGFMT_Y800: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
118 case IMGFMT_Y8: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
119 *gl_texfmt = 1; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
120 *bpp = 8; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
121 *gl_format = GL_LUMINANCE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
122 *gl_type = GL_UNSIGNED_BYTE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
123 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
124 #ifdef GL_VERSION_1_2 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
125 #if 0 |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
126 // 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
|
127 // swscale produces works |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
128 case IMGFMT_RGB8: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
129 gl_format = GL_RGB; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
130 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
|
131 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
132 #endif |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
133 case IMGFMT_RGB15: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
134 *gl_format = GL_RGBA; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
135 *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
|
136 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
137 case IMGFMT_RGB16: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
138 *gl_format = GL_RGB; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
139 *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
|
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 case IMGFMT_BGR8: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
143 // 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
|
144 // 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
|
145 // 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
|
146 // 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
|
147 gl_format = GL_RGB; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
148 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
|
149 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
150 #endif |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
151 case IMGFMT_BGR15: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
152 *gl_format = GL_BGRA; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
153 *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
|
154 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
155 case IMGFMT_BGR16: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
156 *gl_format = GL_RGB; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
157 *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
|
158 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
159 case IMGFMT_BGR24: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
160 *gl_format = GL_BGR; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
161 *gl_type = GL_UNSIGNED_BYTE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
162 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
163 case IMGFMT_BGRA: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
164 *gl_texfmt = 4; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
165 *gl_format = GL_BGRA; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
166 *gl_type = GL_UNSIGNED_BYTE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
167 break; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
168 #endif |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
169 default: |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
170 *gl_texfmt = 4; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
171 *gl_format = GL_RGBA; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
172 *gl_type = GL_UNSIGNED_BYTE; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
173 return 0; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
174 } |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
175 #ifdef TEXTUREFORMAT_ALWAYS |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
176 *gl_texfmt = TEXTUREFORMAT_ALWAYS; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
177 #endif |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
178 return 1; |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
179 } |
c4033dcb986f
More similar code from gl and gl2 moved to gl_common
reimar
parents:
13843
diff
changeset
|
180 |
13843 | 181 #ifndef GL_WIN32 |
182 /** | |
183 * Returns the XVisualInfo associated with Window win. | |
184 * \param win Window whose XVisualInfo is returne. | |
185 * \return XVisualInfo of the window. Caller must use XFree to free it. | |
186 */ | |
187 static XVisualInfo *getWindowVisualInfo(Window win) { | |
188 XWindowAttributes xw_attr; | |
189 XVisualInfo vinfo_template; | |
190 int tmp; | |
191 XGetWindowAttributes(mDisplay, win, &xw_attr); | |
192 vinfo_template.visualid = XVisualIDFromVisual(xw_attr.visual); | |
193 return XGetVisualInfo(mDisplay, VisualIDMask, &vinfo_template, &tmp); | |
194 } | |
195 | |
196 /** | |
197 * \brief Changes the window in which video is displayed. | |
198 * If possible only transfers the context to the new window, otherwise | |
199 * creates a new one, which must be initialized by the caller. | |
200 * \param vinfo Currently used visual. | |
201 * \param context Currently used context. | |
202 * \param win window that should be used for drawing. | |
203 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT. | |
204 * In case of SET_WINDOW_REINIT the context could not be transfered | |
205 * and the caller must initialize it correctly. | |
206 */ | |
207 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win) | |
208 { | |
209 XVisualInfo *new_vinfo; | |
210 GLXContext new_context = NULL; | |
211 int keep_context = 0; | |
212 | |
213 // should only be needed when keeping context, but not doing glFinish | |
214 // can cause flickering even when we do not keep it. | |
215 glFinish(); | |
216 new_vinfo = getWindowVisualInfo(win); | |
217 if (*context && *vinfo && new_vinfo && | |
218 (*vinfo)->visualid == new_vinfo->visualid) { | |
219 // we can keep the GLXContext | |
220 new_context = *context; | |
221 XFree(new_vinfo); | |
222 new_vinfo = *vinfo; | |
223 keep_context = 1; | |
224 } else { | |
225 // create a context | |
226 new_context = glXCreateContext(mDisplay, new_vinfo, NULL, True); | |
227 if (!new_context) { | |
228 mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GLX context!\n"); | |
229 XFree(new_vinfo); | |
230 return SET_WINDOW_FAILED; | |
231 } | |
232 } | |
233 | |
234 // set context | |
235 if (!glXMakeCurrent(mDisplay, vo_window, new_context)) { | |
236 mp_msg (MSGT_VO, MSGL_FATAL, "[gl] Could not set GLX context!\n"); | |
237 if (!keep_context) { | |
238 glXDestroyContext (mDisplay, new_context); | |
239 XFree(new_vinfo); | |
240 } | |
241 return SET_WINDOW_FAILED; | |
242 } | |
243 | |
244 // set new values | |
245 vo_window = win; | |
246 { | |
247 Window root; | |
248 int tmp; | |
249 XGetGeometry(mDisplay, vo_window, &root, &tmp, &tmp, | |
250 &vo_dwidth, &vo_dheight, &tmp, &tmp); | |
251 } | |
252 if (!keep_context) { | |
253 if (*context) | |
254 glXDestroyContext(mDisplay, *context); | |
255 *context = new_context; | |
256 if (*vinfo) | |
257 XFree(*vinfo); | |
258 *vinfo = new_vinfo; | |
259 | |
260 // and inform that reinit is neccessary | |
261 return SET_WINDOW_REINIT; | |
262 } | |
263 return SET_WINDOW_OK; | |
264 } | |
265 | |
266 /** | |
267 * \brief free the VisualInfo and GLXContext of an OpenGL context. | |
268 */ | |
269 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) { | |
270 if (*vinfo) | |
271 XFree(*vinfo); | |
272 *vinfo = NULL; | |
273 if (*context) | |
14089
00283cb37fd0
Make the context not current before destroying it.
reimar
parents:
14078
diff
changeset
|
274 { |
00283cb37fd0
Make the context not current before destroying it.
reimar
parents:
14078
diff
changeset
|
275 glFinish(); |
00283cb37fd0
Make the context not current before destroying it.
reimar
parents:
14078
diff
changeset
|
276 glXMakeCurrent(mDisplay, None, NULL); |
13843 | 277 glXDestroyContext(mDisplay, *context); |
14089
00283cb37fd0
Make the context not current before destroying it.
reimar
parents:
14078
diff
changeset
|
278 } |
13843 | 279 *context = 0; |
280 } | |
281 #endif | |
282 |