Commit ef300b15 by Jamie Madill Committed by Commit Bot

Refactor some entry point stuff.

BUG=angleproject:747 Change-Id: I80634b5e6de8bae1433c49a56a92d3b19c24e11d Reviewed-on: https://chromium-review.googlesource.com/395568 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 740d9020
...@@ -817,16 +817,6 @@ Buffer *Context::getBuffer(GLuint handle) const ...@@ -817,16 +817,6 @@ Buffer *Context::getBuffer(GLuint handle) const
return mResourceManager->getBuffer(handle); return mResourceManager->getBuffer(handle);
} }
Shader *Context::getShader(GLuint handle) const
{
return mResourceManager->getShader(handle);
}
Program *Context::getProgram(GLuint handle) const
{
return mResourceManager->getProgram(handle);
}
Texture *Context::getTexture(GLuint handle) const Texture *Context::getTexture(GLuint handle) const
{ {
return mResourceManager->getTexture(handle); return mResourceManager->getTexture(handle);
...@@ -3559,4 +3549,12 @@ void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, con ...@@ -3559,4 +3549,12 @@ void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, con
handleError(buffer->bufferSubData(target, data, size, offset)); handleError(buffer->bufferSubData(target, data, size, offset));
} }
void Context::attachShader(GLuint program, GLuint shader)
{
auto programObject = mResourceManager->getProgram(program);
auto shaderObject = mResourceManager->getShader(shader);
ASSERT(programObject && shaderObject);
programObject->attachShader(shaderObject);
}
} // namespace gl } // namespace gl
...@@ -165,8 +165,6 @@ class Context final : public ValidationContext ...@@ -165,8 +165,6 @@ class Context final : public ValidationContext
Buffer *getBuffer(GLuint handle) const; Buffer *getBuffer(GLuint handle) const;
FenceNV *getFenceNV(GLuint handle); FenceNV *getFenceNV(GLuint handle);
FenceSync *getFenceSync(GLsync handle) const; FenceSync *getFenceSync(GLsync handle) const;
Shader *getShader(GLuint handle) const;
Program *getProgram(GLuint handle) const;
Texture *getTexture(GLuint handle) const; Texture *getTexture(GLuint handle) const;
Framebuffer *getFramebuffer(GLuint handle) const; Framebuffer *getFramebuffer(GLuint handle) const;
Renderbuffer *getRenderbuffer(GLuint handle) const; Renderbuffer *getRenderbuffer(GLuint handle) const;
...@@ -576,6 +574,7 @@ class Context final : public ValidationContext ...@@ -576,6 +574,7 @@ class Context final : public ValidationContext
void bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage); void bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage);
void bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data); void bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data);
void attachShader(GLuint program, GLuint shader);
void handleError(const Error &error) override; void handleError(const Error &error) override;
......
...@@ -576,4 +576,14 @@ bool ValidationContext::getIndexedQueryParameterInfo(GLenum target, ...@@ -576,4 +576,14 @@ bool ValidationContext::getIndexedQueryParameterInfo(GLenum target,
return false; return false;
} }
Program *ValidationContext::getProgram(GLuint handle) const
{
return mState.mResourceManager->getProgram(handle);
}
Shader *ValidationContext::getShader(GLuint handle) const
{
return mState.mResourceManager->getShader(handle);
}
} // namespace gl } // namespace gl
...@@ -110,6 +110,9 @@ class ValidationContext : angle::NonCopyable ...@@ -110,6 +110,9 @@ class ValidationContext : angle::NonCopyable
bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams); bool getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams);
bool getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams); bool getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams);
Program *getProgram(GLuint handle) const;
Shader *getShader(GLuint handle) const;
protected: protected:
ContextState mState; ContextState mState;
bool mSkipValidation; bool mSkipValidation;
......
...@@ -377,39 +377,27 @@ const std::string &Program::getLabel() const ...@@ -377,39 +377,27 @@ const std::string &Program::getLabel() const
return mState.mLabel; return mState.mLabel;
} }
bool Program::attachShader(Shader *shader) void Program::attachShader(Shader *shader)
{ {
switch (shader->getType()) switch (shader->getType())
{ {
case GL_VERTEX_SHADER: case GL_VERTEX_SHADER:
{ {
if (mState.mAttachedVertexShader) ASSERT(!mState.mAttachedVertexShader);
{
return false;
}
mState.mAttachedVertexShader = shader; mState.mAttachedVertexShader = shader;
mState.mAttachedVertexShader->addRef(); mState.mAttachedVertexShader->addRef();
break; break;
} }
case GL_FRAGMENT_SHADER: case GL_FRAGMENT_SHADER:
{ {
if (mState.mAttachedFragmentShader) ASSERT(!mState.mAttachedFragmentShader);
{
return false;
}
mState.mAttachedFragmentShader = shader; mState.mAttachedFragmentShader = shader;
mState.mAttachedFragmentShader->addRef(); mState.mAttachedFragmentShader->addRef();
break; break;
} }
case GL_COMPUTE_SHADER: case GL_COMPUTE_SHADER:
{ {
if (mState.mAttachedComputeShader) ASSERT(!mState.mAttachedComputeShader);
{
return false;
}
mState.mAttachedComputeShader = shader; mState.mAttachedComputeShader = shader;
mState.mAttachedComputeShader->addRef(); mState.mAttachedComputeShader->addRef();
break; break;
...@@ -417,8 +405,6 @@ bool Program::attachShader(Shader *shader) ...@@ -417,8 +405,6 @@ bool Program::attachShader(Shader *shader)
default: default:
UNREACHABLE(); UNREACHABLE();
} }
return true;
} }
bool Program::detachShader(Shader *shader) bool Program::detachShader(Shader *shader)
......
...@@ -243,10 +243,14 @@ class Program final : angle::NonCopyable, public LabeledObject ...@@ -243,10 +243,14 @@ class Program final : angle::NonCopyable, public LabeledObject
rx::ProgramImpl *getImplementation() const { return mProgram; } rx::ProgramImpl *getImplementation() const { return mProgram; }
bool attachShader(Shader *shader); void attachShader(Shader *shader);
bool detachShader(Shader *shader); bool detachShader(Shader *shader);
int getAttachedShadersCount() const; int getAttachedShadersCount() const;
const Shader *getAttachedVertexShader() const { return mState.mAttachedVertexShader; }
const Shader *getAttachedFragmentShader() const { return mState.mAttachedFragmentShader; }
const Shader *getAttachedComputeShader() const { return mState.mAttachedComputeShader; }
void bindAttributeLocation(GLuint index, const char *name); void bindAttributeLocation(GLuint index, const char *name);
void bindUniformLocation(GLuint index, const char *name); void bindUniformLocation(GLuint index, const char *name);
......
...@@ -309,7 +309,7 @@ Buffer *ResourceManager::getBuffer(unsigned int handle) ...@@ -309,7 +309,7 @@ Buffer *ResourceManager::getBuffer(unsigned int handle)
} }
} }
Shader *ResourceManager::getShader(unsigned int handle) Shader *ResourceManager::getShader(unsigned int handle) const
{ {
auto shader = mShaderMap.find(handle); auto shader = mShaderMap.find(handle);
......
...@@ -64,7 +64,7 @@ class ResourceManager : angle::NonCopyable ...@@ -64,7 +64,7 @@ class ResourceManager : angle::NonCopyable
void deletePaths(GLuint first, GLsizei range); void deletePaths(GLuint first, GLsizei range);
Buffer *getBuffer(GLuint handle); Buffer *getBuffer(GLuint handle);
Shader *getShader(GLuint handle); Shader *getShader(GLuint handle) const;
Program *getProgram(GLuint handle) const; Program *getProgram(GLuint handle) const;
Texture *getTexture(GLuint handle); Texture *getTexture(GLuint handle);
Renderbuffer *getRenderbuffer(GLuint handle); Renderbuffer *getRenderbuffer(GLuint handle);
......
...@@ -722,7 +722,7 @@ bool ValidQueryType(const Context *context, GLenum queryType) ...@@ -722,7 +722,7 @@ bool ValidQueryType(const Context *context, GLenum queryType)
} }
} }
Program *GetValidProgram(Context *context, GLuint id) Program *GetValidProgram(ValidationContext *context, GLuint id)
{ {
// ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will generate the // 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 // error INVALID_VALUE if the provided name is not the name of either a shader or program object and
...@@ -746,7 +746,7 @@ Program *GetValidProgram(Context *context, GLuint id) ...@@ -746,7 +746,7 @@ Program *GetValidProgram(Context *context, GLuint id)
return validProgram; return validProgram;
} }
Shader *GetValidShader(Context *context, GLuint id) Shader *GetValidShader(ValidationContext *context, GLuint id)
{ {
// See ValidProgram for spec details. // See ValidProgram for spec details.
......
...@@ -65,12 +65,12 @@ bool ValidQueryType(const Context *context, GLenum queryType); ...@@ -65,12 +65,12 @@ bool ValidQueryType(const Context *context, GLenum queryType);
// Returns valid program if id is a valid program name // Returns valid program if id is a valid program name
// Errors INVALID_OPERATION if valid shader is given and returns NULL // Errors INVALID_OPERATION if valid shader is given and returns NULL
// Errors INVALID_VALUE otherwise and returns NULL // Errors INVALID_VALUE otherwise and returns NULL
Program *GetValidProgram(Context *context, GLuint id); Program *GetValidProgram(ValidationContext *context, GLuint id);
// Returns valid shader if id is a valid shader name // Returns valid shader if id is a valid shader name
// Errors INVALID_OPERATION if valid program is given and returns NULL // Errors INVALID_OPERATION if valid program is given and returns NULL
// Errors INVALID_VALUE otherwise and returns NULL // Errors INVALID_VALUE otherwise and returns NULL
Shader *GetValidShader(Context *context, GLuint id); Shader *GetValidShader(ValidationContext *context, GLuint id);
bool ValidateAttachmentTarget(Context *context, GLenum attachment); bool ValidateAttachmentTarget(Context *context, GLenum attachment);
bool ValidateRenderbufferStorageParametersBase(Context *context, GLenum target, GLsizei samples, bool ValidateRenderbufferStorageParametersBase(Context *context, GLenum target, GLsizei samples,
......
...@@ -10,19 +10,19 @@ ...@@ -10,19 +10,19 @@
#include <cstdint> #include <cstdint>
#include "libANGLE/validationES.h" #include "common/mathutil.h"
#include "libANGLE/validationES3.h" #include "common/string_utils.h"
#include "common/utilities.h"
#include "libANGLE/Context.h" #include "libANGLE/Context.h"
#include "libANGLE/Texture.h" #include "libANGLE/Texture.h"
#include "libANGLE/Framebuffer.h" #include "libANGLE/Framebuffer.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/formatutils.h"
#include "libANGLE/FramebufferAttachment.h" #include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Renderbuffer.h"
#include "libANGLE/Shader.h"
#include "libANGLE/Uniform.h" #include "libANGLE/Uniform.h"
#include "libANGLE/formatutils.h"
#include "common/mathutil.h" #include "libANGLE/validationES.h"
#include "common/string_utils.h" #include "libANGLE/validationES3.h"
#include "common/utilities.h"
namespace gl namespace gl
{ {
...@@ -3526,4 +3526,67 @@ bool ValidateEnableExtensionANGLE(ValidationContext *context, const GLchar *name ...@@ -3526,4 +3526,67 @@ bool ValidateEnableExtensionANGLE(ValidationContext *context, const GLchar *name
return true; return true;
} }
bool ValidateActiveTexture(ValidationContext *context, GLenum texture)
{
if (texture < GL_TEXTURE0 ||
texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1)
{
context->handleError(Error(GL_INVALID_ENUM));
return false;
}
return true;
}
bool ValidateAttachShader(ValidationContext *context, GLuint program, GLuint shader)
{
Program *programObject = GetValidProgram(context, program);
if (!programObject)
{
return false;
}
Shader *shaderObject = GetValidShader(context, shader);
if (!shaderObject)
{
return false;
}
switch (shaderObject->getType())
{
case GL_VERTEX_SHADER:
{
if (programObject->getAttachedVertexShader())
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
break;
}
case GL_FRAGMENT_SHADER:
{
if (programObject->getAttachedFragmentShader())
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
break;
}
case GL_COMPUTE_SHADER:
{
if (programObject->getAttachedComputeShader())
{
context->handleError(Error(GL_INVALID_OPERATION));
return false;
}
break;
}
default:
UNREACHABLE();
break;
}
return true;
}
} // namespace gl } // namespace gl
...@@ -341,6 +341,9 @@ bool ValidateBufferSubData(ValidationContext *context, ...@@ -341,6 +341,9 @@ bool ValidateBufferSubData(ValidationContext *context,
bool ValidateEnableExtensionANGLE(ValidationContext *context, const GLchar *name); bool ValidateEnableExtensionANGLE(ValidationContext *context, const GLchar *name);
bool ValidateActiveTexture(ValidationContext *context, GLenum texture);
bool ValidateAttachShader(ValidationContext *context, GLuint program, GLuint shader);
} // namespace gl } // namespace gl
#endif // LIBANGLE_VALIDATION_ES2_H_ #endif // LIBANGLE_VALIDATION_ES2_H_
...@@ -44,9 +44,8 @@ void GL_APIENTRY ActiveTexture(GLenum texture) ...@@ -44,9 +44,8 @@ void GL_APIENTRY ActiveTexture(GLenum texture)
Context *context = GetValidGlobalContext(); Context *context = GetValidGlobalContext();
if (context) if (context)
{ {
if (texture < GL_TEXTURE0 || texture > GL_TEXTURE0 + context->getCaps().maxCombinedTextureImageUnits - 1) if (!context->skipValidation() && !ValidateActiveTexture(context, texture))
{ {
context->handleError(Error(GL_INVALID_ENUM));
return; return;
} }
...@@ -61,23 +60,12 @@ void GL_APIENTRY AttachShader(GLuint program, GLuint shader) ...@@ -61,23 +60,12 @@ void GL_APIENTRY AttachShader(GLuint program, GLuint shader)
Context *context = GetValidGlobalContext(); Context *context = GetValidGlobalContext();
if (context) if (context)
{ {
Program *programObject = GetValidProgram(context, program); if (!context->skipValidation() && !ValidateAttachShader(context, program, shader))
if (!programObject)
{ {
return; return;
} }
Shader *shaderObject = GetValidShader(context, shader); context->attachShader(program, shader);
if (!shaderObject)
{
return;
}
if (!programObject->attachShader(shaderObject))
{
context->handleError(Error(GL_INVALID_OPERATION));
return;
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment