Home | History | Annotate | Download | only in GLcommon
      1 /*
      2 * Copyright 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 
     17 #include <GLcommon/GLESvalidate.h>
     18 #include <GLES/gl.h>
     19 #include <GLES/glext.h>
     20 #include <GLES2/gl2.h>
     21 #include <GLES2/gl2ext.h>
     22 #include <OpenglCodecCommon/ErrorLog.h>
     23 
     24 
     25 bool  GLESvalidate::textureEnum(GLenum e,unsigned int maxTex) {
     26     return e >= GL_TEXTURE0 && e <= (GL_TEXTURE0 + maxTex);
     27 }
     28 
     29 bool GLESvalidate::pixelType(GLEScontext * ctx, GLenum type) {
     30     if ((ctx && ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL) &&
     31        (type == GL_UNSIGNED_INT_24_8_OES) )
     32         return true;
     33 
     34     if (ctx &&
     35        (ctx->getCaps()->GL_ARB_HALF_FLOAT_PIXEL || ctx->getCaps()->GL_NV_HALF_FLOAT) &&
     36        (type == GL_HALF_FLOAT_OES))
     37         return true;
     38 
     39     switch(type) {
     40     case GL_UNSIGNED_BYTE:
     41     case GL_UNSIGNED_SHORT_5_6_5:
     42     case GL_UNSIGNED_SHORT_4_4_4_4:
     43     case GL_UNSIGNED_SHORT_5_5_5_1:
     44     case GL_FLOAT:
     45         return true;
     46     }
     47     return false;
     48 }
     49 
     50 bool GLESvalidate::pixelOp(GLenum format,GLenum type) {
     51      switch(type) {
     52      case GL_UNSIGNED_SHORT_4_4_4_4:
     53      case GL_UNSIGNED_SHORT_5_5_5_1:
     54          return format == GL_RGBA;
     55      case GL_UNSIGNED_SHORT_5_6_5:
     56          return format == GL_RGB;
     57      }
     58      return true;
     59 }
     60 
     61 bool GLESvalidate::pixelFrmt(GLEScontext* ctx ,GLenum format) {
     62     if (ctx && ctx->getCaps()->GL_EXT_TEXTURE_FORMAT_BGRA8888 && format == GL_BGRA_EXT)
     63       return true;
     64     if (ctx && ctx->getCaps()->GL_EXT_PACKED_DEPTH_STENCIL && format == GL_DEPTH_STENCIL_OES)
     65       return true;
     66     switch(format) {
     67     case GL_ALPHA:
     68     case GL_RGB:
     69     case GL_RGBA:
     70     case GL_LUMINANCE:
     71     case GL_LUMINANCE_ALPHA:
     72         return true;
     73     }
     74     return false;
     75 }
     76 
     77 bool GLESvalidate::bufferTarget(GLenum target) {
     78     return target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER;
     79 }
     80 
     81 bool GLESvalidate::bufferParam(GLenum param) {
     82  return  (param == GL_BUFFER_SIZE) || (param == GL_BUFFER_USAGE);
     83 }
     84 
     85 bool GLESvalidate::drawMode(GLenum mode) {
     86     switch(mode) {
     87     case GL_POINTS:
     88     case GL_LINE_STRIP:
     89     case GL_LINE_LOOP:
     90     case GL_LINES:
     91     case GL_TRIANGLE_STRIP:
     92     case GL_TRIANGLE_FAN:
     93     case GL_TRIANGLES:
     94         return true;
     95     }
     96     return false;
     97 }
     98 
     99 bool GLESvalidate::drawType(GLenum mode) {
    100     return  mode == GL_UNSIGNED_BYTE ||
    101             mode == GL_UNSIGNED_SHORT ||
    102             mode == GL_UNSIGNED_INT;
    103 }
    104 
    105 bool GLESvalidate::textureTarget(GLenum target) {
    106     return target==GL_TEXTURE_2D || target==GL_TEXTURE_CUBE_MAP;
    107 }
    108 
    109 bool GLESvalidate::textureTargetLimited(GLenum target) {
    110     return target==GL_TEXTURE_2D;
    111 }
    112 
    113 bool GLESvalidate::textureTargetEx(GLenum target) {
    114     switch(target) {
    115     case GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES:
    116     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES:
    117     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES:
    118     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES:
    119     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES:
    120     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES:
    121     case GL_TEXTURE_2D:
    122       return true;
    123     }
    124     return false;
    125 }
    126 
    127 bool GLESvalidate::blendEquationMode(GLenum mode){
    128     return mode == GL_FUNC_ADD             ||
    129            mode == GL_FUNC_SUBTRACT        ||
    130            mode == GL_FUNC_REVERSE_SUBTRACT;
    131 }
    132 
    133 bool GLESvalidate::framebufferTarget(GLenum target){
    134     return target == GL_FRAMEBUFFER;
    135 }
    136 
    137 bool GLESvalidate::framebufferAttachment(GLenum attachment){
    138     switch(attachment){
    139     case GL_COLOR_ATTACHMENT0:
    140     case GL_DEPTH_ATTACHMENT:
    141     case GL_STENCIL_ATTACHMENT:
    142         return true;
    143     }
    144     return false;
    145 }
    146 
    147 bool GLESvalidate::framebufferAttachmentParams(GLenum pname){
    148     switch(pname){
    149     case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
    150     case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
    151     case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
    152     case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
    153         return true;
    154     }
    155     return false;
    156 }
    157 
    158 bool GLESvalidate::renderbufferTarget(GLenum target){
    159     return target == GL_RENDERBUFFER;
    160 }
    161 
    162 bool GLESvalidate::renderbufferParams(GLenum pname){
    163     switch(pname){
    164     case GL_RENDERBUFFER_WIDTH:
    165     case GL_RENDERBUFFER_HEIGHT:
    166     case GL_RENDERBUFFER_INTERNAL_FORMAT:
    167     case GL_RENDERBUFFER_RED_SIZE:
    168     case GL_RENDERBUFFER_GREEN_SIZE:
    169     case GL_RENDERBUFFER_BLUE_SIZE:
    170     case GL_RENDERBUFFER_ALPHA_SIZE:
    171     case GL_RENDERBUFFER_DEPTH_SIZE:
    172     case GL_RENDERBUFFER_STENCIL_SIZE:
    173         return true;
    174     }
    175     return false;
    176 }
    177 
    178 bool GLESvalidate::texImgDim(GLsizei width,GLsizei height,int maxTexSize) {
    179 
    180  if( width < 0 || height < 0 || width > maxTexSize || height > maxTexSize)
    181     return false;
    182  return isPowerOf2(width) && isPowerOf2(height);
    183 }
    184 
    185