summaryrefslogtreecommitdiffstats
path: root/Project/VertexBufferLayout.h
diff options
context:
space:
mode:
authorThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-07-07 23:12:04 -0300
committerThales Lima Oliveira <thaleslima.ufu@gmail.com>2020-07-07 23:12:04 -0300
commitab30228b1a57053323363674fa7f137c0329a180 (patch)
tree50849a3680d61a2428665cc1035f1f4215870acb /Project/VertexBufferLayout.h
parent6c0e98a2727d07e1fbb38b78c27d68e98ad09465 (diff)
downloadPSP.git-ab30228b1a57053323363674fa7f137c0329a180.tar.gz
PSP.git-ab30228b1a57053323363674fa7f137c0329a180.tar.xz
PSP.git-ab30228b1a57053323363674fa7f137c0329a180.zip
Voltage heat map implemented
Voltage heat map implemented using modern OpenGL =) New external library required: -GLEW -GLFW -GLM (incorporeted at the source) Old memory leaks fixed =)
Diffstat (limited to 'Project/VertexBufferLayout.h')
-rw-r--r--Project/VertexBufferLayout.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/Project/VertexBufferLayout.h b/Project/VertexBufferLayout.h
new file mode 100644
index 0000000..d50b19c
--- /dev/null
+++ b/Project/VertexBufferLayout.h
@@ -0,0 +1,72 @@
+#ifndef VERTEXBUFFERLAYOUT_H
+#define VERTEXBUFFERLAYOUT_H
+
+#include <vector>
+#include <GL/glew.h>
+
+#include "Renderer.h"
+
+struct VertexBufferElement
+{
+ unsigned int type;
+ unsigned int count;
+ unsigned char normalized;
+
+ static unsigned int GetSizeOfType(unsigned int type)
+ {
+ switch (type)
+ {
+ case GL_FLOAT: return 4;
+ case GL_UNSIGNED_INT: return 4;
+ case GL_UNSIGNED_BYTE: return 1;
+ default: break;
+ }
+ ASSERT(false);
+ return(0);
+ }
+};
+
+class VertexBufferLayout
+{
+public:
+ VertexBufferLayout()
+ : m_stride(0) {}
+ ~VertexBufferLayout() {}
+
+
+ template<typename T>
+ void Push(unsigned int count)
+ {
+ static_assert(false);
+ }
+
+ template<>
+ void Push<float>(unsigned int count)
+ {
+ m_elements.push_back({ GL_FLOAT, count, GL_FALSE });
+ m_stride += count * VertexBufferElement::GetSizeOfType(GL_FLOAT);
+ }
+
+ template<>
+ void Push<unsigned int>(unsigned int count)
+ {
+ m_elements.push_back({ GL_UNSIGNED_INT, count, GL_FALSE });
+ m_stride += count * VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT);
+ }
+
+ template<>
+ void Push<unsigned char>(unsigned int count)
+ {
+ m_elements.push_back({ GL_UNSIGNED_BYTE, count, GL_TRUE });
+ m_stride += count * VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE);
+ }
+
+ inline const std::vector<VertexBufferElement> GetElements() const& { return m_elements; }
+ inline unsigned int GetStride() const& { return m_stride; }
+
+private:
+ std::vector<VertexBufferElement> m_elements;
+ unsigned int m_stride;
+};
+
+#endif // VERTEXBUFFERLAYOUT_H