Skip to content

Commit

Permalink
Create vertex arrays using DSA (refs #394)
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibel committed Jul 18, 2019
1 parent ff2eb5a commit d168bdf
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 2 deletions.
8 changes: 6 additions & 2 deletions source/globjects/source/Resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "implementations/AbstractBufferImplementation.h"
#include "implementations/AbstractFramebufferImplementation.h"
#include "implementations/AbstractTextureImplementation.h"
#include "implementations/AbstractVertexAttributeBindingImplementation.h"


using namespace gl;
Expand Down Expand Up @@ -231,13 +232,16 @@ TransformFeedbackResource::~TransformFeedbackResource()


VertexArrayObjectResource::VertexArrayObjectResource()
: IDResource(createObject(glGenVertexArrays))
: IDResource(ImplementationRegistry::current().attributeImplementation().create())
{
}

VertexArrayObjectResource::~VertexArrayObjectResource()
{
deleteObject(glDeleteVertexArrays, id(), hasOwnership());
if (hasOwnership())
{
ImplementationRegistry::current().attributeImplementation().destroy(id());
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class AbstractVertexAttributeBindingImplementation
static AbstractVertexAttributeBindingImplementation * get(VertexArray::AttributeImplementation impl =
VertexArray::AttributeImplementation::VertexAttribBindingARB);

virtual gl::GLuint create() const = 0;
virtual void destroy(gl::GLuint id) const = 0;

virtual void enable(const VertexArray * vertexArray, gl::GLint attributeIndex) const = 0;
virtual void disable(const VertexArray * vertexArray, gl::GLint attributeIndex) const = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ VertexAttributeBindingImplementation_DirectStateAccessARB::~VertexAttributeBindi

}

gl::GLuint VertexAttributeBindingImplementation_DirectStateAccessARB::create() const
{
gl::GLuint result = 0;

gl::glCreateVertexArrays(1, &result);

return result;
}

void VertexAttributeBindingImplementation_DirectStateAccessARB::destroy(gl::GLuint id) const
{
gl::glDeleteVertexArrays(1, &id);
}

void VertexAttributeBindingImplementation_DirectStateAccessARB::enable(const VertexArray * vertexArray, GLint attributeIndex) const
{
glEnableVertexArrayAttrib(vertexArray->id(), attributeIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class VertexAttributeBindingImplementation_DirectStateAccessARB : public Abstrac
VertexAttributeBindingImplementation_DirectStateAccessARB();
virtual ~VertexAttributeBindingImplementation_DirectStateAccessARB();

virtual gl::GLuint create() const override;
virtual void destroy(gl::GLuint id) const override;

virtual void enable(const VertexArray * vertexArray, gl::GLint attributeIndex) const override;
virtual void disable(const VertexArray * vertexArray, gl::GLint attributeIndex) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ VertexAttributeBindingImplementation_Legacy::BindingData::BindingData()
{
}

gl::GLuint VertexAttributeBindingImplementation_Legacy::create() const
{
gl::GLuint result = 0;

gl::glGenVertexArrays(1, &result);

return result;
}

void VertexAttributeBindingImplementation_Legacy::destroy(gl::GLuint id) const
{
gl::glDeleteVertexArrays(1, &id);
}

VertexAttributeBindingImplementation_Legacy::VertexAttributeBindingImplementation_Legacy()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class VertexAttributeBindingImplementation_Legacy : public AbstractVertexAttribu
VertexAttributeBindingImplementation_Legacy();
virtual ~VertexAttributeBindingImplementation_Legacy();

virtual gl::GLuint create() const override;
virtual void destroy(gl::GLuint id) const override;

virtual void enable(const VertexArray * vertexArray, gl::GLint attributeIndex) const override;
virtual void disable(const VertexArray * vertexArray, gl::GLint attributeIndex) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ VertexAttributeBindingImplementation_VertexAttribBindingARB::~VertexAttributeBin
{
}

gl::GLuint VertexAttributeBindingImplementation_VertexAttribBindingARB::create() const
{
gl::GLuint result = 0;

gl::glGenVertexArrays(1, &result);

return result;
}

void VertexAttributeBindingImplementation_VertexAttribBindingARB::destroy(gl::GLuint id) const
{
gl::glDeleteVertexArrays(1, &id);
}

void VertexAttributeBindingImplementation_VertexAttribBindingARB::enable(const VertexArray * vertexArray, GLint attributeIndex) const
{
VertexAttributeBindingImplementation_Legacy::instance()->enable(vertexArray, attributeIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class VertexAttributeBindingImplementation_VertexAttribBindingARB : public Abstr
VertexAttributeBindingImplementation_VertexAttribBindingARB();
virtual ~VertexAttributeBindingImplementation_VertexAttribBindingARB();

virtual gl::GLuint create() const override;
virtual void destroy(gl::GLuint id) const override;

virtual void enable(const VertexArray * vertexArray, gl::GLint attributeIndex) const override;
virtual void disable(const VertexArray * vertexArray, gl::GLint attributeIndex) const override;

Expand Down

0 comments on commit d168bdf

Please sign in to comment.