diff --git a/Makefile b/Makefile index def1c28..f81198e 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CXX=g++ -CXXOPTS=-Og -ggdb -Wall -Wextra -pedantic -Wno-unused-function -Wno-unused-parameter -Wno-sign-compare -std=c++11 +CXXOPTS=-Og -ggdb -Wall -Wextra -pedantic -Wno-unused-function -Wno-unused-parameter -Wno-sign-compare -std=c++11 -flto LDOPTS=-flto LIBS=-lglbinding -lSDL2 -lSDL2_image -lobj CXXSRCS=main.cc objectParser.cc diff --git a/Object.hh b/Object.hh index a235bcb..77c7e4f 100644 --- a/Object.hh +++ b/Object.hh @@ -21,9 +21,13 @@ public: construct(std::get<0>(tmp)); } + Object(Object const& copy) = delete; + ~Object() { glDeleteVertexArrays(1, &_vaID); } + + Object& operator=(Object const& copy) = delete; void draw(glm::mat4 const& modelview, Program *override = nullptr) const { glBindVertexArray(_vaID); diff --git a/VBOManager.hh b/VBOManager.hh index feedfb1..da61f8d 100644 --- a/VBOManager.hh +++ b/VBOManager.hh @@ -40,6 +40,9 @@ public: move._vbo = nullptr; } + VBOAlloc(VBOAlloc const& copy) = delete; + VBOAlloc& operator=(VBOAlloc const& copy) = delete; + VBOAlloc& operator=(VBOAlloc&& move) { _vbo = move._vbo; _ofs = move._ofs; @@ -103,10 +106,22 @@ private: } VBO(VBO const& copy) = delete; - - VBO(VBO&& move) : _bufID(move._bufID), _allocs(move._allocs) { + VBO& operator=(VBO const& copy) = delete; + + VBO(VBO&& move) : _bufID(move._bufID), _allocs(std::move(move._allocs)) { move._bufID = 0; } + + VBO& operator=(VBO&& move) { + for (auto ent : _allocs) { + assert(!ent.used); + } + if (_bufID) + glDeleteBuffers(1, &_bufID); + _bufID = move._bufID; + move._bufID = 0; + _allocs = std::move(move._allocs); + } ~VBO() { for (auto ent : _allocs) { diff --git a/shaders.hh b/shaders.hh index 7e14ccd..0b77257 100644 --- a/shaders.hh +++ b/shaders.hh @@ -34,8 +34,7 @@ public: Shader() : _shaderID(0) { } - Shader(std::string const& program, GLenum type) { - _shaderID = glCreateShader(type); + Shader(std::string const& program, GLenum type) : _shaderID(glCreateShader(type)) { const char* const arr[] = {program.c_str()}; glShaderSource(_shaderID, 1, arr, NULL); glCompileShader(_shaderID); @@ -62,12 +61,11 @@ public: glDeleteShader(_shaderID); } -protected: unsigned getID() const { return _shaderID; } - - friend class Program; + +protected: unsigned int _shaderID; }; @@ -78,7 +76,7 @@ public: VertexShader(std::string const& program) : Shader(program, GL_VERTEX_SHADER) { } - virtual ~VertexShader() { + ~VertexShader() override { } }; @@ -102,9 +100,8 @@ public: class Program { public: - Program(VertexShader& vertex, FragmentShader& frag) : _geom(nullptr), _vertex(vertex), _frag(frag) { - _progID = glCreateProgram(); - + Program(VertexShader& vertex, FragmentShader& frag) + : _geom(nullptr), _vertex(vertex), _frag(frag), _progID(glCreateProgram()) { glAttachShader(_progID, _vertex.getID()); glAttachShader(_progID, _frag.getID()); @@ -131,9 +128,8 @@ public: glDetachShader(_progID, _frag.getID()); } - Program(GeometryShader& geom, VertexShader& vertex, FragmentShader& frag) : _geom(&geom), _vertex(vertex), _frag(frag) { - _progID = glCreateProgram(); - + Program(GeometryShader& geom, VertexShader& vertex, FragmentShader& frag) + : _geom(&geom), _vertex(vertex), _frag(frag), _progID(glCreateProgram()) { glAttachShader(_progID, _geom->getID()); glAttachShader(_progID, _vertex.getID()); glAttachShader(_progID, _frag.getID()); diff --git a/texture.hh b/texture.hh index e4f62cf..b12c5da 100644 --- a/texture.hh +++ b/texture.hh @@ -24,7 +24,7 @@ static unsigned ilog2(unsigned in) class Framebuffer { public: - Framebuffer() { + Framebuffer() : _fbID(0) { glGenFramebuffers(1, &_fbID); } @@ -51,7 +51,7 @@ private: class TextureCubeMap { public: - TextureCubeMap(unsigned size) { + TextureCubeMap(unsigned size) : _texID(0) { glGenTextures(1, &_texID); glBindTexture(GL_TEXTURE_CUBE_MAP, _texID); @@ -106,11 +106,11 @@ private: class Texture2D { public: - Texture2D(unsigned width, unsigned height) { + Texture2D(unsigned width, unsigned height) : _texID(0) { _glCreate(width, height); } - Texture2D(std::string const& file) { + Texture2D(std::string const& file) : _texID(0) { SDL_Surface *surf = IMG_Load(file.c_str()); if (!surf) throw SDLException();