mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Don't call AddIndices for every single face - just do it one bulk go in ExpandCapacity().
This commit is contained in:
parent
4bf4209a4c
commit
572a52dd3c
@ -190,7 +190,7 @@
|
|||||||
<Project>{35FEE071-2DE6-48A1-9343-B5C1F202A12B}</Project>
|
<Project>{35FEE071-2DE6-48A1-9343-B5C1F202A12B}</Project>
|
||||||
<Name>OpenTK</Name>
|
<Name>OpenTK</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\SharpDX\SharpDX.csproj" Condition=" '$(Configuration)' == 'Debug_DX32' " >
|
<ProjectReference Include="..\SharpDX\SharpDX.csproj" Condition=" '$(Configuration)' == 'Debug_DX32' ">
|
||||||
<Project>{B4D984DF-85B8-4BBF-8C3B-5CEF905F40D9}</Project>
|
<Project>{B4D984DF-85B8-4BBF-8C3B-5CEF905F40D9}</Project>
|
||||||
<Name>SharpDX</Name>
|
<Name>SharpDX</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
@ -36,17 +36,27 @@ namespace ClassicalSharp {
|
|||||||
public int vIndex, vCount;
|
public int vIndex, vCount;
|
||||||
public int iIndex, iCount;
|
public int iIndex, iCount;
|
||||||
|
|
||||||
public DrawInfo1DPart() {
|
|
||||||
vertices = new VertexPos3fTex2fCol4b[0];
|
|
||||||
indices = new ushort[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ExpandToCapacity() {
|
public void ExpandToCapacity() {
|
||||||
vCount = ( iCount / 6 ) * 4;
|
vCount = ( iCount / 6 ) * 4;
|
||||||
|
|
||||||
if( vCount > vertices.Length ) {
|
if( vertices == null || vCount > vertices.Length ) {
|
||||||
vertices = new VertexPos3fTex2fCol4b[vCount];
|
vertices = new VertexPos3fTex2fCol4b[vCount];
|
||||||
indices = new ushort[iCount];
|
indices = new ushort[iCount];
|
||||||
|
MakeIndices();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MakeIndices() {
|
||||||
|
int element = 0;
|
||||||
|
for( int i = 0; i < iCount; ) {
|
||||||
|
indices[i++] = (ushort)( element + 0 );
|
||||||
|
indices[i++] = (ushort)( element + 1 );
|
||||||
|
indices[i++] = (ushort)( element + 2 );
|
||||||
|
|
||||||
|
indices[i++] = (ushort)( element + 2 );
|
||||||
|
indices[i++] = (ushort)( element + 3 );
|
||||||
|
indices[i++] = (ushort)( element + 0 );
|
||||||
|
element += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +206,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
||||||
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
||||||
|
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V2, col );
|
||||||
@ -215,7 +224,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
||||||
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
||||||
|
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V1, col );
|
||||||
@ -237,7 +245,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
||||||
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
||||||
|
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
|
||||||
@ -259,7 +266,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
||||||
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
||||||
|
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y, Z, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y, Z, rec.U1, rec.V2, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U2, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U2, rec.V2, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
||||||
@ -281,7 +287,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
||||||
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
||||||
|
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + count, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + count, rec.U2, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V2, col );
|
||||||
@ -303,7 +308,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
|
||||||
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
DrawInfo1DPart part = isTranslucent ? info.Translucent : info.Solid;
|
||||||
|
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z, rec.U2, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z + count, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z + count, rec.U1, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 1, Y, Z + count, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 1, Y, Z + count, rec.U1, rec.V2, col );
|
||||||
@ -321,7 +325,6 @@ namespace ClassicalSharp {
|
|||||||
DrawInfo1DPart part = drawInfoBuffer[drawInfoIndex].Sprite;
|
DrawInfo1DPart part = drawInfoBuffer[drawInfoIndex].Sprite;
|
||||||
|
|
||||||
// Draw stretched Z axis
|
// Draw stretched Z axis
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 0.5f, rec.U2, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y, Z + 0.5f, rec.U2, rec.V2, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 0.5f, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 0.5f, rec.U2, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 0.5f, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 0.5f, rec.U1, rec.V1, col );
|
||||||
@ -332,7 +335,6 @@ namespace ClassicalSharp {
|
|||||||
int startX = X;
|
int startX = X;
|
||||||
|
|
||||||
for( int i = 0; i < count; i++ ) {
|
for( int i = 0; i < count; i++ ) {
|
||||||
AddIndices( part );
|
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y, Z, rec.U1, rec.V2, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y, Z, rec.U1, rec.V2, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z, rec.U1, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z, rec.U1, rec.V1, col );
|
||||||
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
|
part.vertices[part.vIndex++] = new VertexPos3fTex2fCol4b( X + 0.5f, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
|
||||||
@ -341,16 +343,5 @@ namespace ClassicalSharp {
|
|||||||
}
|
}
|
||||||
X = startX;
|
X = startX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddIndices( DrawInfo1DPart part ) {
|
|
||||||
int element = part.vIndex;
|
|
||||||
part.indices[part.iIndex++] = (ushort)( element + 0 );
|
|
||||||
part.indices[part.iIndex++] = (ushort)( element + 1 );
|
|
||||||
part.indices[part.iIndex++] = (ushort)( element + 2 );
|
|
||||||
|
|
||||||
part.indices[part.iIndex++] = (ushort)( element + 2 );
|
|
||||||
part.indices[part.iIndex++] = (ushort)( element + 3 );
|
|
||||||
part.indices[part.iIndex++] = (ushort)( element + 0 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user