Sort mesh sections.
This commit is contained in:
@@ -15,11 +15,13 @@
|
||||
#endif
|
||||
|
||||
// Forward declarations.
|
||||
class lcVector2;
|
||||
class lcVector3;
|
||||
class lcVector4;
|
||||
class lcMatrix44;
|
||||
|
||||
class lcMesh;
|
||||
class lcTexture;
|
||||
|
||||
class lcFile;
|
||||
class lcMemFile;
|
||||
|
||||
+49
-9
@@ -482,6 +482,39 @@ bool lcPiecesLibrary::OpenDirectory(const char* Path)
|
||||
return true;
|
||||
}
|
||||
|
||||
int LibraryMeshSectionCompare(const lcLibraryMeshSection* a, const lcLibraryMeshSection* b, void* Data)
|
||||
{
|
||||
if (a->mPrimitiveType != b->mPrimitiveType)
|
||||
{
|
||||
int PrimitiveOrder[LC_MESH_NUM_PRIMITIVE_TYPES] =
|
||||
{
|
||||
LC_MESH_TRIANGLES,
|
||||
LC_MESH_TEXTURED_TRIANGLES,
|
||||
LC_MESH_LINES,
|
||||
LC_MESH_TEXTURED_LINES,
|
||||
};
|
||||
|
||||
for (int PrimitiveType = 0; PrimitiveType < LC_MESH_NUM_PRIMITIVE_TYPES; PrimitiveType++)
|
||||
{
|
||||
int Primitive = PrimitiveOrder[PrimitiveType];
|
||||
|
||||
if (a->mPrimitiveType == Primitive)
|
||||
return -1;
|
||||
|
||||
if (b->mPrimitiveType == Primitive)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
bool TranslucentA = lcIsColorTranslucent(a->mColor);
|
||||
bool TranslucentB = lcIsColorTranslucent(b->mColor);
|
||||
|
||||
if (TranslucentA != TranslucentB)
|
||||
return TranslucentA ? 1 : -1;
|
||||
|
||||
return a->mColor > b->mColor ? -1 : 1;
|
||||
}
|
||||
|
||||
bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
||||
{
|
||||
lcLibraryMeshData MeshData;
|
||||
@@ -520,7 +553,14 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
||||
int NumIndices = 0;
|
||||
|
||||
for (int SectionIdx = 0; SectionIdx < MeshData.mSections.GetSize(); SectionIdx++)
|
||||
NumIndices += MeshData.mSections[SectionIdx]->mIndices.GetSize();
|
||||
{
|
||||
lcLibraryMeshSection* Section = MeshData.mSections[SectionIdx];
|
||||
|
||||
Section->mColor = lcGetColorIndex(Section->mColor);
|
||||
NumIndices += Section->mIndices.GetSize();
|
||||
}
|
||||
|
||||
MeshData.mSections.Sort(LibraryMeshSectionCompare, NULL);
|
||||
|
||||
Mesh->Create(MeshData.mSections.GetSize(), MeshData.mVertices.GetSize(), MeshData.mTexturedVertices.GetSize(), NumIndices);
|
||||
|
||||
@@ -579,7 +619,7 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
||||
lcMeshSection& DstSection = Mesh->mSections[SectionIdx];
|
||||
lcLibraryMeshSection* SrcSection = MeshData.mSections[SectionIdx];
|
||||
|
||||
DstSection.ColorIndex = lcGetColorIndex(SrcSection->mColorCode);
|
||||
DstSection.ColorIndex = SrcSection->mColor;
|
||||
DstSection.PrimitiveType = (SrcSection->mPrimitiveType == LC_MESH_TRIANGLES || SrcSection->mPrimitiveType == LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
||||
DstSection.NumIndices = SrcSection->mIndices.GetSize();
|
||||
DstSection.Texture = SrcSection->mTexture;
|
||||
@@ -608,7 +648,7 @@ bool lcPiecesLibrary::LoadPiece(PieceInfo* Info)
|
||||
|
||||
if (DstSection.PrimitiveType == GL_TRIANGLES)
|
||||
{
|
||||
if (SrcSection->mColorCode == 16)
|
||||
if (SrcSection->mColor == 16)
|
||||
Info->mFlags |= LC_PIECE_HAS_DEFAULT;
|
||||
else
|
||||
{
|
||||
@@ -1072,7 +1112,7 @@ void lcLibraryMeshData::AddLine(int LineType, lcuint32 ColorCode, const lcVector
|
||||
{
|
||||
Section = mSections[SectionIdx];
|
||||
|
||||
if (Section->mColorCode == ColorCode && Section->mPrimitiveType == PrimitiveType)
|
||||
if (Section->mColor == ColorCode && Section->mPrimitiveType == PrimitiveType)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1145,7 +1185,7 @@ void lcLibraryMeshData::AddTexturedLine(int LineType, lcuint32 ColorCode, const
|
||||
{
|
||||
Section = mSections[SectionIdx];
|
||||
|
||||
if (Section->mColorCode == ColorCode && Section->mPrimitiveType == PrimitiveType)
|
||||
if (Section->mColor == ColorCode && Section->mPrimitiveType == PrimitiveType)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1326,7 +1366,7 @@ void lcLibraryMeshData::AddMeshData(const lcLibraryMeshData& Data, const lcMatri
|
||||
{
|
||||
lcLibraryMeshSection* SrcSection = Data.mSections[SrcSectionIdx];
|
||||
lcLibraryMeshSection* DstSection = NULL;
|
||||
lcuint32 ColorCode = SrcSection->mColorCode == 16 ? CurrentColorCode : SrcSection->mColorCode;
|
||||
lcuint32 ColorCode = SrcSection->mColor == 16 ? CurrentColorCode : SrcSection->mColor;
|
||||
lcTexture* Texture;
|
||||
|
||||
if (SrcSection->mTexture)
|
||||
@@ -1340,7 +1380,7 @@ void lcLibraryMeshData::AddMeshData(const lcLibraryMeshData& Data, const lcMatri
|
||||
{
|
||||
lcLibraryMeshSection* Section = mSections[DstSectionIdx];
|
||||
|
||||
if (Section->mColorCode == ColorCode && Section->mPrimitiveType == SrcSection->mPrimitiveType && Section->mTexture == Texture)
|
||||
if (Section->mColor == ColorCode && Section->mPrimitiveType == SrcSection->mPrimitiveType && Section->mTexture == Texture)
|
||||
{
|
||||
DstSection = Section;
|
||||
break;
|
||||
@@ -1425,7 +1465,7 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
|
||||
{
|
||||
lcLibraryMeshSection* SrcSection = Data.mSections[SrcSectionIdx];
|
||||
lcLibraryMeshSection* DstSection = NULL;
|
||||
lcuint32 ColorCode = SrcSection->mColorCode == 16 ? CurrentColorCode : SrcSection->mColorCode;
|
||||
lcuint32 ColorCode = SrcSection->mColor == 16 ? CurrentColorCode : SrcSection->mColor;
|
||||
lcTexture* Texture;
|
||||
|
||||
if (SrcSection->mTexture)
|
||||
@@ -1439,7 +1479,7 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat
|
||||
{
|
||||
lcLibraryMeshSection* Section = mSections[DstSectionIdx];
|
||||
|
||||
if (Section->mColorCode == ColorCode && Section->mPrimitiveType == SrcSection->mPrimitiveType && Section->mTexture == Texture)
|
||||
if (Section->mColor == ColorCode && Section->mPrimitiveType == SrcSection->mPrimitiveType && Section->mTexture == Texture)
|
||||
{
|
||||
DstSection = Section;
|
||||
break;
|
||||
|
||||
+5
-5
@@ -7,7 +7,6 @@
|
||||
#include "str.h"
|
||||
|
||||
class PieceInfo;
|
||||
class lcTexture;
|
||||
class lcZipFile;
|
||||
|
||||
#define LC_CATEGORY_FILE_ID LC_FOURCC('C', 'A', 'T', 0)
|
||||
@@ -18,17 +17,18 @@ enum LC_MESH_PRIMITIVE_TYPE
|
||||
LC_MESH_LINES,
|
||||
LC_MESH_TRIANGLES,
|
||||
LC_MESH_TEXTURED_LINES,
|
||||
LC_MESH_TEXTURED_TRIANGLES
|
||||
LC_MESH_TEXTURED_TRIANGLES,
|
||||
LC_MESH_NUM_PRIMITIVE_TYPES
|
||||
};
|
||||
|
||||
class lcLibraryMeshSection
|
||||
{
|
||||
public:
|
||||
lcLibraryMeshSection(LC_MESH_PRIMITIVE_TYPE PrimitiveType, lcuint32 ColorCode, lcTexture* Texture)
|
||||
lcLibraryMeshSection(LC_MESH_PRIMITIVE_TYPE PrimitiveType, lcuint32 Color, lcTexture* Texture)
|
||||
: mIndices(1024, 1024)
|
||||
{
|
||||
mPrimitiveType = PrimitiveType;
|
||||
mColorCode = ColorCode;
|
||||
mColor = Color;
|
||||
mTexture = Texture;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
}
|
||||
|
||||
LC_MESH_PRIMITIVE_TYPE mPrimitiveType;
|
||||
lcuint32 mColorCode;
|
||||
lcuint32 mColor;
|
||||
lcTexture* mTexture;
|
||||
ObjArray<lcuint32> mIndices;
|
||||
};
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
#include "opengl.h"
|
||||
#include "lc_math.h"
|
||||
|
||||
class lcTexture;
|
||||
|
||||
struct lcVertex
|
||||
{
|
||||
lcVector3 Position;
|
||||
|
||||
+4
-1
@@ -13,7 +13,6 @@ public:
|
||||
lcTexture();
|
||||
~lcTexture();
|
||||
|
||||
bool Load();
|
||||
bool Load(const char* FileName, int Flags = 0);
|
||||
bool Load(lcFile& File, int Flags = 0);
|
||||
void Unload();
|
||||
@@ -42,6 +41,10 @@ public:
|
||||
int mHeight;
|
||||
char mName[LC_MAXPATH];
|
||||
GLuint mTexture;
|
||||
|
||||
protected:
|
||||
bool Load();
|
||||
|
||||
int mRefCount;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "globals.h"
|
||||
#include "project.h"
|
||||
#include "object.h"
|
||||
#include "matrix.h"
|
||||
#include "lc_file.h"
|
||||
#include "lc_application.h"
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ class Piece;
|
||||
class Camera;
|
||||
class Light;
|
||||
class Group;
|
||||
class lcTexture;
|
||||
class Terrain;
|
||||
class PieceInfo;
|
||||
class Matrix;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define _TERRAIN_H_
|
||||
|
||||
class Camera;
|
||||
class lcTexture;
|
||||
|
||||
class TerrainPatch
|
||||
{
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "piece.h"
|
||||
#include "camera.h"
|
||||
#include "light.h"
|
||||
#include "matrix.h"
|
||||
#include "lc_application.h"
|
||||
|
||||
BEGIN_MESSAGE_MAP(CPropertiesPane, CDockablePane)
|
||||
|
||||
Reference in New Issue
Block a user