mirror of
https://github.com/leozide/leocad
synced 2025-01-18 22:26:44 +01:00
Fixed rendering issues with missing textures.
This commit is contained in:
parent
bad9bd5069
commit
a9971b0b1a
2 changed files with 53 additions and 27 deletions
|
@ -944,29 +944,36 @@ void lcLibraryMeshData::WriteSections(lcMesh* Mesh, const lcArray<lcMeshLoaderFi
|
|||
|
||||
auto AddSection = [this, &DstSection, &Index, &BaseVertices, &BaseConditionalVertices](lcMeshLoaderSection* SrcSection, lcMeshDataType SrcDataType)
|
||||
{
|
||||
if (DstSection.PrimitiveType != LC_MESH_CONDITIONAL_LINES)
|
||||
switch (DstSection.PrimitiveType)
|
||||
{
|
||||
if (!mHasTextures)
|
||||
case LC_MESH_LINES:
|
||||
case LC_MESH_TRIANGLES:
|
||||
{
|
||||
const IndexType BaseVertex = BaseVertices[SrcDataType];
|
||||
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.GetSize(); IndexIdx++)
|
||||
*Index++ = BaseVertex + SrcSection->mIndices[IndexIdx];
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case LC_MESH_CONDITIONAL_LINES:
|
||||
{
|
||||
const IndexType BaseVertex = DstSection.Texture ? 0 : BaseVertices[SrcDataType];
|
||||
const IndexType BaseVertex = BaseConditionalVertices[SrcDataType];
|
||||
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.GetSize(); IndexIdx++)
|
||||
*Index++ = BaseVertex + SrcSection->mIndices[IndexIdx];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IndexType BaseVertex = BaseConditionalVertices[SrcDataType];
|
||||
break;
|
||||
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.GetSize(); IndexIdx++)
|
||||
*Index++ = BaseVertex + SrcSection->mIndices[IndexIdx];
|
||||
case LC_MESH_TEXTURED_TRIANGLES:
|
||||
{
|
||||
for (int IndexIdx = 0; IndexIdx < SrcSection->mIndices.GetSize(); IndexIdx++)
|
||||
*Index++ = SrcSection->mIndices[IndexIdx];
|
||||
}
|
||||
break;
|
||||
|
||||
case LC_MESH_NUM_PRIMITIVE_TYPES:
|
||||
break;
|
||||
}
|
||||
|
||||
DstSection.NumIndices += SrcSection->mIndices.GetSize();
|
||||
|
@ -1050,9 +1057,10 @@ void lcLibraryMeshData::UpdateMeshSectionBoundingBox(lcMesh* Mesh, lcMeshSection
|
|||
{
|
||||
const IndexType* IndexBuffer = reinterpret_cast<IndexType*>(static_cast<char*>(Mesh->mIndexData) + Section.IndexOffset);
|
||||
|
||||
if (!Section.Texture)
|
||||
switch (Section.PrimitiveType)
|
||||
{
|
||||
if (Section.PrimitiveType != LC_MESH_CONDITIONAL_LINES)
|
||||
case LC_MESH_LINES:
|
||||
case LC_MESH_TRIANGLES:
|
||||
{
|
||||
const lcVertex* VertexBuffer = Mesh->GetVertexData();
|
||||
|
||||
|
@ -1063,7 +1071,9 @@ void lcLibraryMeshData::UpdateMeshSectionBoundingBox(lcMesh* Mesh, lcMeshSection
|
|||
SectionMax = lcMax(SectionMax, Position);
|
||||
}
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case LC_MESH_CONDITIONAL_LINES:
|
||||
{
|
||||
const lcVertexConditional* VertexBuffer = Mesh->GetConditionalVertexData();
|
||||
|
||||
|
@ -1074,17 +1084,23 @@ void lcLibraryMeshData::UpdateMeshSectionBoundingBox(lcMesh* Mesh, lcMeshSection
|
|||
SectionMax = lcMax(SectionMax, Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const lcVertexTextured* VertexBuffer = Mesh->GetTexturedVertexData();
|
||||
break;
|
||||
|
||||
for (int Index = 0; Index < Section.NumIndices; Index++)
|
||||
case LC_MESH_TEXTURED_TRIANGLES:
|
||||
{
|
||||
const lcVector3& Position = VertexBuffer[IndexBuffer[Index]].Position;
|
||||
SectionMin = lcMin(SectionMin, Position);
|
||||
SectionMax = lcMax(SectionMax, Position);
|
||||
const lcVertexTextured* VertexBuffer = Mesh->GetTexturedVertexData();
|
||||
|
||||
for (int Index = 0; Index < Section.NumIndices; Index++)
|
||||
{
|
||||
const lcVector3& Position = VertexBuffer[IndexBuffer[Index]].Position;
|
||||
SectionMin = lcMin(SectionMin, Position);
|
||||
SectionMax = lcMax(SectionMax, Position);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case LC_MESH_NUM_PRIMITIVE_TYPES:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -262,23 +262,33 @@ void lcScene::DrawOpaqueMeshes(lcContext* Context, bool DrawLit, int PrimitiveTy
|
|||
}
|
||||
}
|
||||
|
||||
lcTexture* const Texture = Section->Texture;
|
||||
int VertexBufferOffset = Mesh->mVertexCacheOffset != -1 ? Mesh->mVertexCacheOffset : 0;
|
||||
const int IndexBufferOffset = Mesh->mIndexCacheOffset != -1 ? Mesh->mIndexCacheOffset : 0;
|
||||
|
||||
if (!Texture)
|
||||
if (Section->PrimitiveType != LC_MESH_TEXTURED_TRIANGLES)
|
||||
{
|
||||
Context->SetMaterial(FlatMaterial);
|
||||
Context->SetVertexFormat(VertexBufferOffset, 3, 1, 0, 0, DrawLit);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Texture->NeedsUpload())
|
||||
Texture->Upload(Context);
|
||||
Context->SetMaterial(TexturedMaterial);
|
||||
lcTexture* const Texture = Section->Texture;
|
||||
|
||||
if (Texture)
|
||||
{
|
||||
if (Texture->NeedsUpload())
|
||||
Texture->Upload(Context);
|
||||
|
||||
Context->SetMaterial(TexturedMaterial);
|
||||
Context->BindTexture2D(Texture->mTexture);
|
||||
}
|
||||
else
|
||||
{
|
||||
Context->SetMaterial(FlatMaterial);
|
||||
}
|
||||
|
||||
VertexBufferOffset += Mesh->mNumVertices * sizeof(lcVertex);
|
||||
Context->SetVertexFormat(VertexBufferOffset, 3, 1, 2, 0, DrawLit);
|
||||
Context->BindTexture2D(Texture->mTexture);
|
||||
}
|
||||
|
||||
const GLenum DrawPrimitiveType = Section->PrimitiveType & (LC_MESH_TRIANGLES | LC_MESH_TEXTURED_TRIANGLES) ? GL_TRIANGLES : GL_LINES;
|
||||
|
|
Loading…
Reference in a new issue