From 260808b1fc3f74b0f2831bb272618febf17e5436 Mon Sep 17 00:00:00 2001 From: Matthias Blankertz Date: Fri, 13 Feb 2015 15:47:56 +0100 Subject: [PATCH] Binary object storage, misc changes --- Makefile | 15 ++++++++++++--- VBOManager.hh | 1 + binifyObj.cc | 14 ++++++++++++++ object.proto | 12 ++++++++++++ objectParser.cc | 34 ++++++++++++++++++++++++++++++++++ objectParser.hh | 3 +++ texture.hh | 30 ++++++++++++++++++++++++++++++ 7 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 binifyObj.cc create mode 100644 object.proto diff --git a/Makefile b/Makefile index def1c28..e8ee015 100644 --- a/Makefile +++ b/Makefile @@ -1,20 +1,29 @@ CXX=g++ CXXOPTS=-Og -ggdb -Wall -Wextra -pedantic -Wno-unused-function -Wno-unused-parameter -Wno-sign-compare -std=c++11 LDOPTS=-flto -LIBS=-lglbinding -lSDL2 -lSDL2_image -lobj -CXXSRCS=main.cc objectParser.cc +LIBS=-lglbinding -lSDL2 -lSDL2_image -lobj -lprotobuf +CXXSRCS=main.cc objectParser.cc object.pb.cc +BINIFY_SRCS=binifyObj.cc objectParser.cc object.pb.cc OBJS=$(addprefix objs/,$(CXXSRCS:.cc=.o)) +BINIFY_OBJS=$(addprefix objs/,$(BINIFY_SRCS:.cc=.o)) objs/%.o: %.cc $(CXX) $(CXXOPTS) -c -MMD -MP -o $@ $< @cp objs/$*.d objs/$*.P; rm -f objs/$*.d +%.pb.cc %.pb.h: %.proto + protoc --cpp_out=. $< + oglpg: $(OBJS) $(CXX) $(CXXOPTS) $(LDOPTS) -o $@ $(OBJS) $(LIBS) +binifyObj: $(BINIFY_OBJS) + $(CXX) $(CXXOPTS) $(LDOPTS) -o $@ $(BINIFY_OBJS) $(LIBS) + clean: - rm -f oglpg $(OBJS) $(addprefix objs/,$(CXXSRCS:.cc=.P)) + rm -f oglpg $(OBJS) $(BINIFY_OBJS) $(addprefix objs/,$(CXXSRCS:.cc=.P)) $(addprefix objs/,$(BINIFY_SRCS:.cc=.P)) .PHONY: clean -include $(addprefix objs/,$(CXXSRCS:.cc=.P)) +-include $(addprefix objs/,$(BINIFY_SRCS:.cc=.P)) diff --git a/VBOManager.hh b/VBOManager.hh index feedfb1..e2ff6dd 100644 --- a/VBOManager.hh +++ b/VBOManager.hh @@ -155,6 +155,7 @@ private: it->size += std::prev(it)->size; _allocs.erase(std::prev(it)); } + return; } pos += it->size; } diff --git a/binifyObj.cc b/binifyObj.cc new file mode 100644 index 0000000..aad9079 --- /dev/null +++ b/binifyObj.cc @@ -0,0 +1,14 @@ +#include + +#include "objectParser.hh" + +int main(int argc, char* argv[]) +{ + if(argc != 3) + return 1; + + auto obj = readObject(argv[1]); + writeObjectPB(argv[2], obj); + + return 0; +} diff --git a/object.proto b/object.proto new file mode 100644 index 0000000..87cde69 --- /dev/null +++ b/object.proto @@ -0,0 +1,12 @@ +package pb; + +message VertexAttribs { + repeated float vertex = 1 [packed=true]; + repeated uint32 texCoords = 2 [packed=true]; + required fixed32 normal = 3; +} + +message Object { + repeated VertexAttribs attribs = 1; + repeated uint32 indices = 2 [packed=true]; +} diff --git a/objectParser.cc b/objectParser.cc index dc83161..a98f69b 100644 --- a/objectParser.cc +++ b/objectParser.cc @@ -418,3 +418,37 @@ std::tuple, std::vector > readObject(std parser.parse(filename); return std::tuple, std::vector >(parser.buildVA(), parser.buildIndices()); } + + +#include + +#include "object.pb.h" + +using std::ios; + +void writeObjectPB(std::string const& filename, std::tuple, std::vector > obj) +{ + std::fstream output(filename, ios::out | ios::binary); + + pb::Object pbObj; + for (auto const& ind : std::get<1>(obj)) { + pbObj.add_indices(ind); + } + + for (auto const& attr : std::get<0>(obj)) { + auto a = pbObj.add_attribs(); + for(int i = 0;i < 3;++i) + a->add_vertex(attr.vertex[i]); + for(int i = 0;i < 2;++i) + a->add_texcoords(attr.texCoords[i]); + a->set_normal(attr.normal); + } + + pbObj.SerializeToOstream(&output); +} + +std::tuple, std::vector > readObjectPB(std::string const& filename) +{ + return std::tuple, std::vector >(); +} + diff --git a/objectParser.hh b/objectParser.hh index 2579240..0a467e7 100644 --- a/objectParser.hh +++ b/objectParser.hh @@ -32,4 +32,7 @@ struct objVertexAttribs { std::tuple, std::vector > readObject(std::string const& filename); +void writeObjectPB(std::string const& filename, std::tuple, std::vector > obj); +std::tuple, std::vector > readObjectPB(std::string const& filename); + #endif diff --git a/texture.hh b/texture.hh index e4f62cf..8934c1e 100644 --- a/texture.hh +++ b/texture.hh @@ -32,6 +32,21 @@ public: glDeleteFramebuffers(1, &_fbID); } + Framebuffer(Framebuffer const& copy) = delete; + Framebuffer& operator=(Framebuffer const& copy) = delete; + + Framebuffer(Framebuffer && move) : _fbID(move._fbID) { + move._fbID = 0; + } + + Framebuffer& operator=(Framebuffer && move) { + glDeleteFramebuffers(1, &_fbID); + _fbID = move._fbID; + move._fbID = 0; + + return *this; + } + void bind() const { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, _fbID); } @@ -139,6 +154,21 @@ public: glDeleteTextures(1, &_texID); } + Texture2D(Texture2D const& copy) = delete; + Texture2D& operator=(Texture2D const& copy) = delete; + + Texture2D(Texture2D && move) : _texID(move._texID) { + move._texID = 0; + } + + Texture2D& operator=(Texture2D && move) { + glDeleteTextures(1, &_texID); + _texID = move._texID; + move._texID = 0; + + return *this; + } + void bind() { glBindTexture(GL_TEXTURE_2D, _texID); }