0% found this document useful (0 votes)
47 views1 page

"Renderer.H": Vertexbufferelement

This document defines data structures for vertex buffer layouts in OpenGL. It defines a VertexBufferElement struct to store the type, count, and normalization of elements. It also defines a VertexBufferLayout class that stores a vector of elements and the stride. The VertexBufferLayout class has template Push methods to add elements of different data types like float, unsigned int, and unsigned char, and calculates the stride. It provides get methods to retrieve the elements and stride.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views1 page

"Renderer.H": Vertexbufferelement

This document defines data structures for vertex buffer layouts in OpenGL. It defines a VertexBufferElement struct to store the type, count, and normalization of elements. It also defines a VertexBufferLayout class that stores a vector of elements and the stride. The VertexBufferLayout class has template Push methods to add elements of different data types like float, unsigned int, and unsigned char, and calculates the stride. It provides get methods to retrieve the elements and stride.

Uploaded by

iDenis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

#pragma once

#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;
}
ASSERT(false);
return 0;
}
};

class VertexBufferLayout {
private:
std::vector<VertexBufferElement> m_Elements;
unsigned int m_Stride;
public:
VertexBufferLayout()
:m_Stride(0) {}

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; }
};

You might also like