blob: e9630987a178a2d683a8c8728fbb0b5b3da04ae3 [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 Lange4a492b2014-06-19 14:14:41 -0400195 if (!IsFormatCompressed(internalFormat))
Geoff Langd4f180b2013-09-24 13:57:44 -0400196 {
197 return false;
198 }
199
Geoff Lange4a492b2014-06-19 14:14:41 -0400200 GLint blockWidth = GetCompressedBlockWidth(internalFormat);
201 GLint blockHeight = GetCompressedBlockHeight(internalFormat);
Geoff Langd4f180b2013-09-24 13:57:44 -0400202 if (width < 0 || (width > blockWidth && width % blockWidth != 0) ||
203 height < 0 || (height > blockHeight && height % blockHeight != 0))
204 {
205 return false;
206 }
207
208 return true;
209}
210
Geoff Lang37dde692014-01-31 16:34:54 -0500211bool ValidQueryType(const Context *context, GLenum queryType)
212{
213 META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
214 META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
215
216 switch (queryType)
217 {
218 case GL_ANY_SAMPLES_PASSED:
219 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
220 return true;
221 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
222 return (context->getClientVersion() >= 3);
223 default:
224 return false;
225 }
226}
227
Geoff Lang48dcae72014-02-05 16:28:24 -0500228bool ValidProgram(const Context *context, GLuint id)
229{
230 // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
231 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
232 // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
233
234 if (context->getProgram(id) != NULL)
235 {
236 return true;
237 }
238 else if (context->getShader(id) != NULL)
239 {
240 // ID is the wrong type
241 return gl::error(GL_INVALID_OPERATION, false);
242 }
243 else
244 {
245 // No shader/program object has this ID
246 return gl::error(GL_INVALID_VALUE, false);
247 }
248}
249
Jamie Madillb4472272014-07-03 10:38:55 -0400250bool ValidateAttachmentTarget(const gl::Context *context, GLenum attachment)
251{
252 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
253 {
254 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
255
Geoff Langaae65a42014-05-26 12:43:44 -0400256 if (colorAttachment >= context->getCaps().maxColorAttachments)
Jamie Madillb4472272014-07-03 10:38:55 -0400257 {
258 return gl::error(GL_INVALID_VALUE, false);
259 }
260 }
261 else
262 {
263 switch (attachment)
264 {
265 case GL_DEPTH_ATTACHMENT:
266 case GL_STENCIL_ATTACHMENT:
267 break;
268
269 case GL_DEPTH_STENCIL_ATTACHMENT:
270 if (context->getClientVersion() < 3)
271 {
272 return gl::error(GL_INVALID_ENUM, false);
273 }
274 break;
275
276 default:
277 return gl::error(GL_INVALID_ENUM, false);
278 }
279 }
280
281 return true;
282}
283
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400284bool ValidateRenderbufferStorageParameters(const gl::Context *context, GLenum target, GLsizei samples,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400285 GLenum internalformat, GLsizei width, GLsizei height,
286 bool angleExtension)
287{
288 switch (target)
289 {
290 case GL_RENDERBUFFER:
291 break;
292 default:
293 return gl::error(GL_INVALID_ENUM, false);
294 }
295
296 if (width < 0 || height < 0 || samples < 0)
297 {
298 return gl::error(GL_INVALID_VALUE, false);
299 }
300
Geoff Langc0b9ef42014-07-02 10:02:37 -0400301 if (!gl::IsValidInternalFormat(internalformat, context->getExtensions(), context->getClientVersion()))
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 Lange4a492b2014-06-19 14:14:41 -0400310 if (!gl::IsSizedInternalFormat(internalformat))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400311 {
312 return gl::error(GL_INVALID_ENUM, false);
313 }
314
Geoff Lange4a492b2014-06-19 14:14:41 -0400315 GLenum componentType = gl::GetComponentType(internalformat);
Geoff Langb2f3d052013-08-13 12:49:27 -0400316 if ((componentType == GL_UNSIGNED_INT || componentType == GL_INT) && samples > 0)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400317 {
318 return gl::error(GL_INVALID_OPERATION, false);
319 }
320
Geoff Langc0b9ef42014-07-02 10:02:37 -0400321 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
Geoff Lang6cf8e1b2014-07-03 13:03:57 -0400322 if (!formatCaps.renderable)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400323 {
324 return gl::error(GL_INVALID_ENUM, false);
325 }
326
Geoff Langaae65a42014-05-26 12:43:44 -0400327 if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400328 {
329 return gl::error(GL_INVALID_VALUE, false);
330 }
331
332 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
333 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
334 // states that samples must be less than or equal to the maximum samples for the specified
335 // internal format.
336 if (angleExtension)
337 {
Geoff Lang5f4c4632014-07-03 13:46:52 -0400338 ASSERT(context->getExtensions().framebufferMultisample);
339 if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400340 {
341 return gl::error(GL_INVALID_VALUE, false);
342 }
Geoff Lang5f4c4632014-07-03 13:46:52 -0400343
344 // Check if this specific format supports enough samples
345 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
346 {
347 return gl::error(GL_OUT_OF_MEMORY, false);
348 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400349 }
350 else
351 {
Geoff Lang5f4c4632014-07-03 13:46:52 -0400352 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400353 {
354 return gl::error(GL_INVALID_VALUE, false);
355 }
356 }
357
Shannon Woods53a94a82014-06-24 15:20:36 -0400358 GLuint handle = context->getState().getRenderbufferId();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400359 if (handle == 0)
360 {
361 return gl::error(GL_INVALID_OPERATION, false);
362 }
363
364 return true;
365}
366
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500367bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment,
368 GLenum renderbuffertarget, GLuint renderbuffer)
369{
Shannon Woods1da3cf62014-06-27 15:32:23 -0400370 if (!ValidFramebufferTarget(target))
371 {
372 return gl::error(GL_INVALID_ENUM, false);
373 }
374
Shannon Woods53a94a82014-06-24 15:20:36 -0400375 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
376 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500377
378 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
379 {
380 return gl::error(GL_INVALID_OPERATION, false);
381 }
382
Jamie Madillb4472272014-07-03 10:38:55 -0400383 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500384 {
Jamie Madillb4472272014-07-03 10:38:55 -0400385 return false;
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500386 }
387
Jamie Madillab9d82c2014-01-21 16:38:14 -0500388 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
389 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
390 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
391 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
392 if (renderbuffer != 0)
393 {
394 if (!context->getRenderbuffer(renderbuffer))
395 {
396 return gl::error(GL_INVALID_OPERATION, false);
397 }
398 }
399
Jamie Madill1fc7e2c2014-01-21 16:47:10 -0500400 return true;
401}
402
Jamie Madill3c7fa222014-06-05 13:08:51 -0400403static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer,
Geoff Lang125deab2013-08-09 13:34:16 -0400404 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
405 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
406{
407 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
408 dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
409 srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
410 {
411 return true;
412 }
Shannon Woods53a94a82014-06-24 15:20:36 -0400413 else if (context->getState().isScissorTestEnabled())
Geoff Lang125deab2013-08-09 13:34:16 -0400414 {
Shannon Woods53a94a82014-06-24 15:20:36 -0400415 const Rectangle &scissor = context->getState().getScissor();
Geoff Lang125deab2013-08-09 13:34:16 -0400416
Shannon Woods53a94a82014-06-24 15:20:36 -0400417 return scissor.x > 0 || scissor.y > 0 ||
418 scissor.width < writeBuffer->getWidth() ||
419 scissor.height < writeBuffer->getHeight();
Geoff Lang125deab2013-08-09 13:34:16 -0400420 }
421 else
422 {
423 return false;
424 }
425}
426
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400427bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400428 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
429 GLenum filter, bool fromAngleExtension)
430{
431 switch (filter)
432 {
433 case GL_NEAREST:
434 break;
435 case GL_LINEAR:
436 if (fromAngleExtension)
437 {
438 return gl::error(GL_INVALID_ENUM, false);
439 }
440 break;
441 default:
442 return gl::error(GL_INVALID_ENUM, false);
443 }
444
445 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
446 {
447 return gl::error(GL_INVALID_VALUE, false);
448 }
449
450 if (mask == 0)
451 {
452 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
453 // buffers are copied.
454 return false;
455 }
456
457 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
458 {
459 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
460 return gl::error(GL_INVALID_OPERATION, false);
461 }
462
463 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
464 // color buffer, leaving only nearest being unfiltered from above
465 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
466 {
467 return gl::error(GL_INVALID_OPERATION, false);
468 }
469
Shannon Woods53a94a82014-06-24 15:20:36 -0400470 if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400471 {
472 if (fromAngleExtension)
473 {
474 ERR("Blits with the same source and destination framebuffer are not supported by this "
475 "implementation.");
476 }
477 return gl::error(GL_INVALID_OPERATION, false);
478 }
479
Shannon Woods53a94a82014-06-24 15:20:36 -0400480 gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
481 gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400482 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
483 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
484 {
485 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
486 }
487
488 if (drawFramebuffer->getSamples() != 0)
489 {
490 return gl::error(GL_INVALID_OPERATION, false);
491 }
492
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400493 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
494
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400495 if (mask & GL_COLOR_BUFFER_BIT)
496 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400497 gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
498 gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400499
500 if (readColorBuffer && drawColorBuffer)
501 {
Geoff Lang005df412013-10-16 14:12:50 -0400502 GLenum readInternalFormat = readColorBuffer->getActualFormat();
Geoff Lange4a492b2014-06-19 14:14:41 -0400503 GLenum readComponentType = gl::GetComponentType(readInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400504
505 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
506 {
507 if (drawFramebuffer->isEnabledColorAttachment(i))
508 {
Geoff Lang005df412013-10-16 14:12:50 -0400509 GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
Geoff Lange4a492b2014-06-19 14:14:41 -0400510 GLenum drawComponentType = gl::GetComponentType(drawInternalFormat);
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400511
Geoff Langb2f3d052013-08-13 12:49:27 -0400512 // The GL ES 3.0.2 spec (pg 193) states that:
513 // 1) If the read buffer is fixed point format, the draw buffer must be as well
514 // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well
515 // 3) If the read buffer is a signed integer format, the draw buffer must be as well
516 if ( (readComponentType == GL_UNSIGNED_NORMALIZED || readComponentType == GL_SIGNED_NORMALIZED) &&
517 !(drawComponentType == GL_UNSIGNED_NORMALIZED || drawComponentType == GL_SIGNED_NORMALIZED))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400518 {
519 return gl::error(GL_INVALID_OPERATION, false);
520 }
521
Geoff Langb2f3d052013-08-13 12:49:27 -0400522 if (readComponentType == GL_UNSIGNED_INT && drawComponentType != GL_UNSIGNED_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400523 {
524 return gl::error(GL_INVALID_OPERATION, false);
525 }
526
Geoff Langb2f3d052013-08-13 12:49:27 -0400527 if (readComponentType == GL_INT && drawComponentType != GL_INT)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400528 {
529 return gl::error(GL_INVALID_OPERATION, false);
530 }
531
Geoff Langb2f3d052013-08-13 12:49:27 -0400532 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400533 {
534 return gl::error(GL_INVALID_OPERATION, false);
535 }
536 }
537 }
538
Geoff Langb2f3d052013-08-13 12:49:27 -0400539 if ((readComponentType == GL_INT || readComponentType == GL_UNSIGNED_INT) && filter == GL_LINEAR)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400540 {
541 return gl::error(GL_INVALID_OPERATION, false);
542 }
543
544 if (fromAngleExtension)
545 {
546 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
547 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
548 {
549 return gl::error(GL_INVALID_OPERATION, false);
550 }
551
552 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
553 {
554 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
555 {
Jamie Madille92a3542014-07-03 10:38:58 -0400556 FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment);
557 ASSERT(attachment);
558
559 if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400560 {
561 return gl::error(GL_INVALID_OPERATION, false);
562 }
563
Jamie Madille92a3542014-07-03 10:38:58 -0400564 if (attachment->getActualFormat() != readColorBuffer->getActualFormat())
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400565 {
566 return gl::error(GL_INVALID_OPERATION, false);
567 }
568 }
569 }
Geoff Lang125deab2013-08-09 13:34:16 -0400570 if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer,
571 srcX0, srcY0, srcX1, srcY1,
572 dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400573 {
574 return gl::error(GL_INVALID_OPERATION, false);
575 }
576 }
577 }
578 }
579
580 if (mask & GL_DEPTH_BUFFER_BIT)
581 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400582 gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer();
583 gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400584
585 if (readDepthBuffer && drawDepthBuffer)
586 {
587 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
588 {
589 return gl::error(GL_INVALID_OPERATION, false);
590 }
591
592 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
593 {
594 return gl::error(GL_INVALID_OPERATION, false);
595 }
596
597 if (fromAngleExtension)
598 {
Geoff Lang125deab2013-08-09 13:34:16 -0400599 if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer,
600 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400601 {
602 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
603 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
604 }
605
606 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
607 {
608 return gl::error(GL_INVALID_OPERATION, false);
609 }
610 }
611 }
612 }
613
614 if (mask & GL_STENCIL_BUFFER_BIT)
615 {
Jamie Madill3c7fa222014-06-05 13:08:51 -0400616 gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer();
617 gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400618
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400619 if (readStencilBuffer && drawStencilBuffer)
620 {
621 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
622 {
623 return gl::error(GL_INVALID_OPERATION, false);
624 }
625
626 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
627 {
628 return gl::error(GL_INVALID_OPERATION, false);
629 }
630
631 if (fromAngleExtension)
632 {
Geoff Lang125deab2013-08-09 13:34:16 -0400633 if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer,
634 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400635 {
636 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
637 return gl::error(GL_INVALID_OPERATION, false); // only whole-buffer copies are permitted
638 }
639
640 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
641 {
642 return gl::error(GL_INVALID_OPERATION, false);
643 }
644 }
645 }
646 }
647
648 return true;
649}
650
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400651bool ValidateGetVertexAttribParameters(GLenum pname, int clientVersion)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400652{
653 switch (pname)
654 {
655 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
656 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
657 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
658 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
659 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
660 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
661 case GL_CURRENT_VERTEX_ATTRIB:
662 return true;
663
664 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
665 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
666 // the same constant.
667 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
668 return true;
669
670 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
671 return ((clientVersion >= 3) ? true : gl::error(GL_INVALID_ENUM, false));
672
673 default:
674 return gl::error(GL_INVALID_ENUM, false);
675 }
676}
677
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400678bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400679{
680 switch (pname)
681 {
682 case GL_TEXTURE_WRAP_R:
683 case GL_TEXTURE_SWIZZLE_R:
684 case GL_TEXTURE_SWIZZLE_G:
685 case GL_TEXTURE_SWIZZLE_B:
686 case GL_TEXTURE_SWIZZLE_A:
687 case GL_TEXTURE_BASE_LEVEL:
688 case GL_TEXTURE_MAX_LEVEL:
689 case GL_TEXTURE_COMPARE_MODE:
690 case GL_TEXTURE_COMPARE_FUNC:
691 case GL_TEXTURE_MIN_LOD:
692 case GL_TEXTURE_MAX_LOD:
693 if (context->getClientVersion() < 3)
694 {
695 return gl::error(GL_INVALID_ENUM, false);
696 }
697 break;
698
699 default: break;
700 }
701
702 switch (pname)
703 {
704 case GL_TEXTURE_WRAP_S:
705 case GL_TEXTURE_WRAP_T:
706 case GL_TEXTURE_WRAP_R:
707 switch (param)
708 {
709 case GL_REPEAT:
710 case GL_CLAMP_TO_EDGE:
711 case GL_MIRRORED_REPEAT:
712 return true;
713 default:
714 return gl::error(GL_INVALID_ENUM, false);
715 }
716
717 case GL_TEXTURE_MIN_FILTER:
718 switch (param)
719 {
720 case GL_NEAREST:
721 case GL_LINEAR:
722 case GL_NEAREST_MIPMAP_NEAREST:
723 case GL_LINEAR_MIPMAP_NEAREST:
724 case GL_NEAREST_MIPMAP_LINEAR:
725 case GL_LINEAR_MIPMAP_LINEAR:
726 return true;
727 default:
728 return gl::error(GL_INVALID_ENUM, false);
729 }
730 break;
731
732 case GL_TEXTURE_MAG_FILTER:
733 switch (param)
734 {
735 case GL_NEAREST:
736 case GL_LINEAR:
737 return true;
738 default:
739 return gl::error(GL_INVALID_ENUM, false);
740 }
741 break;
742
743 case GL_TEXTURE_USAGE_ANGLE:
744 switch (param)
745 {
746 case GL_NONE:
747 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
748 return true;
749 default:
750 return gl::error(GL_INVALID_ENUM, false);
751 }
752 break;
753
754 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
Geoff Langc0b9ef42014-07-02 10:02:37 -0400755 if (!context->getExtensions().textureFilterAnisotropic)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400756 {
757 return gl::error(GL_INVALID_ENUM, false);
758 }
759
760 // we assume the parameter passed to this validation method is truncated, not rounded
761 if (param < 1)
762 {
763 return gl::error(GL_INVALID_VALUE, false);
764 }
765 return true;
766
767 case GL_TEXTURE_MIN_LOD:
768 case GL_TEXTURE_MAX_LOD:
769 // any value is permissible
770 return true;
771
772 case GL_TEXTURE_COMPARE_MODE:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400773 // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400774 switch (param)
775 {
776 case GL_NONE:
777 case GL_COMPARE_REF_TO_TEXTURE:
778 return true;
779 default:
780 return gl::error(GL_INVALID_ENUM, false);
781 }
782 break;
783
784 case GL_TEXTURE_COMPARE_FUNC:
Geoff Lang63b5f1f2013-09-23 14:52:14 -0400785 // Acceptable function parameters from GLES 3.0.2 spec, table 3.17
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400786 switch (param)
787 {
788 case GL_LEQUAL:
789 case GL_GEQUAL:
790 case GL_LESS:
791 case GL_GREATER:
792 case GL_EQUAL:
793 case GL_NOTEQUAL:
794 case GL_ALWAYS:
795 case GL_NEVER:
796 return true;
797 default:
798 return gl::error(GL_INVALID_ENUM, false);
799 }
800 break;
801
802 case GL_TEXTURE_SWIZZLE_R:
803 case GL_TEXTURE_SWIZZLE_G:
804 case GL_TEXTURE_SWIZZLE_B:
805 case GL_TEXTURE_SWIZZLE_A:
Geoff Langbc90a482013-09-17 16:51:27 -0400806 switch (param)
807 {
808 case GL_RED:
809 case GL_GREEN:
810 case GL_BLUE:
811 case GL_ALPHA:
812 case GL_ZERO:
813 case GL_ONE:
814 return true;
815 default:
816 return gl::error(GL_INVALID_ENUM, false);
817 }
818 break;
819
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400820 case GL_TEXTURE_BASE_LEVEL:
821 case GL_TEXTURE_MAX_LEVEL:
Nicolas Capens8de68282014-04-04 11:10:27 -0400822 if (param < 0)
823 {
824 return gl::error(GL_INVALID_VALUE, false);
825 }
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400826 return true;
827
828 default:
829 return gl::error(GL_INVALID_ENUM, false);
830 }
831}
832
Geoff Lang34dbb6f2013-08-05 15:05:47 -0400833bool ValidateSamplerObjectParameter(GLenum pname)
Geoff Lange8ebe7f2013-08-05 15:03:13 -0400834{
835 switch (pname)
836 {
837 case GL_TEXTURE_MIN_FILTER:
838 case GL_TEXTURE_MAG_FILTER:
839 case GL_TEXTURE_WRAP_S:
840 case GL_TEXTURE_WRAP_T:
841 case GL_TEXTURE_WRAP_R:
842 case GL_TEXTURE_MIN_LOD:
843 case GL_TEXTURE_MAX_LOD:
844 case GL_TEXTURE_COMPARE_MODE:
845 case GL_TEXTURE_COMPARE_FUNC:
846 return true;
847
848 default:
849 return gl::error(GL_INVALID_ENUM, false);
850 }
851}
852
Jamie Madill26e91952014-03-05 15:01:27 -0500853bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
854 GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
855{
Shannon Woods53a94a82014-06-24 15:20:36 -0400856 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -0400857 ASSERT(framebuffer);
Jamie Madill26e91952014-03-05 15:01:27 -0500858
859 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
860 {
861 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
862 }
863
Shannon Woods53a94a82014-06-24 15:20:36 -0400864 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill26e91952014-03-05 15:01:27 -0500865 {
866 return gl::error(GL_INVALID_OPERATION, false);
867 }
868
Jamie Madill893ab082014-05-16 16:56:10 -0400869 if (!framebuffer->getReadColorbuffer())
870 {
871 return gl::error(GL_INVALID_OPERATION, false);
872 }
873
Jamie Madill26e91952014-03-05 15:01:27 -0500874 GLenum currentInternalFormat, currentFormat, currentType;
Geoff Lange4a492b2014-06-19 14:14:41 -0400875 GLuint clientVersion = context->getClientVersion();
Jamie Madill26e91952014-03-05 15:01:27 -0500876
Jamie Madill893ab082014-05-16 16:56:10 -0400877 context->getCurrentReadFormatType(&currentInternalFormat, &currentFormat, &currentType);
Jamie Madill26e91952014-03-05 15:01:27 -0500878
Geoff Langbdc9b2f2014-04-16 14:41:54 -0400879 bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
880 ValidES3ReadFormatType(context, currentInternalFormat, format, type);
Jamie Madill26e91952014-03-05 15:01:27 -0500881
882 if (!(currentFormat == format && currentType == type) && !validReadFormat)
883 {
884 return gl::error(GL_INVALID_OPERATION, false);
885 }
886
Geoff Lange4a492b2014-06-19 14:14:41 -0400887 GLenum sizedInternalFormat = IsSizedInternalFormat(format) ? format
888 : GetSizedInternalFormat(format, type);
Jamie Madill26e91952014-03-05 15:01:27 -0500889
Shannon Woods53a94a82014-06-24 15:20:36 -0400890 GLsizei outputPitch = GetRowPitch(sizedInternalFormat, type, width, context->getState().getPackAlignment());
Jamie Madill26e91952014-03-05 15:01:27 -0500891 // sized query sanity check
892 if (bufSize)
893 {
894 int requiredSize = outputPitch * height;
895 if (requiredSize > *bufSize)
896 {
897 return gl::error(GL_INVALID_OPERATION, false);
898 }
899 }
900
901 return true;
902}
903
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400904bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
905{
906 if (!ValidQueryType(context, target))
907 {
908 return gl::error(GL_INVALID_ENUM, false);
909 }
910
911 if (id == 0)
912 {
913 return gl::error(GL_INVALID_OPERATION, false);
914 }
915
916 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
917 // of zero, if the active query object name for <target> is non-zero (for the
918 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
919 // the active query for either target is non-zero), if <id> is the name of an
920 // existing query object whose type does not match <target>, or if <id> is the
921 // active query object name for any query type, the error INVALID_OPERATION is
922 // generated.
923
924 // Ensure no other queries are active
925 // NOTE: If other queries than occlusion are supported, we will need to check
926 // separately that:
927 // a) The query ID passed is not the current active query for any target/type
928 // b) There are no active queries for the requested target (and in the case
929 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
930 // no query may be active for either if glBeginQuery targets either.
Shannon Woods53a94a82014-06-24 15:20:36 -0400931 if (context->getState().isQueryActive())
Jamie Madilldb2f14c2014-05-13 13:56:30 -0400932 {
933 return gl::error(GL_INVALID_OPERATION, false);
934 }
935
936 Query *queryObject = context->getQuery(id, true, target);
937
938 // check that name was obtained with glGenQueries
939 if (!queryObject)
940 {
941 return gl::error(GL_INVALID_OPERATION, false);
942 }
943
944 // check for type mismatch
945 if (queryObject->getType() != target)
946 {
947 return gl::error(GL_INVALID_OPERATION, false);
948 }
949
950 return true;
951}
952
Jamie Madill45c785d2014-05-13 14:09:34 -0400953bool ValidateEndQuery(gl::Context *context, GLenum target)
954{
955 if (!ValidQueryType(context, target))
956 {
957 return gl::error(GL_INVALID_ENUM, false);
958 }
959
Shannon Woods53a94a82014-06-24 15:20:36 -0400960 const Query *queryObject = context->getState().getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -0400961
962 if (queryObject == NULL)
963 {
964 return gl::error(GL_INVALID_OPERATION, false);
965 }
966
967 if (!queryObject->isStarted())
968 {
969 return gl::error(GL_INVALID_OPERATION, false);
970 }
971
972 return true;
973}
974
Jamie Madill36398922014-05-20 14:51:53 -0400975static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
976 GLint location, GLsizei count, LinkedUniform **uniformOut)
Jamie Madilld7c7bb22014-05-20 10:55:54 -0400977{
978 if (count < 0)
979 {
980 return gl::error(GL_INVALID_VALUE, false);
981 }
982
Shannon Woods53a94a82014-06-24 15:20:36 -0400983 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld7c7bb22014-05-20 10:55:54 -0400984 if (!programBinary)
985 {
986 return gl::error(GL_INVALID_OPERATION, false);
987 }
988
989 if (location == -1)
990 {
991 // Silently ignore the uniform command
992 return false;
993 }
994
Jamie Madill36398922014-05-20 14:51:53 -0400995 if (!programBinary->isValidUniformLocation(location))
996 {
997 return gl::error(GL_INVALID_OPERATION, false);
998 }
999
1000 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1001
1002 // attempting to write an array to a non-array uniform is an INVALID_OPERATION
1003 if (uniform->elementCount() == 1 && count > 1)
1004 {
1005 return gl::error(GL_INVALID_OPERATION, false);
1006 }
1007
1008 *uniformOut = uniform;
Jamie Madilld7c7bb22014-05-20 10:55:54 -04001009 return true;
1010}
1011
Jamie Madillaa981bd2014-05-20 10:55:55 -04001012bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
1013{
1014 // Check for ES3 uniform entry points
Jamie Madillf2575982014-06-25 16:04:54 -04001015 if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
Jamie Madillaa981bd2014-05-20 10:55:55 -04001016 {
1017 return gl::error(GL_INVALID_OPERATION, false);
1018 }
1019
Jamie Madill36398922014-05-20 14:51:53 -04001020 LinkedUniform *uniform = NULL;
1021 if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
1022 {
1023 return false;
1024 }
1025
Jamie Madillf2575982014-06-25 16:04:54 -04001026 GLenum targetBoolType = VariableBoolVectorType(uniformType);
Jamie Madill36398922014-05-20 14:51:53 -04001027 bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
1028 if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
1029 {
1030 return gl::error(GL_INVALID_OPERATION, false);
1031 }
1032
1033 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001034}
1035
1036bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
1037 GLboolean transpose)
1038{
1039 // Check for ES3 uniform entry points
1040 int rows = VariableRowCount(matrixType);
1041 int cols = VariableColumnCount(matrixType);
1042 if (rows != cols && context->getClientVersion() < 3)
1043 {
1044 return gl::error(GL_INVALID_OPERATION, false);
1045 }
1046
1047 if (transpose != GL_FALSE && context->getClientVersion() < 3)
1048 {
1049 return gl::error(GL_INVALID_VALUE, false);
1050 }
1051
Jamie Madill36398922014-05-20 14:51:53 -04001052 LinkedUniform *uniform = NULL;
1053 if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
1054 {
1055 return false;
1056 }
1057
1058 if (uniform->type != matrixType)
1059 {
1060 return gl::error(GL_INVALID_OPERATION, false);
1061 }
1062
1063 return true;
Jamie Madillaa981bd2014-05-20 10:55:55 -04001064}
1065
Jamie Madill893ab082014-05-16 16:56:10 -04001066bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
1067{
1068 if (!context->getQueryParameterInfo(pname, nativeType, numParams))
1069 {
1070 return gl::error(GL_INVALID_ENUM, false);
1071 }
1072
1073 if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
1074 {
1075 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
1076
Geoff Langaae65a42014-05-26 12:43:44 -04001077 if (colorAttachment >= context->getCaps().maxDrawBuffers)
Jamie Madill893ab082014-05-16 16:56:10 -04001078 {
1079 return gl::error(GL_INVALID_OPERATION, false);
1080 }
1081 }
1082
1083 switch (pname)
1084 {
1085 case GL_TEXTURE_BINDING_2D:
1086 case GL_TEXTURE_BINDING_CUBE_MAP:
1087 case GL_TEXTURE_BINDING_3D:
1088 case GL_TEXTURE_BINDING_2D_ARRAY:
Shannon Woods53a94a82014-06-24 15:20:36 -04001089 if (context->getState().getActiveSampler() >= context->getMaximumCombinedTextureImageUnits())
Jamie Madill893ab082014-05-16 16:56:10 -04001090 {
1091 return gl::error(GL_INVALID_OPERATION, false);
1092 }
1093 break;
1094
1095 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1096 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1097 {
Shannon Woods53a94a82014-06-24 15:20:36 -04001098 Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill893ab082014-05-16 16:56:10 -04001099 ASSERT(framebuffer);
1100 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1101 {
1102 return gl::error(GL_INVALID_OPERATION, false);
1103 }
1104
Jamie Madill3c7fa222014-06-05 13:08:51 -04001105 FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
1106 if (!attachment)
Jamie Madill893ab082014-05-16 16:56:10 -04001107 {
1108 return gl::error(GL_INVALID_OPERATION, false);
1109 }
1110 }
1111 break;
1112
1113 default:
1114 break;
1115 }
1116
1117 // pname is valid, but there are no parameters to return
1118 if (numParams == 0)
1119 {
1120 return false;
1121 }
1122
1123 return true;
1124}
1125
Jamie Madill560a8d82014-05-21 13:06:20 -04001126bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
1127 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height,
1128 GLint border, GLenum *textureFormatOut)
1129{
1130
1131 if (!ValidTexture2DDestinationTarget(context, target))
1132 {
1133 return gl::error(GL_INVALID_ENUM, false);
1134 }
1135
1136 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
1137 {
1138 return gl::error(GL_INVALID_VALUE, false);
1139 }
1140
1141 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1142 {
1143 return gl::error(GL_INVALID_VALUE, false);
1144 }
1145
1146 if (border != 0)
1147 {
1148 return gl::error(GL_INVALID_VALUE, false);
1149 }
1150
1151 if (!ValidMipLevel(context, target, level))
1152 {
1153 return gl::error(GL_INVALID_VALUE, false);
1154 }
1155
Shannon Woods53a94a82014-06-24 15:20:36 -04001156 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
Jamie Madill560a8d82014-05-21 13:06:20 -04001157 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1158 {
1159 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1160 }
1161
Shannon Woods53a94a82014-06-24 15:20:36 -04001162 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
Jamie Madill560a8d82014-05-21 13:06:20 -04001163 {
1164 return gl::error(GL_INVALID_OPERATION, false);
1165 }
1166
Geoff Langaae65a42014-05-26 12:43:44 -04001167 const gl::Caps &caps = context->getCaps();
1168
Jamie Madill560a8d82014-05-21 13:06:20 -04001169 gl::Texture *texture = NULL;
1170 GLenum textureInternalFormat = GL_NONE;
1171 bool textureCompressed = false;
1172 bool textureIsDepth = false;
1173 GLint textureLevelWidth = 0;
1174 GLint textureLevelHeight = 0;
1175 GLint textureLevelDepth = 0;
Geoff Langaae65a42014-05-26 12:43:44 -04001176 GLuint maxDimension = 0;
Jamie Madill560a8d82014-05-21 13:06:20 -04001177
1178 switch (target)
1179 {
1180 case GL_TEXTURE_2D:
1181 {
1182 gl::Texture2D *texture2d = context->getTexture2D();
1183 if (texture2d)
1184 {
1185 textureInternalFormat = texture2d->getInternalFormat(level);
1186 textureCompressed = texture2d->isCompressed(level);
1187 textureIsDepth = texture2d->isDepth(level);
1188 textureLevelWidth = texture2d->getWidth(level);
1189 textureLevelHeight = texture2d->getHeight(level);
1190 textureLevelDepth = 1;
1191 texture = texture2d;
Geoff Langaae65a42014-05-26 12:43:44 -04001192 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001193 }
1194 }
1195 break;
1196
1197 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1198 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1199 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1200 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1201 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1202 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1203 {
1204 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1205 if (textureCube)
1206 {
1207 textureInternalFormat = textureCube->getInternalFormat(target, level);
1208 textureCompressed = textureCube->isCompressed(target, level);
1209 textureIsDepth = false;
1210 textureLevelWidth = textureCube->getWidth(target, level);
1211 textureLevelHeight = textureCube->getHeight(target, level);
1212 textureLevelDepth = 1;
1213 texture = textureCube;
Geoff Langaae65a42014-05-26 12:43:44 -04001214 maxDimension = caps.maxCubeMapTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001215 }
1216 }
1217 break;
1218
1219 case GL_TEXTURE_2D_ARRAY:
1220 {
1221 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1222 if (texture2dArray)
1223 {
1224 textureInternalFormat = texture2dArray->getInternalFormat(level);
1225 textureCompressed = texture2dArray->isCompressed(level);
1226 textureIsDepth = texture2dArray->isDepth(level);
1227 textureLevelWidth = texture2dArray->getWidth(level);
1228 textureLevelHeight = texture2dArray->getHeight(level);
1229 textureLevelDepth = texture2dArray->getLayers(level);
1230 texture = texture2dArray;
Geoff Langaae65a42014-05-26 12:43:44 -04001231 maxDimension = caps.max2DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001232 }
1233 }
1234 break;
1235
1236 case GL_TEXTURE_3D:
1237 {
1238 gl::Texture3D *texture3d = context->getTexture3D();
1239 if (texture3d)
1240 {
1241 textureInternalFormat = texture3d->getInternalFormat(level);
1242 textureCompressed = texture3d->isCompressed(level);
1243 textureIsDepth = texture3d->isDepth(level);
1244 textureLevelWidth = texture3d->getWidth(level);
1245 textureLevelHeight = texture3d->getHeight(level);
1246 textureLevelDepth = texture3d->getDepth(level);
1247 texture = texture3d;
Geoff Langaae65a42014-05-26 12:43:44 -04001248 maxDimension = caps.max3DTextureSize;
Jamie Madill560a8d82014-05-21 13:06:20 -04001249 }
1250 }
1251 break;
1252
1253 default:
1254 return gl::error(GL_INVALID_ENUM, false);
1255 }
1256
1257 if (!texture)
1258 {
1259 return gl::error(GL_INVALID_OPERATION, false);
1260 }
1261
1262 if (texture->isImmutable() && !isSubImage)
1263 {
1264 return gl::error(GL_INVALID_OPERATION, false);
1265 }
1266
1267 if (textureIsDepth)
1268 {
1269 return gl::error(GL_INVALID_OPERATION, false);
1270 }
1271
1272 if (textureCompressed)
1273 {
Geoff Lange4a492b2014-06-19 14:14:41 -04001274 GLint blockWidth = GetCompressedBlockWidth(textureInternalFormat);
1275 GLint blockHeight = GetCompressedBlockHeight(textureInternalFormat);
Jamie Madill560a8d82014-05-21 13:06:20 -04001276
1277 if (((width % blockWidth) != 0 && width != textureLevelWidth) ||
1278 ((height % blockHeight) != 0 && height != textureLevelHeight))
1279 {
1280 return gl::error(GL_INVALID_OPERATION, false);
1281 }
1282 }
1283
1284 if (isSubImage)
1285 {
1286 if (xoffset + width > textureLevelWidth ||
1287 yoffset + height > textureLevelHeight ||
1288 zoffset >= textureLevelDepth)
1289 {
1290 return gl::error(GL_INVALID_VALUE, false);
1291 }
1292 }
Jamie Madill6f38f822014-06-06 17:12:20 -04001293 else
1294 {
1295 if (IsCubemapTextureTarget(target) && width != height)
1296 {
1297 return gl::error(GL_INVALID_VALUE, false);
1298 }
1299
Geoff Langc0b9ef42014-07-02 10:02:37 -04001300 if (!IsValidInternalFormat(internalformat, context->getExtensions(), context->getClientVersion()))
Jamie Madill6f38f822014-06-06 17:12:20 -04001301 {
1302 return gl::error(GL_INVALID_ENUM, false);
1303 }
1304
1305 int maxLevelDimension = (maxDimension >> level);
1306 if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension)
1307 {
1308 return gl::error(GL_INVALID_VALUE, false);
1309 }
1310 }
Jamie Madill560a8d82014-05-21 13:06:20 -04001311
1312 *textureFormatOut = textureInternalFormat;
1313 return true;
1314}
1315
Jamie Madill1aeb1312014-06-20 13:21:25 -04001316static bool ValidateDrawBase(const gl::Context *context, GLenum mode, GLsizei count)
Jamie Madill250d33f2014-06-06 17:09:03 -04001317{
Jamie Madill1aeb1312014-06-20 13:21:25 -04001318 switch (mode)
1319 {
1320 case GL_POINTS:
1321 case GL_LINES:
1322 case GL_LINE_LOOP:
1323 case GL_LINE_STRIP:
1324 case GL_TRIANGLES:
1325 case GL_TRIANGLE_STRIP:
1326 case GL_TRIANGLE_FAN:
1327 break;
1328 default:
1329 return gl::error(GL_INVALID_ENUM, false);
1330 }
1331
Jamie Madill250d33f2014-06-06 17:09:03 -04001332 if (count < 0)
1333 {
1334 return gl::error(GL_INVALID_VALUE, false);
1335 }
1336
Jamie Madill250d33f2014-06-06 17:09:03 -04001337 // Check for mapped buffers
Jamie Madillfd716582014-06-06 17:09:04 -04001338 if (context->hasMappedBuffer(GL_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001339 {
1340 return gl::error(GL_INVALID_OPERATION, false);
1341 }
1342
Shannon Woods53a94a82014-06-24 15:20:36 -04001343 const gl::DepthStencilState &depthStencilState = context->getState().getDepthStencilState();
Jamie Madillac528012014-06-20 13:21:23 -04001344 if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
Shannon Woods53a94a82014-06-24 15:20:36 -04001345 context->getState().getStencilRef() != context->getState().getStencilBackRef() ||
Jamie Madillac528012014-06-20 13:21:23 -04001346 depthStencilState.stencilMask != depthStencilState.stencilBackMask)
1347 {
1348 // Note: these separate values are not supported in WebGL, due to D3D's limitations.
1349 // See Section 6.10 of the WebGL 1.0 spec
1350 ERR("This ANGLE implementation does not support separate front/back stencil "
1351 "writemasks, reference values, or stencil mask values.");
1352 return gl::error(GL_INVALID_OPERATION, false);
1353 }
1354
Shannon Woods53a94a82014-06-24 15:20:36 -04001355 const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer();
Jamie Madill13f7d7d2014-06-20 13:21:27 -04001356 if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
1357 {
1358 return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
1359 }
1360
Shannon Woods53a94a82014-06-24 15:20:36 -04001361 if (context->getState().getCurrentProgramId() == 0)
Jamie Madilld4cfa572014-07-08 10:00:32 -04001362 {
1363 return gl::error(GL_INVALID_OPERATION, false);
1364 }
1365
Shannon Woods53a94a82014-06-24 15:20:36 -04001366 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
Jamie Madilld4cfa572014-07-08 10:00:32 -04001367 if (!programBinary->validateSamplers(NULL))
1368 {
1369 return gl::error(GL_INVALID_OPERATION, false);
1370 }
1371
Jamie Madill250d33f2014-06-06 17:09:03 -04001372 // No-op if zero count
1373 return (count > 0);
1374}
1375
Jamie Madillfd716582014-06-06 17:09:04 -04001376bool ValidateDrawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
Jamie Madill250d33f2014-06-06 17:09:03 -04001377{
Jamie Madillfd716582014-06-06 17:09:04 -04001378 if (first < 0)
Jamie Madill250d33f2014-06-06 17:09:03 -04001379 {
1380 return gl::error(GL_INVALID_VALUE, false);
1381 }
1382
Shannon Woods53a94a82014-06-24 15:20:36 -04001383 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
Jamie Madillfd716582014-06-06 17:09:04 -04001384 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() &&
1385 curTransformFeedback->getDrawMode() != mode)
1386 {
1387 // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
1388 // that does not match the current transform feedback object's draw mode (if transform feedback
1389 // is active), (3.0.2, section 2.14, pg 86)
1390 return gl::error(GL_INVALID_OPERATION, false);
1391 }
1392
Jamie Madill1aeb1312014-06-20 13:21:25 -04001393 if (!ValidateDrawBase(context, mode, count))
Jamie Madillfd716582014-06-06 17:09:04 -04001394 {
1395 return false;
1396 }
1397
1398 return true;
1399}
1400
1401bool ValidateDrawArraysInstanced(const gl::Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1402{
1403 if (primcount < 0)
1404 {
1405 return gl::error(GL_INVALID_VALUE, false);
1406 }
1407
1408 if (!ValidateDrawArrays(context, mode, first, count))
1409 {
1410 return false;
1411 }
1412
1413 // No-op if zero primitive count
1414 return (primcount > 0);
1415}
1416
1417bool ValidateDrawElements(const gl::Context *context, GLenum mode, GLsizei count, GLenum type, const GLvoid* indices)
1418{
Jamie Madill250d33f2014-06-06 17:09:03 -04001419 switch (type)
1420 {
1421 case GL_UNSIGNED_BYTE:
1422 case GL_UNSIGNED_SHORT:
1423 break;
1424 case GL_UNSIGNED_INT:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001425 if (!context->getExtensions().elementIndexUint)
Jamie Madill250d33f2014-06-06 17:09:03 -04001426 {
1427 return gl::error(GL_INVALID_ENUM, false);
1428 }
1429 break;
1430 default:
1431 return gl::error(GL_INVALID_ENUM, false);
1432 }
1433
Shannon Woods53a94a82014-06-24 15:20:36 -04001434 gl::TransformFeedback *curTransformFeedback = context->getState().getCurrentTransformFeedback();
Jamie Madill250d33f2014-06-06 17:09:03 -04001435 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
1436 {
1437 // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced
1438 // while transform feedback is active, (3.0.2, section 2.14, pg 86)
1439 return gl::error(GL_INVALID_OPERATION, false);
1440 }
1441
1442 // Check for mapped buffers
Jamie Madillfd716582014-06-06 17:09:04 -04001443 if (context->hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
Jamie Madill250d33f2014-06-06 17:09:03 -04001444 {
1445 return gl::error(GL_INVALID_OPERATION, false);
1446 }
1447
Shannon Woods53a94a82014-06-24 15:20:36 -04001448 gl::VertexArray *vao = context->getState().getVertexArray();
Jamie Madilld4cfa572014-07-08 10:00:32 -04001449 if (!indices && !vao->getElementArrayBuffer())
1450 {
1451 return gl::error(GL_INVALID_OPERATION, false);
1452 }
1453
Jamie Madill1aeb1312014-06-20 13:21:25 -04001454 if (!ValidateDrawBase(context, mode, count))
Jamie Madillfd716582014-06-06 17:09:04 -04001455 {
1456 return false;
1457 }
1458
1459 return true;
1460}
1461
1462bool ValidateDrawElementsInstanced(const gl::Context *context, GLenum mode, GLsizei count, GLenum type,
1463 const GLvoid *indices, GLsizei primcount)
1464{
1465 if (primcount < 0)
1466 {
1467 return gl::error(GL_INVALID_VALUE, false);
1468 }
1469
1470 if (!ValidateDrawElements(context, mode, count, type, indices))
1471 {
1472 return false;
1473 }
1474
1475 // No-op zero primitive count
1476 return (primcount > 0);
Jamie Madill250d33f2014-06-06 17:09:03 -04001477}
1478
Jamie Madill55ec3b12014-07-03 10:38:57 -04001479bool ValidateFramebufferTextureBase(const gl::Context *context, GLenum target, GLenum attachment,
1480 GLuint texture, GLint level)
Jamie Madill570f7c82014-07-03 10:38:54 -04001481{
Jamie Madill55ec3b12014-07-03 10:38:57 -04001482 if (!ValidFramebufferTarget(target))
1483 {
1484 return gl::error(GL_INVALID_ENUM, false);
1485 }
1486
1487 if (!ValidateAttachmentTarget(context, attachment))
Jamie Madill570f7c82014-07-03 10:38:54 -04001488 {
1489 return false;
1490 }
1491
Jamie Madill55ec3b12014-07-03 10:38:57 -04001492 if (texture != 0)
1493 {
1494 gl::Texture *tex = context->getTexture(texture);
1495
1496 if (tex == NULL)
1497 {
1498 return gl::error(GL_INVALID_OPERATION, false);
1499 }
1500
1501 if (level < 0)
1502 {
1503 return gl::error(GL_INVALID_VALUE, false);
1504 }
1505 }
1506
Shannon Woods53a94a82014-06-24 15:20:36 -04001507 const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1508 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
Jamie Madill55ec3b12014-07-03 10:38:57 -04001509
1510 if (framebufferHandle == 0 || !framebuffer)
1511 {
1512 return gl::error(GL_INVALID_OPERATION, false);
1513 }
1514
1515 return true;
1516}
1517
1518bool ValidateFramebufferTexture2D(const gl::Context *context, GLenum target, GLenum attachment,
1519 GLenum textarget, GLuint texture, GLint level)
1520{
1521 // Attachments are required to be bound to level 0 in ES2
1522 if (context->getClientVersion() < 3 && level != 0)
1523 {
1524 return gl::error(GL_INVALID_VALUE, false);
1525 }
1526
1527 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
Jamie Madill570f7c82014-07-03 10:38:54 -04001528 {
1529 return false;
1530 }
1531
Jamie Madill55ec3b12014-07-03 10:38:57 -04001532 if (texture != 0)
1533 {
1534 gl::Texture *tex = context->getTexture(texture);
1535 ASSERT(tex);
1536
Jamie Madill2a6564e2014-07-11 09:53:19 -04001537 const gl::Caps &caps = context->getCaps();
1538
Jamie Madill55ec3b12014-07-03 10:38:57 -04001539 switch (textarget)
1540 {
1541 case GL_TEXTURE_2D:
1542 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001543 if (level > gl::log2(caps.max2DTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001544 {
1545 return gl::error(GL_INVALID_VALUE, false);
1546 }
1547 if (tex->getTarget() != GL_TEXTURE_2D)
1548 {
1549 return gl::error(GL_INVALID_OPERATION, false);
1550 }
1551 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1552 if (tex2d->isCompressed(level))
1553 {
1554 return gl::error(GL_INVALID_OPERATION, false);
1555 }
1556 }
1557 break;
1558
1559 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1560 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1561 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1562 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1563 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1564 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1565 {
Jamie Madill2a6564e2014-07-11 09:53:19 -04001566 if (level > gl::log2(caps.maxCubeMapTextureSize))
Jamie Madill55ec3b12014-07-03 10:38:57 -04001567 {
1568 return gl::error(GL_INVALID_VALUE, false);
1569 }
1570 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1571 {
1572 return gl::error(GL_INVALID_OPERATION, false);
1573 }
1574 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1575 if (texcube->isCompressed(textarget, level))
1576 {
1577 return gl::error(GL_INVALID_OPERATION, false);
1578 }
1579 }
1580 break;
1581
1582 default:
1583 return gl::error(GL_INVALID_ENUM, false);
1584 }
1585 }
1586
Jamie Madill570f7c82014-07-03 10:38:54 -04001587 return true;
1588}
1589
Geoff Lange8ebe7f2013-08-05 15:03:13 -04001590}