Home | History | Annotate | Download | only in GLES_CM
      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 
     24 bool GLEScmValidate::lightEnum(GLenum e,unsigned int maxLights) {
     25     return  e >=GL_LIGHT0 && e <= (GL_LIGHT0+maxLights);
     26 }
     27 
     28 bool GLEScmValidate::clipPlaneEnum(GLenum e,unsigned int maxClipPlanes) {
     29     return  e >=GL_CLIP_PLANE0 && e <= (GL_CLIP_PLANE0+maxClipPlanes);
     30 }
     31 
     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 
     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 
     63 bool GLEScmValidate::vertexPointerParams(GLint size,GLsizei stride) {
     64     return ((size >=2) && (size <= 4)) && (stride >=0) ;
     65 }
     66 
     67 bool GLEScmValidate::colorPointerParams(GLint size,GLsizei stride) {
     68     return ((size >=3) && (size <= 4)) && (stride >=0) ;
     69 }
     70 
     71 bool GLEScmValidate::texCoordPointerParams(GLint size,GLsizei stride) {
     72     return ((size >=2) && (size <= 4)) && (stride >=0) ;
     73 }
     74 
     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 
     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 
    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         break;
    116     default:
    117         return false;
    118     }
    119     return (target == GL_TEXTURE_2D)||(target == GL_TEXTURE_CUBE_MAP_OES);
    120 }
    121 
    122 bool GLEScmValidate::texEnv(GLenum target,GLenum pname) {
    123     switch(pname) {
    124     case GL_TEXTURE_ENV_MODE:
    125     case GL_TEXTURE_ENV_COLOR:
    126     case GL_COMBINE_RGB:
    127     case GL_COMBINE_ALPHA:
    128     case GL_SRC0_RGB:
    129     case GL_SRC1_RGB:
    130     case GL_SRC2_RGB:
    131     case GL_SRC0_ALPHA:
    132     case GL_SRC1_ALPHA:
    133     case GL_SRC2_ALPHA:
    134     case GL_OPERAND0_RGB:
    135     case GL_OPERAND1_RGB:
    136     case GL_OPERAND2_RGB:
    137     case GL_OPERAND0_ALPHA:
    138     case GL_OPERAND1_ALPHA:
    139     case GL_OPERAND2_ALPHA:
    140     case GL_RGB_SCALE:
    141     case GL_ALPHA_SCALE:
    142     case GL_COORD_REPLACE_OES:
    143         break;
    144     default:
    145         return false;
    146     }
    147     return (target == GL_TEXTURE_ENV || target == GL_POINT_SPRITE_OES);
    148 }
    149 
    150 bool GLEScmValidate::capability(GLenum cap,int maxLights,int maxClipPlanes) {
    151     switch(cap) {
    152     case GL_ALPHA_TEST:
    153     case GL_BLEND:
    154     case GL_COLOR_ARRAY:
    155     case GL_COLOR_LOGIC_OP:
    156     case GL_COLOR_MATERIAL:
    157     case GL_CULL_FACE:
    158     case GL_DEPTH_TEST:
    159     case GL_DITHER:
    160     case GL_FOG:
    161     case GL_LIGHTING:
    162     case GL_LINE_SMOOTH:
    163     case GL_MULTISAMPLE:
    164     case GL_NORMAL_ARRAY:
    165     case GL_NORMALIZE:
    166     case GL_POINT_SIZE_ARRAY_OES:
    167     case GL_POINT_SMOOTH:
    168     case GL_POINT_SPRITE_OES:
    169     case GL_POLYGON_OFFSET_FILL:
    170     case GL_RESCALE_NORMAL:
    171     case GL_SAMPLE_ALPHA_TO_COVERAGE:
    172     case GL_SAMPLE_ALPHA_TO_ONE:
    173     case GL_SAMPLE_COVERAGE:
    174     case GL_SCISSOR_TEST:
    175     case GL_STENCIL_TEST:
    176     case GL_TEXTURE_2D:
    177     case GL_TEXTURE_COORD_ARRAY:
    178     case GL_VERTEX_ARRAY:
    179         return true;
    180     }
    181     return GLEScmValidate::lightEnum(cap,maxLights) || GLEScmValidate::clipPlaneEnum(cap,maxClipPlanes);
    182 }
    183 
    184 
    185 bool GLEScmValidate::texCompImgFrmt(GLenum format) {
    186     switch(format) {
    187     case GL_PALETTE4_RGB8_OES:
    188     case GL_PALETTE4_RGBA8_OES:
    189     case GL_PALETTE4_R5_G6_B5_OES:
    190     case GL_PALETTE4_RGBA4_OES:
    191     case GL_PALETTE4_RGB5_A1_OES:
    192     case GL_PALETTE8_RGB8_OES:
    193     case GL_PALETTE8_RGBA8_OES:
    194     case GL_PALETTE8_R5_G6_B5_OES:
    195     case GL_PALETTE8_RGBA4_OES:
    196     case GL_PALETTE8_RGB5_A1_OES:
    197         return true;
    198     }
    199     return false;
    200 }
    201 
    202 bool GLEScmValidate::blendDst(GLenum d) {
    203    switch(d) {
    204     case GL_ZERO:
    205     case GL_ONE:
    206     case GL_SRC_COLOR:
    207     case GL_ONE_MINUS_SRC_COLOR:
    208     case GL_SRC_ALPHA:
    209     case GL_ONE_MINUS_SRC_ALPHA:
    210     case GL_DST_ALPHA:
    211     case GL_ONE_MINUS_DST_ALPHA:
    212         return true;
    213    }
    214    return false;
    215 }
    216 
    217 bool GLEScmValidate::renderbufferInternalFrmt(GLEScontext* ctx, GLenum internalformat)
    218 {
    219     switch (internalformat) {
    220     case GL_DEPTH_COMPONENT16_OES:
    221     case GL_RGBA4_OES:
    222     case GL_RGB5_A1_OES:
    223     case GL_RGB565_OES:
    224     case GL_STENCIL_INDEX1_OES:
    225     case GL_STENCIL_INDEX4_OES:
    226     case GL_STENCIL_INDEX8_OES:
    227     case GL_RGB8_OES:
    228     case GL_RGBA8_OES:
    229     case GL_DEPTH_COMPONENT24_OES:
    230     case GL_DEPTH_COMPONENT32_OES:
    231         return true;
    232     }
    233     if (ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && internalformat==GL_DEPTH24_STENCIL8_OES)
    234         return true;
    235 
    236     return false;
    237 }
    238 
    239 bool GLEScmValidate::stencilOp(GLenum param) {
    240     switch (param) {
    241     case GL_KEEP:
    242     case GL_ZERO:
    243     case GL_REPLACE:
    244     case GL_INCR:
    245     case GL_DECR:
    246     case GL_INVERT:
    247     case GL_INCR_WRAP_OES:
    248     case GL_DECR_WRAP_OES:
    249       return true;
    250     }
    251     return false;
    252 }
    253 
    254 bool GLEScmValidate::texGen(GLenum coord, GLenum pname) {
    255     return (coord == GL_TEXTURE_GEN_STR_OES && pname == GL_TEXTURE_GEN_MODE_OES);
    256 }
    257 
    258 bool GLEScmValidate::colorPointerType(GLenum type){
    259     switch(type){
    260     case GL_UNSIGNED_BYTE:
    261     case GL_FIXED:
    262     case GL_FLOAT:
    263         return true;
    264     }
    265     return false;
    266 }
    267 
    268 bool GLEScmValidate::normalPointerType(GLenum type){
    269 
    270     switch(type){
    271     case GL_BYTE:
    272     case GL_SHORT:
    273     case GL_FLOAT:
    274     case GL_FIXED:
    275         return true;
    276     }
    277     return false;
    278 }
    279 
    280 bool GLEScmValidate::pointPointerType(GLenum type){
    281     return type == GL_FIXED || type == GL_FLOAT;
    282 }
    283 
    284 bool GLEScmValidate::texCoordPointerType(GLenum type){
    285     switch(type){
    286     case GL_BYTE:
    287     case GL_SHORT:
    288     case GL_FLOAT:
    289     case GL_FIXED:
    290         return true;
    291     }
    292     return false;
    293 }
    294 
    295 bool GLEScmValidate::vertexPointerType(GLenum type){
    296     switch(type){
    297     case GL_BYTE:
    298     case GL_SHORT:
    299     case GL_FLOAT:
    300     case GL_FIXED:
    301         return true;
    302     }
    303     return false;
    304 }
    305 
    306