mesa: add glformats integer type/format detection routines
[mesa.git] / src / mesa / main / glformats.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include "imports.h"
28 #include "glformats.h"
29
30
31 /**
32 * Test if the given format is an integer (non-normalized) format.
33 */
34 GLboolean
35 _mesa_is_enum_format_integer(GLenum format)
36 {
37 switch (format) {
38 /* generic integer formats */
39 case GL_RED_INTEGER_EXT:
40 case GL_GREEN_INTEGER_EXT:
41 case GL_BLUE_INTEGER_EXT:
42 case GL_ALPHA_INTEGER_EXT:
43 case GL_RGB_INTEGER_EXT:
44 case GL_RGBA_INTEGER_EXT:
45 case GL_BGR_INTEGER_EXT:
46 case GL_BGRA_INTEGER_EXT:
47 case GL_LUMINANCE_INTEGER_EXT:
48 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
49 case GL_RG_INTEGER:
50 /* specific integer formats */
51 case GL_RGBA32UI_EXT:
52 case GL_RGB32UI_EXT:
53 case GL_RG32UI:
54 case GL_R32UI:
55 case GL_ALPHA32UI_EXT:
56 case GL_INTENSITY32UI_EXT:
57 case GL_LUMINANCE32UI_EXT:
58 case GL_LUMINANCE_ALPHA32UI_EXT:
59 case GL_RGBA16UI_EXT:
60 case GL_RGB16UI_EXT:
61 case GL_RG16UI:
62 case GL_R16UI:
63 case GL_ALPHA16UI_EXT:
64 case GL_INTENSITY16UI_EXT:
65 case GL_LUMINANCE16UI_EXT:
66 case GL_LUMINANCE_ALPHA16UI_EXT:
67 case GL_RGBA8UI_EXT:
68 case GL_RGB8UI_EXT:
69 case GL_RG8UI:
70 case GL_R8UI:
71 case GL_ALPHA8UI_EXT:
72 case GL_INTENSITY8UI_EXT:
73 case GL_LUMINANCE8UI_EXT:
74 case GL_LUMINANCE_ALPHA8UI_EXT:
75 case GL_RGBA32I_EXT:
76 case GL_RGB32I_EXT:
77 case GL_RG32I:
78 case GL_R32I:
79 case GL_ALPHA32I_EXT:
80 case GL_INTENSITY32I_EXT:
81 case GL_LUMINANCE32I_EXT:
82 case GL_LUMINANCE_ALPHA32I_EXT:
83 case GL_RGBA16I_EXT:
84 case GL_RGB16I_EXT:
85 case GL_RG16I:
86 case GL_R16I:
87 case GL_ALPHA16I_EXT:
88 case GL_INTENSITY16I_EXT:
89 case GL_LUMINANCE16I_EXT:
90 case GL_LUMINANCE_ALPHA16I_EXT:
91 case GL_RGBA8I_EXT:
92 case GL_RGB8I_EXT:
93 case GL_RG8I:
94 case GL_R8I:
95 case GL_ALPHA8I_EXT:
96 case GL_INTENSITY8I_EXT:
97 case GL_LUMINANCE8I_EXT:
98 case GL_LUMINANCE_ALPHA8I_EXT:
99 case GL_RGB10_A2UI:
100 return GL_TRUE;
101 default:
102 return GL_FALSE;
103 }
104 }
105
106
107 /**
108 * Test if the given type is an integer (non-normalized) format.
109 */
110 GLboolean
111 _mesa_is_type_integer(GLenum type)
112 {
113 switch (type) {
114 case GL_INT:
115 case GL_UNSIGNED_INT:
116 case GL_SHORT:
117 case GL_UNSIGNED_SHORT:
118 case GL_BYTE:
119 case GL_UNSIGNED_BYTE:
120 return GL_TRUE;
121 default:
122 return GL_FALSE;
123 }
124 }
125
126
127 /**
128 * Test if the given format or type is an integer (non-normalized) format.
129 */
130 extern GLboolean
131 _mesa_is_enum_format_or_type_integer(GLenum format, GLenum type)
132 {
133 return _mesa_is_enum_format_integer(format) || _mesa_is_type_integer(type);
134 }
135
136
137 GLboolean
138 _mesa_is_type_unsigned(GLenum type)
139 {
140 switch (type) {
141 case GL_UNSIGNED_INT:
142 case GL_UNSIGNED_INT_8_8_8_8:
143 case GL_UNSIGNED_INT_8_8_8_8_REV:
144 case GL_UNSIGNED_INT_10_10_10_2:
145 case GL_UNSIGNED_INT_2_10_10_10_REV:
146
147 case GL_UNSIGNED_SHORT:
148 case GL_UNSIGNED_SHORT_4_4_4_4:
149 case GL_UNSIGNED_SHORT_5_5_5_1:
150 case GL_UNSIGNED_SHORT_5_6_5:
151 case GL_UNSIGNED_SHORT_5_6_5_REV:
152 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
153 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
154 case GL_UNSIGNED_SHORT_8_8_MESA:
155 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
156
157 case GL_UNSIGNED_BYTE:
158 case GL_UNSIGNED_BYTE_3_3_2:
159 case GL_UNSIGNED_BYTE_2_3_3_REV:
160 return GL_TRUE;
161
162 default:
163 return GL_FALSE;
164 }
165 }
166
167
168 /**
169 * Convert various base formats to the cooresponding integer format.
170 */
171 GLenum
172 _mesa_base_format_to_integer_format(GLenum format)
173 {
174 switch(format) {
175 case GL_RED:
176 return GL_RED_INTEGER;
177 case GL_GREEN:
178 return GL_GREEN_INTEGER;
179 case GL_BLUE:
180 return GL_BLUE_INTEGER;
181 case GL_RG:
182 return GL_RG_INTEGER;
183 case GL_RGB:
184 return GL_RGB_INTEGER;
185 case GL_RGBA:
186 return GL_RGBA_INTEGER;
187 case GL_BGR:
188 return GL_BGR_INTEGER;
189 case GL_BGRA:
190 return GL_BGRA_INTEGER;
191 case GL_ALPHA:
192 return GL_ALPHA_INTEGER;
193 case GL_LUMINANCE:
194 return GL_LUMINANCE_INTEGER_EXT;
195 case GL_LUMINANCE_ALPHA:
196 return GL_LUMINANCE_ALPHA_INTEGER_EXT;
197 }
198
199 return format;
200 }
201