Conditional line shader.
This commit is contained in:
+44
-14
@@ -164,26 +164,28 @@ void lcContext::CreateShaderPrograms()
|
||||
|
||||
const char* const VertexShaders[] =
|
||||
{
|
||||
":/resources/shaders/unlit_color_vs.glsl", // UnlitColor
|
||||
":/resources/shaders/unlit_texture_modulate_vs.glsl", // UnlitTextureModulate
|
||||
":/resources/shaders/unlit_texture_decal_vs.glsl", // UnlitTextureDecal
|
||||
":/resources/shaders/unlit_vertex_color_vs.glsl", // UnlitVertexColor
|
||||
":/resources/shaders/unlit_view_sphere_vs.glsl", // UnlitViewSphere
|
||||
":/resources/shaders/fakelit_color_vs.glsl", // FakeLitColor
|
||||
":/resources/shaders/fakelit_texture_decal_vs.glsl" // FakeLitTextureDecal
|
||||
":/resources/shaders/unlit_color_vs.glsl", // UnlitColor
|
||||
":/resources/shaders/unlit_color_conditional_vs.glsl", // UnlitColorConditional
|
||||
":/resources/shaders/unlit_texture_modulate_vs.glsl", // UnlitTextureModulate
|
||||
":/resources/shaders/unlit_texture_decal_vs.glsl", // UnlitTextureDecal
|
||||
":/resources/shaders/unlit_vertex_color_vs.glsl", // UnlitVertexColor
|
||||
":/resources/shaders/unlit_view_sphere_vs.glsl", // UnlitViewSphere
|
||||
":/resources/shaders/fakelit_color_vs.glsl", // FakeLitColor
|
||||
":/resources/shaders/fakelit_texture_decal_vs.glsl" // FakeLitTextureDecal
|
||||
};
|
||||
|
||||
LC_ARRAY_SIZE_CHECK(VertexShaders, lcMaterialType::Count);
|
||||
|
||||
const char* const FragmentShaders[] =
|
||||
{
|
||||
":/resources/shaders/unlit_color_ps.glsl", // UnlitColor
|
||||
":/resources/shaders/unlit_texture_modulate_ps.glsl", // UnlitTextureModulate
|
||||
":/resources/shaders/unlit_texture_decal_ps.glsl", // UnlitTextureDecal
|
||||
":/resources/shaders/unlit_vertex_color_ps.glsl", // UnlitVertexColor
|
||||
":/resources/shaders/unlit_view_sphere_ps.glsl", // UnlitViewSphere
|
||||
":/resources/shaders/fakelit_color_ps.glsl", // FakeLitColor
|
||||
":/resources/shaders/fakelit_texture_decal_ps.glsl" // FakeLitTextureDecal
|
||||
":/resources/shaders/unlit_color_ps.glsl", // UnlitColor
|
||||
":/resources/shaders/unlit_color_conditional_ps.glsl", // UnlitColorConditional
|
||||
":/resources/shaders/unlit_texture_modulate_ps.glsl", // UnlitTextureModulate
|
||||
":/resources/shaders/unlit_texture_decal_ps.glsl", // UnlitTextureDecal
|
||||
":/resources/shaders/unlit_vertex_color_ps.glsl", // UnlitVertexColor
|
||||
":/resources/shaders/unlit_view_sphere_ps.glsl", // UnlitViewSphere
|
||||
":/resources/shaders/fakelit_color_ps.glsl", // FakeLitColor
|
||||
":/resources/shaders/fakelit_texture_decal_ps.glsl" // FakeLitTextureDecal
|
||||
};
|
||||
|
||||
LC_ARRAY_SIZE_CHECK(FragmentShaders, lcMaterialType::Count);
|
||||
@@ -483,6 +485,7 @@ void lcContext::SetMaterial(lcMaterialType MaterialType)
|
||||
break;
|
||||
|
||||
case lcMaterialType::UnlitColor:
|
||||
case lcMaterialType::UnlitColorConditional:
|
||||
case lcMaterialType::UnlitVertexColor:
|
||||
case lcMaterialType::FakeLitColor:
|
||||
if (mTextureEnabled)
|
||||
@@ -891,6 +894,33 @@ void lcContext::SetVertexFormatPosition(int PositionSize)
|
||||
}
|
||||
}
|
||||
|
||||
void lcContext::SetVertexFormatConditional(int BufferOffset)
|
||||
{
|
||||
const int VertexSize = 12 * sizeof(float);
|
||||
char* VertexBufferPointer = mVertexBufferPointer + BufferOffset;
|
||||
|
||||
if (gSupportsShaderObjects)
|
||||
{
|
||||
if (mVertexBufferOffset != VertexBufferPointer)
|
||||
{
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, false, VertexSize, VertexBufferPointer);
|
||||
glVertexAttribPointer(1, 3, GL_FLOAT, false, VertexSize, VertexBufferPointer + 3 * sizeof(float));
|
||||
glVertexAttribPointer(2, 3, GL_FLOAT, false, VertexSize, VertexBufferPointer + 6 * sizeof(float));
|
||||
glVertexAttribPointer(3, 3, GL_FLOAT, false, VertexSize, VertexBufferPointer + 9 * sizeof(float));
|
||||
|
||||
mVertexBufferOffset = VertexBufferPointer;
|
||||
|
||||
glEnableVertexAttribArray(1);
|
||||
glEnableVertexAttribArray(2);
|
||||
glEnableVertexAttribArray(3);
|
||||
|
||||
mNormalEnabled = true; // todo: store state using an array
|
||||
mTexCoordEnabled = true;
|
||||
mColorEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lcContext::SetVertexFormat(int BufferOffset, int PositionSize, int NormalSize, int TexCoordSize, int ColorSize, bool EnableNormals)
|
||||
{
|
||||
const int VertexSize = (PositionSize + TexCoordSize) * sizeof(float) + NormalSize * sizeof(quint32) + ColorSize;
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
enum class lcMaterialType
|
||||
{
|
||||
UnlitColor,
|
||||
UnlitColorConditional,
|
||||
UnlitTextureModulate,
|
||||
UnlitTextureDecal,
|
||||
UnlitVertexColor,
|
||||
@@ -191,6 +192,7 @@ public:
|
||||
|
||||
void SetVertexFormat(int BufferOffset, int PositionSize, int NormalSize, int TexCoordSize, int ColorSize, bool EnableNormals);
|
||||
void SetVertexFormatPosition(int PositionSize);
|
||||
void SetVertexFormatConditional(int BufferOffset);
|
||||
void DrawPrimitives(GLenum Mode, GLint First, GLsizei Count);
|
||||
void DrawIndexedPrimitives(GLenum Mode, GLsizei Count, GLenum Type, int Offset);
|
||||
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public:
|
||||
void Unload()
|
||||
{
|
||||
mState = lcPrimitiveState::NotLoaded;
|
||||
mMeshData.RemoveAll();
|
||||
mMeshData.Clear();
|
||||
}
|
||||
|
||||
QString mFileName;
|
||||
|
||||
+20
-16
@@ -8,7 +8,7 @@
|
||||
#include "lc_library.h"
|
||||
|
||||
#define LC_MESH_FILE_ID LC_FOURCC('M', 'E', 'S', 'H')
|
||||
#define LC_MESH_FILE_VERSION 0x0118
|
||||
#define LC_MESH_FILE_VERSION 0x0120
|
||||
|
||||
lcMesh* gPlaceholderMesh;
|
||||
|
||||
@@ -39,7 +39,7 @@ lcMesh::~lcMesh()
|
||||
delete[] mLods[LodIdx].Sections;
|
||||
}
|
||||
|
||||
void lcMesh::Create(quint16 NumSections[LC_NUM_MESH_LODS], int NumVertices, int NumTexturedVertices, int NumIndices)
|
||||
void lcMesh::Create(quint16(&NumSections)[LC_NUM_MESH_LODS], int VertexCount, int TexturedVertexCount, int ConditionalVertexCount, int IndexCount)
|
||||
{
|
||||
for (int LodIdx = 0; LodIdx < LC_NUM_MESH_LODS; LodIdx++)
|
||||
{
|
||||
@@ -48,20 +48,21 @@ void lcMesh::Create(quint16 NumSections[LC_NUM_MESH_LODS], int NumVertices, int
|
||||
mLods[LodIdx].NumSections = NumSections[LodIdx];
|
||||
}
|
||||
|
||||
mNumVertices = NumVertices;
|
||||
mNumTexturedVertices = NumTexturedVertices;
|
||||
mVertexDataSize = NumVertices * sizeof(lcVertex) + NumTexturedVertices * sizeof(lcVertexTextured);
|
||||
mNumVertices = VertexCount;
|
||||
mNumTexturedVertices = TexturedVertexCount;
|
||||
mConditionalVertexCount = ConditionalVertexCount;
|
||||
mVertexDataSize = VertexCount * sizeof(lcVertex) + TexturedVertexCount * sizeof(lcVertexTextured) + ConditionalVertexCount * sizeof(lcVertexConditional);
|
||||
mVertexData = malloc(mVertexDataSize);
|
||||
|
||||
if (NumVertices < 0x10000 && NumTexturedVertices < 0x10000)
|
||||
if (VertexCount < 0x10000 && TexturedVertexCount < 0x10000 && ConditionalVertexCount < 0x10000)
|
||||
{
|
||||
mIndexType = GL_UNSIGNED_SHORT;
|
||||
mIndexDataSize = NumIndices * sizeof(GLushort);
|
||||
mIndexDataSize = IndexCount * sizeof(GLushort);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndexType = GL_UNSIGNED_INT;
|
||||
mIndexDataSize = NumIndices * sizeof(GLuint);
|
||||
mIndexDataSize = IndexCount * sizeof(GLuint);
|
||||
}
|
||||
|
||||
mIndexData = malloc(mIndexDataSize);
|
||||
@@ -73,7 +74,7 @@ void lcMesh::CreateBox()
|
||||
memset(NumSections, 0, sizeof(NumSections));
|
||||
NumSections[LC_MESH_LOD_HIGH] = 2;
|
||||
|
||||
Create(NumSections, 24, 0, 36 + 24);
|
||||
Create(NumSections, 24, 0, 0, 36 + 24);
|
||||
|
||||
lcVector3 Min(-10.0f, -10.0f, -24.0f);
|
||||
lcVector3 Max(10.0f, 10.0f, 4.0f);
|
||||
@@ -378,16 +379,16 @@ bool lcMesh::FileLoad(lcMemFile& File)
|
||||
mBoundingBox.Max = File.ReadVector3();
|
||||
mRadius = File.ReadFloat();
|
||||
|
||||
quint32 NumVertices, NumTexturedVertices, NumIndices;
|
||||
quint32 VertexCount, TexturedVertexCount, ConditionalVertexCount, IndexCount;
|
||||
quint16 NumLods, NumSections[LC_NUM_MESH_LODS];
|
||||
|
||||
if (!File.ReadU32(&NumVertices, 1) || !File.ReadU32(&NumTexturedVertices, 1) || !File.ReadU32(&NumIndices, 1))
|
||||
if (!File.ReadU32(&VertexCount, 1) || !File.ReadU32(&TexturedVertexCount, 1) || !File.ReadU32(&ConditionalVertexCount, 1) || !File.ReadU32(&IndexCount, 1))
|
||||
return false;
|
||||
|
||||
if (!File.ReadU16(&NumLods, 1) || NumLods != LC_NUM_MESH_LODS || !File.ReadU16(NumSections, LC_NUM_MESH_LODS))
|
||||
return false;
|
||||
|
||||
Create(NumSections, NumVertices, NumTexturedVertices, NumIndices);
|
||||
Create(NumSections, VertexCount, TexturedVertexCount, ConditionalVertexCount, IndexCount);
|
||||
|
||||
for (int LodIdx = 0; LodIdx < LC_NUM_MESH_LODS; LodIdx++)
|
||||
{
|
||||
@@ -398,12 +399,12 @@ bool lcMesh::FileLoad(lcMemFile& File)
|
||||
quint32 ColorCode, IndexOffset;
|
||||
quint16 PrimtiveType, Length;
|
||||
|
||||
if (!File.ReadU32(&ColorCode, 1) || !File.ReadU32(&IndexOffset, 1) || !File.ReadU32(&NumIndices, 1) || !File.ReadU16(&PrimtiveType, 1))
|
||||
if (!File.ReadU32(&ColorCode, 1) || !File.ReadU32(&IndexOffset, 1) || !File.ReadU32(&IndexCount, 1) || !File.ReadU16(&PrimtiveType, 1))
|
||||
return false;
|
||||
|
||||
Section.ColorIndex = lcGetColorIndex(ColorCode);
|
||||
Section.IndexOffset = IndexOffset;
|
||||
Section.NumIndices = NumIndices;
|
||||
Section.NumIndices = IndexCount;
|
||||
Section.PrimitiveType = (lcMeshPrimitiveType)PrimtiveType;
|
||||
Section.BoundingBox.Min = File.ReadVector3();
|
||||
Section.BoundingBox.Max = File.ReadVector3();
|
||||
@@ -429,7 +430,8 @@ bool lcMesh::FileLoad(lcMemFile& File)
|
||||
}
|
||||
}
|
||||
|
||||
File.ReadBuffer(mVertexData, mNumVertices * sizeof(lcVertex) + mNumTexturedVertices * sizeof(lcVertexTextured));
|
||||
File.ReadBuffer(mVertexData, mNumVertices * sizeof(lcVertex) + mNumTexturedVertices * sizeof(lcVertexTextured) + mConditionalVertexCount * sizeof(lcVertexConditional));
|
||||
|
||||
if (mIndexType == GL_UNSIGNED_SHORT)
|
||||
File.ReadU16((quint16*)mIndexData, mIndexDataSize / 2);
|
||||
else
|
||||
@@ -450,6 +452,7 @@ bool lcMesh::FileSave(lcMemFile& File)
|
||||
|
||||
File.WriteU32(mNumVertices);
|
||||
File.WriteU32(mNumTexturedVertices);
|
||||
File.WriteU32(mConditionalVertexCount);
|
||||
File.WriteU32(mIndexDataSize / (mIndexType == GL_UNSIGNED_SHORT ? 2 : 4));
|
||||
|
||||
File.WriteU16(LC_NUM_MESH_LODS);
|
||||
@@ -481,7 +484,8 @@ bool lcMesh::FileSave(lcMemFile& File)
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteBuffer(mVertexData, mNumVertices * sizeof(lcVertex) + mNumTexturedVertices * sizeof(lcVertexTextured));
|
||||
File.WriteBuffer(mVertexData, mNumVertices * sizeof(lcVertex) + mNumTexturedVertices * sizeof(lcVertexTextured) + mConditionalVertexCount * sizeof(lcVertexConditional));
|
||||
|
||||
if (mIndexType == GL_UNSIGNED_SHORT)
|
||||
File.WriteU16((quint16*)mIndexData, mIndexDataSize / 2);
|
||||
else
|
||||
|
||||
+10
-1
@@ -24,6 +24,14 @@ struct lcVertexTextured
|
||||
lcVector2 TexCoord;
|
||||
};
|
||||
|
||||
struct lcVertexConditional
|
||||
{
|
||||
lcVector3 Position1;
|
||||
lcVector3 Position2;
|
||||
lcVector3 Position3;
|
||||
lcVector3 Position4;
|
||||
};
|
||||
|
||||
struct lcMeshSection
|
||||
{
|
||||
int ColorIndex;
|
||||
@@ -72,7 +80,7 @@ public:
|
||||
lcMesh& operator=(const lcMesh&) = delete;
|
||||
lcMesh& operator=(lcMesh&&) = delete;
|
||||
|
||||
void Create(quint16 NumSections[LC_NUM_MESH_LODS], int NumVertices, int NumTexturedVertices, int NumIndices);
|
||||
void Create(quint16 (&NumSections)[LC_NUM_MESH_LODS], int VertexCount, int TexturedVertexCount, int ConditionalVertexCount, int IndexCount);
|
||||
void CreateBox();
|
||||
|
||||
bool FileLoad(lcMemFile& File);
|
||||
@@ -110,6 +118,7 @@ public:
|
||||
|
||||
int mNumVertices;
|
||||
int mNumTexturedVertices;
|
||||
int mConditionalVertexCount;
|
||||
int mIndexType;
|
||||
};
|
||||
|
||||
|
||||
+562
-431
File diff suppressed because it is too large
Load Diff
+66
-41
@@ -15,7 +15,7 @@ enum lcMeshDataType
|
||||
LC_NUM_MESHDATA_TYPES
|
||||
};
|
||||
|
||||
struct lcLibraryMeshVertex
|
||||
struct lcMeshLoaderVertex
|
||||
{
|
||||
lcVector3 Position;
|
||||
lcVector3 Normal;
|
||||
@@ -24,6 +24,11 @@ struct lcLibraryMeshVertex
|
||||
quint32 Usage;
|
||||
};
|
||||
|
||||
struct lcMeshLoaderConditionalVertex
|
||||
{
|
||||
lcVector3 Position[4];
|
||||
};
|
||||
|
||||
class lcLibraryMeshSection
|
||||
{
|
||||
public:
|
||||
@@ -41,14 +46,14 @@ public:
|
||||
lcArray<quint32> mIndices;
|
||||
};
|
||||
|
||||
enum class lcLibraryTextureMapType
|
||||
enum class lcMeshLoaderTextureMapType
|
||||
{
|
||||
PLANAR,
|
||||
CYLINDRICAL,
|
||||
SPHERICAL
|
||||
Planar,
|
||||
Cylindrical,
|
||||
Spherical
|
||||
};
|
||||
|
||||
struct lcLibraryTextureMap
|
||||
struct lcMeshLoaderTextureMap
|
||||
{
|
||||
lcTexture* Texture;
|
||||
|
||||
@@ -82,11 +87,54 @@ struct lcLibraryTextureMap
|
||||
|
||||
float Angle1;
|
||||
float Angle2;
|
||||
lcLibraryTextureMapType Type;
|
||||
lcMeshLoaderTextureMapType Type;
|
||||
bool Fallback;
|
||||
bool Next;
|
||||
};
|
||||
|
||||
class lcMeshLoaderTypeData
|
||||
{
|
||||
public:
|
||||
lcMeshLoaderTypeData()
|
||||
{
|
||||
mVertices.SetGrow(1024);
|
||||
mConditionalVertices.SetGrow(1024);
|
||||
}
|
||||
|
||||
lcMeshLoaderTypeData(const lcMeshLoaderTypeData&) = delete;
|
||||
lcMeshLoaderTypeData& operator=(const lcMeshLoaderTypeData&) = delete;
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
return mSections.empty();
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
mSections.clear();
|
||||
mVertices.RemoveAll();
|
||||
mConditionalVertices.RemoveAll();
|
||||
}
|
||||
|
||||
lcLibraryMeshSection* AddSection(lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, lcTexture* Texture);
|
||||
|
||||
quint32 AddVertex(const lcVector3& Position, bool Optimize);
|
||||
quint32 AddVertex(const lcVector3& Position, const lcVector3& Normal, bool Optimize);
|
||||
quint32 AddTexturedVertex(const lcVector3& Position, const lcVector2& TexCoord, bool Optimize);
|
||||
quint32 AddTexturedVertex(const lcVector3& Position, const lcVector3& Normal, const lcVector2& TexCoord, bool Optimize);
|
||||
quint32 AddConditionalVertex(const lcVector3* Position, bool Optimize);
|
||||
|
||||
void ProcessLine(int LineType, quint32 ColorCode, bool WindingCCW, lcVector3* Vertices, bool Optimize);
|
||||
void ProcessTexturedLine(int LineType, quint32 ColorCode, bool WindingCCW, const lcMeshLoaderTextureMap& Map, const lcVector3* Vertices, bool Optimize);
|
||||
|
||||
void AddMeshData(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap);
|
||||
void AddMeshDataNoDuplicateCheck(const lcMeshLoaderTypeData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap);
|
||||
|
||||
std::vector<std::unique_ptr<lcLibraryMeshSection>> mSections;
|
||||
lcArray<lcMeshLoaderVertex> mVertices;
|
||||
lcArray<lcMeshLoaderConditionalVertex> mConditionalVertices;
|
||||
};
|
||||
|
||||
class lcLibraryMeshData
|
||||
{
|
||||
public:
|
||||
@@ -94,59 +142,36 @@ public:
|
||||
{
|
||||
mHasTextures = false;
|
||||
mHasStyleStud = false;
|
||||
|
||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
mVertices[MeshDataIdx].SetGrow(1024);
|
||||
}
|
||||
|
||||
~lcLibraryMeshData()
|
||||
{
|
||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
mSections[MeshDataIdx].DeleteAll();
|
||||
}
|
||||
|
||||
lcLibraryMeshData(const lcLibraryMeshData&) = delete;
|
||||
lcLibraryMeshData(lcLibraryMeshData&&) = delete;
|
||||
lcLibraryMeshData& operator=(const lcLibraryMeshData&) = delete;
|
||||
lcLibraryMeshData& operator=(lcLibraryMeshData&&) = delete;
|
||||
|
||||
bool IsEmpty() const
|
||||
{
|
||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
if (!mSections[MeshDataIdx].IsEmpty())
|
||||
for (const lcMeshLoaderTypeData& Data : mData)
|
||||
if (!Data.IsEmpty())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void RemoveAll()
|
||||
void Clear()
|
||||
{
|
||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
mVertices[MeshDataIdx].RemoveAll();
|
||||
|
||||
for (int MeshDataIdx = 0; MeshDataIdx < LC_NUM_MESHDATA_TYPES; MeshDataIdx++)
|
||||
mSections[MeshDataIdx].RemoveAll();
|
||||
for (lcMeshLoaderTypeData& Data : mData)
|
||||
Data.Clear();
|
||||
|
||||
mHasTextures = false;
|
||||
mHasStyleStud = false;
|
||||
}
|
||||
|
||||
lcMesh* CreateMesh();
|
||||
lcLibraryMeshSection* AddSection(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, lcTexture* Texture);
|
||||
quint32 AddVertex(lcMeshDataType MeshDataType, const lcVector3& Position, bool Optimize);
|
||||
quint32 AddVertex(lcMeshDataType MeshDataType, const lcVector3& Position, const lcVector3& Normal, bool Optimize);
|
||||
quint32 AddTexturedVertex(lcMeshDataType MeshDataType, const lcVector3& Position, const lcVector2& TexCoord, bool Optimize);
|
||||
quint32 AddTexturedVertex(lcMeshDataType MeshDataType, const lcVector3& Position, const lcVector3& Normal, const lcVector2& TexCoord, bool Optimize);
|
||||
void AddVertices(lcMeshDataType MeshDataType, int VertexCount, int* BaseVertex, lcLibraryMeshVertex** VertexBuffer);
|
||||
void AddVertices(lcMeshDataType MeshDataType, int VertexCount, int* BaseVertex, lcMeshLoaderVertex** VertexBuffer);
|
||||
void AddIndices(lcMeshDataType MeshDataType, lcMeshPrimitiveType PrimitiveType, quint32 ColorCode, int IndexCount, quint32** IndexBuffer);
|
||||
void AddLine(lcMeshDataType MeshDataType, int LineType, quint32 ColorCode, bool WindingCCW, const lcVector3* Vertices, bool Optimize);
|
||||
void AddTexturedLine(lcMeshDataType MeshDataType, int LineType, quint32 ColorCode, bool WindingCCW, const lcLibraryTextureMap& Map, const lcVector3* Vertices, bool Optimize);
|
||||
void AddMeshData(const lcLibraryMeshData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcLibraryTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
||||
void AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcLibraryTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
||||
void TestQuad(int* QuadIndices, const lcVector3* Vertices);
|
||||
void ResequenceQuad(int* QuadIndices, int a, int b, int c, int d);
|
||||
void AddMeshData(const lcLibraryMeshData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
||||
void AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Data, const lcMatrix44& Transform, quint32 CurrentColorCode, bool InvertWinding, bool InvertNormals, lcMeshLoaderTextureMap* TextureMap, lcMeshDataType OverrideDestIndex);
|
||||
|
||||
lcArray<lcLibraryMeshSection*> mSections[LC_NUM_MESHDATA_TYPES];
|
||||
lcArray<lcLibraryMeshVertex> mVertices[LC_NUM_MESHDATA_TYPES];
|
||||
std::array<lcMeshLoaderTypeData, LC_NUM_MESHDATA_TYPES> mData;
|
||||
bool mHasTextures;
|
||||
bool mHasStyleStud;
|
||||
};
|
||||
@@ -159,7 +184,7 @@ public:
|
||||
bool LoadMesh(lcFile& File, lcMeshDataType MeshDataType);
|
||||
|
||||
protected:
|
||||
bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, quint32 CurrentColorCode, bool InvertWinding, lcArray<lcLibraryTextureMap>& TextureStack, lcMeshDataType MeshDataType);
|
||||
bool ReadMeshData(lcFile& File, const lcMatrix44& CurrentTransform, quint32 CurrentColorCode, bool InvertWinding, lcArray<lcMeshLoaderTextureMap>& TextureStack, lcMeshDataType MeshDataType);
|
||||
|
||||
lcLibraryMeshData& mMeshData;
|
||||
bool mOptimize;
|
||||
|
||||
+9
-49
@@ -242,53 +242,16 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
||||
}
|
||||
else if (Section->PrimitiveType == LC_MESH_CONDITIONAL_LINES)
|
||||
{
|
||||
const lcMatrix44 WorldViewProjectionMatrix = lcMul(RenderMesh.WorldMatrix, lcMul(mViewMatrix, Context->GetProjectionMatrix()));
|
||||
const lcVertex* const VertexBuffer = (lcVertex*)Mesh->mVertexData;
|
||||
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
||||
VertexBufferOffset += Mesh->mNumVertices * sizeof(lcVertex) + Mesh->mNumTexturedVertices * sizeof(lcVertexTextured);
|
||||
const int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
||||
|
||||
const int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
||||
Context->SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0, DrawLit);
|
||||
Context->SetEdgeColorIndex(ColorIndex);
|
||||
Context->SetMaterial(lcMaterialType::UnlitColorConditional);
|
||||
Context->SetVertexFormatConditional(VertexBufferOffset);
|
||||
|
||||
if (Mesh->mIndexType == GL_UNSIGNED_SHORT)
|
||||
{
|
||||
const quint16* const Indices = (quint16*)((char*)Mesh->mIndexData + Section->IndexOffset);
|
||||
|
||||
for (int i = 0; i < Section->NumIndices; i += 4)
|
||||
{
|
||||
lcVector4 p1 = lcMul4(lcVector4(VertexBuffer[Indices[i + 0]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
lcVector4 p2 = lcMul4(lcVector4(VertexBuffer[Indices[i + 1]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
lcVector4 p3 = lcMul4(lcVector4(VertexBuffer[Indices[i + 2]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
lcVector4 p4 = lcMul4(lcVector4(VertexBuffer[Indices[i + 3]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
|
||||
p1 /= p1.w;
|
||||
p2 /= p2.w;
|
||||
p3 /= p3.w;
|
||||
p4 /= p4.w;
|
||||
|
||||
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0)
|
||||
Context->DrawIndexedPrimitives(GL_LINES, 2, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset + i * sizeof(quint16));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const quint32* const Indices = (quint32*)((char*)Mesh->mIndexData + Section->IndexOffset);
|
||||
|
||||
for (int i = 0; i < Section->NumIndices; i += 4)
|
||||
{
|
||||
lcVector4 p1 = lcMul4(lcVector4(VertexBuffer[Indices[i + 0]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
lcVector4 p2 = lcMul4(lcVector4(VertexBuffer[Indices[i + 1]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
lcVector4 p3 = lcMul4(lcVector4(VertexBuffer[Indices[i + 2]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
lcVector4 p4 = lcMul4(lcVector4(VertexBuffer[Indices[i + 3]].Position, 1.0f), WorldViewProjectionMatrix);
|
||||
|
||||
p1 /= p1.w;
|
||||
p2 /= p2.w;
|
||||
p3 /= p3.w;
|
||||
p4 /= p4.w;
|
||||
|
||||
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0)
|
||||
Context->DrawIndexedPrimitives(GL_LINES, 2, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset + i * sizeof(quint32));
|
||||
}
|
||||
}
|
||||
const GLenum DrawPrimitiveType = Section->PrimitiveType & (LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
||||
Context->DrawIndexedPrimitives(DrawPrimitiveType, Section->NumIndices, Mesh->mIndexType, IndexBufferOffset + Section->IndexOffset);
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -440,8 +403,9 @@ void lcScene::Draw(lcContext* Context) const
|
||||
|
||||
Context->SetViewMatrix(mViewMatrix);
|
||||
|
||||
constexpr bool DrawConditional = false;
|
||||
const lcPreferences& Preferences = lcGetPreferences();
|
||||
const bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
||||
const bool DrawConditional = false;
|
||||
|
||||
// lcShadingMode ShadingMode = Preferences.mShadingMode;
|
||||
// if (ShadingMode == lcShadingMode::Wireframe && !mAllowWireframe)
|
||||
@@ -461,8 +425,6 @@ void lcScene::Draw(lcContext* Context) const
|
||||
}
|
||||
else if (mShadingMode == lcShadingMode::Flat)
|
||||
{
|
||||
const bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
||||
|
||||
int LinePrimitiveTypes = 0;
|
||||
|
||||
if (DrawLines)
|
||||
@@ -501,8 +463,6 @@ void lcScene::Draw(lcContext* Context) const
|
||||
}
|
||||
else
|
||||
{
|
||||
const bool DrawLines = Preferences.mDrawEdgeLines && Preferences.mLineWidth != 0.0f;
|
||||
|
||||
int LinePrimitiveTypes = LC_MESH_LINES;
|
||||
|
||||
if (DrawConditional)
|
||||
|
||||
+8
-8
@@ -935,7 +935,7 @@ void lcSynthInfoFlexSystemHose::AddParts(lcMemFile& File, lcLibraryMeshData& Mes
|
||||
File.WriteBuffer(Line, strlen(Line));
|
||||
}
|
||||
|
||||
const lcLibraryMeshVertex OutsideSectionVertices[16] =
|
||||
const lcMeshLoaderVertex OutsideSectionVertices[16] =
|
||||
{
|
||||
{ lcVector3( 4.00000f, 0.0f, 0.00000f), lcVector3( 1.000000f, 0.0f, 0.000000f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
{ lcVector3( 3.69552f, 0.0f, 1.53073f), lcVector3( 0.923880f, 0.0f, 0.382683f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
@@ -955,7 +955,7 @@ void lcSynthInfoFlexSystemHose::AddParts(lcMemFile& File, lcLibraryMeshData& Mes
|
||||
{ lcVector3( 3.69552f, 0.0f, -1.53073f), lcVector3( 0.923880f, 0.0f, -0.382683f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
};
|
||||
|
||||
const lcLibraryMeshVertex InsideSectionVertices[16] =
|
||||
const lcMeshLoaderVertex InsideSectionVertices[16] =
|
||||
{
|
||||
{ lcVector3( 2.00000f, 0.0f, 0.00000f), lcVector3(-1.00000f, 0.0f, 0.00000f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
{ lcVector3( 1.84776f, 0.0f, 0.76536f), lcVector3(-0.92388f, 0.0f, -0.38268f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
@@ -975,10 +975,10 @@ void lcSynthInfoFlexSystemHose::AddParts(lcMemFile& File, lcLibraryMeshData& Mes
|
||||
{ lcVector3( 1.84776f, 0.0f, -0.76536f), lcVector3(-0.92388f, 0.0f, 0.38268f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
};
|
||||
|
||||
auto AddSectionVertices = [&MeshData, &Sections](const lcLibraryMeshVertex* SectionVertices, int NumSectionVertices)
|
||||
auto AddSectionVertices = [&MeshData, &Sections](const lcMeshLoaderVertex* SectionVertices, int NumSectionVertices)
|
||||
{
|
||||
int BaseVertex;
|
||||
lcLibraryMeshVertex* VertexBuffer;
|
||||
lcMeshLoaderVertex* VertexBuffer;
|
||||
quint32* IndexBuffer;
|
||||
MeshData.AddVertices(LC_MESHDATA_SHARED, NumSectionVertices * (Sections.GetSize() - 1), &BaseVertex, &VertexBuffer);
|
||||
|
||||
@@ -1098,7 +1098,7 @@ void lcSynthInfoFlexibleAxle::AddParts(lcMemFile& File, lcLibraryMeshData& MeshD
|
||||
File.WriteBuffer(Line, strlen(Line));
|
||||
}
|
||||
|
||||
const lcLibraryMeshVertex SectionVertices[28] =
|
||||
const lcMeshLoaderVertex SectionVertices[28] =
|
||||
{
|
||||
{ lcVector3(-6.000f, 0.0f, 0.000f), lcVector3(-1.000f, 0.0f, 0.000f), 2.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
{ lcVector3(-5.602f, 0.0f, 2.000f), lcVector3(-0.942f, 0.0f, 0.336f), 4.0f, lcVector2(0.0f, 0.0f), 0 },
|
||||
@@ -1133,7 +1133,7 @@ void lcSynthInfoFlexibleAxle::AddParts(lcMemFile& File, lcLibraryMeshData& MeshD
|
||||
const int NumSectionVertices = LC_ARRAY_COUNT(SectionVertices);
|
||||
|
||||
int BaseVertex;
|
||||
lcLibraryMeshVertex* VertexBuffer;
|
||||
lcMeshLoaderVertex* VertexBuffer;
|
||||
quint32* IndexBuffer;
|
||||
MeshData.AddVertices(LC_MESHDATA_SHARED, NumSectionVertices * (Sections.GetSize() - 1), &BaseVertex, &VertexBuffer);
|
||||
MeshData.AddIndices(LC_MESHDATA_SHARED, LC_MESH_LINES, 24, 2 * 12 * (Sections.GetSize() - 2), &IndexBuffer);
|
||||
@@ -1217,7 +1217,7 @@ void lcSynthInfoBraidedString::AddParts(lcMemFile& File, lcLibraryMeshData& Mesh
|
||||
};
|
||||
|
||||
int BaseVertex;
|
||||
lcLibraryMeshVertex* VertexBuffer;
|
||||
lcMeshLoaderVertex* VertexBuffer;
|
||||
quint32* IndexBuffer;
|
||||
MeshData.AddVertices(LC_MESHDATA_SHARED, NumBraids * ((Sections.GetSize() - 2) * NumSegments + 1), &BaseVertex, &VertexBuffer);
|
||||
MeshData.AddIndices(LC_MESHDATA_SHARED, LC_MESH_LINES, 24, NumBraids * (Sections.GetSize() - 2) * NumSegments * 2, &IndexBuffer);
|
||||
@@ -1402,7 +1402,7 @@ lcMesh* lcSynthInfo::CreateMesh(const lcArray<lcPieceControlPoint>& ControlPoint
|
||||
|
||||
File.WriteU8(0);
|
||||
|
||||
lcArray<lcLibraryTextureMap> TextureStack;
|
||||
lcArray<lcMeshLoaderTextureMap> TextureStack;
|
||||
File.Seek(0, SEEK_SET);
|
||||
|
||||
lcMeshLoader MeshLoader(MeshData, false, nullptr, false);
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ void PieceInfo::SetModel(lcModel* Model, bool UpdateMesh, Project* CurrentProjec
|
||||
}
|
||||
|
||||
lcLibraryMeshData MeshData;
|
||||
lcArray<lcLibraryTextureMap> TextureStack;
|
||||
lcArray<lcMeshLoaderTextureMap> TextureStack;
|
||||
PieceFile.Seek(0, SEEK_SET);
|
||||
|
||||
lcMeshLoader MeshLoader(MeshData, true, CurrentProject, SearchProjectFolder);
|
||||
|
||||
@@ -122,6 +122,8 @@
|
||||
<file>resources/shaders/fakelit_color_vs.glsl</file>
|
||||
<file>resources/shaders/fakelit_texture_decal_ps.glsl</file>
|
||||
<file>resources/shaders/fakelit_texture_decal_vs.glsl</file>
|
||||
<file>resources/shaders/unlit_color_conditional_ps.glsl</file>
|
||||
<file>resources/shaders/unlit_color_conditional_vs.glsl</file>
|
||||
<file>resources/shaders/unlit_color_ps.glsl</file>
|
||||
<file>resources/shaders/unlit_color_vs.glsl</file>
|
||||
<file>resources/shaders/unlit_texture_decal_ps.glsl</file>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
LC_PIXEL_OUTPUT
|
||||
|
||||
uniform mediump vec4 MaterialColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = MaterialColor;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
LC_VERTEX_INPUT vec3 VertexPosition1;
|
||||
LC_VERTEX_INPUT vec3 VertexPosition2;
|
||||
LC_VERTEX_INPUT vec3 VertexPosition3;
|
||||
LC_VERTEX_INPUT vec3 VertexPosition4;
|
||||
|
||||
uniform mat4 WorldViewProjectionMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 p1 = WorldViewProjectionMatrix * vec4(VertexPosition1, 1.0);
|
||||
vec4 p2 = WorldViewProjectionMatrix * vec4(VertexPosition2, 1.0);
|
||||
vec4 p3 = WorldViewProjectionMatrix * vec4(VertexPosition3, 1.0);
|
||||
vec4 p4 = WorldViewProjectionMatrix * vec4(VertexPosition4, 1.0);
|
||||
vec4 Position = p1;
|
||||
|
||||
p1 /= p1.w;
|
||||
p2 /= p2.w;
|
||||
p3 /= p3.w;
|
||||
p4 /= p4.w;
|
||||
|
||||
if (((p1.y - p2.y) * (p3.x - p1.x) + (p2.x - p1.x) * (p3.y - p1.y)) * ((p1.y - p2.y) * (p4.x - p1.x) + (p2.x - p1.x) * (p4.y - p1.y)) >= 0.0)
|
||||
{
|
||||
if (((p2.y - p1.y) * (p3.x - p2.x) + (p1.x - p2.x) * (p3.y - p2.y)) * ((p2.y - p1.y) * (p4.x - p2.x) + (p1.x - p2.x) * (p4.y - p2.y)) >= 0.0)
|
||||
gl_Position = Position;
|
||||
else
|
||||
gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
else
|
||||
gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
Reference in New Issue
Block a user