Added VertexArray
This commit is contained in:
1 parent
99404714e8
commit
0724c6a84a
11 files changed
+78
-13
No files matched your search
@@ -30,7 +30,7 @@ namespace nf {
|
||||
wglMakeCurrent(m_hdc, m_hglrc);
|
||||
glewExperimental = GL_TRUE;
|
||||
if (glewInit() != GLEW_OK) {
|
||||
Error("Could not initialize GLEW");
|
||||
Error("Could not initialize GLEW!");
|
||||
}
|
||||
const int attrib[] = {
|
||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||
|
||||
@@ -1,9 +1,46 @@
|
||||
#include "VertexArray.h"
|
||||
|
||||
namespace nf{
|
||||
VertexArray::VertexArray(VertexBuffer& buffer) {
|
||||
namespace nf {
|
||||
unsigned int VertexBufferElement::getSizeOfType(unsigned int type) {
|
||||
switch (type)
|
||||
{
|
||||
case GL_FLOAT:
|
||||
return sizeof(type);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
VertexArray::VertexArray(const void* bufferData, size_t bufferSize) :
|
||||
m_id(0),
|
||||
m_vb(bufferData, bufferSize),
|
||||
m_hasLayout(false)
|
||||
{
|
||||
glGenVertexArrays(1, &m_id);
|
||||
//TODO: Bind buffer and set the layout
|
||||
}
|
||||
|
||||
void VertexArray::bind() {
|
||||
glBindVertexArray(m_id);
|
||||
m_vb.bind();
|
||||
if (!m_hasLayout && m_vertexStride > 0) {
|
||||
unsigned int offset = 0;
|
||||
for (unsigned int i = 0; i < m_layoutElements.size(); i++) {
|
||||
const VertexBufferElement& element = m_layoutElements[i];
|
||||
glEnableVertexAttribArray(i);
|
||||
glVertexAttribPointer(i, element.count, element.type, element.normalized, m_vertexStride, (const void*)offset);
|
||||
offset += element.count * VertexBufferElement::getSizeOfType(element.type);
|
||||
}
|
||||
m_hasLayout = true;
|
||||
}
|
||||
else if(!m_hasLayout) {
|
||||
Error("No layout specified for vertex buffer!");
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
void VertexArray::push<float>(unsigned int count) {
|
||||
m_layoutElements.push_back({ GL_FLOAT, count, GL_FALSE });
|
||||
m_vertexStride += VertexBufferElement::getSizeOfType(GL_FLOAT) * count;
|
||||
}
|
||||
|
||||
VertexArray::~VertexArray() {
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace nf {
|
||||
VertexBuffer::VertexBuffer(const void* data, size_t size) {
|
||||
glGenBuffers(1, &m_id);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_id);
|
||||
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);//TODO: See if I need to change this to dynamic
|
||||
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);
|
||||
}
|
||||
|
||||
void VertexBuffer::bind() const {
|
||||
|
||||
Reference in new issue
Block a user