Fix crashing when rainy but not drawing any vertices on nVidia cards, use default.png font for player names.

This commit is contained in:
UnknownShadow200 2015-11-02 17:29:56 +11:00
parent db61780273
commit 42e86be6f0
4 changed files with 16 additions and 18 deletions

View File

@ -23,7 +23,7 @@ namespace ClassicalSharp {
using( Font font = new Font( "Arial", 14 ) ) { using( Font font = new Font( "Arial", 14 ) ) {
DrawTextArgs args = new DrawTextArgs( DisplayName, font, true ); DrawTextArgs args = new DrawTextArgs( DisplayName, font, true );
nameTex = game.Drawer2D.MakeTextTexture( ref args, 0, 0 ); nameTex = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 );
} }
} }

View File

@ -231,18 +231,16 @@ namespace ClassicalSharp.GraphicsAPI {
int batchStride; int batchStride;
public override void DrawDynamicVb<T>( DrawMode mode, int id, T[] vertices, int count ) { public override void DrawDynamicVb<T>( DrawMode mode, int id, T[] vertices, int count ) {
int sizeInBytes = count * batchStride;
GL.BindBuffer( BufferTarget.ArrayBuffer, id ); GL.BindBuffer( BufferTarget.ArrayBuffer, id );
GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( sizeInBytes ), vertices ); GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( count * batchStride ), vertices );
setupBatchFunc(); setupBatchFunc();
GL.DrawArrays( modeMappings[(int)mode], 0, count ); GL.DrawArrays( modeMappings[(int)mode], 0, count );
} }
public override void DrawDynamicIndexedVb<T>( DrawMode mode, int id, T[] vertices, int vCount, int indicesCount ) { public override void DrawDynamicIndexedVb<T>( DrawMode mode, int id, T[] vertices, int vCount, int indicesCount ) {
int sizeInBytes = vCount * batchStride;
GL.BindBuffer( BufferTarget.ArrayBuffer, id ); GL.BindBuffer( BufferTarget.ArrayBuffer, id );
GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( sizeInBytes ), vertices ); GL.BufferSubData( BufferTarget.ArrayBuffer, IntPtr.Zero, new IntPtr( vCount * batchStride ), vertices );
setupBatchFunc(); setupBatchFunc();
GL.DrawElements( modeMappings[(int)mode], indicesCount, indexType, zero ); GL.DrawElements( modeMappings[(int)mode], indicesCount, indexType, zero );

View File

@ -46,8 +46,11 @@ namespace ClassicalSharp {
MakeRainForSquare( pos.X + dx, rainY, height, pos.Z + dz, col, ref index ); MakeRainForSquare( pos.X + dx, rainY, height, pos.Z + dz, col, ref index );
} }
} }
graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b ); // fixes crashing on nVidia cards in OpenGL builds.
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, weatherVb, vertices, index, index * 6 / 4 ); if( index > 0 ) {
graphics.BeginVbBatch( VertexFormat.Pos3fTex2fCol4b );
graphics.DrawDynamicIndexedVb( DrawMode.Triangles, weatherVb, vertices, index, index * 6 / 4 );
}
graphics.AlphaBlending = false; graphics.AlphaBlending = false;
graphics.Texturing = false; graphics.Texturing = false;
graphics.DepthWrite = true; graphics.DepthWrite = true;
@ -55,7 +58,7 @@ namespace ClassicalSharp {
float AlphaAt( float x ) { float AlphaAt( float x ) {
// Wolfram Alpha: fit {0,178},{1,169},{4,147},{9,114},{16,59},{25,9} // Wolfram Alpha: fit {0,178},{1,169},{4,147},{9,114},{16,59},{25,9}
return (float)( 0.05 * x * x - 8 * x + 178 ); return 0.05f * x * x - 8 * x + 178;
} }
void MakeRainForSquare( int x, int y, int height, int z, FastColour col, ref int index ) { void MakeRainForSquare( int x, int y, int height, int z, FastColour col, ref int index ) {
@ -63,12 +66,12 @@ namespace ClassicalSharp {
float v2 = height / 6f + v1; float v2 = height / 6f + v1;
vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z, 0, v2, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z, 0, v2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z, 0, v1, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z, 0, v1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z + 1, 2, v1, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z + 1, 2, v1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z + 1, 2, v2, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z + 1, 2, v2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z, 2, v2, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y, z, 2, v2, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z, 2, v1, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x + 1, y + height, z, 2, v1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z + 1, 0, v1, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x, y + height, z + 1, 0, v1, col );
vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z + 1, 0, v2, col ); vertices[index++] = new VertexPos3fTex2fCol4b( x, y, z + 1, 0, v2, col );
} }
@ -104,7 +107,7 @@ namespace ClassicalSharp {
int GetRainHeight( int x, int z ) { int GetRainHeight( int x, int z ) {
if( x < 0 || z < 0 || x >= width || z >= length ) return map.EdgeHeight - 1; if( x < 0 || z < 0 || x >= width || z >= length ) return map.EdgeHeight - 1;
int index = ( x * length ) + z; int index = ( x * length ) + z;
int height = heightmap[index]; int height = heightmap[index];
return height == short.MaxValue ? CalcHeightAt( x, maxY, z, index ) : height; return height == short.MaxValue ? CalcHeightAt( x, maxY, z, index ) : height;
} }
@ -117,7 +120,7 @@ namespace ClassicalSharp {
return y; return y;
} }
mapIndex -= oneY; mapIndex -= oneY;
} }
heightmap[index] = -1; heightmap[index] = -1;
return -1; return -1;
} }

View File

@ -67,12 +67,9 @@ namespace Launcher2 {
buttonWidth, buttonHeight, 0, -50, buttonWidth, buttonHeight, 0, -50,
(x, y) => game.SetScreen( new DirectConnectScreen( game ) ) ); (x, y) => game.SetScreen( new DirectConnectScreen( game ) ) );
MakeButtonAt( "Singleplayer", Anchor.LeftOrTop, Anchor.BottomOrRight, MakeButtonAt( "Singleplayer", Anchor.Centre, Anchor.Centre,
sideButtonWidth, buttonHeight, 10, -10, buttonWidth, buttonHeight, 0, 0,
(x, y) => Client.Start( "default.zip" ) ); (x, y) => Client.Start( "default.zip" ) );
MakeButtonAt( "Resume", Anchor.BottomOrRight, Anchor.BottomOrRight,
sideButtonWidth, buttonHeight, -10, -10, null );
} }
const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150; const int buttonWidth = 220, buttonHeight = 35, sideButtonWidth = 150;