Commit ba4c4a85 by Geoff Lang

Implement basic functionality in VertexArrayGL.

No support for raw vertex data pointers yet. BUG=angle:880 Change-Id: Ifa8099b0f49028a1465edecde495ba725ac79598 Reviewed-on: https://chromium-review.googlesource.com/252801Reviewed-by: 's avatarKenneth Russell <kbr@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent c9d9b30a
...@@ -49,6 +49,9 @@ class VertexArray ...@@ -49,6 +49,9 @@ class VertexArray
GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); } GLuint getElementArrayBufferId() const { return mElementArrayBuffer.id(); }
size_t getMaxAttribs() const { return mVertexAttributes.size(); } size_t getMaxAttribs() const { return mVertexAttributes.size(); }
rx::VertexArrayImpl *getImplementation() { return mVertexArray; }
const rx::VertexArrayImpl *getImplementation() const { return mVertexArray; }
private: private:
GLuint mId; GLuint mId;
......
...@@ -112,7 +112,7 @@ BufferImpl *RendererGL::createBuffer() ...@@ -112,7 +112,7 @@ BufferImpl *RendererGL::createBuffer()
VertexArrayImpl *RendererGL::createVertexArray() VertexArrayImpl *RendererGL::createVertexArray()
{ {
return new VertexArrayGL(); return new VertexArrayGL(mFunctions, mStateManager);
} }
QueryImpl *RendererGL::createQuery(GLenum type) QueryImpl *RendererGL::createQuery(GLenum type)
......
...@@ -16,6 +16,7 @@ namespace rx ...@@ -16,6 +16,7 @@ namespace rx
StateManagerGL::StateManagerGL(const FunctionsGL *functions) StateManagerGL::StateManagerGL(const FunctionsGL *functions)
: mFunctions(functions), : mFunctions(functions),
mProgram(0), mProgram(0),
mVAO(0),
mBuffers() mBuffers()
{ {
ASSERT(mFunctions); ASSERT(mFunctions);
...@@ -30,6 +31,15 @@ void StateManagerGL::useProgram(GLuint program) ...@@ -30,6 +31,15 @@ void StateManagerGL::useProgram(GLuint program)
} }
} }
void StateManagerGL::bindVertexArray(GLuint vao)
{
if (mVAO != vao)
{
mVAO = vao;
mFunctions->bindVertexArray(vao);
}
}
void StateManagerGL::bindBuffer(GLenum type, GLuint buffer) void StateManagerGL::bindBuffer(GLenum type, GLuint buffer)
{ {
if (mBuffers[type] == 0) if (mBuffers[type] == 0)
......
...@@ -25,6 +25,7 @@ class StateManagerGL ...@@ -25,6 +25,7 @@ class StateManagerGL
StateManagerGL(const FunctionsGL *functions); StateManagerGL(const FunctionsGL *functions);
void useProgram(GLuint program); void useProgram(GLuint program);
void bindVertexArray(GLuint vao);
void bindBuffer(GLenum type, GLuint buffer); void bindBuffer(GLenum type, GLuint buffer);
private: private:
...@@ -33,6 +34,7 @@ class StateManagerGL ...@@ -33,6 +34,7 @@ class StateManagerGL
const FunctionsGL *mFunctions; const FunctionsGL *mFunctions;
GLuint mProgram; GLuint mProgram;
GLuint mVAO;
std::map<GLenum, GLuint> mBuffers; std::map<GLenum, GLuint> mBuffers;
}; };
......
...@@ -9,35 +9,146 @@ ...@@ -9,35 +9,146 @@
#include "libANGLE/renderer/gl/VertexArrayGL.h" #include "libANGLE/renderer/gl/VertexArrayGL.h"
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/angletypes.h"
#include "libANGLE/renderer/gl/BufferGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
namespace rx namespace rx
{ {
VertexArrayGL::VertexArrayGL() VertexArrayGL::VertexArrayGL(const FunctionsGL *functions, StateManagerGL *stateManager)
: VertexArrayImpl() : VertexArrayImpl(),
{} mFunctions(functions),
mStateManager(stateManager),
mVertexArrayID(0),
mAppliedElementArrayBuffer(0),
mAppliedAttributes()
{
ASSERT(mFunctions);
ASSERT(mStateManager);
mFunctions->genVertexArrays(1, &mVertexArrayID);
// Set the cached vertex attribute array size
GLint maxVertexAttribs;
mFunctions->getIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs);
mAppliedAttributes.resize(maxVertexAttribs);
}
VertexArrayGL::~VertexArrayGL() VertexArrayGL::~VertexArrayGL()
{} {
if (mVertexArrayID != 0)
{
mFunctions->deleteVertexArrays(1, &mVertexArrayID);
mVertexArrayID = 0;
}
for (size_t idx = 0; idx < mAppliedAttributes.size(); idx++)
{
mAppliedAttributes[idx].buffer.set(NULL);
}
}
void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer) void VertexArrayGL::setElementArrayBuffer(const gl::Buffer *buffer)
{ {
//UNIMPLEMENTED(); GLuint elementArrayBufferID = 0;
if (buffer != nullptr)
{
const BufferGL *bufferGL = GetImplAs<BufferGL>(buffer);
elementArrayBufferID = bufferGL->getBufferID();
}
if (elementArrayBufferID != mAppliedElementArrayBuffer)
{
mStateManager->bindVertexArray(mVertexArrayID);
mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementArrayBufferID);
mStateManager->bindVertexArray(0);
mAppliedElementArrayBuffer = elementArrayBufferID;
}
} }
void VertexArrayGL::setAttribute(size_t idx, const gl::VertexAttribute &attr) void VertexArrayGL::setAttribute(size_t idx, const gl::VertexAttribute &attr)
{ {
UNIMPLEMENTED(); if (mAppliedAttributes[idx].type != attr.type ||
mAppliedAttributes[idx].size != attr.size ||
mAppliedAttributes[idx].normalized != attr.normalized ||
mAppliedAttributes[idx].pureInteger != attr.pureInteger ||
mAppliedAttributes[idx].stride != attr.stride ||
mAppliedAttributes[idx].pointer != attr.pointer ||
mAppliedAttributes[idx].buffer.get() != attr.buffer.get())
{
mStateManager->bindVertexArray(mVertexArrayID);
const gl::Buffer *arrayBuffer = attr.buffer.get();
if (arrayBuffer != nullptr)
{
const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer);
mStateManager->bindBuffer(GL_ARRAY_BUFFER, arrayBufferGL->getBufferID());
}
else
{
// This will take some extra work, core OpenGL doesn't support binding raw data pointers
// to VAOs
UNIMPLEMENTED();
}
if (attr.pureInteger)
{
mFunctions->vertexAttribIPointer(idx, attr.size, attr.type, attr.stride, attr.pointer);
}
else
{
mFunctions->vertexAttribPointer(idx, attr.size, attr.type, attr.normalized, attr.stride, attr.pointer);
}
mAppliedAttributes[idx].type = attr.type;
mAppliedAttributes[idx].size = attr.size;
mAppliedAttributes[idx].normalized = attr.normalized;
mAppliedAttributes[idx].pureInteger = attr.pureInteger;
mAppliedAttributes[idx].stride = attr.stride;
mAppliedAttributes[idx].pointer = attr.pointer;
mAppliedAttributes[idx].buffer.set(attr.buffer.get());
mStateManager->bindVertexArray(0);
}
} }
void VertexArrayGL::setAttributeDivisor(size_t idx, GLuint divisor) void VertexArrayGL::setAttributeDivisor(size_t idx, GLuint divisor)
{ {
UNIMPLEMENTED(); if (mAppliedAttributes[idx].divisor != divisor)
{
mStateManager->bindVertexArray(mVertexArrayID);
mFunctions->vertexAttribDivisor(idx, divisor);
mAppliedAttributes[idx].divisor = divisor;
mStateManager->bindVertexArray(0);
}
} }
void VertexArrayGL::enableAttribute(size_t idx, bool enabledState) void VertexArrayGL::enableAttribute(size_t idx, bool enabledState)
{ {
UNIMPLEMENTED(); if (mAppliedAttributes[idx].enabled != enabledState)
{
mStateManager->bindVertexArray(mVertexArrayID);
if (enabledState)
{
mFunctions->enableVertexAttribArray(idx);
}
else
{
mFunctions->disableVertexAttribArray(idx);
}
mAppliedAttributes[idx].enabled = enabledState;
mStateManager->bindVertexArray(0);
}
}
GLuint VertexArrayGL::getVertexArrayID() const
{
return mVertexArrayID;
} }
} }
...@@ -14,10 +14,13 @@ ...@@ -14,10 +14,13 @@
namespace rx namespace rx
{ {
class FunctionsGL;
class StateManagerGL;
class VertexArrayGL : public VertexArrayImpl class VertexArrayGL : public VertexArrayImpl
{ {
public: public:
VertexArrayGL(); VertexArrayGL(const FunctionsGL *functions, StateManagerGL *stateManager);
~VertexArrayGL() override; ~VertexArrayGL() override;
void setElementArrayBuffer(const gl::Buffer *buffer) override; void setElementArrayBuffer(const gl::Buffer *buffer) override;
...@@ -25,8 +28,18 @@ class VertexArrayGL : public VertexArrayImpl ...@@ -25,8 +28,18 @@ class VertexArrayGL : public VertexArrayImpl
void setAttributeDivisor(size_t idx, GLuint divisor) override; void setAttributeDivisor(size_t idx, GLuint divisor) override;
void enableAttribute(size_t idx, bool enabledState) override; void enableAttribute(size_t idx, bool enabledState) override;
GLuint getVertexArrayID() const;
private: private:
DISALLOW_COPY_AND_ASSIGN(VertexArrayGL); DISALLOW_COPY_AND_ASSIGN(VertexArrayGL);
const FunctionsGL *mFunctions;
StateManagerGL *mStateManager;
GLuint mVertexArrayID;
GLuint mAppliedElementArrayBuffer;
std::vector<gl::VertexAttribute> mAppliedAttributes;
}; };
} }
......
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