comparison libvo/gl_common.c @ 14078:c4033dcb986f

More similar code from gl and gl2 moved to gl_common
author reimar
date Wed, 01 Dec 2004 17:05:58 +0000
parents 3f28d2a56758
children 00283cb37fd0
comparison
equal deleted inserted replaced
14077:3d3f3cc8494a 14078:c4033dcb986f
13 else if (stride % 2 == 0) 13 else if (stride % 2 == 0)
14 gl_alignment=2; 14 gl_alignment=2;
15 else 15 else
16 gl_alignment=1; 16 gl_alignment=1;
17 glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment); 17 glPixelStorei (GL_UNPACK_ALIGNMENT, gl_alignment);
18 }
19
20 #include "img_format.h"
21
22 struct gl_name_map_struct {
23 GLint value;
24 char *name;
25 };
26
27 #undef MAP
28 #define MAP(a) {a, #a}
29 static const struct gl_name_map_struct gl_name_map[] = {
30 // internal format
31 MAP(GL_R3_G3_B2), MAP(GL_RGB4), MAP(GL_RGB5), MAP(GL_RGB8),
32 MAP(GL_RGB10), MAP(GL_RGB12), MAP(GL_RGB16), MAP(GL_RGBA2),
33 MAP(GL_RGBA4), MAP(GL_RGB5_A1), MAP(GL_RGBA8), MAP(GL_RGB10_A2),
34 MAP(GL_RGBA12), MAP(GL_RGBA16), MAP(GL_LUMINANCE8),
35
36 // format
37 MAP(GL_RGB), MAP(GL_RGBA), MAP(GL_RED), MAP(GL_GREEN), MAP(GL_BLUE),
38 MAP(GL_ALPHA), MAP(GL_LUMINANCE), MAP(GL_LUMINANCE_ALPHA),
39 MAP(GL_COLOR_INDEX),
40 // rest 1.2 only
41 #ifdef GL_VERSION_1_2
42 MAP(GL_BGR), MAP(GL_BGRA),
43 #endif
44
45 //type
46 MAP(GL_BYTE), MAP(GL_UNSIGNED_BYTE), MAP(GL_SHORT), MAP(GL_UNSIGNED_SHORT),
47 MAP(GL_INT), MAP(GL_UNSIGNED_INT), MAP(GL_FLOAT), MAP(GL_DOUBLE),
48 MAP(GL_2_BYTES), MAP(GL_3_BYTES), MAP(GL_4_BYTES),
49 // rest 1.2 only
50 #ifdef GL_VERSION_1_2
51 MAP(GL_UNSIGNED_BYTE_3_3_2), MAP(GL_UNSIGNED_BYTE_2_3_3_REV),
52 MAP(GL_UNSIGNED_SHORT_5_6_5), MAP(GL_UNSIGNED_SHORT_5_6_5_REV),
53 MAP(GL_UNSIGNED_SHORT_4_4_4_4), MAP(GL_UNSIGNED_SHORT_4_4_4_4_REV),
54 MAP(GL_UNSIGNED_SHORT_5_5_5_1), MAP(GL_UNSIGNED_SHORT_1_5_5_5_REV),
55 MAP(GL_UNSIGNED_INT_8_8_8_8), MAP(GL_UNSIGNED_INT_8_8_8_8_REV),
56 MAP(GL_UNSIGNED_INT_10_10_10_2), MAP(GL_UNSIGNED_INT_2_10_10_10_REV),
57 #endif
58 {0, 0}
59 };
60 #undef MAP
61
62 /**
63 * \brief return the name of an OpenGL constant
64 * \param value the constant
65 * \return name of the constant or "Unknown format!"
66 */
67 const char *glValName(GLint value)
68 {
69 int i = 0;
70
71 while (gl_name_map[i].name) {
72 if (gl_name_map[i].value == value)
73 return gl_name_map[i].name;
74 i++;
75 }
76 return "Unknown format!";
77 }
78
79 #undef TEXTUREFORMAT_ALWAYS
80 //! always return this format as internal texture format in glFindFormat
81 #define TEXTUREFORMAT_ALWAYS GL_RGB8
82
83 /**
84 * \brief find the OpenGL settings coresponding to format.
85 *
86 * All parameters may be NULL.
87 * \param fmt MPlayer format to analyze.
88 * \param bpp [OUT] bits per pixel of that format.
89 * \param gl_texfmt [OUT] internal texture format that fits the
90 * image format, not necessarily the best for performance.
91 * \param gl_format [OUT] OpenGL format for this image format.
92 * \param gl_type [OUT] OpenGL type for this image format.
93 * \return 1 if format is supported by OpenGL, 0 if not.
94 */
95 int glFindFormat(uint32_t fmt, uint32_t *bpp, GLenum *gl_texfmt,
96 GLenum *gl_format, GLenum *gl_type)
97 {
98 int dummy1;
99 GLenum dummy2;
100 if (bpp == NULL) bpp = &dummy1;
101 if (gl_texfmt == NULL) gl_texfmt = &dummy2;
102 if (gl_format == NULL) gl_format = &dummy2;
103 if (gl_type == NULL) gl_type = &dummy2;
104
105 *bpp = IMGFMT_IS_BGR(fmt)?IMGFMT_BGR_DEPTH(fmt):IMGFMT_RGB_DEPTH(fmt);
106 *gl_texfmt = 3;
107 switch (fmt) {
108 case IMGFMT_RGB24:
109 *gl_format = GL_RGB;
110 *gl_type = GL_UNSIGNED_BYTE;
111 break;
112 case IMGFMT_RGBA:
113 *gl_texfmt = 4;
114 *gl_format = GL_RGBA;
115 *gl_type = GL_UNSIGNED_BYTE;
116 break;
117 case IMGFMT_Y800:
118 case IMGFMT_Y8:
119 *gl_texfmt = 1;
120 *bpp = 8;
121 *gl_format = GL_LUMINANCE;
122 *gl_type = GL_UNSIGNED_BYTE;
123 break;
124 #ifdef GL_VERSION_1_2
125 #if 0
126 // we do not support palettized formats, although the format the
127 // swscale produces works
128 case IMGFMT_RGB8:
129 gl_format = GL_RGB;
130 gl_type = GL_UNSIGNED_BYTE_2_3_3_REV;
131 break;
132 #endif
133 case IMGFMT_RGB15:
134 *gl_format = GL_RGBA;
135 *gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
136 break;
137 case IMGFMT_RGB16:
138 *gl_format = GL_RGB;
139 *gl_type = GL_UNSIGNED_SHORT_5_6_5_REV;
140 break;
141 #if 0
142 case IMGFMT_BGR8:
143 // special case as red and blue have a differen number of bits.
144 // GL_BGR and GL_UNSIGNED_BYTE_3_3_2 isn't supported at least
145 // by nVidia drivers, and in addition would give more bits to
146 // blue than to red, which isn't wanted
147 gl_format = GL_RGB;
148 gl_type = GL_UNSIGNED_BYTE_3_3_2;
149 break;
150 #endif
151 case IMGFMT_BGR15:
152 *gl_format = GL_BGRA;
153 *gl_type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
154 break;
155 case IMGFMT_BGR16:
156 *gl_format = GL_RGB;
157 *gl_type = GL_UNSIGNED_SHORT_5_6_5;
158 break;
159 case IMGFMT_BGR24:
160 *gl_format = GL_BGR;
161 *gl_type = GL_UNSIGNED_BYTE;
162 break;
163 case IMGFMT_BGRA:
164 *gl_texfmt = 4;
165 *gl_format = GL_BGRA;
166 *gl_type = GL_UNSIGNED_BYTE;
167 break;
168 #endif
169 default:
170 *gl_texfmt = 4;
171 *gl_format = GL_RGBA;
172 *gl_type = GL_UNSIGNED_BYTE;
173 return 0;
174 }
175 #ifdef TEXTUREFORMAT_ALWAYS
176 *gl_texfmt = TEXTUREFORMAT_ALWAYS;
177 #endif
178 return 1;
18 } 179 }
19 180
20 #ifndef GL_WIN32 181 #ifndef GL_WIN32
21 /** 182 /**
22 * Returns the XVisualInfo associated with Window win. 183 * Returns the XVisualInfo associated with Window win.