• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ErrorLog.h"
23 
24 
textureEnum(GLenum e,unsigned int maxTex)25 bool  GLESvalidate::textureEnum(GLenum e,unsigned int maxTex) {
26     return e >= GL_TEXTURE0 && e < (GL_TEXTURE0 + maxTex);
27 }
28 
pixelType(GLEScontext * ctx,GLenum type)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 || type == GL_HALF_FLOAT))
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 
pixelOp(GLenum format,GLenum type)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 
pixelFrmt(GLEScontext * ctx,GLenum format)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 
bufferTarget(GLenum target)77 bool GLESvalidate::bufferTarget(GLenum target) {
78     return target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER;
79 }
80 
bufferUsage(GLenum usage)81 bool GLESvalidate::bufferUsage(GLenum usage) {
82     switch(usage) {
83         case GL_STREAM_DRAW:
84         case GL_STATIC_DRAW:
85         case GL_DYNAMIC_DRAW:
86             return true;
87     }
88     return false;
89 }
90 
bufferParam(GLenum param)91 bool GLESvalidate::bufferParam(GLenum param) {
92  return  (param == GL_BUFFER_SIZE) || (param == GL_BUFFER_USAGE);
93 }
94 
drawMode(GLenum mode)95 bool GLESvalidate::drawMode(GLenum mode) {
96     switch(mode) {
97     case GL_POINTS:
98     case GL_LINE_STRIP:
99     case GL_LINE_LOOP:
100     case GL_LINES:
101     case GL_TRIANGLE_STRIP:
102     case GL_TRIANGLE_FAN:
103     case GL_TRIANGLES:
104         return true;
105     }
106     return false;
107 }
108 
drawType(GLenum mode)109 bool GLESvalidate::drawType(GLenum mode) {
110     return  mode == GL_UNSIGNED_BYTE ||
111             mode == GL_UNSIGNED_SHORT ||
112             mode == GL_UNSIGNED_INT;
113 }
114 
textureTarget(GLenum target)115 bool GLESvalidate::textureTarget(GLenum target) {
116     return target==GL_TEXTURE_2D || target==GL_TEXTURE_CUBE_MAP;
117 }
118 
textureTargetLimited(GLenum target)119 bool GLESvalidate::textureTargetLimited(GLenum target) {
120     return target==GL_TEXTURE_2D;
121 }
122 
textureTargetEx(GLenum target)123 bool GLESvalidate::textureTargetEx(GLenum target) {
124     switch(target) {
125     case GL_TEXTURE_CUBE_MAP_POSITIVE_X_OES:
126     case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_OES:
127     case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_OES:
128     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_OES:
129     case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_OES:
130     case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_OES:
131     case GL_TEXTURE_2D:
132       return true;
133     }
134     return false;
135 }
136 
blendEquationMode(GLenum mode)137 bool GLESvalidate::blendEquationMode(GLenum mode){
138     return mode == GL_FUNC_ADD             ||
139            mode == GL_FUNC_SUBTRACT        ||
140            mode == GL_FUNC_REVERSE_SUBTRACT;
141 }
142 
framebufferTarget(GLenum target)143 bool GLESvalidate::framebufferTarget(GLenum target){
144     return target == GL_FRAMEBUFFER;
145 }
146 
framebufferAttachment(GLenum attachment)147 bool GLESvalidate::framebufferAttachment(GLenum attachment){
148     switch(attachment){
149     case GL_COLOR_ATTACHMENT0:
150     case GL_DEPTH_ATTACHMENT:
151     case GL_STENCIL_ATTACHMENT:
152         return true;
153     }
154     return false;
155 }
156 
framebufferAttachmentParams(GLenum pname)157 bool GLESvalidate::framebufferAttachmentParams(GLenum pname){
158     switch(pname){
159     case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:
160     case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
161     case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:
162     case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:
163         return true;
164     }
165     return false;
166 }
167 
renderbufferTarget(GLenum target)168 bool GLESvalidate::renderbufferTarget(GLenum target){
169     return target == GL_RENDERBUFFER;
170 }
171 
renderbufferParams(GLenum pname)172 bool GLESvalidate::renderbufferParams(GLenum pname){
173     switch(pname){
174     case GL_RENDERBUFFER_WIDTH:
175     case GL_RENDERBUFFER_HEIGHT:
176     case GL_RENDERBUFFER_INTERNAL_FORMAT:
177     case GL_RENDERBUFFER_RED_SIZE:
178     case GL_RENDERBUFFER_GREEN_SIZE:
179     case GL_RENDERBUFFER_BLUE_SIZE:
180     case GL_RENDERBUFFER_ALPHA_SIZE:
181     case GL_RENDERBUFFER_DEPTH_SIZE:
182     case GL_RENDERBUFFER_STENCIL_SIZE:
183         return true;
184     }
185     return false;
186 }
187 
texImgDim(GLsizei width,GLsizei height,int maxTexSize)188 bool GLESvalidate::texImgDim(GLsizei width,GLsizei height,int maxTexSize) {
189 
190  if( width < 0 || height < 0 || width > maxTexSize || height > maxTexSize)
191     return false;
192  return isPowerOf2(width) && isPowerOf2(height);
193 }
194 
195