From 49f7a3e2d7bdfa710701233a3f0442eae02a9183 Mon Sep 17 00:00:00 2001 From: elipzer Date: Wed, 10 Oct 2018 10:54:13 -0400 Subject: [PATCH] Fixed the textured cube from being broken. The problem was caused by vector re-allocation. This is a similar problem to what happened with the mesh factory. It was solved by converting the texture factory to use lists instead of vectors. The reason for using lists is to prevent the need for explicit deallocation of resources and instead allow the use of a list to automatically allocate/deallocate the textures/samplers/meshes. --- OpenGLEngine/SpriteBatch.h | 1 - OpenGLEngine/TextureFactory.cpp | 4 ++-- OpenGLEngine/TextureFactory.h | 6 +++--- OpenGLEngine/TexturedBatch.cpp | 4 ++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/OpenGLEngine/SpriteBatch.h b/OpenGLEngine/SpriteBatch.h index bbf835f..03213a6 100644 --- a/OpenGLEngine/SpriteBatch.h +++ b/OpenGLEngine/SpriteBatch.h @@ -43,7 +43,6 @@ namespace charcoal glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch >::m_vertex_vbo); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); - // TODO: Figure out how to do this without offsetof :( glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)position_offset); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(VertexType), (void*)uv_offset); glBindBuffer(GL_ARRAY_BUFFER, charcoal::Batch >::m_element_buffers[0]); diff --git a/OpenGLEngine/TextureFactory.cpp b/OpenGLEngine/TextureFactory.cpp index 6c16aac..15aa4c1 100644 --- a/OpenGLEngine/TextureFactory.cpp +++ b/OpenGLEngine/TextureFactory.cpp @@ -2,6 +2,6 @@ namespace charcoal { - std::vector TextureFactory::m_textures; - std::vector TextureFactory::m_samplers; + std::list TextureFactory::m_textures; + std::list TextureFactory::m_samplers; } \ No newline at end of file diff --git a/OpenGLEngine/TextureFactory.h b/OpenGLEngine/TextureFactory.h index 2327e68..28e889c 100644 --- a/OpenGLEngine/TextureFactory.h +++ b/OpenGLEngine/TextureFactory.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "ImageLoader.h" @@ -49,7 +49,7 @@ namespace charcoal } private: - static std::vector m_textures; - static std::vector m_samplers; + static std::list m_textures; + static std::list m_samplers; }; } diff --git a/OpenGLEngine/TexturedBatch.cpp b/OpenGLEngine/TexturedBatch.cpp index 1a8d479..41987ba 100644 --- a/OpenGLEngine/TexturedBatch.cpp +++ b/OpenGLEngine/TexturedBatch.cpp @@ -1,5 +1,7 @@ #include "TexturedBatch.h" +#include "Util.h" // CHECK_GL_ERR + namespace charcoal { namespace builtin @@ -10,7 +12,9 @@ namespace charcoal { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_p_renderable->get_texture()->get_texture()); + CHECK_GL_ERR(); glBindSampler(0, m_p_renderable->get_sampler()->get_sampler()); + CHECK_GL_ERR(); } void Batch::setup_vao()