blob: d608ee64965e3f3b17ca2af78c9e99b3f66dc87b [file] [log] [blame]
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001#include "precompiled.h"
2//
Geoff Langcec35902014-04-16 10:52:36 -04003// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
Geoff Lange8ebe7f2013-08-05 15:03:13 -04004// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6//
7
8// validationES.h: Validation functions for generic OpenGL ES entry point parameters
9
10#include "libGLESv2/validationES.h"
Jamie Madill26e91952014-03-05 15:01:27 -050011#include "libGLESv2/validationES2.h"
12#include "libGLESv2/validationES3.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040013#include "libGLESv2/Context.h"
14#include "libGLESv2/Texture.h"
15#include "libGLESv2/Framebuffer.h"
Jamie Madille261b442014-06-25 12:42:21 -040016#include "libGLESv2/FramebufferAttachment.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040017#include "libGLESv2/formatutils.h"
18#include "libGLESv2/main.h"
Jamie Madilldb2f14c2014-05-13 13:56:30 -040019#include "libGLESv2/Query.h"
Jamie Madill36398922014-05-20 14:51:53 -040020#include "libGLESv2/ProgramBinary.h"
Jamie Madill250d33f2014-06-06 17:09:03 -040021#include "libGLESv2/TransformFeedback.h"
Jamie Madilld4cfa572014-07-08 10:00:32 -040022#include "libGLESv2/VertexArray.h"
Geoff Lange8ebe7f2013-08-05 15:03:13 -040023
24#include "common/mathutil.h"
25#include "common/utilities.h"
26
27namespace gl
28{
29
Geoff Lang0550d032014-01-30 11:29:07 -050030bool ValidCap(const Context *context, GLenum cap)
31{
32 switch (cap)
33 {
34 case GL_CULL_FACE:
35 case GL_POLYGON_OFFSET_FILL:
36 case GL_SAMPLE_ALPHA_TO_COVERAGE:
37 case GL_SAMPLE_COVERAGE:
38 case GL_SCISSOR_TEST:
39 case GL_STENCIL_TEST:
40 case GL_DEPTH_TEST:
41 case GL_BLEND:
42 case GL_DITHER:
43 return true;
44 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
45 case GL_RASTERIZER_DISCARD:
46 return (context->getClientVersion() >= 3);
47 default:
48 return false;
49 }
50}
51
Jamie Madill1fc7e2c2014-01-21 16:47:10 -050052bool ValidTextureTarget(const Context *context, GLenum target)
Jamie Madill35d15012013-10-07 10:46:37 -040053{
Jamie Madilld7460c72014-01-21 16:38:14 -050054 switch (target)
Jamie Madill35d15012013-10-07 10:46:37 -040055 {
Jamie Madilld7460c72014-01-21 16:38:14 -050056 case GL_TEXTURE_2D:
57 case GL_TEXTURE_CUBE_MAP:
58 return true;
Jamie Madill35d15012013-10-07 10:46:37 -040059
Jamie Madilld7460c72014-01-21 16:38:14 -050060 case GL_TEXTURE_3D:
61 case GL_TEXTURE_2D_ARRAY:
62 return (context->getClientVersion() >= 3);
63
64 default:
65 return false;
66 }
Jamie Madill35d15012013-10-07 10:46:37 -040067}
68
Shannon Woods4dfed832014-03-17 20:03:39 -040069// This function differs from ValidTextureTarget in that the target must be
70// usable as the destination of a 2D operation-- so a cube face is valid, but
71// GL_TEXTURE_CUBE_MAP is not.
Jamie Madill560a8d82014-05-21 13:06:20 -040072// Note: duplicate of IsInternalTextureTarget
Shannon Woods4dfed832014-03-17 20:03:39 -040073bool ValidTexture2DDestinationTarget(const Context *context, GLenum target)
74{
75 switch (target)
76 {
77 case GL_TEXTURE_2D:
78 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
79 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
80 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
81 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
82 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
83 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
84 return true;
85 case GL_TEXTURE_2D_ARRAY:
86 case GL_TEXTURE_3D:
87 return (context->getClientVersion() >= 3);
88 default:
89 return false;
90 }
91}
92
Jamie Madill1fc7e2c2014-01-21 16:47:10 -050093bool ValidFramebufferTarget(GLenum target)
94{
95 META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER);
96
97 switch (target)
98 {
99 case GL_FRAMEBUFFER: return true;
100 case GL_READ_FRAMEBUFFER: return true;
101 case GL_DRAW_FRAMEBUFFER: return true;
102 default: return false;
103 }
104}
105
Jamie Madill8c96d582014-03-05 15:01:23 -0500106bool ValidBufferTarget(const Context *context, GLenum target)
107{
108 switch (target)
109 {
110 case GL_ARRAY_BUFFER:
111 case GL_ELEMENT_ARRAY_BUFFER:
112 return true;
113
Jamie Madill8c96d582014-03-05 15:01:23 -0500114 case GL_PIXEL_PACK_BUFFER:
115 case GL_PIXEL_UNPACK_BUFFER:
Geoff Langc0b9ef42014-07-02 10:02:37 -0400116 return context->getExtensions().pixelBufferObject;
Shannon Woods158c4382014-05-06 13:00:07 -0400117
Shannon Woodsb3801742014-03-27 14:59:19 -0400118 case GL_COPY_READ_BUFFER:
119 case GL_COPY_WRITE_BUFFER:
Jamie Madill8c96d582014-03-05 15:01:23 -0500120 case GL_TRANSFORM_FEEDBACK_BUFFER:
121 case GL_UNIFORM_BUFFER:
122 return (context->getClientVersion() >= 3);
123
124 default:
125 return false;
126 }
127}
128
Jamie Madill70656a62014-03-05 15:01:26 -0500129bool ValidBufferParameter(const Context *context, GLenum pname)
130{
131 switch (pname)
132 {
133 case GL_BUFFER_USAGE:
134 case GL_BUFFER_SIZE:
135 return true;
136
137 // GL_BUFFER_MAP_POINTER is a special case, and may only be
138 // queried with GetBufferPointerv
139 case GL_BUFFER_ACCESS_FLAGS:
140 case GL_BUFFER_MAPPED:
141 case GL_BUFFER_MAP_OFFSET:
142 case GL_BUFFER_MAP_LENGTH:
143 return (context->getClientVersion() >= 3);
144
145 default:
146 return false;
147 }
148}
149
Jamie Madill8c96d582014-03-05 15:01:23 -0500150bool ValidMipLevel(const Context *context, GLenum target, GLint level)
Geoff Langce635692013-09-24 13:56:32 -0400151{
Geoff Langaae65a42014-05-26 12:43:44 -0400152 size_t maxDimension = 0;
Geoff Langce635692013-09-24 13:56:32 -0400153 switch (target)
154 {
Geoff Langaae65a42014-05-26 12:43:44 -0400155 case GL_TEXTURE_2D: maxDimension = context->getCaps().max2DTextureSize; break;
Geoff Langce635692013-09-24 13:56:32 -0400156 case GL_TEXTURE_CUBE_MAP:
157 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
158 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
159 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
160 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
161 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
Geoff Langaae65a42014-05-26 12:43:44 -0400162 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: maxDimension = context->getCaps().maxCubeMapTextureSize; break;
163 case GL_TEXTURE_3D: maxDimension = context->getCaps().max3DTextureSize; break;
164 case GL_TEXTURE_2D_ARRAY: maxDimension = context->getCaps().max2DTextureSize; break;
Geoff Langce635692013-09-24 13:56:32 -0400165 default: UNREACHABLE();
166 }
167
Geoff Langaae65a42014-05-26 12:43:44 -0400168 return level <= gl::log2(maxDimension);
Geoff Langce635692013-09-24 13:56:32 -0400169}
170
Jamie Madill4fd75c12014-06-23 10:53:54 -0400171bool ValidImageSize(const gl::Context *context, GLenum target, GLint level,
172 GLsizei width, GLsizei height, GLsizei depth)
Geoff Langce635692013-09-24 13:56:32 -0400173{
174 if (level < 0 || width < 0 || height < 0 || depth < 0)
175 {
176 return false;
177 }
178
Geoff Langc0b9ef42014-07-02 10:02:37 -0400179 if (!context->getExtensions().textureNPOT &&
Jamie Madill4fd75c12014-06-23 10:53:54 -0400180 (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth))))
Geoff Langce635692013-09-24 13:56:32 -0400181 {
182 return false;
183 }
184
185 if (!ValidMipLevel(context, target, level))
186 {
187 return false;
188 }
189
190 return true;
191}
192
Geoff Lang005df412013-10-16 14:12:50 -0400193bool ValidCompressedImageSize(const gl::Context *context, GLenum internalFormat, GLsizei width, GLsizei height)
Geoff Langd4f180b2013-09-24 13:57:44 -0400194{
Geoff Lang5d601382014-07-22 15:14:06 -0400195 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
196 if (!formatInfo.compressed)
Geoff Langd4f180b2013-09-24 13:57:44 -0400197 {
198 return false;
199 }
200
Geoff Lang5d601382014-07-22 15:14:06 -0400201 if (width < 0 || (static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && width % formatInfo.compressedBlockWidth != 0) ||
202 height < 0 || (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && height % formatInfo.compressedBlockHeight != 0))
Geoff Langd4f180b2013-09-24 13:57:44 -0400203 {
204 return false;
205 }
206
207 return true;
208}
209
Geoff Lang37dde692014-01-31 16:34:54 -0500210bool ValidQueryType(const Context *context, GLenum queryType)
211{
212 META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
213 META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
214
215 switch (queryType)
216 {
217 case GL_ANY_SAMPLES_PASSED:
218 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
219 return true;
220 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
221 return (context->getClientVersion() >= 3);
222 default:
223 return false;
224 }
225}
226
Geoff Lang48dcae72014-02-05 16:28:24 -0500227bool ValidProgram(const Context *context, GLuint id)
228{
229 // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
230 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
231 // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
232
233 if (context->getProgram(id) != NULL)
234 {
235 return true;
236 }
237 else if (context->getShader(id) != NULL)
238 {
239 // ID is the wrong type
240 return gl::error(GL_INVALID_OPERATION, false);
241 }
242 else
243 {
244 // No shader/program object has this ID
245 return gl::error(GL_INVALID_VALUE, false);
246 }
247}
248
Jamie Madillb4472272014-07-03 10:38:55 -0400249bool ValidateAttachmentTarget(const gl::Context *context, GLenum attachment)
250{
251 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
252 {
253 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
254
Geoff Langaae65a42014-05-26 12:43:44 -0400255 if (colorAttachment >= context->getCaps().maxColorAttachments)
Jamie Madillb4472272014-07-03 10:38:55 -0400256 {
257 return gl::error(GL_INVALID_VALUE, false);
258 }
259 }
260 else
261 {
262 switch (attachment)
263 {
264 case GL_DEPTH_ATTACHMENT:
265 case GL_STENCIL_ATTACHMENT:
266 break;
267
268 case GL_DEPTH_STENCIL_ATTACHMENT:
269 if (context->getClientVersion() < 3)
270 {
271 return gl::error(GL_INVALID_ENUM, false);
272 }
273 break;
274
275 default:
276 return gl::error(GL_INVALID_ENUM, false);
277 }
278 }
279
280 return true;
281}
282
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400283bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400284 GLenum internalformat, GLsizei width, GLsizei height,
285 bool angleExtension)
286{
287 switch (target)
288 {
289 case GL_RENDERBUFFER:
290 break;
291 default:
292 return gl::error(GL_INVALID_ENUM, false);
293 }
294
295 if (width < 0 || height < 0 || samples < 0)
296 {
297 return gl::error(GL_INVALID_VALUE, false);
298 }
299
Geoff Lang5d601382014-07-22 15:14:06 -0400300 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
301 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400302 {
303 return gl::error(GL_INVALID_ENUM, false);
304 }
305
306 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
307 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
308 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
309 // internal format must be sized and not an integer format if samples is greater than zero.
Geoff Lang5d601382014-07-22 15:14:06 -0400310 if (formatInfo.pixelBytes == 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400311 {
312 return gl::error(GL_INVALID_ENUM, false);
313 }
314
Geoff Lang5d601382014-07-22 15:14:06 -0400315 if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400316 {
317 return gl::error(GL_INVALID_OPERATION, false);
318 }
319
Geoff Langc0b9ef42014-07-02 10:02:37 -0400320 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
Geoff Lang6cf8e1b2014-07-03 13:03:57 -0400321 if (!formatCaps.renderable)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400322 {
323 return gl::error(GL_INVALID_ENUM, false);
324 }
325
Geoff Langaae65a42014-05-26 12:43:44 -0400326 if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400327 {
328 return gl::error(GL_INVALID_VALUE, false);
329 }
330
331 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
332 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
333 // states that samples must be less than or equal to the maximum samples for the specified
334 // internal format.
335 if (angleExtension)
336 {
Geoff Lang5f4c4632014-07-03 13:46:52 -0400337 ASSERT(context->getExtensions().framebufferMultisample);
338 if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400339 {
340 return gl::error(GL_INVALID_VALUE, false);
341 }
Geoff Lang5f4c4632014-07-03 13:46:52 -0400342
343 // Check if this specific format supports enough samples
344 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
345 {
346 return gl::error(GL_OUT_OF_MEMORY, false);
347 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400348 }
349 else
350 {
Geoff Lang5f4c4632014-07-03 13:46:52 -0400351 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400352 {
353 return gl::error(GL_INVALID_VALUE, false);
354 }
355 }
356
Shannon Woods53a94a82014-06-24 15:20:36 -0400357 GLuint handle = context->getState().getRenderbufferId();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400358 if (handle == 0)
359 {
360 return gl::error(GL_INVALID_OPERATION, false);
361 }
362
363 return true;
364}
365
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500366bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment,
367 GLenum renderbuffertarget, GLuint renderbuffer)
368{
Shannon Woods1da3cf62014-06-27 15:32:23 -0400369 if (!ValidFramebufferTarget(target))
370 {
371 return gl::error(GL_INVALID_ENUM, false);
372 }
373
Shannon Woods53a94a82014-06-24 15:20:36 -0400374 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
375 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500376
377 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
378 {
379 return gl::error(GL_INVALID_OPERATION, false);
380 }
381
Jamie Madillb4472272014-07-03 10:38:55 -0400382 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500383 {
Jamie Madillb4472272014-07-03 10:38:55 -0400384 return false;
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500385 }
386
Jamie Madillab9d82c2014-01-21 16:38:14 -0500387 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
388 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
389 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
390 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
391 if (renderbuffer != 0)
392 {
393 if (!context->getRenderbuffer(renderbuffer))
394 {
395 return gl::error(GL_INVALID_OPERATION, false);
396 }
397 }
398
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500399 return true;
400}
401
Jamie Madill3c7fa222014-06-05 13:08:51 -0400402static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer,
Geoff Lang125deab2013-08-09 13:34:16 -0400403 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
404 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
405{
406 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
407 dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
408 srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
409 {
410 return true;
411 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400412 else if (context->getState().isScissorTestEnabled())
Geoff Lang125deab2013-08-09 13:34:16 -0400413 {
Shannon Woods53a94a82014-06-24 15:20:36 -0400414 const Rectangle &scissor = context->getState().getScissor();
Geoff Lang125deab2013-08-09 13:34:16 -0400415
Shannon Woods53a94a82014-06-24 15:20:36 -0400416 return scissor.x > 0 || scissor.y > 0 ||
417 scissor.width < writeBuffer->getWidth() ||
418 scissor.height < writeBuffer->getHeight();
Geoff Lang125deab2013-08-09 13:34:16 -0400419 }
420 else
421 {
422 return false;
423 }
424}
425
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400426bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400427 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
428 GLenum filter, bool fromAngleExtension)
429{
430 switch (filter)
431 {
432 case GL_NEAREST:
433 break;
434 case GL_LINEAR:
435 if (fromAngleExtension)
436 {
437 return gl::error(GL_INVALID_ENUM, false);
438 }
439 break;
440 default:
441 return gl::error(GL_INVALID_ENUM, false);
442 }
443
444 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
445 {
446 return gl::error(GL_INVALID_VALUE, false);
447 }
448
449 if (mask == 0)
450 {
451 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
452 // buffers are copied.
453 return false;
454 }
455
456 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
457 {
458 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
459 return gl::error(GL_INVALID_OPERATION, false);
460 }
461
462 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
463 // color buffer, leaving only nearest being unfiltered from above
464 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
465 {
466 return gl::error(GL_INVALID_OPERATION, false);
467 }
468
Shannon Woods53a94a82014-06-24 15:20:36 -0400469 if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400470 {
471 if (fromAngleExtension)
472 {
473 ERR("Blits with the same source and destination framebuffer are not supported by this "
474 "implementation.");
475 }
476 return gl::error(GL_INVALID_OPERATION, false);
477 }
478
Shannon Woods53a94a82014-06-24 15:20:36 -0400479 gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
480 gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400481 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
482 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
483 {
484 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
485 }
486
487 if (drawFramebuffer->getSamples() != 0)
488 {
489 return gl::error(GL_INVALID_OPERATION, false);
490 }
491
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400492 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
493
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400494 if (mask & GL_COLOR_BUFFER_BIT)
495 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400496 gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
497 gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400498
499 if (readColorBuffer && drawColorBuffer)
500 {
Geoff Lang005df412013-10-16 14:12:50 -0400501 GLenum readInternalFormat = readColorBuffer->getActualFormat();
Geoff Lang5d601382014-07-22 15:14:06 -0400502 const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400503
504 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
505 {
506 if (drawFramebuffer->isEnabledColorAttachment(i))
507 {
Geoff Lang005df412013-10-16 14:12:50 -0400508 GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
Geoff Lang5d601382014-07-22 15:14:06 -0400509 const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400510
Geoff Langb2f3d052013-08-13 12:49:27 -0400511 // The GL ES 3.0.2 spec (pg 193) states that:
512 // 1) If the read buffer is fixed point format, the draw buffer must be as well
513 // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well
514 // 3) If the read buffer is a signed integer format, the draw buffer must be as well
Geoff Lang5d601382014-07-22 15:14:06 -0400515 if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) &&
516 !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400517 {
518 return gl::error(GL_INVALID_OPERATION, false);
519 }
520
Geoff Lang5d601382014-07-22 15:14:06 -0400521 if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400522 {
523 return gl::error(GL_INVALID_OPERATION, false);
524 }
525
Geoff Lang5d601382014-07-22 15:14:06 -0400526 if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400527 {
528 return gl::error(GL_INVALID_OPERATION, false);
529 }
530
Geoff Langb2f3d052013-08-13 12:49:27 -0400531 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400532 {
533 return gl::error(GL_INVALID_OPERATION, false);
534 }
535 }
536 }
537
Geoff Lang5d601382014-07-22 15:14:06 -0400538 if ((readFormatInfo.componentType == GL_INT || readFormatInfo.componentType == GL_UNSIGNED_INT) && filter == GL_LINEAR)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400539 {
540 return gl::error(GL_INVALID_OPERATION, false);
541 }
542
543 if (fromAngleExtension)
544 {
545 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
546 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
547 {
548 return gl::error(GL_INVALID_OPERATION, false);
549 }
550
551 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
552 {
553 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
554 {
Jamie Madille92a3542014-07-03 10:38:58 -0400555 FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment);
556 ASSERT(attachment);
557
558 if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400559 {
560 return gl::error(GL_INVALID_OPERATION, false);
561 }
562
Jamie Madille92a3542014-07-03 10:38:58 -0400563 if (attachment->getActualFormat() != readColorBuffer->getActualFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400564 {
565 return gl::error(GL_INVALID_OPERATION, false);
566 }
567 }
568 }
Geoff Lang125deab2013-08-09 13:34:16 -0400569 if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer,
570 srcX0, srcY0, srcX1, srcY1,
571 dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400572 {
573 return gl::error(GL_INVALID_OPERATION, false);
574 }
575 }
576 }
577 }
578
579 if (mask & GL_DEPTH_BUFFER_BIT)
580 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400581 gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer();
582 gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400583
584 if (readDepthBuffer && drawDepthBuffer)
585 {
586 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
587 {
588 return gl::error(GL_INVALID_OPERATION, false);
589 }
590
591 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
592 {
593 return gl::error(GL_INVALID_OPERATION, false);
594 }
595
596 if (fromAngleExtension)
597 {
Geoff Lang125deab2013-08-09 13:34:16 -0400598 if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer,
599 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400600 {
601 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
602 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
603 }
604
605 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
606 {
607 return gl::error(GL_INVALID_OPERATION, false);
608 }
609 }
610 }
611 }
612
613 if (mask & GL_STENCIL_BUFFER_BIT)
614 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400615 gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer();
616 gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400617
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400618 if (readStencilBuffer && drawStencilBuffer)
619 {
620 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
621 {
622 return gl::error(GL_INVALID_OPERATION, false);
623 }
624
625 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
626 {
627 return gl::error(GL_INVALID_OPERATION, false);
628 }
629
630 if (fromAngleExtension)
631 {
Geoff Lang125deab2013-08-09 13:34:16 -0400632 if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer,
633 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400634 {
635 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
636 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
637 }
638
639 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
640 {
641 return gl::error(GL_INVALID_OPERATION, false);
642 }
643 }
644 }
645 }
646
647 return true;
648}
649
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400650bool ValidateGetVertexAttribParameters(GLenum pname, int clientVersion)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400651{
652 switch (pname)
653 {
654 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
655 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
656 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
657 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
658 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
659 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
660 case GL_CURRENT_VERTEX_ATTRIB:
661 return true;
662
663 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
664 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
665 // the same constant.
666 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
667 return true;
668
669 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
670 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
671
672 default:
673 return gl::error(GL_INVALID_ENUM, false);
674 }
675}
676
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400677bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400678{
679 switch (pname)
680 {
681 case GL_TEXTURE_WRAP_R:
682 case GL_TEXTURE_SWIZZLE_R:
683 case GL_TEXTURE_SWIZZLE_G:
684 case GL_TEXTURE_SWIZZLE_B:
685 case GL_TEXTURE_SWIZZLE_A:
686 case GL_TEXTURE_BASE_LEVEL:
687 case GL_TEXTURE_MAX_LEVEL:
688 case GL_TEXTURE_COMPARE_MODE:
689 case GL_TEXTURE_COMPARE_FUNC:
690 case GL_TEXTURE_MIN_LOD:
691 case GL_TEXTURE_MAX_LOD:
692 if (context->getClientVersion() < 3)
693 {
694 return gl::error(GL_INVALID_ENUM, false);
695 }
696 break;
697
698 default: break;
699 }
700
701 switch (pname)
702 {
703 case GL_TEXTURE_WRAP_S:
704 case GL_TEXTURE_WRAP_T:
705 case GL_TEXTURE_WRAP_R:
706 switch (param)
707 {
708 case GL_REPEAT:
709 case GL_CLAMP_TO_EDGE:
710 case GL_MIRRORED_REPEAT:
711 return true;
712 default:
713 return gl::error(GL_INVALID_ENUM, false);
714 }
715
716 case GL_TEXTURE_MIN_FILTER:
717 switch (param)
718 {
719 case GL_NEAREST:
720 case GL_LINEAR:
721 case GL_NEAREST_MIPMAP_NEAREST:
722 case GL_LINEAR_MIPMAP_NEAREST:
723 case GL_NEAREST_MIPMAP_LINEAR:
724 case GL_LINEAR_MIPMAP_LINEAR:
725 return true;
726 default:
727 return gl::error(GL_INVALID_ENUM, false);
728 }
729 break;
730
731 case GL_TEXTURE_MAG_FILTER:
732 switch (param)
733 {
734 case GL_NEAREST:
735 case GL_LINEAR:
736 return true;
737 default:
738 return gl::error(GL_INVALID_ENUM, false);
739 }
740 break;
741
742 case GL_TEXTURE_USAGE_ANGLE:
743 switch (param)
744 {
745 case GL_NONE:
746 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
747 return true;
748 default:
749 return gl::error(GL_INVALID_ENUM, false);
750 }
751 break;
752
753 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
Geoff Langc0b9ef42014-07-02 10:02:37 -0400754 if (!context->getExtensions().textureFilterAnisotropic)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400755 {
756 return gl::error(GL_INVALID_ENUM, false);
757 }
758
759 // we assume the parameter passed to this validation method is truncated, not rounded
760 if (param < 1)
761 {
762 return gl::error(GL_INVALID_VALUE, false);
763 }
764 return true;
765
766 case GL_TEXTURE_MIN_LOD:
767 case GL_TEXTURE_MAX_LOD:
768 // any value is permissible
769 return true;
770
771 case GL_TEXTURE_COMPARE_MODE:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400772 // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400773 switch (param)
774 {
775 case GL_NONE:
776 case GL_COMPARE_REF_TO_TEXTURE:
777 return true;
778 default:
779 return gl::error(GL_INVALID_ENUM, false);
780 }
781 break;
782
783 case GL_TEXTURE_COMPARE_FUNC:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400784 // Acceptable function parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400785 switch (param)
786 {
787 case GL_LEQUAL:
788 case GL_GEQUAL:
789 case GL_LESS:
790 case GL_GREATER:
791 case GL_EQUAL:
792 case GL_NOTEQUAL:
793 case GL_ALWAYS:
794 case GL_NEVER:
795 return true;
796 default:
797 return gl::error(GL_INVALID_ENUM, false);
798 }
799 break;
800
801 case GL_TEXTURE_SWIZZLE_R:
802 case GL_TEXTURE_SWIZZLE_G:
803 case GL_TEXTURE_SWIZZLE_B:
804 case GL_TEXTURE_SWIZZLE_A:
Geoff Langbc90a482013-09-17 16:51:27 -0400805 switch (param)
806 {
807 case GL_RED:
808 case GL_GREEN:
809 case GL_BLUE:
810 case GL_ALPHA:
811 case GL_ZERO:
812 case GL_ONE:
813 return true;
814 default:
815 return gl::error(GL_INVALID_ENUM, false);
816 }
817 break;
818
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400819 case GL_TEXTURE_BASE_LEVEL:
820 case GL_TEXTURE_MAX_LEVEL:
Nicolas Capens8de68282014-04-04 11:10:27 -0400821 if (param < 0)
822 {
823 return gl::error(GL_INVALID_VALUE, false);
824 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400825 return true;
826
827 default:
828 return gl::error(GL_INVALID_ENUM, false);
829 }
830}
831
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400832bool ValidateSamplerObjectParameter(GLenum pname)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400833{
834 switch (pname)
835 {
836 case GL_TEXTURE_MIN_FILTER:
837 case GL_TEXTURE_MAG_FILTER:
838 case GL_TEXTURE_WRAP_S:
839 case GL_TEXTURE_WRAP_T:
840 case GL_TEXTURE_WRAP_R:
841 case GL_TEXTURE_MIN_LOD:
842 case GL_TEXTURE_MAX_LOD:
843 case GL_TEXTURE_COMPARE_MODE:
844 case GL_TEXTURE_COMPARE_FUNC:
845 return true;
846
847 default:
848 return gl::error(GL_INVALID_ENUM, false);
849 }
850}
851
Jamie Madill26e91952014-03-05 15:01:27 -0500852bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
853 GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
854{
Shannon Woods53a94a82014-06-24 15:20:36 -0400855 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -0400856 ASSERT(framebuffer);
Jamie Madill26e91952014-03-05 15:01:27 -0500857
858 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
859 {
860 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
861 }
862
Shannon Woods53a94a82014-06-24 15:20:36 -0400863 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill26e91952014-03-05 15:01:27 -0500864 {
865 return gl::error(GL_INVALID_OPERATION, false);
866 }
867
Jamie Madill893ab082014-05-16 16:56:10 -0400868 if (!framebuffer->getReadColorbuffer())
869 {
870 return gl::error(GL_INVALID_OPERATION, false);
871 }
872
Jamie Madill26e91952014-03-05 15:01:27 -0500873 GLenum currentInternalFormat, currentFormat, currentType;
Geoff Lange4a492b2014-06-19 14:14:41 -0400874 GLuint clientVersion = context->getClientVersion();
Jamie Madill26e91952014-03-05 15:01:27 -0500875
Jamie Madill893ab082014-05-16 16:56:10 -0400876 context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType);
Jamie Madill26e91952014-03-05 15:01:27 -0500877
Geoff Langbdc9b2f2014-04-16 14:41:54 -0400878 bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
879 ValidES3ReadFormatType(context, currentInternalFormat, format, type);
Jamie Madill26e91952014-03-05 15:01:27 -0500880
881 if (!(currentFormat == format && currentType == type) && !validReadFormat)
882 {
883 return gl::error(GL_INVALID_OPERATION, false);
884 }
885
Geoff Lang5d601382014-07-22 15:14:06 -0400886 GLenum sizedInternalFormat = GetSizedInternalFormat(format, type);
887 const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat);
Jamie Madill26e91952014-03-05 15:01:27 -0500888
Geoff Lang5d601382014-07-22 15:14:06 -0400889 GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment());
Jamie Madill26e91952014-03-05 15:01:27 -0500890 // sized query sanity check
891 if (bufSize)
892 {
893 int requiredSize = outputPitch * height;
894 if (requiredSize > *bufSize)
895 {
896 return gl::error(GL_INVALID_OPERATION, false);
897 }
898 }
899
900 return true;
901}
902
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400903bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
904{
905 if (!ValidQueryType(context, target))
906 {
907 return gl::error(GL_INVALID_ENUM, false);
908 }
909
910 if (id == 0)
911 {
912 return gl::error(GL_INVALID_OPERATION, false);
913 }
914
915 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
916 // of zero, if the active query object name for <target> is non-zero (for the
917 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
918 // the active query for either target is non-zero), if <id> is the name of an
919 // existing query object whose type does not match <target>, or if <id> is the
920 // active query object name for any query type, the error INVALID_OPERATION is
921 // generated.
922
923 // Ensure no other queries are active
924 // NOTE: If other queries than occlusion are supported, we will need to check
925 // separately that:
926 // a) The query ID passed is not the current active query for any target/type
927 // b) There are no active queries for the requested target (and in the case
928 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
929 // no query may be active for either if glBeginQuery targets either.
Shannon Woods53a94a82014-06-24 15:20:36 -0400930 if (context->getState().isQueryActive())
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400931 {
932 return gl::error(GL_INVALID_OPERATION, false);
933 }
934
935 Query *queryObject = context->getQuery(id, true, target);
936
937 // check that name was obtained with glGenQueries
938 if (!queryObject)
939 {
940 return gl::error(GL_INVALID_OPERATION, false);
941 }
942
943 // check for type mismatch
944 if (queryObject->getType() != target)
945 {
946 return gl::error(GL_INVALID_OPERATION, false);
947 }
948
949 return true;
950}
951
Jamie Madill45c785d2014-05-13 14:09:34 -0400952bool ValidateEndQuery(gl::Context *context, GLenum target)
953{
954 if (!ValidQueryType(context, target))
955 {
956 return gl::error(GL_INVALID_ENUM, false);
957 }
958
Shannon Woods53a94a82014-06-24 15:20:36 -0400959 const Query *queryObject = context->getState().getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -0400960
961 if (queryObject == NULL)
962 {
963 return gl::error(GL_INVALID_OPERATION, false);
964 }
965
966 if (!queryObject->isStarted())
967 {
968 return gl::error(GL_INVALID_OPERATION, false);
969 }
970
971 return true;
972}
973
Jamie Madill36398922014-05-20 14:51:53 -0400974static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
975 GLint location, GLsizei count, LinkedUniform **uniformOut)
Jamie Madilld7c7bb22014-05-20 10:55:54 -0400976{
977 if (count < 0)
978 {
979 return gl::error(GL_INVALID_VALUE, false);
980 }
981
Shannon Woods53a94a82014-06-24 15:20:36 -0400982 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld7c7bb22014-05-20 10:55:54 -0400983 if (!programBinary)
984 {
985 return gl::error(GL_INVALID_OPERATION, false);
986 }
987
988 if (location == -1)
989 {
990 // Silently ignore the uniform command
991 return false;
992 }
993
Jamie Madill36398922014-05-20 14:51:53 -0400994 if (!programBinary->isValidUniformLocation(location))
995 {
996 return gl::error(GL_INVALID_OPERATION, false);
997 }
998
999 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1000
1001 // attempting to write an array to a non-array uniform is an INVALID_OPERATION
1002 if (uniform->elementCount() == 1 && count > 1)
1003 {
1004 return gl::error(GL_INVALID_OPERATION, false);
1005 }
1006
1007 *uniformOut = uniform;
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001008 return true;
1009}
1010
Jamie Madillaa981bd2014-05-20 10:55:55 -04001011bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
1012{
1013 // Check for ES3 uniform entry points
Jamie Madillf2575982014-06-25 16:04:54 -04001014 if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
Jamie Madillaa981bd2014-05-20 10:55:55 -04001015 {
1016 return gl::error(GL_INVALID_OPERATION, false);
1017 }
1018
Jamie Madill36398922014-05-20 14:51:53 -04001019 LinkedUniform *uniform = NULL;
1020 if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
1021 {
1022 return false;
1023 }
1024
Jamie Madillf2575982014-06-25 16:04:54 -04001025 GLenum targetBoolType = VariableBoolVectorType(uniformType);
Jamie Madill36398922014-05-20 14:51:53 -04001026 bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
1027 if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
1028 {
1029 return gl::error(GL_INVALID_OPERATION, false);
1030 }
1031
1032 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001033}
1034
1035bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
1036 GLboolean transpose)
1037{
1038 // Check for ES3 uniform entry points
1039 int rows = VariableRowCount(matrixType);
1040 int cols = VariableColumnCount(matrixType);
1041 if (rows != cols && context->getClientVersion() < 3)
1042 {
1043 return gl::error(GL_INVALID_OPERATION, false);
1044 }
1045
1046 if (transpose != GL_FALSE && context->getClientVersion() < 3)
1047 {
1048 return gl::error(GL_INVALID_VALUE, false);
1049 }
1050
Jamie Madill36398922014-05-20 14:51:53 -04001051 LinkedUniform *uniform = NULL;
1052 if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
1053 {
1054 return false;
1055 }
1056
1057 if (uniform->type != matrixType)
1058 {
1059 return gl::error(GL_INVALID_OPERATION, false);
1060 }
1061
1062 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001063}
1064
Jamie Madill893ab082014-05-16 16:56:10 -04001065bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
1066{
1067 if (!context->getQueryParameterInfo(pname, nativeType, numParams))
1068 {
1069 return gl::error(GL_INVALID_ENUM, false);
1070 }
1071
1072 if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
1073 {
1074 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
1075
Geoff Langaae65a42014-05-26 12:43:44 -04001076 if (colorAttachment >= context->getCaps().maxDrawBuffers)
Jamie Madill893ab082014-05-16 16:56:10 -04001077 {
1078 return gl::error(GL_INVALID_OPERATION, false);
1079 }
1080 }
1081
1082 switch (pname)
1083 {
1084 case GL_TEXTURE_BINDING_2D:
1085 case GL_TEXTURE_BINDING_CUBE_MAP:
1086 case GL_TEXTURE_BINDING_3D:
1087 case GL_TEXTURE_BINDING_2D_ARRAY:
Shannon Woods53a94a82014-06-24 15:20:36 -04001088 if (context->getState().getActiveSampler() >= context->getMaximumCombinedTextureImageUnits())
Jamie Madill893ab082014-05-16 16:56:10 -04001089 {
1090 return gl::error(GL_INVALID_OPERATION, false);
1091 }
1092 break;
1093
1094 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1095 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1096 {
Shannon Woods53a94a82014-06-24 15:20:36 -04001097 Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -04001098 ASSERT(framebuffer);
1099 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1100 {
1101 return gl::error(GL_INVALID_OPERATION, false);
1102 }
1103
Jamie Madill3c7fa222014-06-05 13:08:51 -04001104 FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
1105 if (!attachment)
Jamie Madill893ab082014-05-16 16:56:10 -04001106 {
1107 return gl::error(GL_INVALID_OPERATION, false);
1108 }
1109 }
1110 break;
1111
1112 default:
1113 break;
1114 }
1115
1116 // pname is valid, but there are no parameters to return
1117 if (numParams == 0)
1118 {
1119 return false;
1120 }
1121
1122 return true;
1123}
1124
Jamie Madill560a8d82014-05-21 13:06:20 -04001125bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
1126 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height,
1127 GLint border, GLenum *textureFormatOut)
1128{
1129
1130 if (!ValidTexture2DDestinationTarget(context, target))
1131 {
1132 return gl::error(GL_INVALID_ENUM, false);
1133 }
1134
1135 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
1136 {
1137 return gl::error(GL_INVALID_VALUE, false);
1138 }
1139
1140 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1141 {
1142 return gl::error(GL_INVALID_VALUE, false);
1143 }
1144
1145 if (border != 0)
1146 {
1147 return gl::error(GL_INVALID_VALUE, false);
1148 }
1149
1150 if (!ValidMipLevel(context, target, level))
1151 {
1152 return gl::error(GL_INVALID_VALUE, false);
1153 }
1154
Shannon Woods53a94a82014-06-24 15:20:36 -04001155 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill560a8d82014-05-21 13:06:20 -04001156 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1157 {
1158 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1159 }
1160
Shannon Woods53a94a82014-06-24 15:20:36 -04001161 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill560a8d82014-05-21 13:06:20 -04001162 {
1163 return gl::error(GL_INVALID_OPERATION, false);
1164 }
1165
Geoff Langaae65a42014-05-26 12:43:44 -04001166 const gl::Caps &caps = context->getCaps();
1167
Jamie Madill560a8d82014-05-21 13:06:20 -04001168 gl::Texture *texture = NULL;
1169 GLenum textureInternalFormat = GL_NONE;
Jamie Madill560a8d82014-05-21 13:06:20 -04001170 GLint textureLevelWidth = 0;
1171 GLint textureLevelHeight = 0;
1172 GLint textureLevelDepth = 0;
Geoff Langaae65a42014-05-26 12:43:44 -04001173 GLuint maxDimension = 0;
Jamie Madill560a8d82014-05-21 13:06:20 -04001174
1175 switch (target)
1176 {
1177 case GL_TEXTURE_2D:
1178 {
1179 gl::Texture2D *texture2d = context->getTexture2D();
1180 if (texture2d)
1181 {
1182 textureInternalFormat = texture2d->getInternalFormat(level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001183 textureLevelWidth = texture2d->getWidth(level);
1184 textureLevelHeight = texture2d->getHeight(level);
1185 textureLevelDepth = 1;
1186 texture = texture2d;
Geoff Langaae65a42014-05-26 12:43:44 -04001187 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001188 }
1189 }
1190 break;
1191
1192 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1193 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1194 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1195 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1196 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1197 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1198 {
1199 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1200 if (textureCube)
1201 {
1202 textureInternalFormat = textureCube->getInternalFormat(target, level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001203 textureLevelWidth = textureCube->getWidth(target, level);
1204 textureLevelHeight = textureCube->getHeight(target, level);
1205 textureLevelDepth = 1;
1206 texture = textureCube;
Geoff Langaae65a42014-05-26 12:43:44 -04001207 maxDimension = caps.maxCubeMapTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001208 }
1209 }
1210 break;
1211
1212 case GL_TEXTURE_2D_ARRAY:
1213 {
1214 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1215 if (texture2dArray)
1216 {
1217 textureInternalFormat = texture2dArray->getInternalFormat(level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001218 textureLevelWidth = texture2dArray->getWidth(level);
1219 textureLevelHeight = texture2dArray->getHeight(level);
1220 textureLevelDepth = texture2dArray->getLayers(level);
1221 texture = texture2dArray;
Geoff Langaae65a42014-05-26 12:43:44 -04001222 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001223 }
1224 }
1225 break;
1226
1227 case GL_TEXTURE_3D:
1228 {
1229 gl::Texture3D *texture3d = context->getTexture3D();
1230 if (texture3d)
1231 {
1232 textureInternalFormat = texture3d->getInternalFormat(level);
Jamie Madill560a8d82014-05-21 13:06:20 -04001233 textureLevelWidth = texture3d->getWidth(level);
1234 textureLevelHeight = texture3d->getHeight(level);
1235 textureLevelDepth = texture3d->getDepth(level);
1236 texture = texture3d;
Geoff Langaae65a42014-05-26 12:43:44 -04001237 maxDimension = caps.max3DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001238 }
1239 }
1240 break;
1241
1242 default:
1243 return gl::error(GL_INVALID_ENUM, false);
1244 }
1245
1246 if (!texture)
1247 {
1248 return gl::error(GL_INVALID_OPERATION, false);
1249 }
1250
1251 if (texture->isImmutable() && !isSubImage)
1252 {
1253 return gl::error(GL_INVALID_OPERATION, false);
1254 }
1255
Geoff Lang5d601382014-07-22 15:14:06 -04001256 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
1257
1258 if (formatInfo.depthBits > 0)
Jamie Madill560a8d82014-05-21 13:06:20 -04001259 {
1260 return gl::error(GL_INVALID_OPERATION, false);
1261 }
1262
Geoff Lang5d601382014-07-22 15:14:06 -04001263 if (formatInfo.compressed)
Jamie Madill560a8d82014-05-21 13:06:20 -04001264 {
Geoff Lang5d601382014-07-22 15:14:06 -04001265 if (((width % formatInfo.compressedBlockWidth) != 0 && width != textureLevelWidth) ||
1266 ((height % formatInfo.compressedBlockHeight) != 0 && height != textureLevelHeight))
Jamie Madill560a8d82014-05-21 13:06:20 -04001267 {
1268 return gl::error(GL_INVALID_OPERATION, false);
1269 }
1270 }
1271
1272 if (isSubImage)
1273 {
1274 if (xoffset + width > textureLevelWidth ||
1275 yoffset + height > textureLevelHeight ||
1276 zoffset >= textureLevelDepth)
1277 {
1278 return gl::error(GL_INVALID_VALUE, false);
1279 }
1280 }
Jamie Madill6f38f822014-06-06 17:12:20 -04001281 else
1282 {
1283 if (IsCubemapTextureTarget(target) && width != height)
1284 {
1285 return gl::error(GL_INVALID_VALUE, false);
1286 }
1287
Geoff Lang5d601382014-07-22 15:14:06 -04001288 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
Jamie Madill6f38f822014-06-06 17:12:20 -04001289 {
1290 return gl::error(GL_INVALID_ENUM, false);
1291 }
1292
1293 int maxLevelDimension = (maxDimension >> level);
1294 if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension)
1295 {
1296 return gl::error(GL_INVALID_VALUE, false);
1297 }
1298 }
Jamie Madill560a8d82014-05-21 13:06:20 -04001299
1300 *textureFormatOut = textureInternalFormat;
1301 return true;
1302}
1303
Jamie Madill1aeb1312014-06-20 13:21:25 -04001304static bool ValidateDrawBase(const gl::Context *context, GLenum mode, GLsizei count)
Jamie Madill250d33f2014-06-06 17:09:03 -04001305{
Jamie Madill1aeb1312014-06-20 13:21:25 -04001306 switch (mode)
1307 {
1308 case GL_POINTS:
1309 case GL_LINES:
1310 case GL_LINE_LOOP:
1311 case GL_LINE_STRIP:
1312 case GL_TRIANGLES:
1313 case GL_TRIANGLE_STRIP:
1314 case GL_TRIANGLE_FAN:
1315 break;
1316 default:
1317 return gl::error(GL_INVALID_ENUM, false);
1318 }
1319
Jamie Madill250d33f2014-06-06 17:09:03 -04001320 if (count < 0)
1321 {
1322 return gl::error(GL_INVALID_VALUE, false);
1323 }
1324
Jamie Madill250d33f2014-06-06 17:09:03 -04001325 // Check for mapped buffers
Jamie Madillfd716582014-06-06 17:09:04 -04001326 if (context->hasMappedBuffer(GL_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001327 {
1328 return gl::error(GL_INVALID_OPERATION, false);
1329 }
1330
Shannon Woods53a94a82014-06-24 15:20:36 -04001331 const gl::DepthStencilState &depthStencilState = context->getState().getDepthStencilState();
Jamie Madillac528012014-06-20 13:21:23 -04001332 if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
Shannon Woods53a94a82014-06-24 15:20:36 -04001333 context->getState().getStencilRef() != context->getState().getStencilBackRef() ||
Jamie Madillac528012014-06-20 13:21:23 -04001334 depthStencilState.stencilMask != depthStencilState.stencilBackMask)
1335 {
1336 // Note: these separate values are not supported in WebGL, due to D3D's limitations.
1337 // See Section 6.10 of the WebGL 1.0 spec
1338 ERR("This ANGLE implementation does not support separate front/back stencil "
1339 "writemasks, reference values, or stencil mask values.");
1340 return gl::error(GL_INVALID_OPERATION, false);
1341 }
1342
Shannon Woods53a94a82014-06-24 15:20:36 -04001343 const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer();
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001344 if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
1345 {
1346 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1347 }
1348
Shannon Woods53a94a82014-06-24 15:20:36 -04001349 if (context->getState().getCurrentProgramId() == 0)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001350 {
1351 return gl::error(GL_INVALID_OPERATION, false);
1352 }
1353
Shannon Woods53a94a82014-06-24 15:20:36 -04001354 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld4cfa572014-07-08 10:00:32 -04001355 if (!programBinary->validateSamplers(NULL))
1356 {
1357 return gl::error(GL_INVALID_OPERATION, false);
1358 }
1359
Jamie Madill250d33f2014-06-06 17:09:03 -04001360 // No-op if zero count
1361 return (count > 0);
1362}
1363
Jamie Madillfd716582014-06-06 17:09:04 -04001364bool ValidateDrawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
Jamie Madill250d33f2014-06-06 17:09:03 -04001365{
Jamie Madillfd716582014-06-06 17:09:04 -04001366 if (first < 0)
Jamie Madill250d33f2014-06-06 17:09:03 -04001367 {
1368 return gl::error(GL_INVALID_VALUE, false);
1369 }
1370
Shannon Woods53a94a82014-06-24 15:20:36 -04001371 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
Jamie Madillfd716582014-06-06 17:09:04 -04001372 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() &&
1373 curTransformFeedback->getDrawMode() != mode)
1374 {
1375 // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
1376 // that does not match the current transform feedback object's draw mode (if transform feedback
1377 // is active), (3.0.2, section 2.14, pg 86)
1378 return gl::error(GL_INVALID_OPERATION, false);
1379 }
1380
Jamie Madill1aeb1312014-06-20 13:21:25 -04001381 if (!ValidateDrawBase(context, mode, count))
Jamie Madillfd716582014-06-06 17:09:04 -04001382 {
1383 return false;
1384 }
1385
1386 return true;
1387}
1388
1389bool ValidateDrawArraysInstanced(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1390{
1391 if (primcount < 0)
1392 {
1393 return gl::error(GL_INVALID_VALUE, false);
1394 }
1395
1396 if (!ValidateDrawArrays(context, mode, first, count))
1397 {
1398 return false;
1399 }
1400
1401 // No-op if zero primitive count
1402 return (primcount > 0);
1403}
1404
1405bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
1406{
Jamie Madill250d33f2014-06-06 17:09:03 -04001407 switch (type)
1408 {
1409 case GL_UNSIGNED_BYTE:
1410 case GL_UNSIGNED_SHORT:
1411 break;
1412 case GL_UNSIGNED_INT:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001413 if (!context->getExtensions().elementIndexUint)
Jamie Madill250d33f2014-06-06 17:09:03 -04001414 {
1415 return gl::error(GL_INVALID_ENUM, false);
1416 }
1417 break;
1418 default:
1419 return gl::error(GL_INVALID_ENUM, false);
1420 }
1421
Shannon Woods53a94a82014-06-24 15:20:36 -04001422 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
Jamie Madill250d33f2014-06-06 17:09:03 -04001423 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
1424 {
1425 // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced
1426 // while transform feedback is active, (3.0.2, section 2.14, pg 86)
1427 return gl::error(GL_INVALID_OPERATION, false);
1428 }
1429
1430 // Check for mapped buffers
Jamie Madillfd716582014-06-06 17:09:04 -04001431 if (context->hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001432 {
1433 return gl::error(GL_INVALID_OPERATION, false);
1434 }
1435
Shannon Woods53a94a82014-06-24 15:20:36 -04001436 gl::VertexArray *vao = context->getState().getVertexArray();
Jamie Madilld4cfa572014-07-08 10:00:32 -04001437 if (!indices && !vao->getElementArrayBuffer())
1438 {
1439 return gl::error(GL_INVALID_OPERATION, false);
1440 }
1441
Jamie Madill1aeb1312014-06-20 13:21:25 -04001442 if (!ValidateDrawBase(context, mode, count))
Jamie Madillfd716582014-06-06 17:09:04 -04001443 {
1444 return false;
1445 }
1446
1447 return true;
1448}
1449
1450bool ValidateDrawElementsInstanced(const gl::Context *context, GLenum mode, GLsizei count, GLenum type,
1451 const GLvoid *indices, GLsizei primcount)
1452{
1453 if (primcount < 0)
1454 {
1455 return gl::error(GL_INVALID_VALUE, false);
1456 }
1457
1458 if (!ValidateDrawElements(context, mode, count, type, indices))
1459 {
1460 return false;
1461 }
1462
1463 // No-op zero primitive count
1464 return (primcount > 0);
Jamie Madill250d33f2014-06-06 17:09:03 -04001465}
1466
Jamie Madill55ec3b12014-07-03 10:38:57 -04001467bool ValidateFramebufferTextureBase(const gl::Context *context, GLenum target, GLenum attachment,
1468 GLuint texture, GLint level)
Jamie Madill570f7c82014-07-03 10:38:54 -04001469{
Jamie Madill55ec3b12014-07-03 10:38:57 -04001470 if (!ValidFramebufferTarget(target))
1471 {
1472 return gl::error(GL_INVALID_ENUM, false);
1473 }
1474
1475 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill570f7c82014-07-03 10:38:54 -04001476 {
1477 return false;
1478 }
1479
Jamie Madill55ec3b12014-07-03 10:38:57 -04001480 if (texture != 0)
1481 {
1482 gl::Texture *tex = context->getTexture(texture);
1483
1484 if (tex == NULL)
1485 {
1486 return gl::error(GL_INVALID_OPERATION, false);
1487 }
1488
1489 if (level < 0)
1490 {
1491 return gl::error(GL_INVALID_VALUE, false);
1492 }
1493 }
1494
Shannon Woods53a94a82014-06-24 15:20:36 -04001495 const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1496 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill55ec3b12014-07-03 10:38:57 -04001497
1498 if (framebufferHandle == 0 || !framebuffer)
1499 {
1500 return gl::error(GL_INVALID_OPERATION, false);
1501 }
1502
1503 return true;
1504}
1505
1506bool ValidateFramebufferTexture2D(const gl::Context *context, GLenum target, GLenum attachment,
1507 GLenum textarget, GLuint texture, GLint level)
1508{
1509 // Attachments are required to be bound to level 0 in ES2
1510 if (context->getClientVersion() < 3 && level != 0)
1511 {
1512 return gl::error(GL_INVALID_VALUE, false);
1513 }
1514
1515 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
Jamie Madill570f7c82014-07-03 10:38:54 -04001516 {
1517 return false;
1518 }
1519
Jamie Madill55ec3b12014-07-03 10:38:57 -04001520 if (texture != 0)
1521 {
1522 gl::Texture *tex = context->getTexture(texture);
1523 ASSERT(tex);
1524
Jamie Madill2a6564e2014-07-11 09:53:19 -04001525 const gl::Caps &caps = context->getCaps();
1526
Jamie Madill55ec3b12014-07-03 10:38:57 -04001527 switch (textarget)
1528 {
1529 case GL_TEXTURE_2D:
1530 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001531 if (level > gl::log2(caps.max2DTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001532 {
1533 return gl::error(GL_INVALID_VALUE, false);
1534 }
1535 if (tex->getTarget() != GL_TEXTURE_2D)
1536 {
1537 return gl::error(GL_INVALID_OPERATION, false);
1538 }
1539 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1540 if (tex2d->isCompressed(level))
1541 {
1542 return gl::error(GL_INVALID_OPERATION, false);
1543 }
1544 }
1545 break;
1546
1547 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1548 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1549 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1550 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1551 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1552 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1553 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001554 if (level > gl::log2(caps.maxCubeMapTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001555 {
1556 return gl::error(GL_INVALID_VALUE, false);
1557 }
1558 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1559 {
1560 return gl::error(GL_INVALID_OPERATION, false);
1561 }
1562 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1563 if (texcube->isCompressed(textarget, level))
1564 {
1565 return gl::error(GL_INVALID_OPERATION, false);
1566 }
1567 }
1568 break;
1569
1570 default:
1571 return gl::error(GL_INVALID_ENUM, false);
1572 }
1573 }
1574
Jamie Madill570f7c82014-07-03 10:38:54 -04001575 return true;
1576}
1577
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001578}