Commit 868d73e2 authored by hybrid's avatar hybrid

Performance optimization.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2228 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 8a0a5544
...@@ -197,7 +197,7 @@ bool COgreMeshFileLoader::readObjectChunk(io::IReadFile* file, ChunkData& parent ...@@ -197,7 +197,7 @@ bool COgreMeshFileLoader::readObjectChunk(io::IReadFile* file, ChunkData& parent
{ {
readVector(file, data, mesh.BBoxMinEdge); readVector(file, data, mesh.BBoxMinEdge);
readVector(file, data, mesh.BBoxMaxEdge); readVector(file, data, mesh.BBoxMaxEdge);
readFloat(file, data, mesh.BBoxRadius); readFloat(file, data, &mesh.BBoxRadius);
} }
break; break;
case COGRE_SKELETON_LINK: case COGRE_SKELETON_LINK:
...@@ -225,7 +225,7 @@ bool COgreMeshFileLoader::readGeometry(io::IReadFile* file, ChunkData& parent, O ...@@ -225,7 +225,7 @@ bool COgreMeshFileLoader::readGeometry(io::IReadFile* file, ChunkData& parent, O
#ifdef IRR_OGRE_LOADER_DEBUG #ifdef IRR_OGRE_LOADER_DEBUG
os::Printer::log("Read Geometry"); os::Printer::log("Read Geometry");
#endif #endif
readInt(file, parent, geometry.NumVertex); readInt(file, parent, &geometry.NumVertex);
while(parent.read < parent.header.length) while(parent.read < parent.header.length)
{ {
ChunkData data; ChunkData data;
...@@ -265,18 +265,18 @@ bool COgreMeshFileLoader::readVertexDeclaration(io::IReadFile* file, ChunkData& ...@@ -265,18 +265,18 @@ bool COgreMeshFileLoader::readVertexDeclaration(io::IReadFile* file, ChunkData&
{ {
case COGRE_GEOMETRY_VERTEX_ELEMENT: case COGRE_GEOMETRY_VERTEX_ELEMENT:
{ {
OgreVertexElement elem; geometry.Elements.push_back(OgreVertexElement());
readShort(file, data, elem.Source); OgreVertexElement& elem = geometry.Elements.getLast();
readShort(file, data, elem.Type); readShort(file, data, &elem.Source);
readShort(file, data, elem.Semantic); readShort(file, data, &elem.Type);
readShort(file, data, &elem.Semantic);
if (elem.Semantic == 7) //Tex coords if (elem.Semantic == 7) //Tex coords
{ {
++NumUV; ++NumUV;
} }
readShort(file, data, elem.Offset); readShort(file, data, &elem.Offset);
elem.Offset /= sizeof(f32); elem.Offset /= sizeof(f32);
readShort(file, data, elem.Index); readShort(file, data, &elem.Index);
geometry.Elements.push_back(elem);
} }
break; break;
default: default:
...@@ -296,17 +296,16 @@ bool COgreMeshFileLoader::readVertexBuffer(io::IReadFile* file, ChunkData& paren ...@@ -296,17 +296,16 @@ bool COgreMeshFileLoader::readVertexBuffer(io::IReadFile* file, ChunkData& paren
os::Printer::log("Read Vertex Buffer"); os::Printer::log("Read Vertex Buffer");
#endif #endif
OgreVertexBuffer buf; OgreVertexBuffer buf;
readShort(file, parent, buf.BindIndex); readShort(file, parent, &buf.BindIndex);
readShort(file, parent, buf.VertexSize); readShort(file, parent, &buf.VertexSize);
buf.VertexSize /= sizeof(f32); buf.VertexSize /= sizeof(f32);
ChunkData data; ChunkData data;
readChunkData(file, data); readChunkData(file, data);
if (data.header.id == COGRE_GEOMETRY_VERTEX_BUFFER_DATA) if (data.header.id == COGRE_GEOMETRY_VERTEX_BUFFER_DATA)
{ {
buf.Data = new f32[geometry.NumVertex*buf.VertexSize]; buf.Data.set_used(geometry.NumVertex*buf.VertexSize);
for (s32 i=0; i<geometry.NumVertex*buf.VertexSize; ++i) readFloat(file, data, buf.Data.pointer(), geometry.NumVertex*buf.VertexSize);
readFloat(file, data, buf.Data[i]);
} }
geometry.Buffers.push_back(buf); geometry.Buffers.push_back(buf);
...@@ -324,19 +323,18 @@ bool COgreMeshFileLoader::readSubMesh(io::IReadFile* file, ChunkData& parent, Og ...@@ -324,19 +323,18 @@ bool COgreMeshFileLoader::readSubMesh(io::IReadFile* file, ChunkData& parent, Og
readBool(file, parent, subMesh.SharedVertices); readBool(file, parent, subMesh.SharedVertices);
s32 numIndices; s32 numIndices;
readInt(file, parent, numIndices); readInt(file, parent, &numIndices);
subMesh.Indices.set_used(numIndices); subMesh.Indices.set_used(numIndices);
readBool(file, parent, subMesh.Indices32Bit); readBool(file, parent, subMesh.Indices32Bit);
if (subMesh.Indices32Bit) if (subMesh.Indices32Bit)
for (s32 i=0; i<numIndices; ++i) readInt(file, parent, subMesh.Indices.pointer(), numIndices);
readInt(file, parent, subMesh.Indices[i]);
else else
for (s32 i=0; i<numIndices; ++i) for (s32 i=0; i<numIndices; ++i)
{ {
u16 num; u16 num;
readShort(file, parent, num); readShort(file, parent, &num);
subMesh.Indices[i]=num; subMesh.Indices[i]=num;
} }
...@@ -360,7 +358,7 @@ bool COgreMeshFileLoader::readSubMesh(io::IReadFile* file, ChunkData& parent, Og ...@@ -360,7 +358,7 @@ bool COgreMeshFileLoader::readSubMesh(io::IReadFile* file, ChunkData& parent, Og
switch(data.header.id) switch(data.header.id)
{ {
case COGRE_SUBMESH_OPERATION: case COGRE_SUBMESH_OPERATION:
readShort(file, data, subMesh.Operation); readShort(file, data, &subMesh.Operation);
break; break;
case COGRE_SUBMESH_TEXTURE_ALIAS: case COGRE_SUBMESH_TEXTURE_ALIAS:
{ {
...@@ -1135,53 +1133,50 @@ void COgreMeshFileLoader::readBool(io::IReadFile* file, ChunkData& data, bool& o ...@@ -1135,53 +1133,50 @@ void COgreMeshFileLoader::readBool(io::IReadFile* file, ChunkData& data, bool& o
} }
void COgreMeshFileLoader::readInt(io::IReadFile* file, ChunkData& data, s32& out) void COgreMeshFileLoader::readInt(io::IReadFile* file, ChunkData& data, s32* out, u32 num)
{ {
// normal C type because we read a bit string // normal C type because we read a bit string
int tmp; file->read(out, sizeof(int));
file->read(&tmp, sizeof(int));
if (SwapEndian) if (SwapEndian)
{ {
tmp = os::Byteswap::byteswap(tmp); for (u32 i=0; i<num; ++i)
out[i] = os::Byteswap::byteswap(out[i]);
} }
out=tmp; data.read+=sizeof(int)*num;
data.read+=sizeof(int);
} }
void COgreMeshFileLoader::readShort(io::IReadFile* file, ChunkData& data, u16& out) void COgreMeshFileLoader::readShort(io::IReadFile* file, ChunkData& data, u16* out, u32 num)
{ {
// normal C type because we read a bit string // normal C type because we read a bit string
short tmp; file->read(out, sizeof(short)*num);
file->read(&tmp, sizeof(short));
if (SwapEndian) if (SwapEndian)
{ {
tmp = os::Byteswap::byteswap(tmp); for (u32 i=0; i<num; ++i)
out[i] = os::Byteswap::byteswap(out[i]);
} }
out=tmp; data.read+=sizeof(short)*num;
data.read+=sizeof(short);
} }
void COgreMeshFileLoader::readFloat(io::IReadFile* file, ChunkData& data, f32& out) void COgreMeshFileLoader::readFloat(io::IReadFile* file, ChunkData& data, f32* out, u32 num)
{ {
// normal C type because we read a bit string // normal C type because we read a bit string
float tmp; file->read(out, sizeof(float)*num);
file->read(&tmp, sizeof(float));
if (SwapEndian) if (SwapEndian)
{ {
tmp = os::Byteswap::byteswap(tmp); for (u32 i=0; i<num; ++i)
out[i] = os::Byteswap::byteswap(out[i]);
} }
out=tmp; data.read+=sizeof(float)*num;
data.read+=sizeof(float);
} }
void COgreMeshFileLoader::readVector(io::IReadFile* file, ChunkData& data, core::vector3df& out) void COgreMeshFileLoader::readVector(io::IReadFile* file, ChunkData& data, core::vector3df& out)
{ {
readFloat(file, data, out.X); readFloat(file, data, &out.X);
readFloat(file, data, out.Y); readFloat(file, data, &out.Y);
readFloat(file, data, out.Z); readFloat(file, data, &out.Z);
} }
...@@ -1190,12 +1185,12 @@ void COgreMeshFileLoader::clearMeshes() ...@@ -1190,12 +1185,12 @@ void COgreMeshFileLoader::clearMeshes()
for (u32 i=0; i<Meshes.size(); ++i) for (u32 i=0; i<Meshes.size(); ++i)
{ {
for (int k=0; k<(int)Meshes[i].Geometry.Buffers.size(); ++k) for (int k=0; k<(int)Meshes[i].Geometry.Buffers.size(); ++k)
Meshes[i].Geometry.Buffers[k].destroy(); Meshes[i].Geometry.Buffers[k].Data.clear();
for (u32 j=0; j<Meshes[i].SubMeshes.size(); ++j) for (u32 j=0; j<Meshes[i].SubMeshes.size(); ++j)
{ {
for (int h=0; h<(int)Meshes[i].SubMeshes[j].Geometry.Buffers.size(); ++h) for (int h=0; h<(int)Meshes[i].SubMeshes[j].Geometry.Buffers.size(); ++h)
Meshes[i].SubMeshes[j].Geometry.Buffers[h].destroy(); Meshes[i].SubMeshes[j].Geometry.Buffers[h].Data.clear();
} }
} }
......
...@@ -134,11 +134,10 @@ private: ...@@ -134,11 +134,10 @@ private:
struct OgreVertexBuffer struct OgreVertexBuffer
{ {
OgreVertexBuffer() : BindIndex(0), VertexSize(0), Data(0) {} OgreVertexBuffer() : BindIndex(0), VertexSize(0), Data(0) {}
void destroy() { delete [] Data; Data = 0; }
u16 BindIndex, u16 BindIndex;
VertexSize; u16 VertexSize;
f32 *Data; core::array<f32> Data;
}; };
struct OgreVertexElement struct OgreVertexElement
...@@ -200,9 +199,9 @@ private: ...@@ -200,9 +199,9 @@ private:
void readChunkData(io::IReadFile* file, ChunkData& data); void readChunkData(io::IReadFile* file, ChunkData& data);
void readString(io::IReadFile* file, ChunkData& data, core::stringc& out); void readString(io::IReadFile* file, ChunkData& data, core::stringc& out);
void readBool(io::IReadFile* file, ChunkData& data, bool& out); void readBool(io::IReadFile* file, ChunkData& data, bool& out);
void readInt(io::IReadFile* file, ChunkData& data, s32& out); void readInt(io::IReadFile* file, ChunkData& data, s32* out, u32 num=1);
void readShort(io::IReadFile* file, ChunkData& data, u16& out); void readShort(io::IReadFile* file, ChunkData& data, u16* out, u32 num=1);
void readFloat(io::IReadFile* file, ChunkData& data, f32& out); void readFloat(io::IReadFile* file, ChunkData& data, f32* out, u32 num=1);
void readVector(io::IReadFile* file, ChunkData& data, core::vector3df& out); void readVector(io::IReadFile* file, ChunkData& data, core::vector3df& out);
void composeMeshBufferMaterial(scene::IMeshBuffer* mb, const core::stringc& materialName); void composeMeshBufferMaterial(scene::IMeshBuffer* mb, const core::stringc& materialName);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment