1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "GLEScmValidate.h"
17 #include <GLcommon/GLutils.h>
18 #include <GLES/gl.h>
19 #include <GLES/glext.h>
20 #include <GLcommon/GLEScontext.h>
21 #include "GLEScmValidate.h"
22
23
lightEnum(GLenum e,unsigned int maxLights)24 bool GLEScmValidate::lightEnum(GLenum e,unsigned int maxLights) {
25 return e >=GL_LIGHT0 && e <= (GL_LIGHT0+maxLights);
26 }
27
clipPlaneEnum(GLenum e,unsigned int maxClipPlanes)28 bool GLEScmValidate::clipPlaneEnum(GLenum e,unsigned int maxClipPlanes) {
29 return e >=GL_CLIP_PLANE0 && e <= (GL_CLIP_PLANE0+maxClipPlanes);
30 }
31
alphaFunc(GLenum f)32 bool GLEScmValidate::alphaFunc(GLenum f) {
33 switch(f) {
34 case GL_NEVER:
35 case GL_LESS:
36 case GL_EQUAL:
37 case GL_LEQUAL:
38 case GL_GREATER:
39 case GL_NOTEQUAL:
40 case GL_GEQUAL:
41 case GL_ALWAYS:
42 return true;
43 }
44 return false;
45 }
46
blendSrc(GLenum s)47 bool GLEScmValidate::blendSrc(GLenum s) {
48 switch(s) {
49 case GL_ZERO:
50 case GL_ONE:
51 case GL_DST_COLOR:
52 case GL_ONE_MINUS_DST_COLOR:
53 case GL_SRC_ALPHA:
54 case GL_ONE_MINUS_SRC_ALPHA:
55 case GL_DST_ALPHA:
56 case GL_ONE_MINUS_DST_ALPHA:
57 case GL_SRC_ALPHA_SATURATE:
58 return true;
59 }
60 return false;
61 }
62
vertexPointerParams(GLint size,GLsizei stride)63 bool GLEScmValidate::vertexPointerParams(GLint size,GLsizei stride) {
64 return ((size >=2) && (size <= 4)) && (stride >=0) ;
65 }
66
colorPointerParams(GLint size,GLsizei stride)67 bool GLEScmValidate::colorPointerParams(GLint size,GLsizei stride) {
68 return (size == 4) && (stride >=0) ;
69 }
70
texCoordPointerParams(GLint size,GLsizei stride)71 bool GLEScmValidate::texCoordPointerParams(GLint size,GLsizei stride) {
72 return ((size >=2) && (size <= 4)) && (stride >=0) ;
73 }
74
supportedArrays(GLenum arr)75 bool GLEScmValidate::supportedArrays(GLenum arr) {
76 switch(arr) {
77 case GL_COLOR_ARRAY:
78 case GL_NORMAL_ARRAY:
79 case GL_POINT_SIZE_ARRAY_OES:
80 case GL_TEXTURE_COORD_ARRAY:
81 case GL_VERTEX_ARRAY:
82 return true;
83 }
84 return false;
85 }
86
hintTargetMode(GLenum target,GLenum mode)87 bool GLEScmValidate::hintTargetMode(GLenum target,GLenum mode) {
88 switch(target) {
89 case GL_FOG_HINT:
90 case GL_GENERATE_MIPMAP_HINT:
91 case GL_LINE_SMOOTH_HINT:
92 case GL_PERSPECTIVE_CORRECTION_HINT:
93 case GL_POINT_SMOOTH_HINT:
94 break;
95 default: return false;
96 }
97 switch(mode) {
98 case GL_FASTEST:
99 case GL_NICEST:
100 case GL_DONT_CARE:
101 break;
102 default: return false;
103 }
104 return true;
105 }
106
texParams(GLenum target,GLenum pname)107 bool GLEScmValidate::texParams(GLenum target,GLenum pname) {
108 switch(pname) {
109 case GL_TEXTURE_MIN_FILTER:
110 case GL_TEXTURE_MAG_FILTER:
111 case GL_TEXTURE_WRAP_S:
112 case GL_TEXTURE_WRAP_T:
113 case GL_TEXTURE_CROP_RECT_OES:
114 case GL_GENERATE_MIPMAP:
115 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
116 break;
117 default:
118 return false;
119 }
120 return (target == GL_TEXTURE_2D)||(target == GL_TEXTURE_CUBE_MAP_OES);
121 }
122
texEnv(GLenum target,GLenum pname)123 bool GLEScmValidate::texEnv(GLenum target,GLenum pname) {
124 switch(pname) {
125 case GL_TEXTURE_ENV_MODE:
126 case GL_TEXTURE_ENV_COLOR:
127 case GL_COMBINE_RGB:
128 case GL_COMBINE_ALPHA:
129 case GL_SRC0_RGB:
130 case GL_SRC1_RGB:
131 case GL_SRC2_RGB:
132 case GL_SRC0_ALPHA:
133 case GL_SRC1_ALPHA:
134 case GL_SRC2_ALPHA:
135 case GL_OPERAND0_RGB:
136 case GL_OPERAND1_RGB:
137 case GL_OPERAND2_RGB:
138 case GL_OPERAND0_ALPHA:
139 case GL_OPERAND1_ALPHA:
140 case GL_OPERAND2_ALPHA:
141 case GL_RGB_SCALE:
142 case GL_ALPHA_SCALE:
143 case GL_COORD_REPLACE_OES:
144 break;
145 default:
146 return false;
147 }
148 return (target == GL_TEXTURE_ENV || target == GL_POINT_SPRITE_OES);
149 }
150
capability(GLenum cap,int maxLights,int maxClipPlanes)151 bool GLEScmValidate::capability(GLenum cap,int maxLights,int maxClipPlanes) {
152 switch(cap) {
153 case GL_ALPHA_TEST:
154 case GL_BLEND:
155 case GL_COLOR_ARRAY:
156 case GL_COLOR_LOGIC_OP:
157 case GL_COLOR_MATERIAL:
158 case GL_CULL_FACE:
159 case GL_DEPTH_TEST:
160 case GL_DITHER:
161 case GL_FOG:
162 case GL_LIGHTING:
163 case GL_LINE_SMOOTH:
164 case GL_MULTISAMPLE:
165 case GL_NORMAL_ARRAY:
166 case GL_NORMALIZE:
167 case GL_POINT_SIZE_ARRAY_OES:
168 case GL_POINT_SMOOTH:
169 case GL_POINT_SPRITE_OES:
170 case GL_POLYGON_OFFSET_FILL:
171 case GL_RESCALE_NORMAL:
172 case GL_SAMPLE_ALPHA_TO_COVERAGE:
173 case GL_SAMPLE_ALPHA_TO_ONE:
174 case GL_SAMPLE_COVERAGE:
175 case GL_SCISSOR_TEST:
176 case GL_STENCIL_TEST:
177 case GL_TEXTURE_2D:
178 case GL_TEXTURE_COORD_ARRAY:
179 case GL_VERTEX_ARRAY:
180 return true;
181 }
182 return GLEScmValidate::lightEnum(cap,maxLights) || GLEScmValidate::clipPlaneEnum(cap,maxClipPlanes);
183 }
184
185
texCompImgFrmt(GLenum format)186 bool GLEScmValidate::texCompImgFrmt(GLenum format) {
187 switch(format) {
188 case GL_PALETTE4_RGB8_OES:
189 case GL_PALETTE4_RGBA8_OES:
190 case GL_PALETTE4_R5_G6_B5_OES:
191 case GL_PALETTE4_RGBA4_OES:
192 case GL_PALETTE4_RGB5_A1_OES:
193 case GL_PALETTE8_RGB8_OES:
194 case GL_PALETTE8_RGBA8_OES:
195 case GL_PALETTE8_R5_G6_B5_OES:
196 case GL_PALETTE8_RGBA4_OES:
197 case GL_PALETTE8_RGB5_A1_OES:
198 return true;
199 }
200 return false;
201 }
202
blendDst(GLenum d)203 bool GLEScmValidate::blendDst(GLenum d) {
204 switch(d) {
205 case GL_ZERO:
206 case GL_ONE:
207 case GL_SRC_COLOR:
208 case GL_ONE_MINUS_SRC_COLOR:
209 case GL_SRC_ALPHA:
210 case GL_ONE_MINUS_SRC_ALPHA:
211 case GL_DST_ALPHA:
212 case GL_ONE_MINUS_DST_ALPHA:
213 return true;
214 }
215 return false;
216 }
217
renderbufferInternalFrmt(GLEScontext * ctx,GLenum internalformat)218 bool GLEScmValidate::renderbufferInternalFrmt(GLEScontext* ctx, GLenum internalformat)
219 {
220 switch (internalformat) {
221 case GL_DEPTH_COMPONENT16_OES:
222 case GL_RGBA4_OES:
223 case GL_RGB5_A1_OES:
224 case GL_RGB565_OES:
225 case GL_STENCIL_INDEX1_OES:
226 case GL_STENCIL_INDEX4_OES:
227 case GL_STENCIL_INDEX8_OES:
228 case GL_RGB8_OES:
229 case GL_RGBA8_OES:
230 case GL_DEPTH_COMPONENT24_OES:
231 case GL_DEPTH_COMPONENT32_OES:
232 return true;
233 }
234 if (ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && internalformat==GL_DEPTH24_STENCIL8_OES)
235 return true;
236
237 return false;
238 }
239
stencilOp(GLenum param)240 bool GLEScmValidate::stencilOp(GLenum param) {
241 switch (param) {
242 case GL_KEEP:
243 case GL_ZERO:
244 case GL_REPLACE:
245 case GL_INCR:
246 case GL_DECR:
247 case GL_INVERT:
248 case GL_INCR_WRAP_OES:
249 case GL_DECR_WRAP_OES:
250 return true;
251 }
252 return false;
253 }
254
texGen(GLenum coord,GLenum pname)255 bool GLEScmValidate::texGen(GLenum coord, GLenum pname) {
256 return (coord == GL_TEXTURE_GEN_STR_OES && pname == GL_TEXTURE_GEN_MODE_OES);
257 }
258
colorPointerType(GLenum type)259 bool GLEScmValidate::colorPointerType(GLenum type){
260 switch(type){
261 case GL_UNSIGNED_BYTE:
262 case GL_FIXED:
263 case GL_FLOAT:
264 return true;
265 }
266 return false;
267 }
268
normalPointerType(GLenum type)269 bool GLEScmValidate::normalPointerType(GLenum type){
270
271 switch(type){
272 case GL_BYTE:
273 case GL_SHORT:
274 case GL_FLOAT:
275 case GL_FIXED:
276 return true;
277 }
278 return false;
279 }
280
pointPointerType(GLenum type)281 bool GLEScmValidate::pointPointerType(GLenum type){
282 return type == GL_FIXED || type == GL_FLOAT;
283 }
284
texCoordPointerType(GLenum type)285 bool GLEScmValidate::texCoordPointerType(GLenum type){
286 switch(type){
287 case GL_BYTE:
288 case GL_SHORT:
289 case GL_FLOAT:
290 case GL_FIXED:
291 return true;
292 }
293 return false;
294 }
295
vertexPointerType(GLenum type)296 bool GLEScmValidate::vertexPointerType(GLenum type){
297 switch(type){
298 case GL_BYTE:
299 case GL_SHORT:
300 case GL_FLOAT:
301 case GL_FIXED:
302 return true;
303 }
304 return false;
305 }
306
307