Binary object storage, misc changes
This commit is contained in:
15
Makefile
15
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))
|
||||
|
||||
@@ -155,6 +155,7 @@ private:
|
||||
it->size += std::prev(it)->size;
|
||||
_allocs.erase(std::prev(it));
|
||||
}
|
||||
return;
|
||||
}
|
||||
pos += it->size;
|
||||
}
|
||||
|
||||
14
binifyObj.cc
Normal file
14
binifyObj.cc
Normal file
@@ -0,0 +1,14 @@
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
}
|
||||
12
object.proto
Normal file
12
object.proto
Normal file
@@ -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];
|
||||
}
|
||||
@@ -418,3 +418,37 @@ std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> > readObject(std
|
||||
parser.parse(filename);
|
||||
return std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> >(parser.buildVA(), parser.buildIndices());
|
||||
}
|
||||
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "object.pb.h"
|
||||
|
||||
using std::ios;
|
||||
|
||||
void writeObjectPB(std::string const& filename, std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> > 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<objVertexAttribs>, std::vector<uint16_t> > readObjectPB(std::string const& filename)
|
||||
{
|
||||
return std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> >();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,4 +32,7 @@ struct objVertexAttribs {
|
||||
|
||||
std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> > readObject(std::string const& filename);
|
||||
|
||||
void writeObjectPB(std::string const& filename, std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> > obj);
|
||||
std::tuple<std::vector<objVertexAttribs>, std::vector<uint16_t> > readObjectPB(std::string const& filename);
|
||||
|
||||
#endif
|
||||
|
||||
30
texture.hh
30
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user