[broken] Attempting to fix vertices > 65536.

This commit is contained in:
UnknownShadow200 2015-04-26 08:42:33 +10:00
parent 08b7bdb854
commit a2e50e914f
2 changed files with 51 additions and 15 deletions

View file

@ -8,6 +8,7 @@ namespace ClassicalSharp {
DrawInfo1D[] drawInfoBuffer; DrawInfo1D[] drawInfoBuffer;
TextureAtlas1D atlas; TextureAtlas1D atlas;
int arraysCount = 0; int arraysCount = 0;
const int maxIndices = 65536;
public ChunkMeshBuilderTex2Col4( Game window ) : base( window ) { public ChunkMeshBuilderTex2Col4( Game window ) : base( window ) {
Window.TerrainAtlasChanged += TerrainAtlasChanged; Window.TerrainAtlasChanged += TerrainAtlasChanged;
@ -31,27 +32,47 @@ namespace ClassicalSharp {
} }
class DrawInfo1DPart { class DrawInfo1DPart {
public VertexPos3fTex2fCol4b[] vertices; public VertexPos3fTex2fCol4b[] vertices1, vertices2, vertices;
public ushort[] indices; public ushort[] indices1, indices2, indices;
public int vIndex, vCount; public int vIndex, vCount;
public int iIndex, iCount; public int iIndex, iCount;
public int vCount1, vCount2;
public int iCount1, iCount2;
public DrawInfo1DPart() { public DrawInfo1DPart() {
vertices = new VertexPos3fTex2fCol4b[0]; vertices1 = new VertexPos3fTex2fCol4b[0];
indices = new ushort[0]; indices1 = new ushort[0];
vertices2 = new VertexPos3fTex2fCol4b[0];
indices2 = new ushort[0];
vertices = vertices1;
indices = indices1;
} }
public void ExpandToCapacity() { public void ExpandToCapacity() {
vCount = ( iCount / 6 ) * 4; vCount = ( iCount / 6 ) * 4;
if( vCount > vertices.Length ) {
vertices = new VertexPos3fTex2fCol4b[vCount]; vCount1 = Math.Min( vCount, maxIndices );
indices = new ushort[iCount]; if( vCount1 > vertices1.Length ) {
vertices1 = new VertexPos3fTex2fCol4b[vCount1];
iCount1 = ( vCount1 / 4 ) * 6;
indices1 = new ushort[iCount1];
}
vCount2 = Math.Max( 0, vCount - maxIndices );
if( vCount2 > vertices2.Length ) {
vertices2 = new VertexPos3fTex2fCol4b[vCount2];
iCount2 = ( vCount2 / 4 ) * 6;
indices2 = new ushort[iCount2];
} }
} }
public void ResetState() { public void ResetState() {
vIndex = iIndex = 0; vIndex = iIndex = 0;
vCount = iCount = 0; vCount = iCount = 0;
vCount1 = vCount2 = 0;
iCount1 = iCount2 = 0;
vertices = vertices1;
indices = indices1;
} }
} }
@ -117,22 +138,26 @@ namespace ClassicalSharp {
} }
protected override ChunkDrawInfo GetChunkInfo( int x, int y, int z ) { protected override ChunkDrawInfo GetChunkInfo( int x, int y, int z ) {
ChunkDrawInfo info = new ChunkDrawInfo( arraysCount ); ChunkDrawInfo info = new ChunkDrawInfo( arraysCount * 2 );
for( int i = 0; i < arraysCount; i++ ) { for( int i = 0; i < arraysCount; i++ ) {
DrawInfo1D drawInfo = drawInfoBuffer[i]; DrawInfo1D drawInfo = drawInfoBuffer[i];
info.SolidParts[i] = GetPartInfo( drawInfo.Solid ); SetPartInfo( drawInfo.Solid, i, info.SolidParts );
info.TranslucentParts[i] = GetPartInfo( drawInfo.Translucent ); SetPartInfo( drawInfo.Translucent, i, info.TranslucentParts );
info.SpriteParts[i] = GetPartInfo( drawInfo.Sprite ); SetPartInfo( drawInfo.Sprite, i, info.SpriteParts );
} }
return info; return info;
} }
ChunkPartInfo GetPartInfo( DrawInfo1DPart part ) { void SetPartInfo( DrawInfo1DPart part, int i, ChunkPartInfo[] parts ) {
ChunkPartInfo info = new ChunkPartInfo( new IndexedVbInfo( 0, 0 ), part.iCount ); ChunkPartInfo info = new ChunkPartInfo( new IndexedVbInfo( 0, 0 ), part.iCount );
if( part.iCount > 0 ) { if( part.iCount1 > 0 ) {
info.VbId = Graphics.InitIndexedVb( part.vertices, part.indices, DrawMode.Triangles, part.vCount, part.iCount ); IndexedVbInfo id = Graphics.InitIndexedVb( part.vertices1, part.indices1, DrawMode.Triangles, part.vCount1, part.iCount1 );
parts[i] = new ChunkPartInfo( id, part.iCount1 );
}
if( part.iCount2 > 0 ) {
IndexedVbInfo id = Graphics.InitIndexedVb( part.vertices2, part.indices2, DrawMode.Triangles, part.vCount2, part.iCount2 );
parts[i + arraysCount] = new ChunkPartInfo( id, part.iCount2 );
} }
return info;
} }
bool isTranslucent; bool isTranslucent;
@ -364,6 +389,13 @@ namespace ClassicalSharp {
void AddIndices( DrawInfo1DPart part ) { void AddIndices( DrawInfo1DPart part ) {
int element = part.vIndex; int element = part.vIndex;
if( element == maxIndices ) {
part.indices = part.indices2;
part.vertices = part.vertices2;
part.iIndex = 0;
part.vIndex = 0;
element = 0;
}
part.indices[part.iIndex++] = (ushort)( element + 0 ); part.indices[part.iIndex++] = (ushort)( element + 0 );
part.indices[part.iIndex++] = (ushort)( element + 1 ); part.indices[part.iIndex++] = (ushort)( element + 1 );
part.indices[part.iIndex++] = (ushort)( element + 2 ); part.indices[part.iIndex++] = (ushort)( element + 2 );

View file

@ -218,11 +218,13 @@ namespace ClassicalSharp {
for( int batch = 0; batch < _1Dcount; batch++ ) { for( int batch = 0; batch < _1Dcount; batch++ ) {
Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] ); Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] );
RenderSolidBatch( batch ); RenderSolidBatch( batch );
RenderSolidBatch( batch + _1Dcount );
} }
Graphics.FaceCulling = false; Graphics.FaceCulling = false;
for( int batch = 0; batch < _1Dcount; batch++ ) { for( int batch = 0; batch < _1Dcount; batch++ ) {
Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] ); Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] );
RenderSpriteBatch( batch ); RenderSpriteBatch( batch );
RenderSpriteBatch( batch + _1Dcount );
} }
Graphics.AlphaTest = false; Graphics.AlphaTest = false;
Graphics.Texturing = false; Graphics.Texturing = false;
@ -241,6 +243,7 @@ namespace ClassicalSharp {
Graphics.ColourMask( false, false, false, false ); Graphics.ColourMask( false, false, false, false );
for( int batch = 0; batch < _1Dcount; batch++ ) { for( int batch = 0; batch < _1Dcount; batch++ ) {
RenderTranslucentBatchNoAdd( batch ); RenderTranslucentBatchNoAdd( batch );
RenderTranslucentBatchNoAdd( batch + _1Dcount );
} }
// Then actually draw the transluscent blocks // Then actually draw the transluscent blocks
Graphics.AlphaBlending = true; Graphics.AlphaBlending = true;
@ -249,6 +252,7 @@ namespace ClassicalSharp {
for( int batch = 0; batch < _1Dcount; batch++ ) { for( int batch = 0; batch < _1Dcount; batch++ ) {
Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] ); Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] );
RenderTranslucentBatch( batch ); RenderTranslucentBatch( batch );
RenderTranslucentBatch( batch + _1Dcount );
} }
Graphics.DepthTestFunc( CompareFunc.Less ); Graphics.DepthTestFunc( CompareFunc.Less );