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