2 // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 // validationES.h: Validation functions for generic OpenGL ES entry point parameters
9 #include "libGLESv2/validationES.h"
10 #include "libGLESv2/validationES2.h"
11 #include "libGLESv2/validationES3.h"
12 #include "libGLESv2/Context.h"
13 #include "libGLESv2/Texture.h"
14 #include "libGLESv2/Framebuffer.h"
15 #include "libGLESv2/FramebufferAttachment.h"
16 #include "libGLESv2/formatutils.h"
17 #include "libGLESv2/main.h"
18 #include "libGLESv2/Query.h"
19 #include "libGLESv2/ProgramBinary.h"
20 #include "libGLESv2/TransformFeedback.h"
21 #include "libGLESv2/VertexArray.h"
22 #include "libGLESv2/renderer/BufferImpl.h"
24 #include "common/mathutil.h"
25 #include "common/utilities.h"
27 // FIXME(jmadill): remove this when we support buffer data caching
28 #include "libGLESv2/renderer/d3d/BufferD3D.h"
33 bool ValidCap(const Context *context, GLenum cap)
38 case GL_POLYGON_OFFSET_FILL:
39 case GL_SAMPLE_ALPHA_TO_COVERAGE:
40 case GL_SAMPLE_COVERAGE:
47 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
48 case GL_RASTERIZER_DISCARD:
49 return (context->getClientVersion() >= 3);
55 bool ValidTextureTarget(const Context *context, GLenum target)
60 case GL_TEXTURE_CUBE_MAP:
64 case GL_TEXTURE_2D_ARRAY:
65 return (context->getClientVersion() >= 3);
72 // This function differs from ValidTextureTarget in that the target must be
73 // usable as the destination of a 2D operation-- so a cube face is valid, but
74 // GL_TEXTURE_CUBE_MAP is not.
75 // Note: duplicate of IsInternalTextureTarget
76 bool ValidTexture2DDestinationTarget(const Context *context, GLenum target)
81 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
82 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
83 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
84 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
85 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
86 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
88 case GL_TEXTURE_2D_ARRAY:
90 return (context->getClientVersion() >= 3);
96 bool ValidFramebufferTarget(GLenum target)
98 META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER);
102 case GL_FRAMEBUFFER: return true;
103 case GL_READ_FRAMEBUFFER: return true;
104 case GL_DRAW_FRAMEBUFFER: return true;
105 default: return false;
109 bool ValidBufferTarget(const Context *context, GLenum target)
113 case GL_ARRAY_BUFFER:
114 case GL_ELEMENT_ARRAY_BUFFER:
117 case GL_PIXEL_PACK_BUFFER:
118 case GL_PIXEL_UNPACK_BUFFER:
119 return context->getExtensions().pixelBufferObject;
121 case GL_COPY_READ_BUFFER:
122 case GL_COPY_WRITE_BUFFER:
123 case GL_TRANSFORM_FEEDBACK_BUFFER:
124 case GL_UNIFORM_BUFFER:
125 return (context->getClientVersion() >= 3);
132 bool ValidBufferParameter(const Context *context, GLenum pname)
136 case GL_BUFFER_USAGE:
140 // GL_BUFFER_MAP_POINTER is a special case, and may only be
141 // queried with GetBufferPointerv
142 case GL_BUFFER_ACCESS_FLAGS:
143 case GL_BUFFER_MAPPED:
144 case GL_BUFFER_MAP_OFFSET:
145 case GL_BUFFER_MAP_LENGTH:
146 return (context->getClientVersion() >= 3);
153 bool ValidMipLevel(const Context *context, GLenum target, GLint level)
155 size_t maxDimension = 0;
158 case GL_TEXTURE_2D: maxDimension = context->getCaps().max2DTextureSize; break;
159 case GL_TEXTURE_CUBE_MAP:
160 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
161 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
162 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
163 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
164 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
165 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: maxDimension = context->getCaps().maxCubeMapTextureSize; break;
166 case GL_TEXTURE_3D: maxDimension = context->getCaps().max3DTextureSize; break;
167 case GL_TEXTURE_2D_ARRAY: maxDimension = context->getCaps().max2DTextureSize; break;
168 default: UNREACHABLE();
171 return level <= gl::log2(maxDimension);
174 bool ValidImageSize(const Context *context, GLenum target, GLint level,
175 GLsizei width, GLsizei height, GLsizei depth)
177 if (level < 0 || width < 0 || height < 0 || depth < 0)
182 if (!context->getExtensions().textureNPOT &&
183 (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth))))
188 if (!ValidMipLevel(context, target, level))
196 bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height)
198 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
199 if (!formatInfo.compressed)
204 if (width < 0 || (static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && width % formatInfo.compressedBlockWidth != 0) ||
205 height < 0 || (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && height % formatInfo.compressedBlockHeight != 0))
213 bool ValidQueryType(const Context *context, GLenum queryType)
215 META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
216 META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
220 case GL_ANY_SAMPLES_PASSED:
221 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
223 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
224 return (context->getClientVersion() >= 3);
230 bool ValidProgram(Context *context, GLuint id)
232 // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
233 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
234 // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
236 if (context->getProgram(id) != NULL)
240 else if (context->getShader(id) != NULL)
242 // ID is the wrong type
243 context->recordError(Error(GL_INVALID_OPERATION));
248 // No shader/program object has this ID
249 context->recordError(Error(GL_INVALID_VALUE));
254 bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
256 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
258 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
260 if (colorAttachment >= context->getCaps().maxColorAttachments)
262 context->recordError(Error(GL_INVALID_VALUE));
270 case GL_DEPTH_ATTACHMENT:
271 case GL_STENCIL_ATTACHMENT:
274 case GL_DEPTH_STENCIL_ATTACHMENT:
275 if (context->getClientVersion() < 3)
277 context->recordError(Error(GL_INVALID_ENUM));
283 context->recordError(Error(GL_INVALID_ENUM));
291 bool ValidateRenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples,
292 GLenum internalformat, GLsizei width, GLsizei height,
297 case GL_RENDERBUFFER:
300 context->recordError(Error(GL_INVALID_ENUM));
304 if (width < 0 || height < 0 || samples < 0)
306 context->recordError(Error(GL_INVALID_VALUE));
310 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
311 if (!formatCaps.renderable)
313 context->recordError(Error(GL_INVALID_ENUM));
317 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
318 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
319 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
320 // internal format must be sized and not an integer format if samples is greater than zero.
321 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
322 if (formatInfo.pixelBytes == 0)
324 context->recordError(Error(GL_INVALID_ENUM));
328 if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0)
330 context->recordError(Error(GL_INVALID_OPERATION));
334 if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
336 context->recordError(Error(GL_INVALID_VALUE));
340 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
341 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
342 // states that samples must be less than or equal to the maximum samples for the specified
346 ASSERT(context->getExtensions().framebufferMultisample);
347 if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples)
349 context->recordError(Error(GL_INVALID_VALUE));
353 // Check if this specific format supports enough samples
354 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
356 context->recordError(Error(GL_OUT_OF_MEMORY));
362 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
364 context->recordError(Error(GL_INVALID_VALUE));
369 GLuint handle = context->getState().getRenderbufferId();
372 context->recordError(Error(GL_INVALID_OPERATION));
379 bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment,
380 GLenum renderbuffertarget, GLuint renderbuffer)
382 if (!ValidFramebufferTarget(target))
384 context->recordError(Error(GL_INVALID_ENUM));
388 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
389 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
391 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
393 context->recordError(Error(GL_INVALID_OPERATION));
397 if (!ValidateAttachmentTarget(context, attachment))
402 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
403 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
404 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
405 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
406 if (renderbuffer != 0)
408 if (!context->getRenderbuffer(renderbuffer))
410 context->recordError(Error(GL_INVALID_OPERATION));
418 static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer,
419 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
420 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
422 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
423 dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
424 srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
428 else if (context->getState().isScissorTestEnabled())
430 const Rectangle &scissor = context->getState().getScissor();
432 return scissor.x > 0 || scissor.y > 0 ||
433 scissor.width < writeBuffer->getWidth() ||
434 scissor.height < writeBuffer->getHeight();
442 bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
443 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
444 GLenum filter, bool fromAngleExtension)
451 if (fromAngleExtension)
453 context->recordError(Error(GL_INVALID_ENUM));
458 context->recordError(Error(GL_INVALID_ENUM));
462 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
464 context->recordError(Error(GL_INVALID_VALUE));
470 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
471 // buffers are copied.
475 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
477 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
478 context->recordError(Error(GL_INVALID_OPERATION));
482 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
483 // color buffer, leaving only nearest being unfiltered from above
484 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
486 context->recordError(Error(GL_INVALID_OPERATION));
490 if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id())
492 if (fromAngleExtension)
494 ERR("Blits with the same source and destination framebuffer are not supported by this "
497 context->recordError(Error(GL_INVALID_OPERATION));
501 gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
502 gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
503 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
504 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
506 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
510 if (drawFramebuffer->getSamples() != 0)
512 context->recordError(Error(GL_INVALID_OPERATION));
516 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
518 if (mask & GL_COLOR_BUFFER_BIT)
520 gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
521 gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
523 if (readColorBuffer && drawColorBuffer)
525 GLenum readInternalFormat = readColorBuffer->getActualFormat();
526 const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat);
528 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
530 if (drawFramebuffer->isEnabledColorAttachment(i))
532 GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
533 const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat);
535 // The GL ES 3.0.2 spec (pg 193) states that:
536 // 1) If the read buffer is fixed point format, the draw buffer must be as well
537 // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well
538 // 3) If the read buffer is a signed integer format, the draw buffer must be as well
539 if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) &&
540 !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED))
542 context->recordError(Error(GL_INVALID_OPERATION));
546 if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT)
548 context->recordError(Error(GL_INVALID_OPERATION));
552 if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT)
554 context->recordError(Error(GL_INVALID_OPERATION));
558 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds))
560 context->recordError(Error(GL_INVALID_OPERATION));
566 if ((readFormatInfo.componentType == GL_INT || readFormatInfo.componentType == GL_UNSIGNED_INT) && filter == GL_LINEAR)
568 context->recordError(Error(GL_INVALID_OPERATION));
572 if (fromAngleExtension)
574 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
575 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
577 context->recordError(Error(GL_INVALID_OPERATION));
581 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
583 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
585 FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment);
588 if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER)
590 context->recordError(Error(GL_INVALID_OPERATION));
594 // Return an error if the destination formats do not match
595 if (attachment->getInternalFormat() != readColorBuffer->getInternalFormat())
597 context->recordError(Error(GL_INVALID_OPERATION));
602 if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer,
603 srcX0, srcY0, srcX1, srcY1,
604 dstX0, dstY0, dstX1, dstY1))
606 context->recordError(Error(GL_INVALID_OPERATION));
613 if (mask & GL_DEPTH_BUFFER_BIT)
615 gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer();
616 gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
618 if (readDepthBuffer && drawDepthBuffer)
620 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
622 context->recordError(Error(GL_INVALID_OPERATION));
626 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
628 context->recordError(Error(GL_INVALID_OPERATION));
632 if (fromAngleExtension)
634 if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer,
635 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
637 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
638 context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted
642 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
644 context->recordError(Error(GL_INVALID_OPERATION));
651 if (mask & GL_STENCIL_BUFFER_BIT)
653 gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer();
654 gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
656 if (readStencilBuffer && drawStencilBuffer)
658 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
660 context->recordError(Error(GL_INVALID_OPERATION));
664 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
666 context->recordError(Error(GL_INVALID_OPERATION));
670 if (fromAngleExtension)
672 if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer,
673 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
675 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
676 context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted
680 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
682 context->recordError(Error(GL_INVALID_OPERATION));
692 bool ValidateGetVertexAttribParameters(Context *context, GLenum pname)
696 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
697 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
698 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
699 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
700 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
701 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
702 case GL_CURRENT_VERTEX_ATTRIB:
705 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
706 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
707 // the same constant.
708 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
711 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
712 if (context->getClientVersion() < 3)
714 context->recordError(Error(GL_INVALID_ENUM));
720 context->recordError(Error(GL_INVALID_ENUM));
725 bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
729 case GL_TEXTURE_WRAP_R:
730 case GL_TEXTURE_SWIZZLE_R:
731 case GL_TEXTURE_SWIZZLE_G:
732 case GL_TEXTURE_SWIZZLE_B:
733 case GL_TEXTURE_SWIZZLE_A:
734 case GL_TEXTURE_BASE_LEVEL:
735 case GL_TEXTURE_MAX_LEVEL:
736 case GL_TEXTURE_COMPARE_MODE:
737 case GL_TEXTURE_COMPARE_FUNC:
738 case GL_TEXTURE_MIN_LOD:
739 case GL_TEXTURE_MAX_LOD:
740 if (context->getClientVersion() < 3)
742 context->recordError(Error(GL_INVALID_ENUM));
752 case GL_TEXTURE_WRAP_S:
753 case GL_TEXTURE_WRAP_T:
754 case GL_TEXTURE_WRAP_R:
758 case GL_CLAMP_TO_EDGE:
759 case GL_MIRRORED_REPEAT:
762 context->recordError(Error(GL_INVALID_ENUM));
766 case GL_TEXTURE_MIN_FILTER:
771 case GL_NEAREST_MIPMAP_NEAREST:
772 case GL_LINEAR_MIPMAP_NEAREST:
773 case GL_NEAREST_MIPMAP_LINEAR:
774 case GL_LINEAR_MIPMAP_LINEAR:
777 context->recordError(Error(GL_INVALID_ENUM));
782 case GL_TEXTURE_MAG_FILTER:
789 context->recordError(Error(GL_INVALID_ENUM));
794 case GL_TEXTURE_USAGE_ANGLE:
798 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
801 context->recordError(Error(GL_INVALID_ENUM));
806 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
807 if (!context->getExtensions().textureFilterAnisotropic)
809 context->recordError(Error(GL_INVALID_ENUM));
813 // we assume the parameter passed to this validation method is truncated, not rounded
816 context->recordError(Error(GL_INVALID_VALUE));
821 case GL_TEXTURE_MIN_LOD:
822 case GL_TEXTURE_MAX_LOD:
823 // any value is permissible
826 case GL_TEXTURE_COMPARE_MODE:
827 // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
831 case GL_COMPARE_REF_TO_TEXTURE:
834 context->recordError(Error(GL_INVALID_ENUM));
839 case GL_TEXTURE_COMPARE_FUNC:
840 // Acceptable function parameters from GLES 3.0.2 spec, table 3.17
853 context->recordError(Error(GL_INVALID_ENUM));
858 case GL_TEXTURE_SWIZZLE_R:
859 case GL_TEXTURE_SWIZZLE_G:
860 case GL_TEXTURE_SWIZZLE_B:
861 case GL_TEXTURE_SWIZZLE_A:
872 context->recordError(Error(GL_INVALID_ENUM));
877 case GL_TEXTURE_BASE_LEVEL:
878 case GL_TEXTURE_MAX_LEVEL:
881 context->recordError(Error(GL_INVALID_VALUE));
887 context->recordError(Error(GL_INVALID_ENUM));
892 bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname)
896 case GL_TEXTURE_MIN_FILTER:
897 case GL_TEXTURE_MAG_FILTER:
898 case GL_TEXTURE_WRAP_S:
899 case GL_TEXTURE_WRAP_T:
900 case GL_TEXTURE_WRAP_R:
901 case GL_TEXTURE_MIN_LOD:
902 case GL_TEXTURE_MAX_LOD:
903 case GL_TEXTURE_COMPARE_MODE:
904 case GL_TEXTURE_COMPARE_FUNC:
908 context->recordError(Error(GL_INVALID_ENUM));
913 bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
914 GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
916 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
919 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
921 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
925 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
927 context->recordError(Error(GL_INVALID_OPERATION));
931 if (!framebuffer->getReadColorbuffer())
933 context->recordError(Error(GL_INVALID_OPERATION));
937 GLenum currentInternalFormat, currentFormat, currentType;
938 GLuint clientVersion = context->getClientVersion();
940 context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType);
942 bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
943 ValidES3ReadFormatType(context, currentInternalFormat, format, type);
945 if (!(currentFormat == format && currentType == type) && !validReadFormat)
947 context->recordError(Error(GL_INVALID_OPERATION));
951 GLenum sizedInternalFormat = GetSizedInternalFormat(format, type);
952 const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat);
954 GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment());
955 // sized query sanity check
958 int requiredSize = outputPitch * height;
959 if (requiredSize > *bufSize)
961 context->recordError(Error(GL_INVALID_OPERATION));
969 bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
971 if (!ValidQueryType(context, target))
973 context->recordError(Error(GL_INVALID_ENUM));
979 context->recordError(Error(GL_INVALID_OPERATION));
983 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
984 // of zero, if the active query object name for <target> is non-zero (for the
985 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
986 // the active query for either target is non-zero), if <id> is the name of an
987 // existing query object whose type does not match <target>, or if <id> is the
988 // active query object name for any query type, the error INVALID_OPERATION is
991 // Ensure no other queries are active
992 // NOTE: If other queries than occlusion are supported, we will need to check
994 // a) The query ID passed is not the current active query for any target/type
995 // b) There are no active queries for the requested target (and in the case
996 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
997 // no query may be active for either if glBeginQuery targets either.
998 if (context->getState().isQueryActive())
1000 context->recordError(Error(GL_INVALID_OPERATION));
1004 Query *queryObject = context->getQuery(id, true, target);
1006 // check that name was obtained with glGenQueries
1009 context->recordError(Error(GL_INVALID_OPERATION));
1013 // check for type mismatch
1014 if (queryObject->getType() != target)
1016 context->recordError(Error(GL_INVALID_OPERATION));
1023 bool ValidateEndQuery(gl::Context *context, GLenum target)
1025 if (!ValidQueryType(context, target))
1027 context->recordError(Error(GL_INVALID_ENUM));
1031 const Query *queryObject = context->getState().getActiveQuery(target);
1033 if (queryObject == NULL)
1035 context->recordError(Error(GL_INVALID_OPERATION));
1042 static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
1043 GLint location, GLsizei count, LinkedUniform **uniformOut)
1047 context->recordError(Error(GL_INVALID_VALUE));
1051 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
1054 context->recordError(Error(GL_INVALID_OPERATION));
1060 // Silently ignore the uniform command
1064 if (!programBinary->isValidUniformLocation(location))
1066 context->recordError(Error(GL_INVALID_OPERATION));
1070 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1072 // attempting to write an array to a non-array uniform is an INVALID_OPERATION
1073 if (uniform->elementCount() == 1 && count > 1)
1075 context->recordError(Error(GL_INVALID_OPERATION));
1079 *uniformOut = uniform;
1083 bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
1085 // Check for ES3 uniform entry points
1086 if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
1088 context->recordError(Error(GL_INVALID_OPERATION));
1092 LinkedUniform *uniform = NULL;
1093 if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
1098 GLenum targetBoolType = VariableBoolVectorType(uniformType);
1099 bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
1100 if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
1102 context->recordError(Error(GL_INVALID_OPERATION));
1109 bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
1110 GLboolean transpose)
1112 // Check for ES3 uniform entry points
1113 int rows = VariableRowCount(matrixType);
1114 int cols = VariableColumnCount(matrixType);
1115 if (rows != cols && context->getClientVersion() < 3)
1117 context->recordError(Error(GL_INVALID_OPERATION));
1121 if (transpose != GL_FALSE && context->getClientVersion() < 3)
1123 context->recordError(Error(GL_INVALID_VALUE));
1127 LinkedUniform *uniform = NULL;
1128 if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
1133 if (uniform->type != matrixType)
1135 context->recordError(Error(GL_INVALID_OPERATION));
1142 bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
1144 if (!context->getQueryParameterInfo(pname, nativeType, numParams))
1146 context->recordError(Error(GL_INVALID_ENUM));
1150 if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
1152 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
1154 if (colorAttachment >= context->getCaps().maxDrawBuffers)
1156 context->recordError(Error(GL_INVALID_OPERATION));
1163 case GL_TEXTURE_BINDING_2D:
1164 case GL_TEXTURE_BINDING_CUBE_MAP:
1165 case GL_TEXTURE_BINDING_3D:
1166 case GL_TEXTURE_BINDING_2D_ARRAY:
1167 if (context->getState().getActiveSampler() >= context->getCaps().maxCombinedTextureImageUnits)
1169 context->recordError(Error(GL_INVALID_OPERATION));
1174 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1175 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1177 Framebuffer *framebuffer = context->getState().getReadFramebuffer();
1178 ASSERT(framebuffer);
1179 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1181 context->recordError(Error(GL_INVALID_OPERATION));
1185 FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
1188 context->recordError(Error(GL_INVALID_OPERATION));
1198 // pname is valid, but there are no parameters to return
1207 bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
1208 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height,
1209 GLint border, GLenum *textureFormatOut)
1212 if (!ValidTexture2DDestinationTarget(context, target))
1214 context->recordError(Error(GL_INVALID_ENUM));
1218 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
1220 context->recordError(Error(GL_INVALID_VALUE));
1224 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1226 context->recordError(Error(GL_INVALID_VALUE));
1232 context->recordError(Error(GL_INVALID_VALUE));
1236 if (!ValidMipLevel(context, target, level))
1238 context->recordError(Error(GL_INVALID_VALUE));
1242 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
1243 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1245 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
1249 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
1251 context->recordError(Error(GL_INVALID_OPERATION));
1255 const gl::Caps &caps = context->getCaps();
1257 gl::Texture *texture = NULL;
1258 GLenum textureInternalFormat = GL_NONE;
1259 GLint textureLevelWidth = 0;
1260 GLint textureLevelHeight = 0;
1261 GLint textureLevelDepth = 0;
1262 GLuint maxDimension = 0;
1268 gl::Texture2D *texture2d = context->getTexture2D();
1271 textureInternalFormat = texture2d->getInternalFormat(level);
1272 textureLevelWidth = texture2d->getWidth(level);
1273 textureLevelHeight = texture2d->getHeight(level);
1274 textureLevelDepth = 1;
1275 texture = texture2d;
1276 maxDimension = caps.max2DTextureSize;
1281 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1282 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1283 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1285 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1286 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1288 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1291 textureInternalFormat = textureCube->getInternalFormat(target, level);
1292 textureLevelWidth = textureCube->getWidth(target, level);
1293 textureLevelHeight = textureCube->getHeight(target, level);
1294 textureLevelDepth = 1;
1295 texture = textureCube;
1296 maxDimension = caps.maxCubeMapTextureSize;
1301 case GL_TEXTURE_2D_ARRAY:
1303 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1306 textureInternalFormat = texture2dArray->getInternalFormat(level);
1307 textureLevelWidth = texture2dArray->getWidth(level);
1308 textureLevelHeight = texture2dArray->getHeight(level);
1309 textureLevelDepth = texture2dArray->getLayers(level);
1310 texture = texture2dArray;
1311 maxDimension = caps.max2DTextureSize;
1318 gl::Texture3D *texture3d = context->getTexture3D();
1321 textureInternalFormat = texture3d->getInternalFormat(level);
1322 textureLevelWidth = texture3d->getWidth(level);
1323 textureLevelHeight = texture3d->getHeight(level);
1324 textureLevelDepth = texture3d->getDepth(level);
1325 texture = texture3d;
1326 maxDimension = caps.max3DTextureSize;
1332 context->recordError(Error(GL_INVALID_ENUM));
1338 context->recordError(Error(GL_INVALID_OPERATION));
1342 if (texture->isImmutable() && !isSubImage)
1344 context->recordError(Error(GL_INVALID_OPERATION));
1348 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
1350 if (formatInfo.depthBits > 0)
1352 context->recordError(Error(GL_INVALID_OPERATION));
1356 if (formatInfo.compressed)
1358 if (((width % formatInfo.compressedBlockWidth) != 0 && width != textureLevelWidth) ||
1359 ((height % formatInfo.compressedBlockHeight) != 0 && height != textureLevelHeight))
1361 context->recordError(Error(GL_INVALID_OPERATION));
1368 if (xoffset + width > textureLevelWidth ||
1369 yoffset + height > textureLevelHeight ||
1370 zoffset >= textureLevelDepth)
1372 context->recordError(Error(GL_INVALID_VALUE));
1378 if (IsCubemapTextureTarget(target) && width != height)
1380 context->recordError(Error(GL_INVALID_VALUE));
1384 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
1386 context->recordError(Error(GL_INVALID_ENUM));
1390 int maxLevelDimension = (maxDimension >> level);
1391 if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension)
1393 context->recordError(Error(GL_INVALID_VALUE));
1398 *textureFormatOut = textureInternalFormat;
1402 static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsizei maxVertex, GLsizei primcount)
1411 case GL_TRIANGLE_STRIP:
1412 case GL_TRIANGLE_FAN:
1415 context->recordError(Error(GL_INVALID_ENUM));
1421 context->recordError(Error(GL_INVALID_VALUE));
1425 const State &state = context->getState();
1427 // Check for mapped buffers
1428 if (state.hasMappedBuffer(GL_ARRAY_BUFFER))
1430 context->recordError(Error(GL_INVALID_OPERATION));
1434 const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
1435 if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
1436 state.getStencilRef() != state.getStencilBackRef() ||
1437 depthStencilState.stencilMask != depthStencilState.stencilBackMask)
1439 // Note: these separate values are not supported in WebGL, due to D3D's limitations.
1440 // See Section 6.10 of the WebGL 1.0 spec
1441 ERR("This ANGLE implementation does not support separate front/back stencil "
1442 "writemasks, reference values, or stencil mask values.");
1443 context->recordError(Error(GL_INVALID_OPERATION));
1447 const gl::Framebuffer *fbo = state.getDrawFramebuffer();
1448 if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
1450 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
1454 if (state.getCurrentProgramId() == 0)
1456 context->recordError(Error(GL_INVALID_OPERATION));
1460 gl::ProgramBinary *programBinary = state.getCurrentProgramBinary();
1461 if (!programBinary->validateSamplers(NULL, context->getCaps()))
1463 context->recordError(Error(GL_INVALID_OPERATION));
1467 // Buffer validations
1468 const VertexArray *vao = state.getVertexArray();
1469 for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1471 const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex);
1472 bool attribActive = (programBinary->getSemanticIndex(attributeIndex) != -1);
1473 if (attribActive && attrib.enabled)
1475 gl::Buffer *buffer = attrib.buffer.get();
1479 GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib));
1480 GLint64 maxVertexElement = 0;
1482 if (attrib.divisor > 0)
1484 maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor);
1488 maxVertexElement = static_cast<GLint64>(maxVertex);
1491 GLint64 attribDataSize = maxVertexElement * attribStride;
1493 // [OpenGL ES 3.0.2] section 2.9.4 page 40:
1494 // We can return INVALID_OPERATION if our vertex attribute does not have
1495 // enough backing data.
1496 if (attribDataSize > buffer->getSize())
1498 context->recordError(Error(GL_INVALID_OPERATION));
1502 else if (attrib.pointer == NULL)
1504 // This is an application error that would normally result in a crash,
1505 // but we catch it and return an error
1506 context->recordError(Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer."));
1512 // No-op if zero count
1516 bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1520 context->recordError(Error(GL_INVALID_VALUE));
1524 const State &state = context->getState();
1525 gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
1526 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() &&
1527 curTransformFeedback->getDrawMode() != mode)
1529 // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
1530 // that does not match the current transform feedback object's draw mode (if transform feedback
1531 // is active), (3.0.2, section 2.14, pg 86)
1532 context->recordError(Error(GL_INVALID_OPERATION));
1536 if (!ValidateDrawBase(context, mode, count, count, primcount))
1544 bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1548 context->recordError(Error(GL_INVALID_VALUE));
1552 if (!ValidateDrawArrays(context, mode, first, count, primcount))
1557 // No-op if zero primitive count
1558 return (primcount > 0);
1561 static bool ValidateDrawInstancedANGLE(Context *context)
1563 // Verify there is at least one active attribute with a divisor of zero
1564 const gl::State& state = context->getState();
1566 gl::ProgramBinary *programBinary = state.getCurrentProgramBinary();
1568 const VertexArray *vao = state.getVertexArray();
1569 for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1571 const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex);
1572 bool active = (programBinary->getSemanticIndex(attributeIndex) != -1);
1573 if (active && attrib.divisor == 0)
1579 context->recordError(Error(GL_INVALID_OPERATION, "ANGLE_instanced_arrays requires that at least one active attribute"
1580 "has a divisor of zero."));
1584 bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1586 if (!ValidateDrawInstancedANGLE(context))
1591 return ValidateDrawArraysInstanced(context, mode, first, count, primcount);
1594 bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type,
1595 const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut)
1599 case GL_UNSIGNED_BYTE:
1600 case GL_UNSIGNED_SHORT:
1602 case GL_UNSIGNED_INT:
1603 if (!context->getExtensions().elementIndexUint)
1605 context->recordError(Error(GL_INVALID_ENUM));
1610 context->recordError(Error(GL_INVALID_ENUM));
1614 const State &state = context->getState();
1616 gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
1617 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
1619 // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced
1620 // while transform feedback is active, (3.0.2, section 2.14, pg 86)
1621 context->recordError(Error(GL_INVALID_OPERATION));
1625 // Check for mapped buffers
1626 if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
1628 context->recordError(Error(GL_INVALID_OPERATION));
1632 const gl::VertexArray *vao = state.getVertexArray();
1633 const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer();
1634 if (!indices && !elementArrayBuffer)
1636 context->recordError(Error(GL_INVALID_OPERATION));
1640 if (elementArrayBuffer)
1642 const gl::Type &typeInfo = gl::GetTypeInfo(type);
1644 GLint64 offset = reinterpret_cast<GLint64>(indices);
1645 GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset;
1647 // check for integer overflows
1648 if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) ||
1649 byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max()))
1651 context->recordError(Error(GL_OUT_OF_MEMORY));
1655 // Check for reading past the end of the bound buffer object
1656 if (byteCount > elementArrayBuffer->getSize())
1658 context->recordError(Error(GL_INVALID_OPERATION));
1664 // Catch this programming error here
1665 context->recordError(Error(GL_INVALID_OPERATION));
1669 // Use max index to validate if our vertex buffers are large enough for the pull.
1670 // TODO: offer fast path, with disabled index validation.
1671 // TODO: also disable index checking on back-ends that are robust to out-of-range accesses.
1672 if (elementArrayBuffer)
1674 uintptr_t offset = reinterpret_cast<uintptr_t>(indices);
1675 if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL))
1677 // FIXME(jmadill): Use buffer data caching instead of the D3D back-end
1678 rx::BufferD3D *bufferD3D = rx::BufferD3D::makeBufferD3D(elementArrayBuffer->getImplementation());
1679 const uint8_t *dataPointer = NULL;
1680 Error error = bufferD3D->getData(&dataPointer);
1681 if (error.isError())
1683 context->recordError(error);
1687 const uint8_t *offsetPointer = dataPointer + offset;
1688 *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count);
1693 *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count);
1696 if (!ValidateDrawBase(context, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount))
1704 bool ValidateDrawElementsInstanced(Context *context,
1705 GLenum mode, GLsizei count, GLenum type,
1706 const GLvoid *indices, GLsizei primcount,
1707 rx::RangeUI *indexRangeOut)
1711 context->recordError(Error(GL_INVALID_VALUE));
1715 if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut))
1720 // No-op zero primitive count
1721 return (primcount > 0);
1724 bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type,
1725 const GLvoid *indices, GLsizei primcount, rx::RangeUI *indexRangeOut)
1727 if (!ValidateDrawInstancedANGLE(context))
1732 return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut);
1735 bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment,
1736 GLuint texture, GLint level)
1738 if (!ValidFramebufferTarget(target))
1740 context->recordError(Error(GL_INVALID_ENUM));
1744 if (!ValidateAttachmentTarget(context, attachment))
1751 gl::Texture *tex = context->getTexture(texture);
1755 context->recordError(Error(GL_INVALID_OPERATION));
1761 context->recordError(Error(GL_INVALID_VALUE));
1766 const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1767 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
1769 if (framebufferHandle == 0 || !framebuffer)
1771 context->recordError(Error(GL_INVALID_OPERATION));
1778 bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment,
1779 GLenum textarget, GLuint texture, GLint level)
1781 // Attachments are required to be bound to level 0 in ES2
1782 if (context->getClientVersion() < 3 && level != 0)
1784 context->recordError(Error(GL_INVALID_VALUE));
1788 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
1795 gl::Texture *tex = context->getTexture(texture);
1798 const gl::Caps &caps = context->getCaps();
1804 if (level > gl::log2(caps.max2DTextureSize))
1806 context->recordError(Error(GL_INVALID_VALUE));
1809 if (tex->getTarget() != GL_TEXTURE_2D)
1811 context->recordError(Error(GL_INVALID_OPERATION));
1814 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1815 if (tex2d->isCompressed(level))
1817 context->recordError(Error(GL_INVALID_OPERATION));
1823 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1824 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1825 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1826 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1827 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1828 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1830 if (level > gl::log2(caps.maxCubeMapTextureSize))
1832 context->recordError(Error(GL_INVALID_VALUE));
1835 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1837 context->recordError(Error(GL_INVALID_OPERATION));
1840 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1841 if (texcube->isCompressed(textarget, level))
1843 context->recordError(Error(GL_INVALID_OPERATION));
1850 context->recordError(Error(GL_INVALID_ENUM));
1858 bool ValidateGetUniformBase(Context *context, GLuint program, GLint location)
1862 context->recordError(Error(GL_INVALID_VALUE));
1866 gl::Program *programObject = context->getProgram(program);
1868 if (!programObject || !programObject->isLinked())
1870 context->recordError(Error(GL_INVALID_OPERATION));
1874 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1877 context->recordError(Error(GL_INVALID_OPERATION));
1881 if (!programBinary->isValidUniformLocation(location))
1883 context->recordError(Error(GL_INVALID_OPERATION));
1890 bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params)
1892 return ValidateGetUniformBase(context, program, location);
1895 bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params)
1897 return ValidateGetUniformBase(context, program, location);
1900 static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize)
1902 if (!ValidateGetUniformBase(context, program, location))
1907 gl::Program *programObject = context->getProgram(program);
1908 ASSERT(programObject);
1909 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1911 // sized queries -- ensure the provided buffer is large enough
1912 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1913 size_t requiredBytes = VariableExternalSize(uniform->type);
1914 if (static_cast<size_t>(bufSize) < requiredBytes)
1916 context->recordError(Error(GL_INVALID_OPERATION));
1923 bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
1925 return ValidateSizedGetUniform(context, program, location, bufSize);
1928 bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params)
1930 return ValidateSizedGetUniform(context, program, location, bufSize);