Edit

kc3-lang/angle/src/libANGLE/validationESEXT.cpp

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2019-10-28 13:51:42
    Hash : dfc20daf
    Message : Plumb more logic for ANGLE_get_image. Also implements and tests validation / negative API. Bug: angleproject:3944 Change-Id: I3385a4255f4fab6a12eee2abfa5ffcce2107359a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1879961 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>

  • src/libANGLE/validationESEXT.cpp
  • //
    // Copyright 2019 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.
    //
    // validationESEXT.cpp: Validation functions for OpenGL ES extension entry points.
    
    #include "libANGLE/validationESEXT_autogen.h"
    
    #include "libANGLE/Context.h"
    #include "libANGLE/ErrorStrings.h"
    #include "libANGLE/validationES.h"
    
    namespace gl
    {
    using namespace err;
    
    namespace
    {
    template <typename ObjectT>
    bool ValidateGetImageFormatAndType(Context *context, ObjectT *obj, GLenum format, GLenum type)
    {
        GLenum implFormat = obj->getImplementationColorReadFormat(context);
        if (!ValidES3Format(format) && (format != implFormat || format == GL_NONE))
        {
            context->validationError(GL_INVALID_ENUM, kInvalidFormat);
            return false;
        }
    
        GLenum implType = obj->getImplementationColorReadType(context);
        if (!ValidES3Type(type) && (type != implType || type == GL_NONE))
        {
            context->validationError(GL_INVALID_ENUM, kInvalidType);
            return false;
        }
    
        // Format/type combinations are not yet validated.
    
        return true;
    }
    
    }  // namespace
    
    bool ValidateGetTexImageANGLE(Context *context,
                                  TextureTarget target,
                                  GLint level,
                                  GLenum format,
                                  GLenum type,
                                  void *pixels)
    {
        if (!context->getExtensions().getImageANGLE)
        {
            context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
            return false;
        }
    
        if (!ValidTexture2DDestinationTarget(context, target) &&
            !ValidTexture3DDestinationTarget(context, target))
        {
            context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget);
            return false;
        }
    
        if (level < 0)
        {
            context->validationError(GL_INVALID_VALUE, kNegativeLevel);
            return false;
        }
    
        TextureType textureType = TextureTargetToType(target);
        if (!ValidMipLevel(context, textureType, level))
        {
            context->validationError(GL_INVALID_VALUE, kInvalidMipLevel);
            return false;
        }
    
        Texture *texture = context->getTextureByTarget(target);
    
        if (!ValidateGetImageFormatAndType(context, texture, format, type))
        {
            return false;
        }
    
        GLsizei width  = static_cast<GLsizei>(texture->getWidth(target, level));
        GLsizei height = static_cast<GLsizei>(texture->getHeight(target, level));
        if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
        {
            return false;
        }
    
        return true;
    }
    
    bool ValidateGetRenderbufferImageANGLE(Context *context,
                                           GLenum target,
                                           GLenum format,
                                           GLenum type,
                                           void *pixels)
    {
        if (!context->getExtensions().getImageANGLE)
        {
            context->validationError(GL_INVALID_OPERATION, kGetImageExtensionNotEnabled);
            return false;
        }
    
        if (target != GL_RENDERBUFFER)
        {
            context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget);
            return false;
        }
    
        Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer();
    
        if (!ValidateGetImageFormatAndType(context, renderbuffer, format, type))
        {
            return false;
        }
    
        GLsizei width  = renderbuffer->getWidth();
        GLsizei height = renderbuffer->getHeight();
        if (!ValidatePixelPack(context, format, type, 0, 0, width, height, -1, nullptr, pixels))
        {
            return false;
        }
    
        return true;
    }
    }  // namespace gl