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"
30 bool ValidCap(const Context *context, GLenum cap)
35 case GL_POLYGON_OFFSET_FILL:
36 case GL_SAMPLE_ALPHA_TO_COVERAGE:
37 case GL_SAMPLE_COVERAGE:
44 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
45 case GL_RASTERIZER_DISCARD:
46 return (context->getClientVersion() >= 3);
52 bool ValidTextureTarget(const Context *context, GLenum target)
57 case GL_TEXTURE_CUBE_MAP:
61 case GL_TEXTURE_2D_ARRAY:
62 return (context->getClientVersion() >= 3);
69 // 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.
72 // Note: duplicate of IsInternalTextureTarget
73 bool ValidTexture2DDestinationTarget(const Context *context, GLenum target)
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:
85 case GL_TEXTURE_2D_ARRAY:
87 return (context->getClientVersion() >= 3);
93 bool ValidFramebufferTarget(GLenum target)
95 META_ASSERT(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER);
99 case GL_FRAMEBUFFER: return true;
100 case GL_READ_FRAMEBUFFER: return true;
101 case GL_DRAW_FRAMEBUFFER: return true;
102 default: return false;
106 bool ValidBufferTarget(const Context *context, GLenum target)
110 case GL_ARRAY_BUFFER:
111 case GL_ELEMENT_ARRAY_BUFFER:
114 case GL_PIXEL_PACK_BUFFER:
115 case GL_PIXEL_UNPACK_BUFFER:
116 return context->getExtensions().pixelBufferObject;
118 case GL_COPY_READ_BUFFER:
119 case GL_COPY_WRITE_BUFFER:
120 case GL_TRANSFORM_FEEDBACK_BUFFER:
121 case GL_UNIFORM_BUFFER:
122 return (context->getClientVersion() >= 3);
129 bool ValidBufferParameter(const Context *context, GLenum pname)
133 case GL_BUFFER_USAGE:
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);
150 bool ValidMipLevel(const Context *context, GLenum target, GLint level)
152 size_t maxDimension = 0;
155 case GL_TEXTURE_2D: maxDimension = context->getCaps().max2DTextureSize; break;
156 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:
162 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;
165 default: UNREACHABLE();
168 return level <= gl::log2(maxDimension);
171 bool ValidImageSize(const Context *context, GLenum target, GLint level,
172 GLsizei width, GLsizei height, GLsizei depth)
174 if (level < 0 || width < 0 || height < 0 || depth < 0)
179 if (!context->getExtensions().textureNPOT &&
180 (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth))))
185 if (!ValidMipLevel(context, target, level))
193 bool ValidCompressedImageSize(const Context *context, GLenum internalFormat, GLsizei width, GLsizei height)
195 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
196 if (!formatInfo.compressed)
201 if (width < 0 || (static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && width % formatInfo.compressedBlockWidth != 0) ||
202 height < 0 || (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && height % formatInfo.compressedBlockHeight != 0))
210 bool ValidQueryType(const Context *context, GLenum queryType)
212 META_ASSERT(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT);
213 META_ASSERT(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT);
217 case GL_ANY_SAMPLES_PASSED:
218 case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
220 case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
221 return (context->getClientVersion() >= 3);
227 bool ValidProgram(Context *context, GLuint id)
229 // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the
230 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
231 // INVALID_OPERATION if the provided name identifies an object that is not the expected type."
233 if (context->getProgram(id) != NULL)
237 else if (context->getShader(id) != NULL)
239 // ID is the wrong type
240 context->recordError(Error(GL_INVALID_OPERATION));
245 // No shader/program object has this ID
246 context->recordError(Error(GL_INVALID_VALUE));
251 bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
253 if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
255 const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
257 if (colorAttachment >= context->getCaps().maxColorAttachments)
259 context->recordError(Error(GL_INVALID_VALUE));
267 case GL_DEPTH_ATTACHMENT:
268 case GL_STENCIL_ATTACHMENT:
271 case GL_DEPTH_STENCIL_ATTACHMENT:
272 if (context->getClientVersion() < 3)
274 context->recordError(Error(GL_INVALID_ENUM));
280 context->recordError(Error(GL_INVALID_ENUM));
288 bool ValidateRenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples,
289 GLenum internalformat, GLsizei width, GLsizei height,
294 case GL_RENDERBUFFER:
297 context->recordError(Error(GL_INVALID_ENUM));
301 if (width < 0 || height < 0 || samples < 0)
303 context->recordError(Error(GL_INVALID_VALUE));
307 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
308 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
310 context->recordError(Error(GL_INVALID_ENUM));
314 // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
315 // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
316 // only sized internal formats. The ES3 spec (section 4.4.2) does, however, state that the
317 // internal format must be sized and not an integer format if samples is greater than zero.
318 if (formatInfo.pixelBytes == 0)
320 context->recordError(Error(GL_INVALID_ENUM));
324 if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0)
326 context->recordError(Error(GL_INVALID_OPERATION));
330 const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
331 if (!formatCaps.renderable)
333 context->recordError(Error(GL_INVALID_ENUM));
337 if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
339 context->recordError(Error(GL_INVALID_VALUE));
343 // ANGLE_framebuffer_multisample states that the value of samples must be less than or equal
344 // to MAX_SAMPLES_ANGLE (Context::getMaxSupportedSamples) while the ES3.0 spec (section 4.4.2)
345 // states that samples must be less than or equal to the maximum samples for the specified
349 ASSERT(context->getExtensions().framebufferMultisample);
350 if (static_cast<GLuint>(samples) > context->getExtensions().maxSamples)
352 context->recordError(Error(GL_INVALID_VALUE));
356 // Check if this specific format supports enough samples
357 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
359 context->recordError(Error(GL_OUT_OF_MEMORY));
365 if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples())
367 context->recordError(Error(GL_INVALID_VALUE));
372 GLuint handle = context->getState().getRenderbufferId();
375 context->recordError(Error(GL_INVALID_OPERATION));
382 bool ValidateFramebufferRenderbufferParameters(gl::Context *context, GLenum target, GLenum attachment,
383 GLenum renderbuffertarget, GLuint renderbuffer)
385 if (!ValidFramebufferTarget(target))
387 context->recordError(Error(GL_INVALID_ENUM));
391 gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
392 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
394 if (!framebuffer || (framebufferHandle == 0 && renderbuffer != 0))
396 context->recordError(Error(GL_INVALID_OPERATION));
400 if (!ValidateAttachmentTarget(context, attachment))
405 // [OpenGL ES 2.0.25] Section 4.4.3 page 112
406 // [OpenGL ES 3.0.2] Section 4.4.2 page 201
407 // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
408 // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
409 if (renderbuffer != 0)
411 if (!context->getRenderbuffer(renderbuffer))
413 context->recordError(Error(GL_INVALID_OPERATION));
421 static bool IsPartialBlit(gl::Context *context, gl::FramebufferAttachment *readBuffer, gl::FramebufferAttachment *writeBuffer,
422 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
423 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1)
425 if (srcX0 != 0 || srcY0 != 0 || dstX0 != 0 || dstY0 != 0 ||
426 dstX1 != writeBuffer->getWidth() || dstY1 != writeBuffer->getHeight() ||
427 srcX1 != readBuffer->getWidth() || srcY1 != readBuffer->getHeight())
431 else if (context->getState().isScissorTestEnabled())
433 const Rectangle &scissor = context->getState().getScissor();
435 return scissor.x > 0 || scissor.y > 0 ||
436 scissor.width < writeBuffer->getWidth() ||
437 scissor.height < writeBuffer->getHeight();
445 bool ValidateBlitFramebufferParameters(gl::Context *context, GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
446 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask,
447 GLenum filter, bool fromAngleExtension)
454 if (fromAngleExtension)
456 context->recordError(Error(GL_INVALID_ENUM));
461 context->recordError(Error(GL_INVALID_ENUM));
465 if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
467 context->recordError(Error(GL_INVALID_VALUE));
473 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
474 // buffers are copied.
478 if (fromAngleExtension && (srcX1 - srcX0 != dstX1 - dstX0 || srcY1 - srcY0 != dstY1 - dstY0))
480 ERR("Scaling and flipping in BlitFramebufferANGLE not supported by this implementation.");
481 context->recordError(Error(GL_INVALID_OPERATION));
485 // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
486 // color buffer, leaving only nearest being unfiltered from above
487 if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
489 context->recordError(Error(GL_INVALID_OPERATION));
493 if (context->getState().getReadFramebuffer()->id() == context->getState().getDrawFramebuffer()->id())
495 if (fromAngleExtension)
497 ERR("Blits with the same source and destination framebuffer are not supported by this "
500 context->recordError(Error(GL_INVALID_OPERATION));
504 gl::Framebuffer *readFramebuffer = context->getState().getReadFramebuffer();
505 gl::Framebuffer *drawFramebuffer = context->getState().getDrawFramebuffer();
506 if (!readFramebuffer || readFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE ||
507 !drawFramebuffer || drawFramebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
509 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
513 if (drawFramebuffer->getSamples() != 0)
515 context->recordError(Error(GL_INVALID_OPERATION));
519 bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
521 if (mask & GL_COLOR_BUFFER_BIT)
523 gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
524 gl::FramebufferAttachment *drawColorBuffer = drawFramebuffer->getFirstColorbuffer();
526 if (readColorBuffer && drawColorBuffer)
528 GLenum readInternalFormat = readColorBuffer->getActualFormat();
529 const InternalFormat &readFormatInfo = GetInternalFormatInfo(readInternalFormat);
531 for (unsigned int i = 0; i < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; i++)
533 if (drawFramebuffer->isEnabledColorAttachment(i))
535 GLenum drawInternalFormat = drawFramebuffer->getColorbuffer(i)->getActualFormat();
536 const InternalFormat &drawFormatInfo = GetInternalFormatInfo(drawInternalFormat);
538 // The GL ES 3.0.2 spec (pg 193) states that:
539 // 1) If the read buffer is fixed point format, the draw buffer must be as well
540 // 2) If the read buffer is an unsigned integer format, the draw buffer must be as well
541 // 3) If the read buffer is a signed integer format, the draw buffer must be as well
542 if ( (readFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || readFormatInfo.componentType == GL_SIGNED_NORMALIZED) &&
543 !(drawFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || drawFormatInfo.componentType == GL_SIGNED_NORMALIZED))
545 context->recordError(Error(GL_INVALID_OPERATION));
549 if (readFormatInfo.componentType == GL_UNSIGNED_INT && drawFormatInfo.componentType != GL_UNSIGNED_INT)
551 context->recordError(Error(GL_INVALID_OPERATION));
555 if (readFormatInfo.componentType == GL_INT && drawFormatInfo.componentType != GL_INT)
557 context->recordError(Error(GL_INVALID_OPERATION));
561 if (readColorBuffer->getSamples() > 0 && (readInternalFormat != drawInternalFormat || !sameBounds))
563 context->recordError(Error(GL_INVALID_OPERATION));
569 if ((readFormatInfo.componentType == GL_INT || readFormatInfo.componentType == GL_UNSIGNED_INT) && filter == GL_LINEAR)
571 context->recordError(Error(GL_INVALID_OPERATION));
575 if (fromAngleExtension)
577 const GLenum readColorbufferType = readFramebuffer->getReadColorbufferType();
578 if (readColorbufferType != GL_TEXTURE_2D && readColorbufferType != GL_RENDERBUFFER)
580 context->recordError(Error(GL_INVALID_OPERATION));
584 for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
586 if (drawFramebuffer->isEnabledColorAttachment(colorAttachment))
588 FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(colorAttachment);
591 if (attachment->type() != GL_TEXTURE_2D && attachment->type() != GL_RENDERBUFFER)
593 context->recordError(Error(GL_INVALID_OPERATION));
597 if (attachment->getActualFormat() != readColorBuffer->getActualFormat())
599 context->recordError(Error(GL_INVALID_OPERATION));
604 if (readFramebuffer->getSamples() != 0 && IsPartialBlit(context, readColorBuffer, drawColorBuffer,
605 srcX0, srcY0, srcX1, srcY1,
606 dstX0, dstY0, dstX1, dstY1))
608 context->recordError(Error(GL_INVALID_OPERATION));
615 if (mask & GL_DEPTH_BUFFER_BIT)
617 gl::FramebufferAttachment *readDepthBuffer = readFramebuffer->getDepthbuffer();
618 gl::FramebufferAttachment *drawDepthBuffer = drawFramebuffer->getDepthbuffer();
620 if (readDepthBuffer && drawDepthBuffer)
622 if (readDepthBuffer->getActualFormat() != drawDepthBuffer->getActualFormat())
624 context->recordError(Error(GL_INVALID_OPERATION));
628 if (readDepthBuffer->getSamples() > 0 && !sameBounds)
630 context->recordError(Error(GL_INVALID_OPERATION));
634 if (fromAngleExtension)
636 if (IsPartialBlit(context, readDepthBuffer, drawDepthBuffer,
637 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
639 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
640 context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted
644 if (readDepthBuffer->getSamples() != 0 || drawDepthBuffer->getSamples() != 0)
646 context->recordError(Error(GL_INVALID_OPERATION));
653 if (mask & GL_STENCIL_BUFFER_BIT)
655 gl::FramebufferAttachment *readStencilBuffer = readFramebuffer->getStencilbuffer();
656 gl::FramebufferAttachment *drawStencilBuffer = drawFramebuffer->getStencilbuffer();
658 if (readStencilBuffer && drawStencilBuffer)
660 if (readStencilBuffer->getActualFormat() != drawStencilBuffer->getActualFormat())
662 context->recordError(Error(GL_INVALID_OPERATION));
666 if (readStencilBuffer->getSamples() > 0 && !sameBounds)
668 context->recordError(Error(GL_INVALID_OPERATION));
672 if (fromAngleExtension)
674 if (IsPartialBlit(context, readStencilBuffer, drawStencilBuffer,
675 srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1))
677 ERR("Only whole-buffer depth and stencil blits are supported by this implementation.");
678 context->recordError(Error(GL_INVALID_OPERATION)); // only whole-buffer copies are permitted
682 if (readStencilBuffer->getSamples() != 0 || drawStencilBuffer->getSamples() != 0)
684 context->recordError(Error(GL_INVALID_OPERATION));
694 bool ValidateGetVertexAttribParameters(Context *context, GLenum pname)
698 case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
699 case GL_VERTEX_ATTRIB_ARRAY_SIZE:
700 case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
701 case GL_VERTEX_ATTRIB_ARRAY_TYPE:
702 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
703 case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
704 case GL_CURRENT_VERTEX_ATTRIB:
707 case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
708 // Don't verify ES3 context because GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE uses
709 // the same constant.
710 META_ASSERT(GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);
713 case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
714 if (context->getClientVersion() < 3)
716 context->recordError(Error(GL_INVALID_ENUM));
722 context->recordError(Error(GL_INVALID_ENUM));
727 bool ValidateTexParamParameters(gl::Context *context, GLenum pname, GLint param)
731 case GL_TEXTURE_WRAP_R:
732 case GL_TEXTURE_SWIZZLE_R:
733 case GL_TEXTURE_SWIZZLE_G:
734 case GL_TEXTURE_SWIZZLE_B:
735 case GL_TEXTURE_SWIZZLE_A:
736 case GL_TEXTURE_BASE_LEVEL:
737 case GL_TEXTURE_MAX_LEVEL:
738 case GL_TEXTURE_COMPARE_MODE:
739 case GL_TEXTURE_COMPARE_FUNC:
740 case GL_TEXTURE_MIN_LOD:
741 case GL_TEXTURE_MAX_LOD:
742 if (context->getClientVersion() < 3)
744 context->recordError(Error(GL_INVALID_ENUM));
754 case GL_TEXTURE_WRAP_S:
755 case GL_TEXTURE_WRAP_T:
756 case GL_TEXTURE_WRAP_R:
760 case GL_CLAMP_TO_EDGE:
761 case GL_MIRRORED_REPEAT:
764 context->recordError(Error(GL_INVALID_ENUM));
768 case GL_TEXTURE_MIN_FILTER:
773 case GL_NEAREST_MIPMAP_NEAREST:
774 case GL_LINEAR_MIPMAP_NEAREST:
775 case GL_NEAREST_MIPMAP_LINEAR:
776 case GL_LINEAR_MIPMAP_LINEAR:
779 context->recordError(Error(GL_INVALID_ENUM));
784 case GL_TEXTURE_MAG_FILTER:
791 context->recordError(Error(GL_INVALID_ENUM));
796 case GL_TEXTURE_USAGE_ANGLE:
800 case GL_FRAMEBUFFER_ATTACHMENT_ANGLE:
803 context->recordError(Error(GL_INVALID_ENUM));
808 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
809 if (!context->getExtensions().textureFilterAnisotropic)
811 context->recordError(Error(GL_INVALID_ENUM));
815 // we assume the parameter passed to this validation method is truncated, not rounded
818 context->recordError(Error(GL_INVALID_VALUE));
823 case GL_TEXTURE_MIN_LOD:
824 case GL_TEXTURE_MAX_LOD:
825 // any value is permissible
828 case GL_TEXTURE_COMPARE_MODE:
829 // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
833 case GL_COMPARE_REF_TO_TEXTURE:
836 context->recordError(Error(GL_INVALID_ENUM));
841 case GL_TEXTURE_COMPARE_FUNC:
842 // Acceptable function parameters from GLES 3.0.2 spec, table 3.17
855 context->recordError(Error(GL_INVALID_ENUM));
860 case GL_TEXTURE_SWIZZLE_R:
861 case GL_TEXTURE_SWIZZLE_G:
862 case GL_TEXTURE_SWIZZLE_B:
863 case GL_TEXTURE_SWIZZLE_A:
874 context->recordError(Error(GL_INVALID_ENUM));
879 case GL_TEXTURE_BASE_LEVEL:
880 case GL_TEXTURE_MAX_LEVEL:
883 context->recordError(Error(GL_INVALID_VALUE));
889 context->recordError(Error(GL_INVALID_ENUM));
894 bool ValidateSamplerObjectParameter(gl::Context *context, GLenum pname)
898 case GL_TEXTURE_MIN_FILTER:
899 case GL_TEXTURE_MAG_FILTER:
900 case GL_TEXTURE_WRAP_S:
901 case GL_TEXTURE_WRAP_T:
902 case GL_TEXTURE_WRAP_R:
903 case GL_TEXTURE_MIN_LOD:
904 case GL_TEXTURE_MAX_LOD:
905 case GL_TEXTURE_COMPARE_MODE:
906 case GL_TEXTURE_COMPARE_FUNC:
910 context->recordError(Error(GL_INVALID_ENUM));
915 bool ValidateReadPixelsParameters(gl::Context *context, GLint x, GLint y, GLsizei width, GLsizei height,
916 GLenum format, GLenum type, GLsizei *bufSize, GLvoid *pixels)
918 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
921 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
923 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
927 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
929 context->recordError(Error(GL_INVALID_OPERATION));
933 if (!framebuffer->getReadColorbuffer())
935 context->recordError(Error(GL_INVALID_OPERATION));
939 GLenum currentInternalFormat, currentFormat, currentType;
940 GLuint clientVersion = context->getClientVersion();
942 context->getCurrentReadFormatType(¤tInternalFormat, ¤tFormat, ¤tType);
944 bool validReadFormat = (clientVersion < 3) ? ValidES2ReadFormatType(context, format, type) :
945 ValidES3ReadFormatType(context, currentInternalFormat, format, type);
947 if (!(currentFormat == format && currentType == type) && !validReadFormat)
949 context->recordError(Error(GL_INVALID_OPERATION));
953 GLenum sizedInternalFormat = GetSizedInternalFormat(format, type);
954 const InternalFormat &sizedFormatInfo = GetInternalFormatInfo(sizedInternalFormat);
956 GLsizei outputPitch = sizedFormatInfo.computeRowPitch(type, width, context->getState().getPackAlignment());
957 // sized query sanity check
960 int requiredSize = outputPitch * height;
961 if (requiredSize > *bufSize)
963 context->recordError(Error(GL_INVALID_OPERATION));
971 bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id)
973 if (!ValidQueryType(context, target))
975 context->recordError(Error(GL_INVALID_ENUM));
981 context->recordError(Error(GL_INVALID_OPERATION));
985 // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
986 // of zero, if the active query object name for <target> is non-zero (for the
987 // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
988 // the active query for either target is non-zero), if <id> is the name of an
989 // existing query object whose type does not match <target>, or if <id> is the
990 // active query object name for any query type, the error INVALID_OPERATION is
993 // Ensure no other queries are active
994 // NOTE: If other queries than occlusion are supported, we will need to check
996 // a) The query ID passed is not the current active query for any target/type
997 // b) There are no active queries for the requested target (and in the case
998 // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
999 // no query may be active for either if glBeginQuery targets either.
1000 if (context->getState().isQueryActive())
1002 context->recordError(Error(GL_INVALID_OPERATION));
1006 Query *queryObject = context->getQuery(id, true, target);
1008 // check that name was obtained with glGenQueries
1011 context->recordError(Error(GL_INVALID_OPERATION));
1015 // check for type mismatch
1016 if (queryObject->getType() != target)
1018 context->recordError(Error(GL_INVALID_OPERATION));
1025 bool ValidateEndQuery(gl::Context *context, GLenum target)
1027 if (!ValidQueryType(context, target))
1029 context->recordError(Error(GL_INVALID_ENUM));
1033 const Query *queryObject = context->getState().getActiveQuery(target);
1035 if (queryObject == NULL)
1037 context->recordError(Error(GL_INVALID_OPERATION));
1044 static bool ValidateUniformCommonBase(gl::Context *context, GLenum targetUniformType,
1045 GLint location, GLsizei count, LinkedUniform **uniformOut)
1049 context->recordError(Error(GL_INVALID_VALUE));
1053 gl::ProgramBinary *programBinary = context->getState().getCurrentProgramBinary();
1056 context->recordError(Error(GL_INVALID_OPERATION));
1062 // Silently ignore the uniform command
1066 if (!programBinary->isValidUniformLocation(location))
1068 context->recordError(Error(GL_INVALID_OPERATION));
1072 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1074 // attempting to write an array to a non-array uniform is an INVALID_OPERATION
1075 if (uniform->elementCount() == 1 && count > 1)
1077 context->recordError(Error(GL_INVALID_OPERATION));
1081 *uniformOut = uniform;
1085 bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count)
1087 // Check for ES3 uniform entry points
1088 if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && context->getClientVersion() < 3)
1090 context->recordError(Error(GL_INVALID_OPERATION));
1094 LinkedUniform *uniform = NULL;
1095 if (!ValidateUniformCommonBase(context, uniformType, location, count, &uniform))
1100 GLenum targetBoolType = VariableBoolVectorType(uniformType);
1101 bool samplerUniformCheck = (IsSampler(uniform->type) && uniformType == GL_INT);
1102 if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type)
1104 context->recordError(Error(GL_INVALID_OPERATION));
1111 bool ValidateUniformMatrix(gl::Context *context, GLenum matrixType, GLint location, GLsizei count,
1112 GLboolean transpose)
1114 // Check for ES3 uniform entry points
1115 int rows = VariableRowCount(matrixType);
1116 int cols = VariableColumnCount(matrixType);
1117 if (rows != cols && context->getClientVersion() < 3)
1119 context->recordError(Error(GL_INVALID_OPERATION));
1123 if (transpose != GL_FALSE && context->getClientVersion() < 3)
1125 context->recordError(Error(GL_INVALID_VALUE));
1129 LinkedUniform *uniform = NULL;
1130 if (!ValidateUniformCommonBase(context, matrixType, location, count, &uniform))
1135 if (uniform->type != matrixType)
1137 context->recordError(Error(GL_INVALID_OPERATION));
1144 bool ValidateStateQuery(gl::Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams)
1146 if (!context->getQueryParameterInfo(pname, nativeType, numParams))
1148 context->recordError(Error(GL_INVALID_ENUM));
1152 if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
1154 unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
1156 if (colorAttachment >= context->getCaps().maxDrawBuffers)
1158 context->recordError(Error(GL_INVALID_OPERATION));
1165 case GL_TEXTURE_BINDING_2D:
1166 case GL_TEXTURE_BINDING_CUBE_MAP:
1167 case GL_TEXTURE_BINDING_3D:
1168 case GL_TEXTURE_BINDING_2D_ARRAY:
1169 if (context->getState().getActiveSampler() >= context->getCaps().maxCombinedTextureImageUnits)
1171 context->recordError(Error(GL_INVALID_OPERATION));
1176 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
1177 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
1179 Framebuffer *framebuffer = context->getState().getReadFramebuffer();
1180 ASSERT(framebuffer);
1181 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1183 context->recordError(Error(GL_INVALID_OPERATION));
1187 FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
1190 context->recordError(Error(GL_INVALID_OPERATION));
1200 // pname is valid, but there are no parameters to return
1209 bool ValidateCopyTexImageParametersBase(gl::Context* context, GLenum target, GLint level, GLenum internalformat, bool isSubImage,
1210 GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height,
1211 GLint border, GLenum *textureFormatOut)
1214 if (!ValidTexture2DDestinationTarget(context, target))
1216 context->recordError(Error(GL_INVALID_ENUM));
1220 if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
1222 context->recordError(Error(GL_INVALID_VALUE));
1226 if (std::numeric_limits<GLsizei>::max() - xoffset < width || std::numeric_limits<GLsizei>::max() - yoffset < height)
1228 context->recordError(Error(GL_INVALID_VALUE));
1234 context->recordError(Error(GL_INVALID_VALUE));
1238 if (!ValidMipLevel(context, target, level))
1240 context->recordError(Error(GL_INVALID_VALUE));
1244 gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
1245 if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
1247 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
1251 if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
1253 context->recordError(Error(GL_INVALID_OPERATION));
1257 const gl::Caps &caps = context->getCaps();
1259 gl::Texture *texture = NULL;
1260 GLenum textureInternalFormat = GL_NONE;
1261 GLint textureLevelWidth = 0;
1262 GLint textureLevelHeight = 0;
1263 GLint textureLevelDepth = 0;
1264 GLuint maxDimension = 0;
1270 gl::Texture2D *texture2d = context->getTexture2D();
1273 textureInternalFormat = texture2d->getInternalFormat(level);
1274 textureLevelWidth = texture2d->getWidth(level);
1275 textureLevelHeight = texture2d->getHeight(level);
1276 textureLevelDepth = 1;
1277 texture = texture2d;
1278 maxDimension = caps.max2DTextureSize;
1283 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1285 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1286 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1287 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1288 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1290 gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
1293 textureInternalFormat = textureCube->getInternalFormat(target, level);
1294 textureLevelWidth = textureCube->getWidth(target, level);
1295 textureLevelHeight = textureCube->getHeight(target, level);
1296 textureLevelDepth = 1;
1297 texture = textureCube;
1298 maxDimension = caps.maxCubeMapTextureSize;
1303 case GL_TEXTURE_2D_ARRAY:
1305 gl::Texture2DArray *texture2dArray = context->getTexture2DArray();
1308 textureInternalFormat = texture2dArray->getInternalFormat(level);
1309 textureLevelWidth = texture2dArray->getWidth(level);
1310 textureLevelHeight = texture2dArray->getHeight(level);
1311 textureLevelDepth = texture2dArray->getLayers(level);
1312 texture = texture2dArray;
1313 maxDimension = caps.max2DTextureSize;
1320 gl::Texture3D *texture3d = context->getTexture3D();
1323 textureInternalFormat = texture3d->getInternalFormat(level);
1324 textureLevelWidth = texture3d->getWidth(level);
1325 textureLevelHeight = texture3d->getHeight(level);
1326 textureLevelDepth = texture3d->getDepth(level);
1327 texture = texture3d;
1328 maxDimension = caps.max3DTextureSize;
1334 context->recordError(Error(GL_INVALID_ENUM));
1340 context->recordError(Error(GL_INVALID_OPERATION));
1344 if (texture->isImmutable() && !isSubImage)
1346 context->recordError(Error(GL_INVALID_OPERATION));
1350 const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat);
1352 if (formatInfo.depthBits > 0)
1354 context->recordError(Error(GL_INVALID_OPERATION));
1358 if (formatInfo.compressed)
1360 if (((width % formatInfo.compressedBlockWidth) != 0 && width != textureLevelWidth) ||
1361 ((height % formatInfo.compressedBlockHeight) != 0 && height != textureLevelHeight))
1363 context->recordError(Error(GL_INVALID_OPERATION));
1370 if (xoffset + width > textureLevelWidth ||
1371 yoffset + height > textureLevelHeight ||
1372 zoffset >= textureLevelDepth)
1374 context->recordError(Error(GL_INVALID_VALUE));
1380 if (IsCubemapTextureTarget(target) && width != height)
1382 context->recordError(Error(GL_INVALID_VALUE));
1386 if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
1388 context->recordError(Error(GL_INVALID_ENUM));
1392 int maxLevelDimension = (maxDimension >> level);
1393 if (static_cast<int>(width) > maxLevelDimension || static_cast<int>(height) > maxLevelDimension)
1395 context->recordError(Error(GL_INVALID_VALUE));
1400 *textureFormatOut = textureInternalFormat;
1404 static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsizei maxVertex, GLsizei primcount)
1413 case GL_TRIANGLE_STRIP:
1414 case GL_TRIANGLE_FAN:
1417 context->recordError(Error(GL_INVALID_ENUM));
1423 context->recordError(Error(GL_INVALID_VALUE));
1427 const State &state = context->getState();
1429 // Check for mapped buffers
1430 if (state.hasMappedBuffer(GL_ARRAY_BUFFER))
1432 context->recordError(Error(GL_INVALID_OPERATION));
1436 const gl::DepthStencilState &depthStencilState = state.getDepthStencilState();
1437 if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask ||
1438 state.getStencilRef() != state.getStencilBackRef() ||
1439 depthStencilState.stencilMask != depthStencilState.stencilBackMask)
1441 // Note: these separate values are not supported in WebGL, due to D3D's limitations.
1442 // See Section 6.10 of the WebGL 1.0 spec
1443 ERR("This ANGLE implementation does not support separate front/back stencil "
1444 "writemasks, reference values, or stencil mask values.");
1445 context->recordError(Error(GL_INVALID_OPERATION));
1449 const gl::Framebuffer *fbo = state.getDrawFramebuffer();
1450 if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
1452 context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
1456 if (state.getCurrentProgramId() == 0)
1458 context->recordError(Error(GL_INVALID_OPERATION));
1462 gl::ProgramBinary *programBinary = state.getCurrentProgramBinary();
1463 if (!programBinary->validateSamplers(NULL, context->getCaps()))
1465 context->recordError(Error(GL_INVALID_OPERATION));
1469 // Buffer validations
1470 const VertexArray *vao = state.getVertexArray();
1471 for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1473 const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex);
1474 bool attribActive = (programBinary->getSemanticIndex(attributeIndex) != -1);
1475 if (attribActive && attrib.enabled)
1477 gl::Buffer *buffer = attrib.buffer.get();
1481 GLint64 attribStride = static_cast<GLint64>(ComputeVertexAttributeStride(attrib));
1482 GLint64 maxVertexElement = 0;
1484 if (attrib.divisor > 0)
1486 maxVertexElement = static_cast<GLint64>(primcount) / static_cast<GLint64>(attrib.divisor);
1490 maxVertexElement = static_cast<GLint64>(maxVertex);
1493 GLint64 attribDataSize = maxVertexElement * attribStride;
1495 // [OpenGL ES 3.0.2] section 2.9.4 page 40:
1496 // We can return INVALID_OPERATION if our vertex attribute does not have
1497 // enough backing data.
1498 if (attribDataSize > buffer->getSize())
1500 context->recordError(Error(GL_INVALID_OPERATION));
1504 else if (attrib.pointer == NULL)
1506 // This is an application error that would normally result in a crash,
1507 // but we catch it and return an error
1508 context->recordError(Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer."));
1514 // No-op if zero count
1518 bool ValidateDrawArrays(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1522 context->recordError(Error(GL_INVALID_VALUE));
1526 const State &state = context->getState();
1527 gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
1528 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused() &&
1529 curTransformFeedback->getDrawMode() != mode)
1531 // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
1532 // that does not match the current transform feedback object's draw mode (if transform feedback
1533 // is active), (3.0.2, section 2.14, pg 86)
1534 context->recordError(Error(GL_INVALID_OPERATION));
1538 if (!ValidateDrawBase(context, mode, count, count, primcount))
1546 bool ValidateDrawArraysInstanced(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1550 context->recordError(Error(GL_INVALID_VALUE));
1554 if (!ValidateDrawArrays(context, mode, first, count, primcount))
1559 // No-op if zero primitive count
1560 return (primcount > 0);
1563 static bool ValidateDrawInstancedANGLE(Context *context)
1565 // Verify there is at least one active attribute with a divisor of zero
1566 const gl::State& state = context->getState();
1568 gl::ProgramBinary *programBinary = state.getCurrentProgramBinary();
1570 const VertexArray *vao = state.getVertexArray();
1571 for (int attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
1573 const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex);
1574 bool active = (programBinary->getSemanticIndex(attributeIndex) != -1);
1575 if (active && attrib.divisor == 0)
1581 context->recordError(Error(GL_INVALID_OPERATION, "ANGLE_instanced_arrays requires that at least one active attribute"
1582 "has a divisor of zero."));
1586 bool ValidateDrawArraysInstancedANGLE(Context *context, GLenum mode, GLint first, GLsizei count, GLsizei primcount)
1588 if (!ValidateDrawInstancedANGLE(context))
1593 return ValidateDrawArraysInstanced(context, mode, first, count, primcount);
1596 bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum type,
1597 const GLvoid* indices, GLsizei primcount, rx::RangeUI *indexRangeOut)
1601 case GL_UNSIGNED_BYTE:
1602 case GL_UNSIGNED_SHORT:
1604 case GL_UNSIGNED_INT:
1605 if (!context->getExtensions().elementIndexUint)
1607 context->recordError(Error(GL_INVALID_ENUM));
1612 context->recordError(Error(GL_INVALID_ENUM));
1616 const State &state = context->getState();
1618 gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
1619 if (curTransformFeedback && curTransformFeedback->isStarted() && !curTransformFeedback->isPaused())
1621 // It is an invalid operation to call DrawElements, DrawRangeElements or DrawElementsInstanced
1622 // while transform feedback is active, (3.0.2, section 2.14, pg 86)
1623 context->recordError(Error(GL_INVALID_OPERATION));
1627 // Check for mapped buffers
1628 if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER))
1630 context->recordError(Error(GL_INVALID_OPERATION));
1634 const gl::VertexArray *vao = state.getVertexArray();
1635 const gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer();
1636 if (!indices && !elementArrayBuffer)
1638 context->recordError(Error(GL_INVALID_OPERATION));
1642 if (elementArrayBuffer)
1644 const gl::Type &typeInfo = gl::GetTypeInfo(type);
1646 GLint64 offset = reinterpret_cast<GLint64>(indices);
1647 GLint64 byteCount = static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count)+offset;
1649 // check for integer overflows
1650 if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) ||
1651 byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max()))
1653 context->recordError(Error(GL_OUT_OF_MEMORY));
1657 // Check for reading past the end of the bound buffer object
1658 if (byteCount > elementArrayBuffer->getSize())
1660 context->recordError(Error(GL_INVALID_OPERATION));
1666 // Catch this programming error here
1667 context->recordError(Error(GL_INVALID_OPERATION));
1671 // Use max index to validate if our vertex buffers are large enough for the pull.
1672 // TODO: offer fast path, with disabled index validation.
1673 // TODO: also disable index checking on back-ends that are robust to out-of-range accesses.
1674 if (elementArrayBuffer)
1676 unsigned int offset = reinterpret_cast<unsigned int>(indices);
1677 if (!elementArrayBuffer->getIndexRangeCache()->findRange(type, offset, count, indexRangeOut, NULL))
1679 const void *dataPointer = elementArrayBuffer->getImplementation()->getData();
1680 const uint8_t *offsetPointer = static_cast<const uint8_t *>(dataPointer) + offset;
1681 *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, offsetPointer, count);
1686 *indexRangeOut = rx::IndexRangeCache::ComputeRange(type, indices, count);
1689 if (!ValidateDrawBase(context, mode, count, static_cast<GLsizei>(indexRangeOut->end), primcount))
1697 bool ValidateDrawElementsInstanced(Context *context,
1698 GLenum mode, GLsizei count, GLenum type,
1699 const GLvoid *indices, GLsizei primcount,
1700 rx::RangeUI *indexRangeOut)
1704 context->recordError(Error(GL_INVALID_VALUE));
1708 if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut))
1713 // No-op zero primitive count
1714 return (primcount > 0);
1717 bool ValidateDrawElementsInstancedANGLE(Context *context, GLenum mode, GLsizei count, GLenum type,
1718 const GLvoid *indices, GLsizei primcount, rx::RangeUI *indexRangeOut)
1720 if (!ValidateDrawInstancedANGLE(context))
1725 return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, indexRangeOut);
1728 bool ValidateFramebufferTextureBase(Context *context, GLenum target, GLenum attachment,
1729 GLuint texture, GLint level)
1731 if (!ValidFramebufferTarget(target))
1733 context->recordError(Error(GL_INVALID_ENUM));
1737 if (!ValidateAttachmentTarget(context, attachment))
1744 gl::Texture *tex = context->getTexture(texture);
1748 context->recordError(Error(GL_INVALID_OPERATION));
1754 context->recordError(Error(GL_INVALID_VALUE));
1759 const gl::Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target);
1760 GLuint framebufferHandle = context->getState().getTargetFramebuffer(target)->id();
1762 if (framebufferHandle == 0 || !framebuffer)
1764 context->recordError(Error(GL_INVALID_OPERATION));
1771 bool ValidateFramebufferTexture2D(Context *context, GLenum target, GLenum attachment,
1772 GLenum textarget, GLuint texture, GLint level)
1774 // Attachments are required to be bound to level 0 in ES2
1775 if (context->getClientVersion() < 3 && level != 0)
1777 context->recordError(Error(GL_INVALID_VALUE));
1781 if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
1788 gl::Texture *tex = context->getTexture(texture);
1791 const gl::Caps &caps = context->getCaps();
1797 if (level > gl::log2(caps.max2DTextureSize))
1799 context->recordError(Error(GL_INVALID_VALUE));
1802 if (tex->getTarget() != GL_TEXTURE_2D)
1804 context->recordError(Error(GL_INVALID_OPERATION));
1807 gl::Texture2D *tex2d = static_cast<gl::Texture2D *>(tex);
1808 if (tex2d->isCompressed(level))
1810 context->recordError(Error(GL_INVALID_OPERATION));
1816 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1817 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1818 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1819 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1820 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1821 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1823 if (level > gl::log2(caps.maxCubeMapTextureSize))
1825 context->recordError(Error(GL_INVALID_VALUE));
1828 if (tex->getTarget() != GL_TEXTURE_CUBE_MAP)
1830 context->recordError(Error(GL_INVALID_OPERATION));
1833 gl::TextureCubeMap *texcube = static_cast<gl::TextureCubeMap *>(tex);
1834 if (texcube->isCompressed(textarget, level))
1836 context->recordError(Error(GL_INVALID_OPERATION));
1843 context->recordError(Error(GL_INVALID_ENUM));
1851 bool ValidateGetUniformBase(Context *context, GLuint program, GLint location)
1855 context->recordError(Error(GL_INVALID_VALUE));
1859 gl::Program *programObject = context->getProgram(program);
1861 if (!programObject || !programObject->isLinked())
1863 context->recordError(Error(GL_INVALID_OPERATION));
1867 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1870 context->recordError(Error(GL_INVALID_OPERATION));
1874 if (!programBinary->isValidUniformLocation(location))
1876 context->recordError(Error(GL_INVALID_OPERATION));
1883 bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat* params)
1885 return ValidateGetUniformBase(context, program, location);
1888 bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint* params)
1890 return ValidateGetUniformBase(context, program, location);
1893 static bool ValidateSizedGetUniform(Context *context, GLuint program, GLint location, GLsizei bufSize)
1895 if (!ValidateGetUniformBase(context, program, location))
1900 gl::Program *programObject = context->getProgram(program);
1901 ASSERT(programObject);
1902 gl::ProgramBinary *programBinary = programObject->getProgramBinary();
1904 // sized queries -- ensure the provided buffer is large enough
1905 LinkedUniform *uniform = programBinary->getUniformByLocation(location);
1906 size_t requiredBytes = VariableExternalSize(uniform->type);
1907 if (static_cast<size_t>(bufSize) < requiredBytes)
1909 context->recordError(Error(GL_INVALID_OPERATION));
1916 bool ValidateGetnUniformfvEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLfloat* params)
1918 return ValidateSizedGetUniform(context, program, location, bufSize);
1921 bool ValidateGetnUniformivEXT(Context *context, GLuint program, GLint location, GLsizei bufSize, GLint* params)
1923 return ValidateSizedGetUniform(context, program, location, bufSize);