From c25a7e6f931b034c6514673f86b36acba8c89a62 Mon Sep 17 00:00:00 2001 From: Angelo Papenhoff Date: Thu, 25 Dec 2014 09:06:42 +0100 Subject: [PATCH] Small fixes in Geometry. --- src/geometry.cpp | 35 ++++++++++++++++------------------- src/plugins.cpp | 7 +++++-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/geometry.cpp b/src/geometry.cpp index 7b920ab..fe6a7e1 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -18,8 +18,9 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags) { this->geoflags = flags & 0xFF00FFFF; this->numTexCoordSets = (flags & 0xFF0000) >> 16; - if(this->numTexCoordSets == 0 && (this->geoflags & TEXTURED)) - this->numTexCoordSets = 1; + if(this->numTexCoordSets == 0) + this->numTexCoordSets = (this->geoflags & TEXTURED) ? 1 : + (this->geoflags & TEXTURED2) ? 2 : 0; this->numTriangles = numTris; this->numVertices = numVerts; this->numMorphTargets = 1; @@ -28,7 +29,7 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags) for(int32 i = 0; i < this->numTexCoordSets; i++) this->texCoords[i] = NULL; this->triangles = NULL; - if(!(this->geoflags & 0xFF000000)){ + if(!(this->geoflags & NATIVE)){ if(this->geoflags & PRELIT) this->colors = new uint8[4*this->numVertices]; if((this->geoflags & TEXTURED) || (this->geoflags & TEXTURED2)) @@ -41,7 +42,7 @@ Geometry::Geometry(int32 numVerts, int32 numTris, uint32 flags) MorphTarget *m = this->morphTargets; m->vertices = NULL; m->normals = NULL; - if(!(this->geoflags & 0xFF000000)){ + if(!(this->geoflags & NATIVE)){ m->vertices = new float32[3*this->numVertices]; if(this->geoflags & NORMALS) m->normals = new float32[3*this->numVertices]; @@ -111,13 +112,12 @@ Geometry::streamRead(istream &stream) if(version < 0x34000) stream.seekg(12, ios::cur); - if(!(geo->geoflags & 0xFF000000)){ + if(!(geo->geoflags & NATIVE)){ if(geo->geoflags & PRELIT) stream.read((char*)geo->colors, 4*geo->numVertices); - if((geo->geoflags & TEXTURED) || (geo->geoflags & TEXTURED2)) - for(int32 i = 0; i < geo->numTexCoordSets; i++) - stream.read((char*)geo->texCoords[i], - 2*geo->numVertices*4); + for(int32 i = 0; i < geo->numTexCoordSets; i++) + stream.read((char*)geo->texCoords[i], + 2*geo->numVertices*4); stream.read((char*)geo->triangles, 4*geo->numTriangles*2); } @@ -157,10 +157,8 @@ geoStructSize(Geometry *geo) if(!(geo->geoflags & 0xFF000000)){ if(geo->geoflags&geo->PRELIT) size += 4*geo->numVertices; - if((geo->geoflags & geo->TEXTURED) || - (geo->geoflags & geo->TEXTURED2)) - for(int32 i = 0; i < geo->numTexCoordSets; i++) - size += 2*geo->numVertices*4; + for(int32 i = 0; i < geo->numTexCoordSets; i++) + size += 2*geo->numVertices*4; size += 4*geo->numTriangles*2; } for(int32 i = 0; i < geo->numMorphTargets; i++){ @@ -192,13 +190,12 @@ Geometry::streamWrite(ostream &stream) if(Version < 0x34000) stream.write((char*)fbuf, sizeof(fbuf)); - if(!(this->geoflags & 0xFF000000)){ + if(!(this->geoflags & NATIVE)){ if(this->geoflags & PRELIT) stream.write((char*)this->colors, 4*this->numVertices); - if((this->geoflags & TEXTURED) || (this->geoflags & TEXTURED2)) - for(int32 i = 0; i < this->numTexCoordSets; i++) - stream.write((char*)this->texCoords[i], - 2*this->numVertices*4); + for(int32 i = 0; i < this->numTexCoordSets; i++) + stream.write((char*)this->texCoords[i], + 2*this->numVertices*4); stream.write((char*)this->triangles, 4*this->numTriangles*2); } @@ -254,7 +251,7 @@ Geometry::addMorphTargets(int32 n) MorphTarget *m = &morphTargets[i]; m->vertices = NULL; m->normals = NULL; - if(!(this->geoflags & 0xFF000000)){ + if(!(this->geoflags & NATIVE)){ m->vertices = new float32[3*this->numVertices]; if(this->geoflags & NORMALS) m->normals = new float32[3*this->numVertices]; diff --git a/src/plugins.cpp b/src/plugins.cpp index 76dd2ae..097b835 100644 --- a/src/plugins.cpp +++ b/src/plugins.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -144,7 +145,8 @@ writeMesh(ostream &stream, int32, void *object, int32, int32) geo->numMaterials); stream.write((char*)buf, 8); if(geo->geoflags & Geometry::NATIVE){ - if(mesh->indices) + assert(geo->instData != NULL); + if(geo->instData->platform == PLATFORM_OGL) stream.write((char*)mesh->indices, mesh->numIndices*2); }else{ @@ -170,7 +172,8 @@ getSizeMesh(void *object, int32) return -1; int32 size = 12 + geo->meshHeader->numMeshes*8; if(geo->geoflags & Geometry::NATIVE){ - if(geo->meshHeader[0].mesh->indices) + assert(geo->instData != NULL); + if(geo->instData->platform == PLATFORM_OGL) size += geo->meshHeader->totalIndices*2; }else{ size += geo->meshHeader->totalIndices*4;