• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "GLESv2Validate.h"
17 #include <string.h>
18 
blendEquationMode(GLenum mode)19 bool GLESv2Validate::blendEquationMode(GLenum mode){
20     return mode == GL_FUNC_ADD             ||
21            mode == GL_FUNC_SUBTRACT        ||
22            mode == GL_FUNC_REVERSE_SUBTRACT;
23 }
24 
blendSrc(GLenum s)25 bool GLESv2Validate::blendSrc(GLenum s) {
26    switch(s) {
27    case GL_ZERO:
28    case GL_ONE:
29    case GL_SRC_COLOR:
30    case GL_ONE_MINUS_SRC_COLOR:
31    case GL_DST_COLOR:
32    case GL_ONE_MINUS_DST_COLOR:
33    case GL_SRC_ALPHA:
34    case GL_ONE_MINUS_SRC_ALPHA:
35    case GL_DST_ALPHA:
36    case GL_ONE_MINUS_DST_ALPHA:
37    case GL_CONSTANT_COLOR:
38    case GL_ONE_MINUS_CONSTANT_COLOR:
39    case GL_CONSTANT_ALPHA:
40    case GL_ONE_MINUS_CONSTANT_ALPHA:
41    case GL_SRC_ALPHA_SATURATE:
42         return true;
43   }
44   return false;
45 }
46 
47 
blendDst(GLenum d)48 bool GLESv2Validate::blendDst(GLenum d) {
49    switch(d) {
50    case GL_ZERO:
51    case GL_ONE:
52    case GL_SRC_COLOR:
53    case GL_ONE_MINUS_SRC_COLOR:
54    case GL_DST_COLOR:
55    case GL_ONE_MINUS_DST_COLOR:
56    case GL_SRC_ALPHA:
57    case GL_ONE_MINUS_SRC_ALPHA:
58    case GL_DST_ALPHA:
59    case GL_ONE_MINUS_DST_ALPHA:
60    case GL_CONSTANT_COLOR:
61    case GL_ONE_MINUS_CONSTANT_COLOR:
62    case GL_CONSTANT_ALPHA:
63    case GL_ONE_MINUS_CONSTANT_ALPHA:
64         return true;
65    }
66    return false;
67 }
68 
textureParams(GLenum param)69 bool GLESv2Validate::textureParams(GLenum param){
70     switch(param) {
71     case GL_TEXTURE_MIN_FILTER:
72     case GL_TEXTURE_MAG_FILTER:
73     case GL_TEXTURE_WRAP_S:
74     case GL_TEXTURE_WRAP_T:
75         return true;
76     default:
77         return false;
78     }
79 }
80 
hintTargetMode(GLenum target,GLenum mode)81 bool GLESv2Validate::hintTargetMode(GLenum target,GLenum mode){
82 
83    switch(mode) {
84    case GL_FASTEST:
85    case GL_NICEST:
86    case GL_DONT_CARE:
87        break;
88    default: return false;
89    }
90    return target == GL_GENERATE_MIPMAP_HINT || target == GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES;
91 }
92 
capability(GLenum cap)93 bool GLESv2Validate::capability(GLenum cap){
94     switch(cap){
95     case GL_BLEND:
96     case GL_CULL_FACE:
97     case GL_DEPTH_TEST:
98     case GL_DITHER:
99     case GL_POLYGON_OFFSET_FILL:
100     case GL_SAMPLE_ALPHA_TO_COVERAGE:
101     case GL_SAMPLE_COVERAGE:
102     case GL_SCISSOR_TEST:
103     case GL_STENCIL_TEST:
104         return true;
105     }
106     return false;
107 }
108 
pixelStoreParam(GLenum param)109 bool GLESv2Validate::pixelStoreParam(GLenum param){
110     return param == GL_PACK_ALIGNMENT || param == GL_UNPACK_ALIGNMENT;
111 }
112 
readPixelFrmt(GLenum format)113 bool GLESv2Validate::readPixelFrmt(GLenum format){
114     switch(format) {
115     case GL_ALPHA:
116     case GL_RGB:
117     case GL_RGBA:
118         return true;
119     }
120     return false;
121 }
122 
123 
shaderType(GLenum type)124 bool GLESv2Validate::shaderType(GLenum type){
125     return type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER;
126 }
127 
precisionType(GLenum type)128 bool GLESv2Validate::precisionType(GLenum type){
129     switch(type){
130     case GL_LOW_FLOAT:
131     case GL_MEDIUM_FLOAT:
132     case GL_HIGH_FLOAT:
133     case GL_LOW_INT:
134     case GL_MEDIUM_INT:
135     case GL_HIGH_INT:
136         return true;
137     }
138     return false;
139 }
140 
arrayIndex(GLEScontext * ctx,GLuint index)141 bool GLESv2Validate::arrayIndex(GLEScontext * ctx,GLuint index) {
142     return index < (GLuint)ctx->getCaps()->maxVertexAttribs;
143 }
144 
pixelType(GLEScontext * ctx,GLenum type)145 bool GLESv2Validate::pixelType(GLEScontext * ctx,GLenum type) {
146     if(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT)
147         return true;
148 
149     return GLESvalidate::pixelType(ctx, type);
150 }
151 
pixelFrmt(GLEScontext * ctx,GLenum format)152 bool GLESv2Validate::pixelFrmt(GLEScontext* ctx,GLenum format) {
153     if(format == GL_DEPTH_COMPONENT)
154         return true;
155 
156     return GLESvalidate::pixelFrmt(ctx, format);
157 }
158 
attribName(const GLchar * name)159 bool GLESv2Validate::attribName(const GLchar* name){
160     const GLchar* found = strstr(name,"gl_");
161     return (!found) ||
162            (found != name) ; // attrib name does not start with gl_
163 }
164 
attribIndex(int index)165 bool GLESv2Validate::attribIndex(int index){
166     return index >=0 && index < GL_MAX_VERTEX_ATTRIBS;
167 }
168 
programParam(GLenum pname)169 bool GLESv2Validate::programParam(GLenum pname){
170     switch(pname){
171         case GL_DELETE_STATUS:
172         case GL_LINK_STATUS:
173         case GL_VALIDATE_STATUS:
174         case GL_INFO_LOG_LENGTH:
175         case GL_ATTACHED_SHADERS:
176         case GL_ACTIVE_ATTRIBUTES:
177         case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
178         case GL_ACTIVE_UNIFORMS:
179         case GL_ACTIVE_UNIFORM_MAX_LENGTH:
180             return true;
181     }
182     return false;
183 }
184