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