Commit 8e34494f by Jamie Madill

Share data between VertexArray and Impl.

Using the same design as for the Framebuffer::Data helper, we can use a struct to share between the object and the Impl. This also gives the Impl access to the maxEnabledAttrib, and saves some duplicated storage. BUG=angleproject:1040 TEST=WebGL CTS, end2end_tests, unittests Change-Id: I55c91e8a5f3dcae302cab441182320aafd5375ef Reviewed-on: https://chromium-review.googlesource.com/283930Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 0d208976
...@@ -284,7 +284,7 @@ GLuint Context::createVertexArray() ...@@ -284,7 +284,7 @@ GLuint Context::createVertexArray()
// Although the spec states VAO state is not initialized until the object is bound, // Although the spec states VAO state is not initialized until the object is bound,
// we create it immediately. The resulting behaviour is transparent to the application, // we create it immediately. The resulting behaviour is transparent to the application,
// since it's not currently possible to access the state until the object is bound. // since it's not currently possible to access the state until the object is bound.
VertexArray *vertexArray = new VertexArray(mRenderer->createVertexArray(), handle, MAX_VERTEX_ATTRIBS); VertexArray *vertexArray = new VertexArray(mRenderer, handle, MAX_VERTEX_ATTRIBS);
mVertexArrayMap[handle] = vertexArray; mVertexArrayMap[handle] = vertexArray;
return handle; return handle;
} }
...@@ -588,7 +588,7 @@ void Context::bindVertexArray(GLuint vertexArray) ...@@ -588,7 +588,7 @@ void Context::bindVertexArray(GLuint vertexArray)
{ {
if (!getVertexArray(vertexArray)) if (!getVertexArray(vertexArray))
{ {
VertexArray *vertexArrayObject = new VertexArray(mRenderer->createVertexArray(), vertexArray, MAX_VERTEX_ATTRIBS); VertexArray *vertexArrayObject = new VertexArray(mRenderer, vertexArray, MAX_VERTEX_ATTRIBS);
mVertexArrayMap[vertexArray] = vertexArrayObject; mVertexArrayMap[vertexArray] = vertexArrayObject;
} }
......
...@@ -38,7 +38,7 @@ class RefCountObject : angle::NonCopyable ...@@ -38,7 +38,7 @@ class RefCountObject : angle::NonCopyable
template <class ObjectType> template <class ObjectType>
class BindingPointer class BindingPointer
{ {
public: public:
BindingPointer() BindingPointer()
: mObject(nullptr) : mObject(nullptr)
{ {
......
...@@ -982,7 +982,7 @@ Buffer *State::getTargetBuffer(GLenum target) const ...@@ -982,7 +982,7 @@ Buffer *State::getTargetBuffer(GLenum target) const
case GL_ARRAY_BUFFER: return mArrayBuffer.get(); case GL_ARRAY_BUFFER: return mArrayBuffer.get();
case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get(); case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get();
case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get(); case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get();
case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer(); case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get();
case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get(); case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get();
case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get(); case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get();
case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get(); case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get();
...@@ -1174,7 +1174,7 @@ void State::getIntegerv(const gl::Data &data, GLenum pname, GLint *params) ...@@ -1174,7 +1174,7 @@ void State::getIntegerv(const gl::Data &data, GLenum pname, GLint *params)
switch (pname) switch (pname)
{ {
case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break; case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break;
case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBufferId(); break; case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break;
//case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break; case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break;
case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break; case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break;
...@@ -1413,7 +1413,7 @@ bool State::hasMappedBuffer(GLenum target) const ...@@ -1413,7 +1413,7 @@ bool State::hasMappedBuffer(GLenum target) const
{ {
const VertexArray *vao = getVertexArray(); const VertexArray *vao = getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes(); const auto &vertexAttribs = vao->getVertexAttributes();
unsigned int maxEnabledAttrib = vao->getMaxEnabledAttribute(); size_t maxEnabledAttrib = vao->getMaxEnabledAttribute();
for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++)
{ {
const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex];
......
...@@ -8,29 +8,38 @@ ...@@ -8,29 +8,38 @@
#include "libANGLE/VertexArray.h" #include "libANGLE/VertexArray.h"
#include "libANGLE/Buffer.h" #include "libANGLE/Buffer.h"
#include "libANGLE/renderer/ImplFactory.h"
#include "libANGLE/renderer/VertexArrayImpl.h" #include "libANGLE/renderer/VertexArrayImpl.h"
namespace gl namespace gl
{ {
VertexArray::VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs) VertexArray::Data::Data(size_t maxAttribs)
: mId(id), : mVertexAttributes(maxAttribs),
mVertexArray(impl),
mVertexAttributes(maxAttribs),
mMaxEnabledAttribute(0) mMaxEnabledAttribute(0)
{ {
ASSERT(impl != NULL);
} }
VertexArray::~VertexArray() VertexArray::Data::~Data()
{ {
SafeDelete(mVertexArray);
for (size_t i = 0; i < getMaxAttribs(); i++) for (size_t i = 0; i < getMaxAttribs(); i++)
{ {
mVertexAttributes[i].buffer.set(NULL); mVertexAttributes[i].buffer.set(nullptr);
} }
mElementArrayBuffer.set(NULL); mElementArrayBuffer.set(nullptr);
}
VertexArray::VertexArray(rx::ImplFactory *factory, GLuint id, size_t maxAttribs)
: mId(id),
mVertexArray(factory->createVertexArray(mData)),
mData(maxAttribs)
{
ASSERT(mVertexArray != nullptr);
}
VertexArray::~VertexArray()
{
SafeDelete(mVertexArray);
} }
GLuint VertexArray::id() const GLuint VertexArray::id() const
...@@ -42,75 +51,74 @@ void VertexArray::detachBuffer(GLuint bufferName) ...@@ -42,75 +51,74 @@ void VertexArray::detachBuffer(GLuint bufferName)
{ {
for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++) for (size_t attribute = 0; attribute < getMaxAttribs(); attribute++)
{ {
if (mVertexAttributes[attribute].buffer.id() == bufferName) if (mData.mVertexAttributes[attribute].buffer.id() == bufferName)
{ {
mVertexAttributes[attribute].buffer.set(nullptr); mData.mVertexAttributes[attribute].buffer.set(nullptr);
mVertexArray->setAttribute(attribute, mVertexAttributes[attribute]); mVertexArray->setAttribute(attribute, mData.mVertexAttributes[attribute]);
} }
} }
if (mElementArrayBuffer.id() == bufferName) if (mData.mElementArrayBuffer.id() == bufferName)
{ {
mElementArrayBuffer.set(nullptr); mData.mElementArrayBuffer.set(nullptr);
mVertexArray->setElementArrayBuffer(nullptr); mVertexArray->setElementArrayBuffer(nullptr);
} }
} }
const VertexAttribute& VertexArray::getVertexAttribute(size_t attributeIndex) const const VertexAttribute &VertexArray::getVertexAttribute(size_t attributeIndex) const
{ {
ASSERT(attributeIndex < getMaxAttribs()); ASSERT(attributeIndex < getMaxAttribs());
return mVertexAttributes[attributeIndex]; return mData.mVertexAttributes[attributeIndex];
} }
const std::vector<VertexAttribute> &VertexArray::getVertexAttributes() const void VertexArray::setVertexAttribDivisor(size_t index, GLuint divisor)
{
return mVertexAttributes;
}
void VertexArray::setVertexAttribDivisor(GLuint index, GLuint divisor)
{ {
ASSERT(index < getMaxAttribs()); ASSERT(index < getMaxAttribs());
mVertexAttributes[index].divisor = divisor; mData.mVertexAttributes[index].divisor = divisor;
mVertexArray->setAttributeDivisor(index, divisor); mVertexArray->setAttributeDivisor(index, divisor);
} }
void VertexArray::enableAttribute(unsigned int attributeIndex, bool enabledState) void VertexArray::enableAttribute(size_t attributeIndex, bool enabledState)
{ {
ASSERT(attributeIndex < getMaxAttribs()); ASSERT(attributeIndex < getMaxAttribs());
mVertexAttributes[attributeIndex].enabled = enabledState; mData.mVertexAttributes[attributeIndex].enabled = enabledState;
mVertexArray->enableAttribute(attributeIndex, enabledState); mVertexArray->enableAttribute(attributeIndex, enabledState);
// Update state cache // Update state cache
if (enabledState) if (enabledState)
{ {
mMaxEnabledAttribute = std::max(attributeIndex, mMaxEnabledAttribute); mData.mMaxEnabledAttribute = std::max(attributeIndex, mData.mMaxEnabledAttribute);
} }
else if (mMaxEnabledAttribute == attributeIndex) else if (mData.mMaxEnabledAttribute == attributeIndex)
{ {
while (mMaxEnabledAttribute > 0 && !mVertexAttributes[mMaxEnabledAttribute].enabled) while (mData.mMaxEnabledAttribute > 0 && !mData.mVertexAttributes[mData.mMaxEnabledAttribute].enabled)
{ {
--mMaxEnabledAttribute; --mData.mMaxEnabledAttribute;
} }
} }
} }
void VertexArray::setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, void VertexArray::setAttributeState(size_t attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer) bool normalized, bool pureInteger, GLsizei stride, const void *pointer)
{ {
ASSERT(attributeIndex < getMaxAttribs()); ASSERT(attributeIndex < getMaxAttribs());
mVertexAttributes[attributeIndex].buffer.set(boundBuffer);
mVertexAttributes[attributeIndex].size = size; VertexAttribute *attrib = &mData.mVertexAttributes[attributeIndex];
mVertexAttributes[attributeIndex].type = type;
mVertexAttributes[attributeIndex].normalized = normalized; attrib->buffer.set(boundBuffer);
mVertexAttributes[attributeIndex].pureInteger = pureInteger; attrib->size = size;
mVertexAttributes[attributeIndex].stride = stride; attrib->type = type;
mVertexAttributes[attributeIndex].pointer = pointer; attrib->normalized = normalized;
mVertexArray->setAttribute(attributeIndex, mVertexAttributes[attributeIndex]); attrib->pureInteger = pureInteger;
attrib->stride = stride;
attrib->pointer = pointer;
mVertexArray->setAttribute(attributeIndex, *attrib);
} }
void VertexArray::setElementArrayBuffer(Buffer *buffer) void VertexArray::setElementArrayBuffer(Buffer *buffer)
{ {
mElementArrayBuffer.set(buffer); mData.mElementArrayBuffer.set(buffer);
mVertexArray->setElementArrayBuffer(buffer); mVertexArray->setElementArrayBuffer(buffer);
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
namespace rx namespace rx
{ {
class ImplFactory;
class VertexArrayImpl; class VertexArrayImpl;
} }
...@@ -31,37 +32,54 @@ class Buffer; ...@@ -31,37 +32,54 @@ class Buffer;
class VertexArray class VertexArray
{ {
public: public:
VertexArray(rx::VertexArrayImpl *impl, GLuint id, size_t maxAttribs); VertexArray(rx::ImplFactory *factory, GLuint id, size_t maxAttribs);
~VertexArray(); ~VertexArray();
GLuint id() const; GLuint id() const;
const VertexAttribute& getVertexAttribute(size_t attributeIndex) const; const VertexAttribute &getVertexAttribute(size_t attributeIndex) const;
const std::vector<VertexAttribute> &getVertexAttributes() const;
void detachBuffer(GLuint bufferName); void detachBuffer(GLuint bufferName);
void setVertexAttribDivisor(GLuint index, GLuint divisor); void setVertexAttribDivisor(size_t index, GLuint divisor);
void enableAttribute(unsigned int attributeIndex, bool enabledState); void enableAttribute(size_t attributeIndex, bool enabledState);
void setAttributeState(unsigned int attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type, void setAttributeState(size_t attributeIndex, gl::Buffer *boundBuffer, GLint size, GLenum type,
bool normalized, bool pureInteger, GLsizei stride, const void *pointer); bool normalized, bool pureInteger, GLsizei stride, const void *pointer);
Buffer *getElementArrayBuffer() const { return mElementArrayBuffer.get(); }
void setElementArrayBuffer(Buffer *buffer); void setElementArrayBuffer(Buffer *buffer);
GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); }
size_t getMaxAttribs() const { return mVertexAttributes.size(); } const BindingPointer<Buffer> &getElementArrayBuffer() const { return mData.getElementArrayBuffer(); }
size_t getMaxAttribs() const { return mData.getVertexAttributes().size(); }
const std::vector<VertexAttribute> &getVertexAttributes() const { return mData.getVertexAttributes(); }
rx::VertexArrayImpl *getImplementation() { return mVertexArray; } rx::VertexArrayImpl *getImplementation() { return mVertexArray; }
const rx::VertexArrayImpl *getImplementation() const { return mVertexArray; } const rx::VertexArrayImpl *getImplementation() const { return mVertexArray; }
unsigned int getMaxEnabledAttribute() const { return mMaxEnabledAttribute; } size_t getMaxEnabledAttribute() const { return mData.getMaxEnabledAttribute(); }
class Data final : public angle::NonCopyable
{
public:
explicit Data(size_t maxAttribs);
~Data();
const BindingPointer<Buffer> &getElementArrayBuffer() const { return mElementArrayBuffer; }
size_t getMaxAttribs() const { return mVertexAttributes.size(); }
size_t getMaxEnabledAttribute() const { return mMaxEnabledAttribute; }
const std::vector<VertexAttribute> &getVertexAttributes() const { return mVertexAttributes; }
private:
friend class VertexArray;
std::vector<VertexAttribute> mVertexAttributes;
BindingPointer<Buffer> mElementArrayBuffer;
size_t mMaxEnabledAttribute;
};
private: private:
GLuint mId; GLuint mId;
rx::VertexArrayImpl *mVertexArray; rx::VertexArrayImpl *mVertexArray;
std::vector<VertexAttribute> mVertexAttributes;
BindingPointer<Buffer> mElementArrayBuffer; Data mData;
unsigned int mMaxEnabledAttribute;
}; };
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBANGLE_RENDERER_IMPLFACTORY_H_ #define LIBANGLE_RENDERER_IMPLFACTORY_H_
#include "libANGLE/Framebuffer.h" #include "libANGLE/Framebuffer.h"
#include "libANGLE/VertexArray.h"
namespace rx namespace rx
{ {
...@@ -52,7 +53,7 @@ class ImplFactory : angle::NonCopyable ...@@ -52,7 +53,7 @@ class ImplFactory : angle::NonCopyable
virtual BufferImpl *createBuffer() = 0; virtual BufferImpl *createBuffer() = 0;
// Vertex Array creation // Vertex Array creation
virtual VertexArrayImpl *createVertexArray() = 0; virtual VertexArrayImpl *createVertexArray(const gl::VertexArray::Data &data) = 0;
// Query and Fence creation // Query and Fence creation
virtual QueryImpl *createQuery(GLenum type) = 0; virtual QueryImpl *createQuery(GLenum type) = 0;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Buffer.h" #include "libANGLE/Buffer.h"
#include "libANGLE/VertexAttribute.h" #include "libANGLE/VertexArray.h"
namespace rx namespace rx
{ {
...@@ -19,12 +19,16 @@ namespace rx ...@@ -19,12 +19,16 @@ namespace rx
class VertexArrayImpl : angle::NonCopyable class VertexArrayImpl : angle::NonCopyable
{ {
public: public:
VertexArrayImpl(const gl::VertexArray::Data &data) : mData(data) { }
virtual ~VertexArrayImpl() { } virtual ~VertexArrayImpl() { }
virtual void setElementArrayBuffer(const gl::Buffer *buffer) = 0; virtual void setElementArrayBuffer(const gl::Buffer *buffer) = 0;
virtual void setAttribute(size_t idx, const gl::VertexAttribute &attr) = 0; virtual void setAttribute(size_t idx, const gl::VertexAttribute &attr) = 0;
virtual void setAttributeDivisor(size_t idx, GLuint divisor) = 0; virtual void setAttributeDivisor(size_t idx, GLuint divisor) = 0;
virtual void enableAttribute(size_t idx, bool enabledState) = 0; virtual void enableAttribute(size_t idx, bool enabledState) = 0;
protected:
const gl::VertexArray::Data &mData;
}; };
} }
......
...@@ -111,7 +111,7 @@ gl::Error RendererD3D::drawElements(const gl::Data &data, ...@@ -111,7 +111,7 @@ gl::Error RendererD3D::drawElements(const gl::Data &data,
SourceIndexData sourceIndexInfo; SourceIndexData sourceIndexInfo;
error = applyIndexBuffer(indices, vao->getElementArrayBuffer(), count, mode, type, &indexInfo, &sourceIndexInfo); error = applyIndexBuffer(indices, vao->getElementArrayBuffer().get(), count, mode, type, &indexInfo, &sourceIndexInfo);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -149,7 +149,7 @@ gl::Error RendererD3D::drawElements(const gl::Data &data, ...@@ -149,7 +149,7 @@ gl::Error RendererD3D::drawElements(const gl::Data &data,
if (!skipDraw(data, mode)) if (!skipDraw(data, mode))
{ {
error = drawElements(mode, count, type, indices, vao->getElementArrayBuffer(), indexInfo, instances, program->usesPointSize()); error = drawElements(mode, count, type, indices, vao->getElementArrayBuffer().get(), indexInfo, instances, program->usesPointSize());
if (error.isError()) if (error.isError())
{ {
return error; return error;
......
...@@ -3162,9 +3162,9 @@ BufferImpl *Renderer11::createBuffer() ...@@ -3162,9 +3162,9 @@ BufferImpl *Renderer11::createBuffer()
return new Buffer11(this); return new Buffer11(this);
} }
VertexArrayImpl *Renderer11::createVertexArray() VertexArrayImpl *Renderer11::createVertexArray(const gl::VertexArray::Data &data)
{ {
return new VertexArray11(this); return new VertexArray11(data);
} }
QueryImpl *Renderer11::createQuery(GLenum type) QueryImpl *Renderer11::createQuery(GLenum type)
......
...@@ -220,7 +220,7 @@ class Renderer11 : public RendererD3D ...@@ -220,7 +220,7 @@ class Renderer11 : public RendererD3D
virtual IndexBuffer *createIndexBuffer(); virtual IndexBuffer *createIndexBuffer();
// Vertex Array creation // Vertex Array creation
virtual VertexArrayImpl *createVertexArray(); VertexArrayImpl *createVertexArray(const gl::VertexArray::Data &data) override;
// Query and Fence creation // Query and Fence creation
virtual QueryImpl *createQuery(GLenum type); virtual QueryImpl *createQuery(GLenum type);
......
...@@ -19,8 +19,8 @@ class Renderer11; ...@@ -19,8 +19,8 @@ class Renderer11;
class VertexArray11 : public VertexArrayImpl class VertexArray11 : public VertexArrayImpl
{ {
public: public:
VertexArray11(Renderer11 *renderer) VertexArray11(const gl::VertexArray::Data &data)
: VertexArrayImpl() : VertexArrayImpl(data)
{ {
} }
virtual ~VertexArray11() { } virtual ~VertexArray11() { }
......
...@@ -714,9 +714,9 @@ BufferImpl *Renderer9::createBuffer() ...@@ -714,9 +714,9 @@ BufferImpl *Renderer9::createBuffer()
return new Buffer9(this); return new Buffer9(this);
} }
VertexArrayImpl *Renderer9::createVertexArray() VertexArrayImpl *Renderer9::createVertexArray(const gl::VertexArray::Data &data)
{ {
return new VertexArray9(this); return new VertexArray9(data);
} }
QueryImpl *Renderer9::createQuery(GLenum type) QueryImpl *Renderer9::createQuery(GLenum type)
......
...@@ -206,7 +206,7 @@ class Renderer9 : public RendererD3D ...@@ -206,7 +206,7 @@ class Renderer9 : public RendererD3D
virtual IndexBuffer *createIndexBuffer(); virtual IndexBuffer *createIndexBuffer();
// Vertex Array creation // Vertex Array creation
virtual VertexArrayImpl *createVertexArray(); VertexArrayImpl *createVertexArray(const gl::VertexArray::Data &data) override;
// Query and Fence creation // Query and Fence creation
virtual QueryImpl *createQuery(GLenum type); virtual QueryImpl *createQuery(GLenum type);
......
...@@ -19,8 +19,8 @@ class Renderer9; ...@@ -19,8 +19,8 @@ class Renderer9;
class VertexArray9 : public VertexArrayImpl class VertexArray9 : public VertexArrayImpl
{ {
public: public:
VertexArray9(Renderer9 *renderer) VertexArray9(const gl::VertexArray::Data &data)
: VertexArrayImpl() : VertexArrayImpl(data)
{ {
} }
......
...@@ -205,9 +205,9 @@ BufferImpl *RendererGL::createBuffer() ...@@ -205,9 +205,9 @@ BufferImpl *RendererGL::createBuffer()
return new BufferGL(mFunctions, mStateManager); return new BufferGL(mFunctions, mStateManager);
} }
VertexArrayImpl *RendererGL::createVertexArray() VertexArrayImpl *RendererGL::createVertexArray(const gl::VertexArray::Data &data)
{ {
return new VertexArrayGL(mFunctions, mStateManager); return new VertexArrayGL(data, mFunctions, mStateManager);
} }
QueryImpl *RendererGL::createQuery(GLenum type) QueryImpl *RendererGL::createQuery(GLenum type)
......
...@@ -51,7 +51,7 @@ class RendererGL : public Renderer ...@@ -51,7 +51,7 @@ class RendererGL : public Renderer
BufferImpl *createBuffer() override; BufferImpl *createBuffer() override;
// Vertex Array creation // Vertex Array creation
VertexArrayImpl *createVertexArray() override; VertexArrayImpl *createVertexArray(const gl::VertexArray::Data &data) override;
// Query and Fence creation // Query and Fence creation
QueryImpl *createQuery(GLenum type) override; QueryImpl *createQuery(GLenum type) override;
......
...@@ -21,15 +21,12 @@ ...@@ -21,15 +21,12 @@
namespace rx namespace rx
{ {
VertexArrayGL::VertexArrayGL(const FunctionsGL *functions, StateManagerGL *stateManager) VertexArrayGL::VertexArrayGL(const gl::VertexArray::Data &data, const FunctionsGL *functions, StateManagerGL *stateManager)
: VertexArrayImpl(), : VertexArrayImpl(data),
mFunctions(functions), mFunctions(functions),
mStateManager(stateManager), mStateManager(stateManager),
mVertexArrayID(0), mVertexArrayID(0),
mElementArrayBuffer(),
mAttributes(),
mAppliedElementArrayBuffer(0), mAppliedElementArrayBuffer(0),
mAppliedAttributes(),
mStreamingElementArrayBufferSize(0), mStreamingElementArrayBufferSize(0),
mStreamingElementArrayBuffer(0), mStreamingElementArrayBuffer(0),
mStreamingArrayBufferSize(0), mStreamingArrayBufferSize(0),
...@@ -42,7 +39,6 @@ VertexArrayGL::VertexArrayGL(const FunctionsGL *functions, StateManagerGL *state ...@@ -42,7 +39,6 @@ VertexArrayGL::VertexArrayGL(const FunctionsGL *functions, StateManagerGL *state
// Set the cached vertex attribute array size // Set the cached vertex attribute array size
GLint maxVertexAttribs; GLint maxVertexAttribs;
mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
mAttributes.resize(maxVertexAttribs);
mAppliedAttributes.resize(maxVertexAttribs); mAppliedAttributes.resize(maxVertexAttribs);
} }
...@@ -59,22 +55,14 @@ VertexArrayGL::~VertexArrayGL() ...@@ -59,22 +55,14 @@ VertexArrayGL::~VertexArrayGL()
mStreamingArrayBufferSize = 0; mStreamingArrayBufferSize = 0;
mStreamingArrayBuffer = 0; mStreamingArrayBuffer = 0;
mElementArrayBuffer.set(nullptr);
for (size_t idx = 0; idx < mAttributes.size(); idx++)
{
mAttributes[idx].buffer.set(NULL);
}
for (size_t idx = 0; idx < mAppliedAttributes.size(); idx++) for (size_t idx = 0; idx < mAppliedAttributes.size(); idx++)
{ {
mAppliedAttributes[idx].buffer.set(NULL); mAppliedAttributes[idx].buffer.set(nullptr);
} }
} }
void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer) void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer)
{ {
mElementArrayBuffer.set(buffer);
// If the buffer is being unbound/deleted, reset the currently applied buffer ID // If the buffer is being unbound/deleted, reset the currently applied buffer ID
// so that even if a new buffer is generated with the same ID, it will be re-bound. // so that even if a new buffer is generated with the same ID, it will be re-bound.
if (buffer == nullptr && mAppliedElementArrayBuffer != mStreamingElementArrayBuffer) if (buffer == nullptr && mAppliedElementArrayBuffer != mStreamingElementArrayBuffer)
...@@ -85,17 +73,14 @@ void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer) ...@@ -85,17 +73,14 @@ void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer)
void VertexArrayGL::setAttribute(size_t idx, const gl::VertexAttribute &attr) void VertexArrayGL::setAttribute(size_t idx, const gl::VertexAttribute &attr)
{ {
mAttributes[idx] = attr;
} }
void VertexArrayGL::setAttributeDivisor(size_t idx, GLuint divisor) void VertexArrayGL::setAttributeDivisor(size_t idx, GLuint divisor)
{ {
mAttributes[idx].divisor = divisor;
} }
void VertexArrayGL::enableAttribute(size_t idx, bool enabledState) void VertexArrayGL::enableAttribute(size_t idx, bool enabledState)
{ {
mAttributes[idx].enabled = enabledState;
} }
gl::Error VertexArrayGL::syncDrawArraysState(GLint first, GLsizei count) const gl::Error VertexArrayGL::syncDrawArraysState(GLint first, GLsizei count) const
...@@ -158,9 +143,10 @@ gl::Error VertexArrayGL::syncDrawState(GLint first, GLsizei count, GLenum type, ...@@ -158,9 +143,10 @@ gl::Error VertexArrayGL::syncDrawState(GLint first, GLsizei count, GLenum type,
bool VertexArrayGL::doAttributesNeedStreaming() const bool VertexArrayGL::doAttributesNeedStreaming() const
{ {
// TODO: if GLES, nothing needs to be streamed // TODO: if GLES, nothing needs to be streamed
for (size_t idx = 0; idx < mAttributes.size(); idx++) const auto &attribs = mData.getVertexAttributes();
for (size_t idx = 0; idx < attribs.size(); idx++)
{ {
if (mAttributes[idx].enabled && mAttributes[idx].buffer.get() == nullptr) if (attribs[idx].enabled && attribs[idx].buffer.get() == nullptr)
{ {
return true; return true;
} }
...@@ -175,13 +161,16 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const ...@@ -175,13 +161,16 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const
*outStreamingDataSize = 0; *outStreamingDataSize = 0;
*outMaxAttributeDataSize = 0; *outMaxAttributeDataSize = 0;
for (size_t idx = 0; idx < mAttributes.size(); idx++) const auto &attribs = mData.getVertexAttributes();
for (size_t idx = 0; idx < attribs.size(); idx++)
{ {
const auto &attrib = attribs[idx];
// Always sync the enabled and divisor state, they are required for both streaming and buffered // Always sync the enabled and divisor state, they are required for both streaming and buffered
// attributes // attributes
if (mAppliedAttributes[idx].enabled != mAttributes[idx].enabled) if (mAppliedAttributes[idx].enabled != attrib.enabled)
{ {
if (mAttributes[idx].enabled) if (attrib.enabled)
{ {
mFunctions->enableVertexAttribArray(idx); mFunctions->enableVertexAttribArray(idx);
} }
...@@ -189,15 +178,15 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const ...@@ -189,15 +178,15 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const
{ {
mFunctions->disableVertexAttribArray(idx); mFunctions->disableVertexAttribArray(idx);
} }
mAppliedAttributes[idx].enabled = mAttributes[idx].enabled; mAppliedAttributes[idx].enabled = attrib.enabled;
} }
if (mAppliedAttributes[idx].divisor != mAttributes[idx].divisor) if (mAppliedAttributes[idx].divisor != attrib.divisor)
{ {
mFunctions->vertexAttribDivisor(idx, mAttributes[idx].divisor); mFunctions->vertexAttribDivisor(idx, attrib.divisor);
mAppliedAttributes[idx].divisor = mAttributes[idx].divisor; mAppliedAttributes[idx].divisor = attrib.divisor;
} }
if (mAttributes[idx].enabled && mAttributes[idx].buffer.get() == nullptr) if (attribs[idx].enabled && attrib.buffer.get() == nullptr)
{ {
ASSERT(attributesNeedStreaming); ASSERT(attributesNeedStreaming);
...@@ -206,16 +195,16 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const ...@@ -206,16 +195,16 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const
// If streaming is going to be required, compute the size of the required buffer // If streaming is going to be required, compute the size of the required buffer
// and how much slack space at the beginning of the buffer will be required by determining // and how much slack space at the beginning of the buffer will be required by determining
// the attribute with the largest data size. // the attribute with the largest data size.
size_t typeSize = ComputeVertexAttributeTypeSize(mAttributes[idx]); size_t typeSize = ComputeVertexAttributeTypeSize(attrib);
*outStreamingDataSize += typeSize * streamedVertexCount; *outStreamingDataSize += typeSize * streamedVertexCount;
*outMaxAttributeDataSize = std::max(*outMaxAttributeDataSize, typeSize); *outMaxAttributeDataSize = std::max(*outMaxAttributeDataSize, typeSize);
} }
else else
{ {
// Sync the attribute with no translation // Sync the attribute with no translation
if (mAppliedAttributes[idx] != mAttributes[idx]) if (mAppliedAttributes[idx] != attrib)
{ {
const gl::Buffer *arrayBuffer = mAttributes[idx].buffer.get(); const gl::Buffer *arrayBuffer = attrib.buffer.get();
if (arrayBuffer != nullptr) if (arrayBuffer != nullptr)
{ {
const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer); const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer);
...@@ -226,19 +215,19 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const ...@@ -226,19 +215,19 @@ gl::Error VertexArrayGL::syncAttributeState(bool attributesNeedStreaming, const
mStateManager->bindBuffer(GL_ARRAY_BUFFER, 0); mStateManager->bindBuffer(GL_ARRAY_BUFFER, 0);
} }
if (mAttributes[idx].pureInteger) if (attrib.pureInteger)
{ {
mFunctions->vertexAttribIPointer(idx, mAttributes[idx].size, mAttributes[idx].type, mFunctions->vertexAttribIPointer(idx, attrib.size, attrib.type,
mAttributes[idx].stride, mAttributes[idx].pointer); attrib.stride, attrib.pointer);
} }
else else
{ {
mFunctions->vertexAttribPointer(idx, mAttributes[idx].size, mAttributes[idx].type, mFunctions->vertexAttribPointer(idx, attrib.size, attrib.type,
mAttributes[idx].normalized, mAttributes[idx].stride, attrib.normalized, attrib.stride,
mAttributes[idx].pointer); attrib.pointer);
} }
mAppliedAttributes[idx] = mAttributes[idx]; mAppliedAttributes[idx] = attrib;
} }
} }
} }
...@@ -251,10 +240,12 @@ gl::Error VertexArrayGL::syncIndexData(GLsizei count, GLenum type, const GLvoid ...@@ -251,10 +240,12 @@ gl::Error VertexArrayGL::syncIndexData(GLsizei count, GLenum type, const GLvoid
{ {
ASSERT(outIndices); ASSERT(outIndices);
gl::Buffer *elementArrayBuffer = mData.getElementArrayBuffer().get();
// Need to check the range of indices if attributes need to be streamed // Need to check the range of indices if attributes need to be streamed
if (mElementArrayBuffer.get() != nullptr) if (elementArrayBuffer != nullptr)
{ {
const BufferGL *bufferGL = GetImplAs<BufferGL>(mElementArrayBuffer.get()); const BufferGL *bufferGL = GetImplAs<BufferGL>(elementArrayBuffer);
GLuint elementArrayBufferID = bufferGL->getBufferID(); GLuint elementArrayBufferID = bufferGL->getBufferID();
if (elementArrayBufferID != mAppliedElementArrayBuffer) if (elementArrayBufferID != mAppliedElementArrayBuffer)
{ {
...@@ -266,7 +257,7 @@ gl::Error VertexArrayGL::syncIndexData(GLsizei count, GLenum type, const GLvoid ...@@ -266,7 +257,7 @@ gl::Error VertexArrayGL::syncIndexData(GLsizei count, GLenum type, const GLvoid
if (attributesNeedStreaming) if (attributesNeedStreaming)
{ {
ptrdiff_t elementArrayBufferOffset = reinterpret_cast<ptrdiff_t>(indices); ptrdiff_t elementArrayBufferOffset = reinterpret_cast<ptrdiff_t>(indices);
gl::Error error = mElementArrayBuffer->getIndexRange(type, static_cast<size_t>(elementArrayBufferOffset), count, outIndexRange); gl::Error error = mData.getElementArrayBuffer()->getIndexRange(type, static_cast<size_t>(elementArrayBufferOffset), count, outIndexRange);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -351,14 +342,17 @@ gl::Error VertexArrayGL::streamAttributes(size_t streamingDataSize, size_t maxAt ...@@ -351,14 +342,17 @@ gl::Error VertexArrayGL::streamAttributes(size_t streamingDataSize, size_t maxAt
const size_t streamedVertexCount = indexRange.end - indexRange.start + 1; const size_t streamedVertexCount = indexRange.end - indexRange.start + 1;
for (size_t idx = 0; idx < mAttributes.size(); idx++) const auto &attribs = mData.getVertexAttributes();
for (size_t idx = 0; idx < attribs.size(); idx++)
{ {
if (mAttributes[idx].enabled && mAttributes[idx].buffer.get() == nullptr) const auto &attrib = attribs[idx];
if (attrib.enabled && attrib.buffer.get() == nullptr)
{ {
const size_t sourceStride = ComputeVertexAttributeStride(mAttributes[idx]); const size_t sourceStride = ComputeVertexAttributeStride(attrib);
const size_t destStride = ComputeVertexAttributeTypeSize(mAttributes[idx]); const size_t destStride = ComputeVertexAttributeTypeSize(attrib);
const uint8_t *inputPointer = reinterpret_cast<const uint8_t*>(mAttributes[idx].pointer); const uint8_t *inputPointer = reinterpret_cast<const uint8_t*>(attrib.pointer);
// Pack the data when copying it, user could have supplied a very large stride that would // Pack the data when copying it, user could have supplied a very large stride that would
// cause the buffer to be much larger than needed. // cause the buffer to be much larger than needed.
...@@ -383,8 +377,8 @@ gl::Error VertexArrayGL::streamAttributes(size_t streamingDataSize, size_t maxAt ...@@ -383,8 +377,8 @@ gl::Error VertexArrayGL::streamAttributes(size_t streamingDataSize, size_t maxAt
// Compute where the 0-index vertex would be. // Compute where the 0-index vertex would be.
const size_t vertexStartOffset = curBufferOffset - (indexRange.start * destStride); const size_t vertexStartOffset = curBufferOffset - (indexRange.start * destStride);
mFunctions->vertexAttribPointer(idx, mAttributes[idx].size, mAttributes[idx].type, mFunctions->vertexAttribPointer(idx, attrib.size, attrib.type,
mAttributes[idx].normalized, destStride, attrib.normalized, destStride,
reinterpret_cast<const GLvoid*>(vertexStartOffset)); reinterpret_cast<const GLvoid*>(vertexStartOffset));
curBufferOffset += destStride * streamedVertexCount; curBufferOffset += destStride * streamedVertexCount;
......
...@@ -20,7 +20,7 @@ class StateManagerGL; ...@@ -20,7 +20,7 @@ class StateManagerGL;
class VertexArrayGL : public VertexArrayImpl class VertexArrayGL : public VertexArrayImpl
{ {
public: public:
VertexArrayGL(const FunctionsGL *functions, StateManagerGL *stateManager); VertexArrayGL(const gl::VertexArray::Data &data, const FunctionsGL *functions, StateManagerGL *stateManager);
~VertexArrayGL() override; ~VertexArrayGL() override;
void setElementArrayBuffer(const gl::Buffer *buffer) override; void setElementArrayBuffer(const gl::Buffer *buffer) override;
...@@ -57,9 +57,6 @@ class VertexArrayGL : public VertexArrayImpl ...@@ -57,9 +57,6 @@ class VertexArrayGL : public VertexArrayImpl
GLuint mVertexArrayID; GLuint mVertexArrayID;
BindingPointer<const gl::Buffer> mElementArrayBuffer;
std::vector<gl::VertexAttribute> mAttributes;
mutable GLuint mAppliedElementArrayBuffer; mutable GLuint mAppliedElementArrayBuffer;
mutable std::vector<gl::VertexAttribute> mAppliedAttributes; mutable std::vector<gl::VertexAttribute> mAppliedAttributes;
......
...@@ -1406,7 +1406,7 @@ static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsiz ...@@ -1406,7 +1406,7 @@ static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsiz
const VertexArray *vao = state.getVertexArray(); const VertexArray *vao = state.getVertexArray();
const auto &vertexAttribs = vao->getVertexAttributes(); const auto &vertexAttribs = vao->getVertexAttributes();
const int *semanticIndexes = program->getSemanticIndexes(); const int *semanticIndexes = program->getSemanticIndexes();
unsigned int maxEnabledAttrib = vao->getMaxEnabledAttribute(); size_t maxEnabledAttrib = vao->getMaxEnabledAttribute();
for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex) for (size_t attributeIndex = 0; attributeIndex < maxEnabledAttrib; ++attributeIndex)
{ {
const VertexAttribute &attrib = vertexAttribs[attributeIndex]; const VertexAttribute &attrib = vertexAttribs[attributeIndex];
...@@ -1601,7 +1601,7 @@ bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum t ...@@ -1601,7 +1601,7 @@ bool ValidateDrawElements(Context *context, GLenum mode, GLsizei count, GLenum t
} }
const gl::VertexArray *vao = state.getVertexArray(); const gl::VertexArray *vao = state.getVertexArray();
gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get();
if (!indices && !elementArrayBuffer) if (!indices && !elementArrayBuffer)
{ {
context->recordError(Error(GL_INVALID_OPERATION)); context->recordError(Error(GL_INVALID_OPERATION));
......
...@@ -39,7 +39,7 @@ class NullFactory : public ImplFactory ...@@ -39,7 +39,7 @@ class NullFactory : public ImplFactory
BufferImpl *createBuffer() override { return nullptr; } BufferImpl *createBuffer() override { return nullptr; }
// Vertex Array creation // Vertex Array creation
VertexArrayImpl *createVertexArray() override { return nullptr; } VertexArrayImpl *createVertexArray(const gl::VertexArray::Data &data) override { return nullptr; }
// Query and Fence creation // Query and Fence creation
QueryImpl *createQuery(GLenum type) override { return nullptr; } QueryImpl *createQuery(GLenum type) override { return nullptr; }
......
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