Added VertexArray
This commit is contained in:
parent
99404714e8
commit
0724c6a84a
@ -56,7 +56,7 @@ namespace nf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Error("More than one default state defined");
|
Error("More than one default state defined!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ namespace nf {
|
|||||||
RegisterClass(&wclass);
|
RegisterClass(&wclass);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Error("Cannot run two NF applications at once.");
|
Error("Cannot run two NF applications at once!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ namespace nf {
|
|||||||
wglMakeCurrent(m_hdc, m_hglrc);
|
wglMakeCurrent(m_hdc, m_hglrc);
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
if (glewInit() != GLEW_OK) {
|
if (glewInit() != GLEW_OK) {
|
||||||
Error("Could not initialize GLEW");
|
Error("Could not initialize GLEW!");
|
||||||
}
|
}
|
||||||
const int attrib[] = {
|
const int attrib[] = {
|
||||||
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
||||||
|
@ -1,9 +1,46 @@
|
|||||||
#include "VertexArray.h"
|
#include "VertexArray.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
VertexArray::VertexArray(VertexBuffer& buffer) {
|
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);
|
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() {
|
VertexArray::~VertexArray() {
|
||||||
|
@ -4,7 +4,7 @@ namespace nf {
|
|||||||
VertexBuffer::VertexBuffer(const void* data, size_t size) {
|
VertexBuffer::VertexBuffer(const void* data, size_t size) {
|
||||||
glGenBuffers(1, &m_id);
|
glGenBuffers(1, &m_id);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 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 {
|
void VertexBuffer::bind() const {
|
||||||
|
@ -77,7 +77,7 @@ namespace nf {
|
|||||||
std::ifstream in;
|
std::ifstream in;
|
||||||
in.open(filename);
|
in.open(filename);
|
||||||
if (!in) {
|
if (!in) {
|
||||||
Error("Cannot find file");
|
Error(("File \"" + (std::string)filename + (std::string)"\" could not be read!").c_str());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
#include "IntroGamestate.h"
|
#include "IntroGamestate.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
//TODO: Check #include consistency
|
||||||
|
//TODO: Document ALL frontend functions
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
class Application {
|
class Application {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "GL/glew.h"
|
||||||
#include "Renderer.h"
|
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
class IndexBuffer {
|
class IndexBuffer {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
|
@ -1,13 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef NFENGINE
|
||||||
|
#include "GL/glew.h"
|
||||||
|
#endif
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "VertexBuffer.h"
|
#include "VertexBuffer.h"
|
||||||
|
#include "Utility.h"
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
|
struct VertexBufferElement {
|
||||||
|
unsigned int type;
|
||||||
|
unsigned int count;
|
||||||
|
unsigned char normalized;
|
||||||
|
|
||||||
|
static unsigned int getSizeOfType(unsigned int type);
|
||||||
|
};
|
||||||
|
|
||||||
class VertexArray {
|
class VertexArray {
|
||||||
public:
|
public:
|
||||||
VertexArray(VertexBuffer& buffer);
|
VertexArray(const void* bufferData, size_t bufferSize);
|
||||||
|
|
||||||
|
void bind();
|
||||||
|
template<typename T>
|
||||||
|
void push(unsigned int count);
|
||||||
|
|
||||||
~VertexArray();
|
~VertexArray();
|
||||||
private:
|
private:
|
||||||
unsigned int m_id;
|
unsigned int m_id;
|
||||||
|
VertexBuffer m_vb;
|
||||||
|
bool m_hasLayout;
|
||||||
|
std::vector<VertexBufferElement> m_layoutElements;
|
||||||
|
unsigned int m_vertexStride;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#ifdef NFENGINE
|
||||||
#include "Renderer.h"
|
#include "GL/glew.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace nf {
|
namespace nf {
|
||||||
class VertexBuffer {
|
class VertexBuffer {
|
||||||
|
@ -15,6 +15,9 @@ Remember to use tasks (//TODO: )
|
|||||||
*Engine (Name?) "Nothin' Fancy"
|
*Engine (Name?) "Nothin' Fancy"
|
||||||
*Separate project
|
*Separate project
|
||||||
*Namespaced
|
*Namespaced
|
||||||
|
Refactor NothinFancy.h to ONLY include stuff the frontend needs
|
||||||
|
AND get rid of NFENGINE
|
||||||
|
High CPU usage?
|
||||||
*Debug and log system
|
*Debug and log system
|
||||||
*NatVis
|
*NatVis
|
||||||
*Config changing
|
*Config changing
|
||||||
|
Reference in New Issue
Block a user