refactor: change gl functions name
This commit is contained in:
@@ -51,7 +51,7 @@ bool Renderer::init(){
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::renderVAO(const GL::VAO& vao){
|
||||
void Renderer::renderVAO(const GL::VertexArray& vao){
|
||||
m_WorldShader->start();
|
||||
vao.bind();
|
||||
glDrawArrays(GL_TRIANGLES, 0, vao.getVertexCount());
|
||||
|
||||
@@ -11,9 +11,9 @@ namespace render {
|
||||
|
||||
void WorldRenderer::loadModels(){
|
||||
std::cout << "World Created !\n";
|
||||
m_WorldVao = std::make_unique<GL::VAO>(std::move(WorldLoader::loadWorldModel(m_World)));
|
||||
m_MobVao = std::make_unique<GL::VAO>(std::move(WorldLoader::loadMobModel()));
|
||||
m_SelectTileVao = std::make_unique<GL::VAO>(std::move(WorldLoader::loadTileSelectModel()));
|
||||
m_WorldVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::loadWorldModel(m_World)));
|
||||
m_MobVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::loadMobModel()));
|
||||
m_SelectTileVao = std::make_unique<GL::VertexArray>(std::move(WorldLoader::loadTileSelectModel()));
|
||||
std::cout << "Vertex Count : " << m_WorldVao->getVertexCount() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,35 +13,35 @@ using namespace gl;
|
||||
|
||||
namespace GL{
|
||||
|
||||
VAO::~VAO(){
|
||||
VertexArray::~VertexArray(){
|
||||
if(m_ID != 0)
|
||||
glDeleteVertexArrays(1, &m_ID);
|
||||
}
|
||||
|
||||
VAO::VAO(unsigned int vertexCount) : m_VertexCount(vertexCount){
|
||||
VertexArray::VertexArray(unsigned int vertexCount) : m_VertexCount(vertexCount){
|
||||
glGenVertexArrays(1, &m_ID);
|
||||
}
|
||||
|
||||
void VAO::bind() const{
|
||||
void VertexArray::bind() const{
|
||||
glBindVertexArray(m_ID);
|
||||
}
|
||||
|
||||
void VAO::unbind() const{
|
||||
void VertexArray::unbind() const{
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void VAO::bindVBO(VBO& vbo){
|
||||
vbo.bind();
|
||||
vbo.bindVertexAttribs();
|
||||
m_Vbos.push_back(std::move(vbo));
|
||||
void VertexArray::bindVertexBuffer(VertexBuffer& VertexBuffer){
|
||||
VertexBuffer.bind();
|
||||
VertexBuffer.bindVertexAttribs();
|
||||
m_VertexBuffers.push_back(std::move(VertexBuffer));
|
||||
}
|
||||
|
||||
VBO::~VBO(){
|
||||
VertexBuffer::~VertexBuffer(){
|
||||
if(m_ID != 0)
|
||||
glDeleteBuffers(1, &m_ID);
|
||||
}
|
||||
|
||||
VBO::VBO(const std::vector<float>& data, unsigned int stride) : m_DataStride(stride){
|
||||
VertexBuffer::VertexBuffer(const std::vector<float>& data, unsigned int stride) : m_DataStride(stride){
|
||||
glGenBuffers(1, &m_ID);
|
||||
bind();
|
||||
glBufferData(GL_ARRAY_BUFFER, data.size() * sizeof(float), nullptr, GL_STATIC_DRAW);
|
||||
@@ -49,15 +49,15 @@ namespace GL{
|
||||
unbind();
|
||||
}
|
||||
|
||||
void VBO::bind() const{
|
||||
void VertexBuffer::bind() const{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_ID);
|
||||
}
|
||||
|
||||
void VBO::unbind() const{
|
||||
void VertexBuffer::unbind() const{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
}
|
||||
|
||||
void VBO::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset){
|
||||
void VertexBuffer::addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset){
|
||||
VertexAttribPointer pointer;
|
||||
pointer.m_Index = index;
|
||||
pointer.m_Size = coordinateSize;
|
||||
@@ -65,7 +65,7 @@ namespace GL{
|
||||
m_VertexAttribs.push_back(pointer);
|
||||
}
|
||||
|
||||
void VBO::bindVertexAttribs() const{
|
||||
void VertexBuffer::bindVertexAttribs() const{
|
||||
for(const VertexAttribPointer& pointer : m_VertexAttribs){
|
||||
glEnableVertexAttribArray(pointer.m_Index);
|
||||
glVertexAttribPointer(pointer.m_Index, pointer.m_Size, GL_FLOAT, false, m_DataStride * sizeof(float), (void*)(intptr_t) pointer.m_Offset);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace render {
|
||||
|
||||
namespace WorldLoader {
|
||||
|
||||
GL::VAO loadMobModel(){
|
||||
GL::VertexArray loadMobModel(){
|
||||
std::vector<float> positions = {
|
||||
-0.5, -0.5,
|
||||
0.5, -0.5,
|
||||
@@ -35,20 +35,20 @@ GL::VAO loadMobModel(){
|
||||
yellowFloat
|
||||
};
|
||||
|
||||
GL::VBO positionVBO(positions, 2);
|
||||
GL::VertexBuffer positionVBO(positions, 2);
|
||||
positionVBO.addVertexAttribPointer(0, 2, 0);
|
||||
GL::VBO colorVBO(colors, 1);
|
||||
GL::VertexBuffer colorVBO(colors, 1);
|
||||
colorVBO.addVertexAttribPointer(1, 1, 0);
|
||||
|
||||
GL::VAO mobVao(colors.size()); // each pos = 1 color
|
||||
GL::VertexArray mobVao(colors.size()); // each pos = 1 color
|
||||
mobVao.bind();
|
||||
mobVao.bindVBO(positionVBO);
|
||||
mobVao.bindVBO(colorVBO);
|
||||
mobVao.bindVertexBuffer(positionVBO);
|
||||
mobVao.bindVertexBuffer(colorVBO);
|
||||
mobVao.unbind();
|
||||
return mobVao;
|
||||
}
|
||||
|
||||
GL::VAO loadWorldModel(const td::game::World* world){
|
||||
GL::VertexArray loadWorldModel(const td::game::World* world){
|
||||
std::vector<float> positions;
|
||||
std::vector<float> colors;
|
||||
|
||||
@@ -143,20 +143,20 @@ GL::VAO loadWorldModel(const td::game::World* world){
|
||||
}
|
||||
}
|
||||
|
||||
GL::VBO positionVBO(positions, 2);
|
||||
GL::VertexBuffer positionVBO(positions, 2);
|
||||
positionVBO.addVertexAttribPointer(0, 2, 0);
|
||||
GL::VBO colorVBO(colors, 1);
|
||||
GL::VertexBuffer colorVBO(colors, 1);
|
||||
colorVBO.addVertexAttribPointer(1, 1, 0);
|
||||
|
||||
GL::VAO worldVao(positions.size() / 2); // each pos = 2 vertecies
|
||||
GL::VertexArray worldVao(positions.size() / 2); // each pos = 2 vertecies
|
||||
worldVao.bind();
|
||||
worldVao.bindVBO(positionVBO);
|
||||
worldVao.bindVBO(colorVBO);
|
||||
worldVao.bindVertexBuffer(positionVBO);
|
||||
worldVao.bindVertexBuffer(colorVBO);
|
||||
worldVao.unbind();
|
||||
return worldVao;
|
||||
}
|
||||
|
||||
GL::VAO loadTileSelectModel(){
|
||||
GL::VertexArray loadTileSelectModel(){
|
||||
std::vector<float> positions = {
|
||||
0, 0,
|
||||
1, 0,
|
||||
@@ -174,15 +174,15 @@ GL::VAO loadTileSelectModel(){
|
||||
|
||||
std::vector<float> colors(6, colorFloat);
|
||||
|
||||
GL::VBO positionVBO(positions, 2);
|
||||
GL::VertexBuffer positionVBO(positions, 2);
|
||||
positionVBO.addVertexAttribPointer(0, 2, 0);
|
||||
GL::VBO colorVBO(colors, 1);
|
||||
GL::VertexBuffer colorVBO(colors, 1);
|
||||
colorVBO.addVertexAttribPointer(1, 1, 0);
|
||||
|
||||
GL::VAO tileSelectVao(positions.size() / 2); // each pos = 2 vertecies
|
||||
GL::VertexArray tileSelectVao(positions.size() / 2); // each pos = 2 vertecies
|
||||
tileSelectVao.bind();
|
||||
tileSelectVao.bindVBO(positionVBO);
|
||||
tileSelectVao.bindVBO(colorVBO);
|
||||
tileSelectVao.bindVertexBuffer(positionVBO);
|
||||
tileSelectVao.bindVertexBuffer(colorVBO);
|
||||
tileSelectVao.unbind();
|
||||
|
||||
return tileSelectVao;
|
||||
|
||||
Reference in New Issue
Block a user