aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/host/libs/Translator/GLES_CM/GLEScmValidate.cpp
blob: 1970232c7bca10d1e0b89142f843d122915bef06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLEScmValidate.h"
#include <GLcommon/GLutils.h>
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <GLcommon/GLEScontext.h>
#include "GLEScmValidate.h"


bool GLEScmValidate::lightEnum(GLenum e,unsigned int maxLights) {
    return  e >=GL_LIGHT0 && e <= (GL_LIGHT0+maxLights);
}

bool GLEScmValidate::clipPlaneEnum(GLenum e,unsigned int maxClipPlanes) {
    return  e >=GL_CLIP_PLANE0 && e <= (GL_CLIP_PLANE0+maxClipPlanes);
}

bool GLEScmValidate::alphaFunc(GLenum f) {
    switch(f) {
    case GL_NEVER:
    case GL_LESS:
    case GL_EQUAL:
    case GL_LEQUAL:
    case GL_GREATER:
    case GL_NOTEQUAL:
    case GL_GEQUAL:
    case GL_ALWAYS:
        return true;
    }
    return false;
}

bool GLEScmValidate::blendSrc(GLenum s) {
   switch(s) {
    case GL_ZERO:
    case GL_ONE:
    case GL_DST_COLOR:
    case GL_ONE_MINUS_DST_COLOR:
    case GL_SRC_ALPHA:
    case GL_ONE_MINUS_SRC_ALPHA:
    case GL_DST_ALPHA:
    case GL_ONE_MINUS_DST_ALPHA:
    case GL_SRC_ALPHA_SATURATE:
        return true;
  }
  return false;
}

bool GLEScmValidate::vertexPointerParams(GLint size,GLsizei stride) {
    return ((size >=2) && (size <= 4)) && (stride >=0) ;
}

bool GLEScmValidate::colorPointerParams(GLint size,GLsizei stride) {
    return ((size >=3) && (size <= 4)) && (stride >=0) ;
}

bool GLEScmValidate::texCoordPointerParams(GLint size,GLsizei stride) {
    return ((size >=2) && (size <= 4)) && (stride >=0) ;
}

bool GLEScmValidate::supportedArrays(GLenum arr) {
    switch(arr) {
    case GL_COLOR_ARRAY:
    case GL_NORMAL_ARRAY:
    case GL_POINT_SIZE_ARRAY_OES:
    case GL_TEXTURE_COORD_ARRAY:
    case GL_VERTEX_ARRAY:
        return true;
    }
    return false;
}

bool GLEScmValidate::hintTargetMode(GLenum target,GLenum mode) {
   switch(target) {
   case GL_FOG_HINT:
   case GL_GENERATE_MIPMAP_HINT:
   case GL_LINE_SMOOTH_HINT:
   case GL_PERSPECTIVE_CORRECTION_HINT:
   case GL_POINT_SMOOTH_HINT:
       break;
   default: return false;
   }
   switch(mode) {
   case GL_FASTEST:
   case GL_NICEST:
   case GL_DONT_CARE:
       break;
   default: return false;
   }
   return true;
}

bool GLEScmValidate::texParams(GLenum target,GLenum pname) {
    switch(pname) {
    case GL_TEXTURE_MIN_FILTER:
    case GL_TEXTURE_MAG_FILTER:
    case GL_TEXTURE_WRAP_S:
    case GL_TEXTURE_WRAP_T:
    case GL_TEXTURE_CROP_RECT_OES:
    case GL_GENERATE_MIPMAP:
        break;
    default:
        return false;
    }
    return (target == GL_TEXTURE_2D)||(target == GL_TEXTURE_CUBE_MAP_OES);
}

bool GLEScmValidate::texEnv(GLenum target,GLenum pname) {
    switch(pname) {
    case GL_TEXTURE_ENV_MODE:
    case GL_TEXTURE_ENV_COLOR:
    case GL_COMBINE_RGB:
    case GL_COMBINE_ALPHA:
    case GL_SRC0_RGB:
    case GL_SRC1_RGB:
    case GL_SRC2_RGB:
    case GL_SRC0_ALPHA:
    case GL_SRC1_ALPHA:
    case GL_SRC2_ALPHA:
    case GL_OPERAND0_RGB:
    case GL_OPERAND1_RGB:
    case GL_OPERAND2_RGB:
    case GL_OPERAND0_ALPHA:
    case GL_OPERAND1_ALPHA:
    case GL_OPERAND2_ALPHA:
    case GL_RGB_SCALE:
    case GL_ALPHA_SCALE:
    case GL_COORD_REPLACE_OES:
        break;
    default:
        return false;
    }
    return (target == GL_TEXTURE_ENV || target == GL_POINT_SPRITE_OES);
}

bool GLEScmValidate::capability(GLenum cap,int maxLights,int maxClipPlanes) {
    switch(cap) {
    case GL_ALPHA_TEST:
    case GL_BLEND:
    case GL_COLOR_ARRAY:
    case GL_COLOR_LOGIC_OP:
    case GL_COLOR_MATERIAL:
    case GL_CULL_FACE:
    case GL_DEPTH_TEST:
    case GL_DITHER:
    case GL_FOG:
    case GL_LIGHTING:
    case GL_LINE_SMOOTH:
    case GL_MULTISAMPLE:
    case GL_NORMAL_ARRAY:
    case GL_NORMALIZE:
    case GL_POINT_SIZE_ARRAY_OES:
    case GL_POINT_SMOOTH:
    case GL_POINT_SPRITE_OES:
    case GL_POLYGON_OFFSET_FILL:
    case GL_RESCALE_NORMAL:
    case GL_SAMPLE_ALPHA_TO_COVERAGE:
    case GL_SAMPLE_ALPHA_TO_ONE:
    case GL_SAMPLE_COVERAGE:
    case GL_SCISSOR_TEST:
    case GL_STENCIL_TEST:
    case GL_TEXTURE_2D:
    case GL_TEXTURE_COORD_ARRAY:
    case GL_VERTEX_ARRAY:
        return true;
    }
    return GLEScmValidate::lightEnum(cap,maxLights) || GLEScmValidate::clipPlaneEnum(cap,maxClipPlanes);
}


bool GLEScmValidate::texCompImgFrmt(GLenum format) {
    switch(format) {
    case GL_PALETTE4_RGB8_OES:
    case GL_PALETTE4_RGBA8_OES:
    case GL_PALETTE4_R5_G6_B5_OES:
    case GL_PALETTE4_RGBA4_OES:
    case GL_PALETTE4_RGB5_A1_OES:
    case GL_PALETTE8_RGB8_OES:
    case GL_PALETTE8_RGBA8_OES:
    case GL_PALETTE8_R5_G6_B5_OES:
    case GL_PALETTE8_RGBA4_OES:
    case GL_PALETTE8_RGB5_A1_OES:
        return true;
    }
    return false;
}

bool GLEScmValidate::blendDst(GLenum d) {
   switch(d) {
    case GL_ZERO:
    case GL_ONE:
    case GL_SRC_COLOR:
    case GL_ONE_MINUS_SRC_COLOR:
    case GL_SRC_ALPHA:
    case GL_ONE_MINUS_SRC_ALPHA:
    case GL_DST_ALPHA:
    case GL_ONE_MINUS_DST_ALPHA:
        return true;
   }
   return false;
}

bool GLEScmValidate::renderbufferInternalFrmt(GLEScontext* ctx, GLenum internalformat)
{
    switch (internalformat) {
    case GL_DEPTH_COMPONENT16_OES:
    case GL_RGBA4_OES:
    case GL_RGB5_A1_OES:
    case GL_RGB565_OES:
    case GL_STENCIL_INDEX1_OES:
    case GL_STENCIL_INDEX4_OES:
    case GL_STENCIL_INDEX8_OES:
    case GL_RGB8_OES:
    case GL_RGBA8_OES:
    case GL_DEPTH_COMPONENT24_OES:
    case GL_DEPTH_COMPONENT32_OES:
        return true;
    }
    if (ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && internalformat==GL_DEPTH24_STENCIL8_OES)
        return true;

    return false;
}

bool GLEScmValidate::stencilOp(GLenum param) {
    switch (param) {
    case GL_KEEP:
    case GL_ZERO:
    case GL_REPLACE:
    case GL_INCR:
    case GL_DECR:
    case GL_INVERT:
    case GL_INCR_WRAP_OES:
    case GL_DECR_WRAP_OES:
      return true;
    }
    return false;
}

bool GLEScmValidate::texGen(GLenum coord, GLenum pname) {
    return (coord == GL_TEXTURE_GEN_STR_OES && pname == GL_TEXTURE_GEN_MODE_OES);
}

bool GLEScmValidate::colorPointerType(GLenum type){
    switch(type){
    case GL_UNSIGNED_BYTE:
    case GL_FIXED:
    case GL_FLOAT:
        return true;
    }
    return false;
}

bool GLEScmValidate::normalPointerType(GLenum type){

    switch(type){
    case GL_BYTE:
    case GL_SHORT:
    case GL_FLOAT:
    case GL_FIXED:
        return true;
    }
    return false;
}

bool GLEScmValidate::pointPointerType(GLenum type){
    return type == GL_FIXED || type == GL_FLOAT;
}

bool GLEScmValidate::texCoordPointerType(GLenum type){
    switch(type){
    case GL_BYTE:
    case GL_SHORT:
    case GL_FLOAT:
    case GL_FIXED:
        return true;
    }
    return false;
}

bool GLEScmValidate::vertexPointerType(GLenum type){
    switch(type){
    case GL_BYTE:
    case GL_SHORT:
    case GL_FLOAT:
    case GL_FIXED:
        return true;
    }
    return false;
}