Use face culling. (Breaks sprites though)

This commit is contained in:
UnknownShadow200 2015-01-14 13:48:55 +11:00
parent dabc5aa858
commit 5f05ed73e4
4 changed files with 36 additions and 26 deletions

View file

@ -53,6 +53,8 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract void SetFogMode( Fog fogMode );
public abstract void SetFogStart( float value );
public abstract bool FaceCulling { set; }
/// <summary> Sets the alpha test function that is used when alpha testing is enabled. </summary>

View file

@ -111,6 +111,10 @@ namespace ClassicalSharp.GraphicsAPI {
GL.Fog( FogParameter.FogStart, value );
}
public override bool FaceCulling {
set { ToggleCap( EnableCap.CullFace, value ); }
}
#if TRACK_RESOURCES
Dictionary<int, string> textures = new Dictionary<int, string>();

View file

@ -185,13 +185,13 @@ namespace ClassicalSharp {
}
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U2, rec.V1, col );
}
protected override void DrawBottomFace( int count ) {
@ -209,13 +209,13 @@ namespace ClassicalSharp {
}
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
}
protected override void DrawBackFace( int count ) {
@ -236,13 +236,13 @@ namespace ClassicalSharp {
}
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + 1, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z + 1, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z + 1, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z + 1, rec.U2, rec.V1, col );
}
protected override void DrawFrontFace( int count ) {
@ -263,13 +263,13 @@ namespace ClassicalSharp {
}
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y + blockHeight, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + count, Y, Z, rec.U1, rec.V2, col );
}
protected override void DrawLeftFace( int count ) {
@ -290,13 +290,13 @@ namespace ClassicalSharp {
}
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + count, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + count, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + count, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z + count, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y, Z + count, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X, Y + blockHeight, Z + count, rec.U2, rec.V1, col );
}
protected override void DrawRightFace( int count ) {
@ -317,13 +317,13 @@ namespace ClassicalSharp {
}
DrawInfo1D info = drawInfoBuffer[drawInfoIndex];
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y, Z, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z, rec.U2, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z + count, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y, Z + count, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z + count, rec.U1, rec.V1, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y, Z + count, rec.U1, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y, Z, rec.U2, rec.V2, col );
info.vertices[info.index++] = new VertexPos3fTex2fCol4b( X + 1, Y + blockHeight, Z, rec.U2, rec.V1, col );
}
protected override void DrawSprite( int count ) {

View file

@ -228,12 +228,14 @@ namespace ClassicalSharp {
builder.BeginRender();
Graphics.Texturing = true;
Graphics.AlphaTest = true;
Graphics.FaceCulling = true;
for( int batch = 0; batch < _1Dcount; batch++ ) {
Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] );
RenderBatch( batch );
}
Graphics.AlphaTest = false;
Graphics.Texturing = false;
Graphics.FaceCulling = false;
builder.EndRender();
Window.MapEnvRenderer.RenderMapSides( deltaTime );
Window.MapEnvRenderer.RenderMapEdges( deltaTime );
@ -243,6 +245,7 @@ namespace ClassicalSharp {
Graphics.AlphaTest = false;
Graphics.Texturing = false;
Graphics.AlphaBlending = false;
Graphics.FaceCulling = true;
// First fill depth buffer
Graphics.DepthTestFunc( DepthFunc.LessEqual );
@ -263,6 +266,7 @@ namespace ClassicalSharp {
Graphics.AlphaTest = false;
Graphics.AlphaBlending = false;
Graphics.Texturing = false;
Graphics.FaceCulling = false;
builder.EndRender();
}