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