mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-12 17:17:09 -04:00
Use single index buffer for all chunks. Very minor increase in performance, but does slightly reduce memory usage.
This commit is contained in:
parent
618ded14e0
commit
dd2eb1105a
@ -128,7 +128,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public abstract void BeginIndexedVbBatch();
|
||||
|
||||
public abstract void BindIndexedVb( int vb, int ib );
|
||||
public abstract void BindVb( int vb );
|
||||
|
||||
public abstract void BindIb( int ib );
|
||||
|
||||
public abstract void DrawIndexedVb( DrawMode mode, int indicesCount, int startVertex, int startIndex );
|
||||
|
||||
@ -140,10 +142,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public abstract void LoadMatrix( ref Matrix4 matrix );
|
||||
|
||||
public virtual void LoadIdentityMatrix() {
|
||||
Matrix4 identity = Matrix4.Identity;
|
||||
LoadMatrix( ref identity );
|
||||
}
|
||||
public abstract void LoadIdentityMatrix();
|
||||
|
||||
public abstract void MultiplyMatrix( ref Matrix4 matrix );
|
||||
|
||||
@ -154,8 +153,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
|
||||
public abstract void TakeScreenshot( string output, Size size );
|
||||
|
||||
public virtual void PrintApiSpecificInfo() {
|
||||
}
|
||||
public abstract void PrintApiSpecificInfo();
|
||||
|
||||
public abstract void BeginFrame( Game game );
|
||||
|
||||
|
@ -296,8 +296,11 @@ namespace ClassicalSharp.GraphicsAPI {
|
||||
GL.DrawArrays( modeMappings[(int)mode], startVertex, verticesCount );
|
||||
}
|
||||
|
||||
public override void BindIndexedVb( int vb, int ib ) {
|
||||
public override void BindVb( int vb ) {
|
||||
GL.BindBufferARB( BufferTarget.ArrayBuffer, vb );
|
||||
}
|
||||
|
||||
public override void BindIb( int ib ) {
|
||||
GL.BindBufferARB( BufferTarget.ElementArrayBuffer, ib );
|
||||
}
|
||||
|
||||
|
@ -334,8 +334,7 @@ namespace ClassicalSharp {
|
||||
|
||||
public struct ChunkPartInfo {
|
||||
|
||||
public int VbId, IbId;
|
||||
public int IndicesCount;
|
||||
public int VbId, IndicesCount;
|
||||
public int leftIndex, rightIndex, frontIndex,
|
||||
backIndex, bottomIndex, topIndex;
|
||||
public ushort leftCount, rightCount, frontCount,
|
||||
|
@ -34,7 +34,6 @@ namespace ClassicalSharp {
|
||||
|
||||
class DrawInfo {
|
||||
public VertexPos3fTex2fCol4b[] vertices;
|
||||
public ushort[] indices;
|
||||
public int vCount, iCount;
|
||||
public DrawInfoFaceData vIndex;
|
||||
public DrawInfoFaceData Count;
|
||||
@ -45,8 +44,6 @@ namespace ClassicalSharp {
|
||||
|
||||
if( vertices == null || vCount > vertices.Length ) {
|
||||
vertices = new VertexPos3fTex2fCol4b[vCount];
|
||||
indices = new ushort[iCount];
|
||||
MakeIndices();
|
||||
}
|
||||
vIndex.left = spriteCount / 6 * 4;
|
||||
vIndex.right = vIndex.left + Count.left / 6 * 4;
|
||||
@ -56,20 +53,6 @@ namespace ClassicalSharp {
|
||||
vIndex.top = vIndex.bottom + Count.bottom / 6 * 4;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetState() {
|
||||
vCount = iCount = 0;
|
||||
spriteIndex = spriteCount = 0;
|
||||
@ -147,7 +130,6 @@ namespace ClassicalSharp {
|
||||
|
||||
ChunkPartInfo info;
|
||||
info.VbId = Graphics.InitVb( part.vertices, VertexFormat.Pos3fTex2fCol4b, part.vCount );
|
||||
info.IbId = Graphics.InitIb( part.indices, part.iCount );
|
||||
info.IndicesCount = part.iCount;
|
||||
info.leftCount = (ushort)part.Count.left; info.rightCount = (ushort)part.Count.right;
|
||||
info.frontCount = (ushort)part.Count.front; info.backCount = (ushort)part.Count.back;
|
||||
|
@ -50,7 +50,7 @@ namespace ClassicalSharp {
|
||||
}
|
||||
|
||||
void DrawPart( ChunkInfo info, ref ChunkPartInfo part ) {
|
||||
api.BindIndexedVb( part.VbId, part.IbId );
|
||||
api.BindVb( part.VbId );
|
||||
bool drawLeft = info.DrawLeft && part.leftCount > 0;
|
||||
bool drawRight = info.DrawRight && part.rightCount > 0;
|
||||
bool drawBottom = info.DrawBottom && part.bottomCount > 0;
|
||||
@ -83,7 +83,7 @@ namespace ClassicalSharp {
|
||||
if( part.IndicesCount > maxIndices ) {
|
||||
int part1Count = maxIndices - part.bottomIndex;
|
||||
api.DrawIndexedVb( mode, part1Count, 0, part.bottomIndex );
|
||||
api.DrawIndexedVb( mode, part.bottomCount + part.topCount - part1Count, maxVertex, part.bottomIndex );
|
||||
api.DrawIndexedVb( mode, part.bottomCount + part.topCount - part1Count, maxVertex, 0 );
|
||||
} else {
|
||||
api.DrawIndexedVb( mode, part.bottomCount + part.topCount, 0, part.bottomIndex );
|
||||
}
|
||||
@ -93,7 +93,7 @@ namespace ClassicalSharp {
|
||||
if( part.IndicesCount > maxIndices &&
|
||||
( part1Count = maxIndices - part.bottomIndex ) < part.bottomCount ) {
|
||||
api.DrawIndexedVb( mode, part1Count, 0, part.bottomIndex );
|
||||
api.DrawIndexedVb( mode, part.bottomCount - part1Count, maxVertex, part.bottomIndex );
|
||||
api.DrawIndexedVb( mode, part.bottomCount - part1Count, maxVertex, 0 );
|
||||
} else {
|
||||
api.DrawIndexedVb( mode, part.bottomCount, 0, part.bottomIndex );
|
||||
}
|
||||
@ -102,7 +102,7 @@ namespace ClassicalSharp {
|
||||
if( part.IndicesCount > maxIndices &&
|
||||
( part1Count = maxIndices - part.topIndex ) < part.topCount ) {
|
||||
api.DrawIndexedVb( mode, part1Count, 0, part.topIndex );
|
||||
api.DrawIndexedVb( mode, part.topCount - part1Count, maxVertex, part.topIndex );
|
||||
api.DrawIndexedVb( mode, part.topCount - part1Count, maxVertex, 0 );
|
||||
} else {
|
||||
api.DrawIndexedVb( mode, part.topCount, 0, part.topIndex );
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ namespace ClassicalSharp {
|
||||
game.OnNewMapLoaded -= OnNewMapLoaded;
|
||||
game.EnvVariableChanged -= EnvVariableChanged;
|
||||
builder.Dispose();
|
||||
api.DeleteIb( chunkIb );
|
||||
}
|
||||
|
||||
public void Refresh() {
|
||||
@ -123,7 +124,6 @@ namespace ClassicalSharp {
|
||||
|
||||
for( int i = 0; i < parts.Length; i++ ) {
|
||||
api.DeleteVb( parts[i].VbId );
|
||||
api.DeleteIb( parts[i].IbId );
|
||||
}
|
||||
parts = null;
|
||||
}
|
||||
@ -188,11 +188,15 @@ namespace ClassicalSharp {
|
||||
public void Render( double deltaTime ) {
|
||||
if( chunks == null ) return;
|
||||
UpdateSortOrder();
|
||||
UpdateChunks();
|
||||
UpdateChunks();
|
||||
if( chunkIb == -1 )
|
||||
MakeIndices();
|
||||
|
||||
api.BindIb( chunkIb );
|
||||
RenderNormal();
|
||||
game.MapEnvRenderer.RenderMapSides( deltaTime );
|
||||
game.MapEnvRenderer.RenderMapEdges( deltaTime );
|
||||
api.BindIb( chunkIb );
|
||||
RenderTranslucent();
|
||||
}
|
||||
|
||||
@ -257,7 +261,7 @@ namespace ClassicalSharp {
|
||||
|
||||
// Render solid and fully transparent to fill depth buffer.
|
||||
// These blocks are treated as having an alpha value of either none or full.
|
||||
void RenderNormal() {
|
||||
void RenderNormal() {
|
||||
int[] texIds = game.TerrainAtlas1D.TexIds;
|
||||
api.BeginIndexedVbBatch();
|
||||
api.Texturing = true;
|
||||
@ -272,11 +276,28 @@ namespace ClassicalSharp {
|
||||
api.EndIndexedVbBatch();
|
||||
}
|
||||
|
||||
int chunkIb = -1;
|
||||
void MakeIndices() {
|
||||
int element = 0;
|
||||
ushort[] indices = new ushort[maxIndices];
|
||||
for( int i = 0; i < indices.Length; ) {
|
||||
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;
|
||||
}
|
||||
chunkIb = api.InitIb( indices, indices.Length );
|
||||
}
|
||||
|
||||
// Render translucent(liquid) blocks. These 'blend' into other blocks.
|
||||
void RenderTranslucent() {
|
||||
// First fill depth buffer
|
||||
int[] texIds = game.TerrainAtlas1D.TexIds;
|
||||
api.BeginIndexedVbBatch();
|
||||
api.BeginIndexedVbBatch();
|
||||
api.Texturing = false;
|
||||
api.AlphaBlending = false;
|
||||
api.ColourWrite = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user