some effc++ fixes
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
|||||||
CXX=g++
|
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
|
LDOPTS=-flto
|
||||||
LIBS=-lglbinding -lSDL2 -lSDL2_image -lobj
|
LIBS=-lglbinding -lSDL2 -lSDL2_image -lobj
|
||||||
CXXSRCS=main.cc objectParser.cc
|
CXXSRCS=main.cc objectParser.cc
|
||||||
|
|||||||
@@ -21,9 +21,13 @@ public:
|
|||||||
construct(std::get<0>(tmp));
|
construct(std::get<0>(tmp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object(Object const& copy) = delete;
|
||||||
|
|
||||||
~Object() {
|
~Object() {
|
||||||
glDeleteVertexArrays(1, &_vaID);
|
glDeleteVertexArrays(1, &_vaID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Object& operator=(Object const& copy) = delete;
|
||||||
|
|
||||||
void draw(glm::mat4 const& modelview, Program *override = nullptr) const {
|
void draw(glm::mat4 const& modelview, Program *override = nullptr) const {
|
||||||
glBindVertexArray(_vaID);
|
glBindVertexArray(_vaID);
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ public:
|
|||||||
move._vbo = nullptr;
|
move._vbo = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VBOAlloc(VBOAlloc const& copy) = delete;
|
||||||
|
VBOAlloc& operator=(VBOAlloc const& copy) = delete;
|
||||||
|
|
||||||
VBOAlloc& operator=(VBOAlloc&& move) {
|
VBOAlloc& operator=(VBOAlloc&& move) {
|
||||||
_vbo = move._vbo;
|
_vbo = move._vbo;
|
||||||
_ofs = move._ofs;
|
_ofs = move._ofs;
|
||||||
@@ -103,10 +106,22 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
VBO(VBO const& copy) = delete;
|
VBO(VBO const& copy) = delete;
|
||||||
|
VBO& operator=(VBO const& copy) = delete;
|
||||||
VBO(VBO&& move) : _bufID(move._bufID), _allocs(move._allocs) {
|
|
||||||
|
VBO(VBO&& move) : _bufID(move._bufID), _allocs(std::move(move._allocs)) {
|
||||||
move._bufID = 0;
|
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() {
|
~VBO() {
|
||||||
for (auto ent : _allocs) {
|
for (auto ent : _allocs) {
|
||||||
|
|||||||
20
shaders.hh
20
shaders.hh
@@ -34,8 +34,7 @@ public:
|
|||||||
Shader() : _shaderID(0) {
|
Shader() : _shaderID(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Shader(std::string const& program, GLenum type) {
|
Shader(std::string const& program, GLenum type) : _shaderID(glCreateShader(type)) {
|
||||||
_shaderID = glCreateShader(type);
|
|
||||||
const char* const arr[] = {program.c_str()};
|
const char* const arr[] = {program.c_str()};
|
||||||
glShaderSource(_shaderID, 1, arr, NULL);
|
glShaderSource(_shaderID, 1, arr, NULL);
|
||||||
glCompileShader(_shaderID);
|
glCompileShader(_shaderID);
|
||||||
@@ -62,12 +61,11 @@ public:
|
|||||||
glDeleteShader(_shaderID);
|
glDeleteShader(_shaderID);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
unsigned getID() const {
|
unsigned getID() const {
|
||||||
return _shaderID;
|
return _shaderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
friend class Program;
|
protected:
|
||||||
|
|
||||||
unsigned int _shaderID;
|
unsigned int _shaderID;
|
||||||
};
|
};
|
||||||
@@ -78,7 +76,7 @@ public:
|
|||||||
VertexShader(std::string const& program) : Shader(program, GL_VERTEX_SHADER) {
|
VertexShader(std::string const& program) : Shader(program, GL_VERTEX_SHADER) {
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~VertexShader() {
|
~VertexShader() override {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -102,9 +100,8 @@ public:
|
|||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
public:
|
public:
|
||||||
Program(VertexShader& vertex, FragmentShader& frag) : _geom(nullptr), _vertex(vertex), _frag(frag) {
|
Program(VertexShader& vertex, FragmentShader& frag)
|
||||||
_progID = glCreateProgram();
|
: _geom(nullptr), _vertex(vertex), _frag(frag), _progID(glCreateProgram()) {
|
||||||
|
|
||||||
glAttachShader(_progID, _vertex.getID());
|
glAttachShader(_progID, _vertex.getID());
|
||||||
glAttachShader(_progID, _frag.getID());
|
glAttachShader(_progID, _frag.getID());
|
||||||
|
|
||||||
@@ -131,9 +128,8 @@ public:
|
|||||||
glDetachShader(_progID, _frag.getID());
|
glDetachShader(_progID, _frag.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
Program(GeometryShader& geom, VertexShader& vertex, FragmentShader& frag) : _geom(&geom), _vertex(vertex), _frag(frag) {
|
Program(GeometryShader& geom, VertexShader& vertex, FragmentShader& frag)
|
||||||
_progID = glCreateProgram();
|
: _geom(&geom), _vertex(vertex), _frag(frag), _progID(glCreateProgram()) {
|
||||||
|
|
||||||
glAttachShader(_progID, _geom->getID());
|
glAttachShader(_progID, _geom->getID());
|
||||||
glAttachShader(_progID, _vertex.getID());
|
glAttachShader(_progID, _vertex.getID());
|
||||||
glAttachShader(_progID, _frag.getID());
|
glAttachShader(_progID, _frag.getID());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ static unsigned ilog2(unsigned in)
|
|||||||
|
|
||||||
class Framebuffer {
|
class Framebuffer {
|
||||||
public:
|
public:
|
||||||
Framebuffer() {
|
Framebuffer() : _fbID(0) {
|
||||||
glGenFramebuffers(1, &_fbID);
|
glGenFramebuffers(1, &_fbID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ private:
|
|||||||
|
|
||||||
class TextureCubeMap {
|
class TextureCubeMap {
|
||||||
public:
|
public:
|
||||||
TextureCubeMap(unsigned size) {
|
TextureCubeMap(unsigned size) : _texID(0) {
|
||||||
glGenTextures(1, &_texID);
|
glGenTextures(1, &_texID);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, _texID);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, _texID);
|
||||||
|
|
||||||
@@ -106,11 +106,11 @@ private:
|
|||||||
|
|
||||||
class Texture2D {
|
class Texture2D {
|
||||||
public:
|
public:
|
||||||
Texture2D(unsigned width, unsigned height) {
|
Texture2D(unsigned width, unsigned height) : _texID(0) {
|
||||||
_glCreate(width, height);
|
_glCreate(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D(std::string const& file) {
|
Texture2D(std::string const& file) : _texID(0) {
|
||||||
SDL_Surface *surf = IMG_Load(file.c_str());
|
SDL_Surface *surf = IMG_Load(file.c_str());
|
||||||
if (!surf)
|
if (!surf)
|
||||||
throw SDLException();
|
throw SDLException();
|
||||||
|
|||||||
Reference in New Issue
Block a user