Refactor SubGeometry to use a vector for storage

+ Use memcpy to populate subgeometry data
This commit is contained in:
Daniel Evans 2014-08-10 20:09:54 +01:00
parent d0188880d3
commit d2e19fbdb3
4 changed files with 10 additions and 16 deletions

View file

@ -96,7 +96,7 @@ public:
struct SubGeometry {
GLuint start = 0;
size_t material;
uint32_t* indices;
std::vector<uint32_t> indices;
size_t numIndices;
};

View file

@ -699,8 +699,8 @@ FileHandle GameData::openFile2(const std::string &name)
auto i = _knownFiles.find(name);
if(i != _knownFiles.end())
{
char* data;
size_t length;
char* data = nullptr;
size_t length = 0;
if(i->second.archived)
{

View file

@ -243,7 +243,7 @@ void LoaderDFF::readGeometry(Model *model, const RWBStream &stream)
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER,
sg.start * sizeof(uint32_t),
sizeof(uint32_t) * sg.numIndices,
sg.indices);
sg.indices.data());
}
}
@ -384,12 +384,10 @@ void LoaderDFF::readBinMeshPLG(Model *model, const RWBStream &stream)
sg.start = start;
start += sg.numIndices;
sg.indices = new std::uint32_t[sg.numIndices];
sg.indices.resize(sg.numIndices);
std::memcpy(sg.indices.data(), data, sizeof(std::uint32_t) * sg.numIndices);
data += sizeof(std::uint32_t) * sg.numIndices;
for(size_t i = 0; i < sg.numIndices; ++i) {
sg.indices[i] = *(std::uint32_t*)data;
data += sizeof(std::uint32_t);
}
model->geometries.back()->subgeom.push_back(sg);
}
}

View file

@ -13,11 +13,7 @@ Model::Geometry::Geometry()
Model::Geometry::~Geometry()
{
for(auto& sg : subgeom) {
if( sg.indices ) {
delete[] sg.indices;
}
}
}
ModelFrame::ModelFrame(ModelFrame* parent, glm::mat3 dR, glm::vec3 dT)