blob: 0bfdc24cc7c9ee67149aa4adb287e95f5fc2ebbb [file] [log] [blame]
//
// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationES.h: Validation functions for generic OpenGL ES entry point parameters
#include "libANGLE/validationES.h"
#include "libANGLE/Context.h"
#include "libANGLE/Display.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Image.h"
#include "libANGLE/Program.h"
#include "libANGLE/Query.h"
#include "libANGLE/Texture.h"
#include "libANGLE/TransformFeedback.h"
#include "libANGLE/Uniform.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/validationES2.h"
#include "libANGLE/validationES3.h"
#include "common/mathutil.h"
#include "common/utilities.h"
using namespace angle;
namespace gl
{
const char *g_ExceedsMaxElementErrorMessage = "Element value exceeds maximum element index.";
namespace
{
bool ValidateDrawAttribs(ValidationContext *context,
GLint primcount,
GLint maxVertex,
GLint vertexCount)
{
const gl::State &state = context->getGLState();
const gl::Program *program = state.getProgram();
bool webglCompatibility = context->getExtensions().webglCompatibility;
const VertexArray *vao = state.getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes();
const auto &vertexBindings = vao->getVertexBindings();
size_t maxEnabledAttrib = vao->getMaxEnabledAttribute();
for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex)
{
const VertexAttribute &attrib = vertexAttribs[attributeIndex];
if (!program->isAttribLocationActive(attributeIndex) || !attrib.enabled)
{
continue;
}
const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
// If we have no buffer, then we either get an error, or there are no more checks to be
// done.
gl::Buffer *buffer = binding.buffer.get();
if (!buffer)
{
if (webglCompatibility || !state.areClientArraysEnabled())
{
// [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking
// If a vertex attribute is enabled as an array via enableVertexAttribArray but
// no buffer is bound to that attribute via bindBuffer and vertexAttribPointer,
// then calls to drawArrays or drawElements will generate an INVALID_OPERATION
// error.
context->handleError(
Error(GL_INVALID_OPERATION, "An enabled vertex array has no buffer."));
return false;
}
else if (attrib.pointer == nullptr)
{
// This is an application error that would normally result in a crash,
// but we catch it and return an error
context->handleError(Error(
GL_INVALID_OPERATION, "An enabled vertex array has no buffer and no pointer."));
return false;
}
continue;
}
// If we're drawing zero vertices, we have enough data.
if (vertexCount <= 0 || primcount <= 0)
{
continue;
}
GLint maxVertexElement = 0;
if (binding.divisor == 0)
{
maxVertexElement = maxVertex;
}
else
{
maxVertexElement = (primcount - 1) / binding.divisor;
}
// We do manual overflow checks here instead of using safe_math.h because it was
// a bottleneck. Thanks to some properties of GL we know inequalities that can
// help us make the overflow checks faster.
// The max possible attribSize is 16 for a vector of 4 32 bit values.
constexpr uint64_t kMaxAttribSize = 16;
constexpr uint64_t kIntMax = std::numeric_limits<int>::max();
constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max();
// We know attribStride is given as a GLsizei which is typedefed to int.
// We also know an upper bound for attribSize.
static_assert(std::is_same<int, GLsizei>::value, "");
uint64_t attribStride = ComputeVertexAttributeStride(attrib, binding);
uint64_t attribSize = ComputeVertexAttributeTypeSize(attrib);
ASSERT(attribStride <= kIntMax && attribSize <= kMaxAttribSize);
// Computing the max offset using uint64_t without attrib.offset is overflow
// safe. Note: Last vertex element does not take the full stride!
static_assert(kIntMax * kIntMax < kUint64Max - kMaxAttribSize, "");
uint64_t attribDataSizeNoOffset = maxVertexElement * attribStride + attribSize;
// An overflow can happen when adding the offset, check for it.
uint64_t attribOffset = ComputeVertexAttributeOffset(attrib, binding);
if (attribDataSizeNoOffset > kUint64Max - attribOffset)
{
context->handleError(Error(GL_INVALID_OPERATION, "Integer overflow."));
return false;
}
uint64_t attribDataSizeWithOffset = attribDataSizeNoOffset + attribOffset;
// [OpenGL ES 3.0.2] section 2.9.4 page 40:
// We can return INVALID_OPERATION if our vertex attribute does not have
// enough backing data.
if (attribDataSizeWithOffset > static_cast<uint64_t>(buffer->getSize()))
{
context->handleError(
Error(GL_INVALID_OPERATION, "Vertex buffer is not big enough for the draw call"));
return false;
}
}
return true;
}
bool ValidReadPixelsFormatType(ValidationContext *context,
GLenum framebufferComponentType,
GLenum format,
GLenum type)
{
switch (framebufferComponentType)
{
case GL_UNSIGNED_NORMALIZED:
// TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use
// ReadPixels with BGRA even if the extension is not present
return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) ||
(context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT &&
type == GL_UNSIGNED_BYTE);
case GL_SIGNED_NORMALIZED:
return (format == GL_RGBA && type == GL_UNSIGNED_BYTE);
case GL_INT:
return (format == GL_RGBA_INTEGER && type == GL_INT);
case GL_UNSIGNED_INT:
return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT);
case GL_FLOAT:
return (format == GL_RGBA && type == GL_FLOAT);
default:
UNREACHABLE();
return false;
}
}
template <typename ParamType>
bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool isExternalTextureTarget)
{
switch (ConvertToGLenum(params[0]))
{
case GL_CLAMP_TO_EDGE:
break;
case GL_REPEAT:
case GL_MIRRORED_REPEAT:
if (isExternalTextureTarget)
{
// OES_EGL_image_external specifies this error.
context->handleError(Error(
GL_INVALID_ENUM, "external textures only support CLAMP_TO_EDGE wrap mode"));
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown param value."));
return false;
}
return true;
}
template <typename ParamType>
bool ValidateTextureMinFilterValue(Context *context,
ParamType *params,
bool isExternalTextureTarget)
{
switch (ConvertToGLenum(params[0]))
{
case GL_NEAREST:
case GL_LINEAR:
break;
case GL_NEAREST_MIPMAP_NEAREST:
case GL_LINEAR_MIPMAP_NEAREST:
case GL_NEAREST_MIPMAP_LINEAR:
case GL_LINEAR_MIPMAP_LINEAR:
if (isExternalTextureTarget)
{
// OES_EGL_image_external specifies this error.
context->handleError(
Error(GL_INVALID_ENUM,
"external textures only support NEAREST and LINEAR filtering"));
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown param value."));
return false;
}
return true;
}
template <typename ParamType>
bool ValidateTextureMagFilterValue(Context *context, ParamType *params)
{
switch (ConvertToGLenum(params[0]))
{
case GL_NEAREST:
case GL_LINEAR:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown param value."));
return false;
}
return true;
}
template <typename ParamType>
bool ValidateTextureCompareModeValue(Context *context, ParamType *params)
{
// Acceptable mode parameters from GLES 3.0.2 spec, table 3.17
switch (ConvertToGLenum(params[0]))
{
case GL_NONE:
case GL_COMPARE_REF_TO_TEXTURE:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown param value."));
return false;
}
return true;
}
template <typename ParamType>
bool ValidateTextureCompareFuncValue(Context *context, ParamType *params)
{
// Acceptable function parameters from GLES 3.0.2 spec, table 3.17
switch (ConvertToGLenum(params[0]))
{
case GL_LEQUAL:
case GL_GEQUAL:
case GL_LESS:
case GL_GREATER:
case GL_EQUAL:
case GL_NOTEQUAL:
case GL_ALWAYS:
case GL_NEVER:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown param value."));
return false;
}
return true;
}
template <typename ParamType>
bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params)
{
if (!context->getExtensions().textureSRGBDecode)
{
context->handleError(Error(GL_INVALID_ENUM, "GL_EXT_texture_sRGB_decode is not enabled."));
return false;
}
switch (ConvertToGLenum(params[0]))
{
case GL_DECODE_EXT:
case GL_SKIP_DECODE_EXT:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown param value."));
return false;
}
return true;
}
template <typename ParamType>
bool ValidateSamplerParameterBase(Context *context,
GLuint sampler,
GLenum pname,
GLsizei bufSize,
ParamType *params)
{
if (context->getClientMajorVersion() < 3)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Context does not support OpenGL ES 3.0."));
return false;
}
if (!context->isSampler(sampler))
{
context->handleError(Error(GL_INVALID_OPERATION, "Sampler is not valid."));
return false;
}
const GLsizei minBufSize = 1;
if (bufSize >= 0 && bufSize < minBufSize)
{
context->handleError(
Error(GL_INVALID_OPERATION, "bufSize must be at least %i.", minBufSize));
return false;
}
switch (pname)
{
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
case GL_TEXTURE_WRAP_R:
if (!ValidateTextureWrapModeValue(context, params, false))
{
return false;
}
break;
case GL_TEXTURE_MIN_FILTER:
if (!ValidateTextureMinFilterValue(context, params, false))
{
return false;
}
break;
case GL_TEXTURE_MAG_FILTER:
if (!ValidateTextureMagFilterValue(context, params))
{
return false;
}
break;
case GL_TEXTURE_MIN_LOD:
case GL_TEXTURE_MAX_LOD:
// any value is permissible
break;
case GL_TEXTURE_COMPARE_MODE:
if (!ValidateTextureCompareModeValue(context, params))
{
return false;
}
break;
case GL_TEXTURE_COMPARE_FUNC:
if (!ValidateTextureCompareFuncValue(context, params))
{
return false;
}
break;
case GL_TEXTURE_SRGB_DECODE_EXT:
if (!ValidateTextureSRGBDecodeValue(context, params))
{
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown pname."));
return false;
}
return true;
}
bool ValidateGetSamplerParameterBase(Context *context,
GLuint sampler,
GLenum pname,
GLsizei *length)
{
if (length)
{
*length = 0;
}
if (context->getClientMajorVersion() < 3)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Context does not support OpenGL ES 3.0."));
return false;
}
if (!context->isSampler(sampler))
{
context->handleError(Error(GL_INVALID_OPERATION, "Sampler is not valid."));
return false;
}
switch (pname)
{
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
case GL_TEXTURE_WRAP_R:
case GL_TEXTURE_MIN_FILTER:
case GL_TEXTURE_MAG_FILTER:
case GL_TEXTURE_MIN_LOD:
case GL_TEXTURE_MAX_LOD:
case GL_TEXTURE_COMPARE_MODE:
case GL_TEXTURE_COMPARE_FUNC:
break;
case GL_TEXTURE_SRGB_DECODE_EXT:
if (!context->getExtensions().textureSRGBDecode)
{
context->handleError(
Error(GL_INVALID_ENUM, "GL_EXT_texture_sRGB_decode is not enabled."));
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown pname."));
return false;
}
if (length)
{
*length = 1;
}
return true;
}
bool ValidateGetActiveUniformBlockivBase(Context *context,
GLuint program,
GLuint uniformBlockIndex,
GLenum pname,
GLsizei *length)
{
if (length)
{
*length = 0;
}
if (context->getClientMajorVersion() < 3)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Context does not support OpenGL ES 3.0."));
return false;
}
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
return false;
}
if (uniformBlockIndex >= programObject->getActiveUniformBlockCount())
{
context->handleError(
Error(GL_INVALID_VALUE, "uniformBlockIndex exceeds active uniform block count."));
return false;
}
switch (pname)
{
case GL_UNIFORM_BLOCK_BINDING:
case GL_UNIFORM_BLOCK_DATA_SIZE:
case GL_UNIFORM_BLOCK_NAME_LENGTH:
case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown pname."));
return false;
}
if (length)
{
if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES)
{
const UniformBlock &uniformBlock =
programObject->getUniformBlockByIndex(uniformBlockIndex);
*length = static_cast<GLsizei>(uniformBlock.memberUniformIndexes.size());
}
else
{
*length = 1;
}
}
return true;
}
bool ValidateGetInternalFormativBase(Context *context,
GLenum target,
GLenum internalformat,
GLenum pname,
GLsizei bufSize,
GLsizei *numParams)
{
if (numParams)
{
*numParams = 0;
}
if (context->getClientMajorVersion() < 3)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Context does not support OpenGL ES 3.0."));
return false;
}
const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat);
if (!formatCaps.renderable)
{
context->handleError(Error(GL_INVALID_ENUM, "Internal format is not renderable."));
return false;
}
switch (target)
{
case GL_RENDERBUFFER:
break;
case GL_TEXTURE_2D_MULTISAMPLE:
if (context->getClientVersion() < ES_3_1)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Texture target requires at least OpenGL ES 3.1."));
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Invalid target."));
return false;
}
if (bufSize < 0)
{
context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative."));
return false;
}
GLsizei maxWriteParams = 0;
switch (pname)
{
case GL_NUM_SAMPLE_COUNTS:
maxWriteParams = 1;
break;
case GL_SAMPLES:
maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size());
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Unknown pname."));
return false;
}
if (numParams)
{
// glGetInternalFormativ will not overflow bufSize
*numParams = std::min(bufSize, maxWriteParams);
}
return true;
}
bool ValidateUniformCommonBase(ValidationContext *context,
gl::Program *program,
GLint location,
GLsizei count,
const LinkedUniform **uniformOut)
{
// TODO(Jiajia): Add image uniform check in future.
if (count < 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (!program || !program->isLinked())
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (location == -1)
{
// Silently ignore the uniform command
return false;
}
const auto &uniformLocations = program->getUniformLocations();
size_t castedLocation = static_cast<size_t>(location);
if (castedLocation >= uniformLocations.size())
{
context->handleError(Error(GL_INVALID_OPERATION, "Invalid uniform location"));
return false;
}
const auto &uniformLocation = uniformLocations[castedLocation];
if (uniformLocation.ignored)
{
// Silently ignore the uniform command
return false;
}
if (!uniformLocation.used)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const auto &uniform = program->getUniformByIndex(uniformLocation.index);
// attempting to write an array to a non-array uniform is an INVALID_OPERATION
if (!uniform.isArray() && count > 1)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
*uniformOut = &uniform;
return true;
}
bool ValidateUniform1ivValue(ValidationContext *context,
GLenum uniformType,
GLsizei count,
const GLint *value)
{
// Value type is GL_INT, because we only get here from glUniform1i{v}.
// It is compatible with INT or BOOL.
// Do these cheap tests first, for a little extra speed.
if (GL_INT == uniformType || GL_BOOL == uniformType)
{
return true;
}
if (IsSamplerType(uniformType))
{
// Check that the values are in range.
const GLint max = context->getCaps().maxCombinedTextureImageUnits;
for (GLsizei i = 0; i < count; ++i)
{
if (value[i] < 0 || value[i] >= max)
{
context->handleError(Error(GL_INVALID_VALUE, "sampler uniform value out of range"));
return false;
}
}
return true;
}
context->handleError(Error(GL_INVALID_OPERATION, "wrong type of value for uniform"));
return false;
}
bool ValidateUniformValue(ValidationContext *context, GLenum valueType, GLenum uniformType)
{
// Check that the value type is compatible with uniform type.
// Do the cheaper test first, for a little extra speed.
if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType)
{
return true;
}
context->handleError(Error(GL_INVALID_OPERATION, "wrong type of value for uniform"));
return false;
}
bool ValidateUniformMatrixValue(ValidationContext *context, GLenum valueType, GLenum uniformType)
{
// Check that the value type is compatible with uniform type.
if (valueType == uniformType)
{
return true;
}
context->handleError(Error(GL_INVALID_OPERATION, "wrong type of value for uniform"));
return false;
}
} // anonymous namespace
bool ValidTextureTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP:
return true;
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
return (context->getClientMajorVersion() >= 3);
case GL_TEXTURE_2D_MULTISAMPLE:
return (context->getClientVersion() >= Version(3, 1));
default:
return false;
}
}
bool ValidTexture2DTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP:
return true;
default:
return false;
}
}
bool ValidTexture3DTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
return (context->getClientMajorVersion() >= 3);
default:
return false;
}
}
// Most texture GL calls are not compatible with external textures, so we have a separate validation
// function for use in the GL calls that do
bool ValidTextureExternalTarget(const ValidationContext *context, GLenum target)
{
return (target == GL_TEXTURE_EXTERNAL_OES) &&
(context->getExtensions().eglImageExternal ||
context->getExtensions().eglStreamConsumerExternal);
}
// This function differs from ValidTextureTarget in that the target must be
// usable as the destination of a 2D operation-- so a cube face is valid, but
// GL_TEXTURE_CUBE_MAP is not.
// Note: duplicate of IsInternalTextureTarget
bool ValidTexture2DDestinationTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
return true;
default:
return false;
}
}
bool ValidateDrawElementsInstancedBase(ValidationContext *context,
GLenum mode,
GLsizei count,
GLenum type,
const GLvoid *indices,
GLsizei primcount)
{
if (primcount < 0)
{
context->handleError(Error(GL_INVALID_VALUE, "primcount cannot be negative."));
return false;
}
if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount))
{
return false;
}
// No-op zero primitive count
return (primcount > 0);
}
bool ValidateDrawArraysInstancedBase(Context *context,
GLenum mode,
GLint first,
GLsizei count,
GLsizei primcount)
{
if (primcount < 0)
{
context->handleError(Error(GL_INVALID_VALUE, "primcount cannot be negative."));
return false;
}
if (!ValidateDrawArraysCommon(context, mode, first, count, primcount))
{
return false;
}
// No-op if zero primitive count
return (primcount > 0);
}
bool ValidateDrawInstancedANGLEAndWebGL(ValidationContext *context)
{
// Verify there is at least one active attribute with a divisor of zero
const State &state = context->getGLState();
Program *program = state.getProgram();
const auto &attribs = state.getVertexArray()->getVertexAttributes();
const auto &bindings = state.getVertexArray()->getVertexBindings();
for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++)
{
const VertexAttribute &attrib = attribs[attributeIndex];
const VertexBinding &binding = bindings[attrib.bindingIndex];
if (program->isAttribLocationActive(attributeIndex) && binding.divisor == 0)
{
return true;
}
}
context->handleError(
Error(GL_INVALID_OPERATION, "At least one attribute must have a divisor of zero."));
return false;
}
bool ValidTexture3DDestinationTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
return true;
default:
return false;
}
}
bool ValidTexLevelDestinationTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_TEXTURE_2D:
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
case GL_TEXTURE_3D:
case GL_TEXTURE_2D_ARRAY:
case GL_TEXTURE_2D_MULTISAMPLE:
return true;
default:
return false;
}
}
bool ValidFramebufferTarget(GLenum target)
{
static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER &&
GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER,
"ANGLE framebuffer enums must equal the ES3 framebuffer enums.");
switch (target)
{
case GL_FRAMEBUFFER:
return true;
case GL_READ_FRAMEBUFFER:
return true;
case GL_DRAW_FRAMEBUFFER:
return true;
default:
return false;
}
}
bool ValidBufferTarget(const ValidationContext *context, GLenum target)
{
switch (target)
{
case GL_ARRAY_BUFFER:
case GL_ELEMENT_ARRAY_BUFFER:
return true;
case GL_PIXEL_PACK_BUFFER:
case GL_PIXEL_UNPACK_BUFFER:
return (context->getExtensions().pixelBufferObject ||
context->getClientMajorVersion() >= 3);
case GL_COPY_READ_BUFFER:
case GL_COPY_WRITE_BUFFER:
case GL_TRANSFORM_FEEDBACK_BUFFER:
case GL_UNIFORM_BUFFER:
return (context->getClientMajorVersion() >= 3);
case GL_ATOMIC_COUNTER_BUFFER:
case GL_SHADER_STORAGE_BUFFER:
case GL_DRAW_INDIRECT_BUFFER:
case GL_DISPATCH_INDIRECT_BUFFER:
return context->getClientVersion() >= Version(3, 1);
default:
return false;
}
}
bool ValidMipLevel(const ValidationContext *context, GLenum target, GLint level)
{
const auto &caps = context->getCaps();
size_t maxDimension = 0;
switch (target)
{
case GL_TEXTURE_2D:
maxDimension = caps.max2DTextureSize;
break;
case GL_TEXTURE_CUBE_MAP:
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
maxDimension = caps.maxCubeMapTextureSize;
break;
case GL_TEXTURE_3D:
maxDimension = caps.max3DTextureSize;
break;
case GL_TEXTURE_2D_ARRAY:
maxDimension = caps.max2DTextureSize;
break;
case GL_TEXTURE_2D_MULTISAMPLE:
maxDimension = caps.max2DTextureSize;
break;
default:
UNREACHABLE();
}
return level <= gl::log2(static_cast<int>(maxDimension));
}
bool ValidImageSizeParameters(const ValidationContext *context,
GLenum target,
GLint level,
GLsizei width,
GLsizei height,
GLsizei depth,
bool isSubImage)
{
if (level < 0 || width < 0 || height < 0 || depth < 0)
{
return false;
}
// TexSubImage parameters can be NPOT without textureNPOT extension,
// as long as the destination texture is POT.
bool hasNPOTSupport =
context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0);
if (!isSubImage && !hasNPOTSupport &&
(level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth))))
{
return false;
}
if (!ValidMipLevel(context, target, level))
{
return false;
}
return true;
}
bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat)
{
// List of compressed format that require that the texture size is smaller than or a multiple of
// the compressed block size.
switch (internalFormat)
{
case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE:
case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE:
case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE:
case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE:
case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE:
case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE:
case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE:
case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE:
return true;
default:
return false;
}
}
bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed)
{
return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) ||
(size % blockSize == 0);
}
bool ValidCompressedImageSize(const ValidationContext *context,
GLenum internalFormat,
GLint level,
GLsizei width,
GLsizei height)
{
const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
if (!formatInfo.compressed)
{
return false;
}
if (width < 0 || height < 0)
{
return false;
}
if (CompressedTextureFormatRequiresExactSize(internalFormat))
{
// The ANGLE extensions allow specifying compressed textures with sizes smaller than the
// block size for level 0 but WebGL disallows this.
bool smallerThanBlockSizeAllowed =
level > 0 || !context->getExtensions().webglCompatibility;
if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth,
smallerThanBlockSizeAllowed) ||
!ValidCompressedDimension(height, formatInfo.compressedBlockHeight,
smallerThanBlockSizeAllowed))
{
return false;
}
}
return true;
}
bool ValidCompressedSubImageSize(const ValidationContext *context,
GLenum internalFormat,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
size_t textureWidth,
size_t textureHeight)
{
const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
if (!formatInfo.compressed)
{
return false;
}
if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0)
{
return false;
}
if (CompressedTextureFormatRequiresExactSize(internalFormat))
{
if (xoffset % formatInfo.compressedBlockWidth != 0 ||
yoffset % formatInfo.compressedBlockHeight != 0)
{
return false;
}
// Allowed to either have data that is a multiple of block size or is smaller than the block
// size but fills the entire mip
bool fillsEntireMip = xoffset == 0 && yoffset == 0 &&
static_cast<size_t>(width) == textureWidth &&
static_cast<size_t>(height) == textureHeight;
bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 &&
(height % formatInfo.compressedBlockHeight) == 0;
if (!sizeMultipleOfBlockSize && !fillsEntireMip)
{
return false;
}
}
return true;
}
bool ValidImageDataSize(ValidationContext *context,
GLenum textureTarget,
GLsizei width,
GLsizei height,
GLsizei depth,
GLenum internalFormat,
GLenum type,
const void *pixels,
GLsizei imageSize)
{
gl::Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER);
if (pixelUnpackBuffer == nullptr && imageSize < 0)
{
// Checks are not required
return true;
}
// ...the data would be unpacked from the buffer object such that the memory reads required
// would exceed the data store size.
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type);
const gl::Extents size(width, height, depth);
const auto &unpack = context->getGLState().getUnpackState();
bool targetIs3D = textureTarget == GL_TEXTURE_3D || textureTarget == GL_TEXTURE_2D_ARRAY;
auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D);
if (endByteOrErr.isError())
{
context->handleError(endByteOrErr.getError());
return false;
}
GLuint endByte = endByteOrErr.getResult();
if (pixelUnpackBuffer)
{
CheckedNumeric<size_t> checkedEndByte(endByteOrErr.getResult());
CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels));
checkedEndByte += checkedOffset;
if (!checkedEndByte.IsValid() ||
(checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize())))
{
// Overflow past the end of the buffer
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
}
else
{
ASSERT(imageSize >= 0);
if (pixels == nullptr && imageSize != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "imageSize must be 0 if no texture data is provided."));
return false;
}
if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize))
{
context->handleError(
Error(GL_INVALID_OPERATION, "imageSize must be at least %u.", endByte));
return false;
}
}
return true;
}
bool ValidQueryType(const Context *context, GLenum queryType)
{
static_assert(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT,
"GL extension enums not equal.");
static_assert(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
"GL extension enums not equal.");
switch (queryType)
{
case GL_ANY_SAMPLES_PASSED:
case GL_ANY_SAMPLES_PASSED_CONSERVATIVE:
return true;
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
return (context->getClientMajorVersion() >= 3);
case GL_TIME_ELAPSED_EXT:
return context->getExtensions().disjointTimerQuery;
case GL_COMMANDS_COMPLETED_CHROMIUM:
return context->getExtensions().syncQuery;
default:
return false;
}
}
bool ValidateWebGLVertexAttribPointer(ValidationContext *context,
GLenum type,
GLboolean normalized,
GLsizei stride,
const void *ptr,
bool pureInteger)
{
ASSERT(context->getExtensions().webglCompatibility);
// WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride
// The WebGL API supports vertex attribute data strides up to 255 bytes. A call to
// vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride
// parameter exceeds 255.
constexpr GLsizei kMaxWebGLStride = 255;
if (stride > kMaxWebGLStride)
{
context->handleError(
Error(GL_INVALID_VALUE, "Stride is over the maximum stride allowed by WebGL."));
return false;
}
// WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements
// The offset arguments to drawElements and vertexAttribPointer, and the stride argument to
// vertexAttribPointer, must be a multiple of the size of the data type passed to the call,
// or an INVALID_OPERATION error is generated.
VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger);
size_t typeSize = GetVertexFormatTypeSize(internalType);
ASSERT(isPow2(typeSize) && typeSize > 0);
size_t sizeMask = (typeSize - 1);
if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Offset is not a multiple of the type size."));
return false;
}
if ((stride & sizeMask) != 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Stride is not a multiple of the type size."));
return false;
}
return true;
}
Program *GetValidProgram(ValidationContext *context, GLuint id)
{
// ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will
// generate the error INVALID_VALUE if the provided name is not the name of either a shader
// or program object and INVALID_OPERATION if the provided name identifies an object
// that is not the expected type."
Program *validProgram = context->getProgram(id);
if (!validProgram)
{
if (context->getShader(id))
{
context->handleError(
Error(GL_INVALID_OPERATION, "Expected a program name, but found a shader name"));
}
else
{
context->handleError(Error(GL_INVALID_VALUE, "Program name is not valid"));
}
}
return validProgram;
}
Shader *GetValidShader(ValidationContext *context, GLuint id)
{
// See ValidProgram for spec details.
Shader *validShader = context->getShader(id);
if (!validShader)
{
if (context->getProgram(id))
{
context->handleError(
Error(GL_INVALID_OPERATION, "Expected a shader name, but found a program name"));
}
else
{
context->handleError(Error(GL_INVALID_VALUE, "Shader name is invalid"));
}
}
return validShader;
}
bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment)
{
if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT)
{
const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT);
if (colorAttachment >= context->getCaps().maxColorAttachments)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
}
else
{
switch (attachment)
{
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
break;
case GL_DEPTH_STENCIL_ATTACHMENT:
if (!context->getExtensions().webglCompatibility &&
context->getClientMajorVersion() < 3)
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
}
return true;
}
bool ValidateRenderbufferStorageParametersBase(ValidationContext *context,
GLenum target,
GLsizei samples,
GLenum internalformat,
GLsizei width,
GLsizei height)
{
switch (target)
{
case GL_RENDERBUFFER:
break;
default:
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
if (width < 0 || height < 0 || samples < 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
// Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat);
const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat);
if (!formatCaps.renderable)
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
// ANGLE_framebuffer_multisample does not explicitly state that the internal format must be
// sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains
// only sized internal formats.
const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(convertedInternalFormat);
if (formatInfo.internalFormat == GL_NONE)
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
GLuint handle = context->getGLState().getRenderbufferId();
if (handle == 0)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
return true;
}
bool ValidateFramebufferRenderbufferParameters(gl::Context *context,
GLenum target,
GLenum attachment,
GLenum renderbuffertarget,
GLuint renderbuffer)
{
if (!ValidFramebufferTarget(target))
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target);
ASSERT(framebuffer);
if (framebuffer->id() == 0)
{
context->handleError(
Error(GL_INVALID_OPERATION, "Cannot change default FBO's attachments"));
return false;
}
if (!ValidateAttachmentTarget(context, attachment))
{
return false;
}
// [OpenGL ES 2.0.25] Section 4.4.3 page 112
// [OpenGL ES 3.0.2] Section 4.4.2 page 201
// 'renderbuffer' must be either zero or the name of an existing renderbuffer object of
// type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated.
if (renderbuffer != 0)
{
if (!context->getRenderbuffer(renderbuffer))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
}
return true;
}
bool ValidateBlitFramebufferParameters(ValidationContext *context,
GLint srcX0,
GLint srcY0,
GLint srcX1,
GLint srcY1,
GLint dstX0,
GLint dstY0,
GLint dstX1,
GLint dstY1,
GLbitfield mask,
GLenum filter)
{
switch (filter)
{
case GL_NEAREST:
break;
case GL_LINEAR:
break;
default:
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (mask == 0)
{
// ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
// buffers are copied.
return false;
}
// ES3.0 spec, section 4.3.2 states that linear filtering is only available for the
// color buffer, leaving only nearest being unfiltered from above
if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const auto &glState = context->getGLState();
gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer();
gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer();
if (!readFramebuffer || !drawFramebuffer)
{
context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
if (readFramebuffer->id() == drawFramebuffer->id())
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (readFramebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE)
{
context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
if (drawFramebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE)
{
context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
if (drawFramebuffer->getSamples(context) != 0)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1;
if (mask & GL_COLOR_BUFFER_BIT)
{
const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer();
const Extensions &extensions = context->getExtensions();
if (readColorBuffer)
{
const Format &readFormat = readColorBuffer->getFormat();
for (size_t drawbufferIdx = 0;
drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx)
{
const FramebufferAttachment *attachment =
drawFramebuffer->getDrawBuffer(drawbufferIdx);
if (attachment)
{
const Format &drawFormat = attachment->getFormat();
// The GL ES 3.0.2 spec (pg 193) states that:
// 1) If the read buffer is fixed point format, the draw buffer must be as well
// 2) If the read buffer is an unsigned integer format, the draw buffer must be
// as well
// 3) If the read buffer is a signed integer format, the draw buffer must be as
// well
// Changes with EXT_color_buffer_float:
// Case 1) is changed to fixed point OR floating point
GLenum readComponentType = readFormat.info->componentType;
GLenum drawComponentType = drawFormat.info->componentType;
bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED ||
readComponentType == GL_SIGNED_NORMALIZED);
bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED ||
drawComponentType == GL_SIGNED_NORMALIZED);
if (extensions.colorBufferFloat)
{
bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT);
bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT);
if (readFixedOrFloat != drawFixedOrFloat)
{
context->handleError(Error(GL_INVALID_OPERATION,
"If the read buffer contains fixed-point or "
"floating-point values, the draw buffer "
"must as well."));
return false;
}
}
else if (readFixedPoint != drawFixedPoint)
{
context->handleError(Error(GL_INVALID_OPERATION,
"If the read buffer contains fixed-point "
"values, the draw buffer must as well."));
return false;
}
if (readComponentType == GL_UNSIGNED_INT &&
drawComponentType != GL_UNSIGNED_INT)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (readComponentType == GL_INT && drawComponentType != GL_INT)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (readColorBuffer->getSamples() > 0 &&
(!Format::SameSized(readFormat, drawFormat) || !sameBounds))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (context->getExtensions().webglCompatibility &&
*readColorBuffer == *attachment)
{
context->handleError(
Error(GL_INVALID_OPERATION,
"Read and write color attachments cannot be the same image."));
return false;
}
}
}
if ((readFormat.info->componentType == GL_INT ||
readFormat.info->componentType == GL_UNSIGNED_INT) &&
filter == GL_LINEAR)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
}
// WebGL 2.0 BlitFramebuffer when blitting from a missing attachment
// In OpenGL ES it is undefined what happens when an operation tries to blit from a missing
// attachment and WebGL defines it to be an error. We do the check unconditionally as the
// situation is an application error that would lead to a crash in ANGLE.
else if (drawFramebuffer->hasEnabledDrawBuffer())
{
context->handleError(Error(
GL_INVALID_OPERATION,
"Attempt to read from a missing color attachment of a complete framebuffer."));
return false;
}
}
GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT};
GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT};
for (size_t i = 0; i < 2; i++)
{
if (mask & masks[i])
{
const gl::FramebufferAttachment *readBuffer =
readFramebuffer->getAttachment(attachments[i]);
const gl::FramebufferAttachment *drawBuffer =
drawFramebuffer->getAttachment(attachments[i]);
if (readBuffer && drawBuffer)
{
if (!Format::SameSized(readBuffer->getFormat(), drawBuffer->getFormat()))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (readBuffer->getSamples() > 0 && !sameBounds)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer)
{
context->handleError(Error(
GL_INVALID_OPERATION,
"Read and write depth stencil attachments cannot be the same image."));
return false;
}
}
// WebGL 2.0 BlitFramebuffer when blitting from a missing attachment
else if (drawBuffer)
{
context->handleError(Error(GL_INVALID_OPERATION,
"Attempt to read from a missing depth/stencil "
"attachment of a complete framebuffer."));
return false;
}
}
}
return true;
}
bool ValidateReadPixelsRobustANGLE(ValidationContext *context,
GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLsizei bufSize,
GLsizei *length,
GLsizei *columns,
GLsizei *rows,
void *pixels)
{
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, length,
columns, rows, pixels))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateReadnPixelsEXT(Context *context,
GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLsizei bufSize,
void *pixels)
{
if (bufSize < 0)
{
context->handleError(Error(GL_INVALID_VALUE, "bufSize must be a positive number"));
return false;
}
return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr,
nullptr, nullptr, pixels);
}
bool ValidateReadnPixelsRobustANGLE(ValidationContext *context,
GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
GLsizei bufSize,
GLsizei *length,
GLsizei *columns,
GLsizei *rows,
void *data)
{
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, length,
columns, rows, data))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n)
{
if (!context->getExtensions().occlusionQueryBoolean &&
!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
return ValidateGenOrDelete(context, n);
}
bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n)
{
if (!context->getExtensions().occlusionQueryBoolean &&
!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
return ValidateGenOrDelete(context, n);
}
bool ValidateBeginQueryBase(gl::Context *context, GLenum target, GLuint id)
{
if (!ValidQueryType(context, target))
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid query target"));
return false;
}
if (id == 0)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query id is 0"));
return false;
}
// From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id>
// of zero, if the active query object name for <target> is non-zero (for the
// targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if
// the active query for either target is non-zero), if <id> is the name of an
// existing query object whose type does not match <target>, or if <id> is the
// active query object name for any query type, the error INVALID_OPERATION is
// generated.
// Ensure no other queries are active
// NOTE: If other queries than occlusion are supported, we will need to check
// separately that:
// a) The query ID passed is not the current active query for any target/type
// b) There are no active queries for the requested target (and in the case
// of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT,
// no query may be active for either if glBeginQuery targets either.
if (context->getGLState().isQueryActive(target))
{
context->handleError(Error(GL_INVALID_OPERATION, "Other query is active"));
return false;
}
Query *queryObject = context->getQuery(id, true, target);
// check that name was obtained with glGenQueries
if (!queryObject)
{
context->handleError(Error(GL_INVALID_OPERATION, "Invalid query id"));
return false;
}
// check for type mismatch
if (queryObject->getType() != target)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query type does not match target"));
return false;
}
return true;
}
bool ValidateBeginQueryEXT(gl::Context *context, GLenum target, GLuint id)
{
if (!context->getExtensions().occlusionQueryBoolean &&
!context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
return ValidateBeginQueryBase(context, target, id);
}
bool ValidateEndQueryBase(gl::Context *context, GLenum target)
{
if (!ValidQueryType(context, target))
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid query target"));
return false;
}
const Query *queryObject = context->getGLState().getActiveQuery(target);
if (queryObject == nullptr)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query target not active"));
return false;
}
return true;
}
bool ValidateEndQueryEXT(gl::Context *context, GLenum target)
{
if (!context->getExtensions().occlusionQueryBoolean &&
!context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
return ValidateEndQueryBase(context, target);
}
bool ValidateQueryCounterEXT(Context *context, GLuint id, GLenum target)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Disjoint timer query not enabled"));
return false;
}
if (target != GL_TIMESTAMP_EXT)
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid query target"));
return false;
}
Query *queryObject = context->getQuery(id, true, target);
if (queryObject == nullptr)
{
context->handleError(Error(GL_INVALID_OPERATION, "Invalid query id"));
return false;
}
if (context->getGLState().isQueryActive(queryObject))
{
context->handleError(Error(GL_INVALID_OPERATION, "Query is active"));
return false;
}
return true;
}
bool ValidateGetQueryivBase(Context *context, GLenum target, GLenum pname, GLsizei *numParams)
{
if (numParams)
{
*numParams = 0;
}
if (!ValidQueryType(context, target) && target != GL_TIMESTAMP_EXT)
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid query type"));
return false;
}
switch (pname)
{
case GL_CURRENT_QUERY_EXT:
if (target == GL_TIMESTAMP_EXT)
{
context->handleError(
Error(GL_INVALID_ENUM, "Cannot use current query for timestamp"));
return false;
}
break;
case GL_QUERY_COUNTER_BITS_EXT:
if (!context->getExtensions().disjointTimerQuery ||
(target != GL_TIMESTAMP_EXT && target != GL_TIME_ELAPSED_EXT))
{
context->handleError(Error(GL_INVALID_ENUM, "Invalid pname"));
return false;
}
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Invalid pname"));
return false;
}
if (numParams)
{
// All queries return only one value
*numParams = 1;
}
return true;
}
bool ValidateGetQueryivEXT(Context *context, GLenum target, GLenum pname, GLint *params)
{
if (!context->getExtensions().occlusionQueryBoolean &&
!context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
return ValidateGetQueryivBase(context, target, pname, nullptr);
}
bool ValidateGetQueryivRobustANGLE(Context *context,
GLenum target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateGetQueryivBase(context, target, pname, length))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams)
{
if (numParams)
{
*numParams = 0;
}
Query *queryObject = context->getQuery(id, false, GL_NONE);
if (!queryObject)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query does not exist"));
return false;
}
if (context->getGLState().isQueryActive(queryObject))
{
context->handleError(Error(GL_INVALID_OPERATION, "Query currently active"));
return false;
}
switch (pname)
{
case GL_QUERY_RESULT_EXT:
case GL_QUERY_RESULT_AVAILABLE_EXT:
break;
default:
context->handleError(Error(GL_INVALID_ENUM, "Invalid pname enum"));
return false;
}
if (numParams)
{
*numParams = 1;
}
return true;
}
bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled"));
return false;
}
return ValidateGetQueryObjectValueBase(context, id, pname, nullptr);
}
bool ValidateGetQueryObjectivRobustANGLE(Context *context,
GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint *params)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled"));
return false;
}
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateGetQueryObjectValueBase(context, id, pname, length))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params)
{
if (!context->getExtensions().disjointTimerQuery &&
!context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
return ValidateGetQueryObjectValueBase(context, id, pname, nullptr);
}
bool ValidateGetQueryObjectuivRobustANGLE(Context *context,
GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLuint *params)
{
if (!context->getExtensions().disjointTimerQuery &&
!context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled"));
return false;
}
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateGetQueryObjectValueBase(context, id, pname, length))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled"));
return false;
}
return ValidateGetQueryObjectValueBase(context, id, pname, nullptr);
}
bool ValidateGetQueryObjecti64vRobustANGLE(Context *context,
GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLint64 *params)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled"));
return false;
}
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateGetQueryObjectValueBase(context, id, pname, length))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled"));
return false;
}
return ValidateGetQueryObjectValueBase(context, id, pname, nullptr);
}
bool ValidateGetQueryObjectui64vRobustANGLE(Context *context,
GLuint id,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
GLuint64 *params)
{
if (!context->getExtensions().disjointTimerQuery)
{
context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled"));
return false;
}
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateGetQueryObjectValueBase(context, id, pname, length))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *length))
{
return false;
}
return true;
}
bool ValidateProgramUniform(gl::Context *context,
GLenum valueType,
GLuint program,
GLint location,
GLsizei count)
{
// Check for ES31 program uniform entry points
if (context->getClientVersion() < Version(3, 1))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const LinkedUniform *uniform = nullptr;
gl::Program *programObject = GetValidProgram(context, program);
return ValidateUniformCommonBase(context, programObject, location, count, &uniform) &&
ValidateUniformValue(context, valueType, uniform->type);
}
bool ValidateProgramUniform1iv(gl::Context *context,
GLuint program,
GLint location,
GLsizei count,
const GLint *value)
{
// Check for ES31 program uniform entry points
if (context->getClientVersion() < Version(3, 1))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const LinkedUniform *uniform = nullptr;
gl::Program *programObject = GetValidProgram(context, program);
return ValidateUniformCommonBase(context, programObject, location, count, &uniform) &&
ValidateUniform1ivValue(context, uniform->type, count, value);
}
bool ValidateProgramUniformMatrix(gl::Context *context,
GLenum valueType,
GLuint program,
GLint location,
GLsizei count,
GLboolean transpose)
{
// Check for ES31 program uniform entry points
if (context->getClientVersion() < Version(3, 1))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const LinkedUniform *uniform = nullptr;
gl::Program *programObject = GetValidProgram(context, program);
return ValidateUniformCommonBase(context, programObject, location, count, &uniform) &&
ValidateUniformMatrixValue(context, valueType, uniform->type);
}
bool ValidateUniform(ValidationContext *context, GLenum valueType, GLint location, GLsizei count)
{
// Check for ES3 uniform entry points
if (VariableComponentType(valueType) == GL_UNSIGNED_INT && context->getClientMajorVersion() < 3)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const LinkedUniform *uniform = nullptr;
gl::Program *programObject = context->getGLState().getProgram();
return ValidateUniformCommonBase(context, programObject, location, count, &uniform) &&
ValidateUniformValue(context, valueType, uniform->type);
}
bool ValidateUniform1iv(ValidationContext *context,
GLint location,
GLsizei count,
const GLint *value)
{
const LinkedUniform *uniform = nullptr;
gl::Program *programObject = context->getGLState().getProgram();
return ValidateUniformCommonBase(context, programObject, location, count, &uniform) &&
ValidateUniform1ivValue(context, uniform->type, count, value);
}
bool ValidateUniformMatrix(ValidationContext *context,
GLenum valueType,
GLint location,
GLsizei count,
GLboolean transpose)
{
// Check for ES3 uniform entry points
int rows = VariableRowCount(valueType);
int cols = VariableColumnCount(valueType);
if (rows != cols && context->getClientMajorVersion() < 3)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (transpose != GL_FALSE && context->getClientMajorVersion() < 3)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
const LinkedUniform *uniform = nullptr;
gl::Program *programObject = context->getGLState().getProgram();
return ValidateUniformCommonBase(context, programObject, location, count, &uniform) &&
ValidateUniformMatrixValue(context, valueType, uniform->type);
}
bool ValidateStateQuery(ValidationContext *context,
GLenum pname,
GLenum *nativeType,
unsigned int *numParams)
{
if (!context->getQueryParameterInfo(pname, nativeType, numParams))
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
const Caps &caps = context->getCaps();
if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15)
{
unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0);
if (colorAttachment >= caps.maxDrawBuffers)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
}
switch (pname)
{
case GL_TEXTURE_BINDING_2D:
case GL_TEXTURE_BINDING_CUBE_MAP:
case GL_TEXTURE_BINDING_3D:
case GL_TEXTURE_BINDING_2D_ARRAY:
break;
case GL_TEXTURE_BINDING_EXTERNAL_OES:
if (!context->getExtensions().eglStreamConsumerExternal &&
!context->getExtensions().eglImageExternal)
{
context->handleError(Error(GL_INVALID_ENUM,
"Neither NV_EGL_stream_consumer_external nor "
"GL_OES_EGL_image_external extensions enabled"));
return false;
}
break;
case GL_IMPLEMENTATION_COLOR_READ_TYPE:
case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
{
if (context->getGLState().getReadFramebuffer()->checkStatus(context) !=
GL_FRAMEBUFFER_COMPLETE)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const Framebuffer *framebuffer = context->getGLState().getReadFramebuffer();
ASSERT(framebuffer);
if (framebuffer->getReadBufferState() == GL_NONE)
{
context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE"));
return false;
}
const FramebufferAttachment *attachment = framebuffer->getReadColorbuffer();
if (!attachment)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
}
break;
default:
break;
}
// pname is valid, but there are no parameters to return
if (*numParams == 0)
{
return false;
}
return true;
}
bool ValidateRobustStateQuery(ValidationContext *context,
GLenum pname,
GLsizei bufSize,
GLenum *nativeType,
unsigned int *numParams)
{
if (!ValidateRobustEntryPoint(context, bufSize))
{
return false;
}
if (!ValidateStateQuery(context, pname, nativeType, numParams))
{
return false;
}
if (!ValidateRobustBufferSize(context, bufSize, *numParams))
{
return false;
}
return true;
}
bool ValidateCopyTexImageParametersBase(ValidationContext *context,
GLenum target,
GLint level,
GLenum internalformat,
bool isSubImage,
GLint xoffset,
GLint yoffset,
GLint zoffset,
GLint x,
GLint y,
GLsizei width,
GLsizei height,
GLint border,
Format *textureFormatOut)
{
if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
std::numeric_limits<GLsizei>::max() - yoffset < height)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (border != 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (!ValidMipLevel(context, target, level))
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
const auto &state = context->getGLState();
auto readFramebuffer = state.getReadFramebuffer();
if (readFramebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE)
{
context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
if (readFramebuffer->id() != 0 && readFramebuffer->getSamples(context) != 0)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (readFramebuffer->getReadBufferState() == GL_NONE)
{
context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE"));
return false;
}
// WebGL 1.0 [Section 6.26] Reading From a Missing Attachment
// In OpenGL ES it is undefined what happens when an operation tries to read from a missing
// attachment and WebGL defines it to be an error. We do the check unconditionally as the
// situation is an application error that would lead to a crash in ANGLE.
if (readFramebuffer->getReadColorbuffer() == nullptr)
{
context->handleError(Error(GL_INVALID_OPERATION, "Missing read attachment"));
return false;
}
const gl::Caps &caps = context->getCaps();
GLuint maxDimension = 0;
switch (target)
{
case GL_TEXTURE_2D:
maxDimension = caps.max2DTextureSize;
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
maxDimension = caps.maxCubeMapTextureSize;
break;
case GL_TEXTURE_2D_ARRAY:
maxDimension = caps.max2DTextureSize;
break;
case GL_TEXTURE_3D:
maxDimension = caps.max3DTextureSize;
break;
default:
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
gl::Texture *texture =
state.getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
if (!texture)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (texture->getImmutableFormat() && !isSubImage)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
const gl::InternalFormat &formatInfo =
gl::GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE);
if (formatInfo.depthBits > 0 || formatInfo.compressed)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (isSubImage)
{
if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) ||
static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) ||
static_cast<size_t>(zoffset) >= texture->getDepth(target, level))
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
}
else
{
if (IsCubeMapTextureTarget(target) && width != height)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions()))
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
int maxLevelDimension = (maxDimension >> level);
if (static_cast<int>(width) > maxLevelDimension ||
static_cast<int>(height) > maxLevelDimension)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
}
if (textureFormatOut)
{
*textureFormatOut = texture->getFormat(target, level);
}
// Detect texture copying feedback loops for WebGL.
if (context->getExtensions().webglCompatibility)
{
if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset))
{
context->handleError(Error(GL_INVALID_OPERATION,
"Texture copying feedback loop formed between Framebuffer "
"and specified Texture level."));
return false;
}
}
return true;
}
bool ValidateDrawBase(ValidationContext *context, GLenum mode, GLsizei count)
{
switch (mode)
{
case GL_POINTS:
case GL_LINES:
case GL_LINE_LOOP:
case GL_LINE_STRIP:
case GL_TRIANGLES:
case GL_TRIANGLE_STRIP:
case GL_TRIANGLE_FAN:
break;
default:
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
if (count < 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
const State &state = context->getGLState();
// Check for mapped buffers
if (state.hasMappedBuffer(GL_ARRAY_BUFFER))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
// Note: these separate values are not supported in WebGL, due to D3D's limitations. See
// Section 6.10 of the WebGL 1.0 spec.
Framebuffer *framebuffer = state.getDrawFramebuffer();
if (context->getLimitations().noSeparateStencilRefsAndMasks ||
context->getExtensions().webglCompatibility)
{
const FramebufferAttachment *dsAttachment =
framebuffer->getStencilOrDepthStencilAttachment();
GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0;
GLuint minimumRequiredStencilMask = (1 << stencilBits) - 1;
const DepthStencilState &depthStencilState = state.getDepthStencilState();
bool differentRefs = state.getStencilRef() != state.getStencilBackRef();
bool differentWritemasks =
(depthStencilState.stencilWritemask & minimumRequiredStencilMask) !=
(depthStencilState.stencilBackWritemask & minimumRequiredStencilMask);
bool differentMasks = (depthStencilState.stencilMask & minimumRequiredStencilMask) !=
(depthStencilState.stencilBackMask & minimumRequiredStencilMask);
if (differentRefs || differentWritemasks || differentMasks)
{
if (!context->getExtensions().webglCompatibility)
{
ERR() << "This ANGLE implementation does not support separate front/back stencil "
"writemasks, reference values, or stencil mask values.";
}
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
}
if (framebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE)
{
context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION));
return false;
}
gl::Program *program = state.getProgram();
if (!program)
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (!program->validateSamplers(nullptr, context->getCaps()))
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
// Uniform buffer validation
for (unsigned int uniformBlockIndex = 0;
uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++)
{
const gl::UniformBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex);
GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex);
const OffsetBindingPointer<Buffer> &uniformBuffer =
state.getIndexedUniformBuffer(blockBinding);
if (uniformBuffer.get() == nullptr)
{
// undefined behaviour
context->handleError(
Error(GL_INVALID_OPERATION,
"It is undefined behaviour to have a used but unbound uniform buffer."));
return false;
}
size_t uniformBufferSize = uniformBuffer.getSize();
if (uniformBufferSize == 0)
{
// Bind the whole buffer.
uniformBufferSize = static_cast<size_t>(uniformBuffer->getSize());
}
if (uniformBufferSize < uniformBlock.dataSize)
{
// undefined behaviour
context->handleError(
Error(GL_INVALID_OPERATION,
"It is undefined behaviour to use a uniform buffer that is too small."));
return false;
}
}
// Detect rendering feedback loops for WebGL.
if (context->getExtensions().webglCompatibility)
{
if (framebuffer->formsRenderingFeedbackLoopWith(state))
{
context->handleError(
Error(GL_INVALID_OPERATION,
"Rendering feedback loop formed between Framebuffer and active Texture."));
return false;
}
}
// No-op if zero count
return (count > 0);
}
bool ValidateDrawArraysCommon(ValidationContext *context,
GLenum mode,
GLint first,
GLsizei count,
GLsizei primcount)
{
if (first < 0)
{
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
const State &state = context->getGLState();
gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
if (curTransformFeedback && curTransformFeedback->isActive() &&
!curTransformFeedback->isPaused() && curTransformFeedback->getPrimitiveMode() != mode)
{
// It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode
// that does not match the current transform feedback object's draw mode (if transform
// feedback
// is active), (3.0.2, section 2.14, pg 86)
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
if (!ValidateDrawBase(context, mode, count))