mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 03:55:19 -04:00
Combine AlphaFunc and DepthFunc into CompareFunc, start work on supporting indexed drawing.
This commit is contained in:
parent
2273bace85
commit
75d88ddeb2
@ -135,9 +135,9 @@ namespace ClassicalSharp {
|
|||||||
blocksTable = new BlockDrawInfo[blocksCount];
|
blocksTable = new BlockDrawInfo[blocksCount];
|
||||||
|
|
||||||
int tableIndex = 0;
|
int tableIndex = 0;
|
||||||
for( int i = 0; i < BlockInfo.BlocksCount; i++ ) {
|
for( int tile = 1; tile < BlockInfo.BlocksCount; tile++ ) {
|
||||||
if( Window.CanPlace[i] || Window.CanDelete[i] ) {
|
if( Window.CanPlace[tile] || Window.CanDelete[tile] ) {
|
||||||
Block block = (Block)i;
|
Block block = (Block)tile;
|
||||||
int texId = Window.BlockInfo.GetOptimTextureLoc( (byte)block, TileSide.Left );
|
int texId = Window.BlockInfo.GetOptimTextureLoc( (byte)block, TileSide.Left );
|
||||||
TextureRectangle rec = Window.TerrainAtlas.GetTexRec( texId );
|
TextureRectangle rec = Window.TerrainAtlas.GetTexRec( texId );
|
||||||
int verSize = blockSize;
|
int verSize = blockSize;
|
||||||
|
@ -177,7 +177,7 @@ namespace ClassicalSharp {
|
|||||||
Graphics.DepthTest = true;
|
Graphics.DepthTest = true;
|
||||||
//Graphics.DepthWrite = true;
|
//Graphics.DepthWrite = true;
|
||||||
Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
|
Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha );
|
||||||
Graphics.AlphaTestFunc( AlphaFunc.Greater, 0.5f );
|
Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f );
|
||||||
RegisterInputHandlers();
|
RegisterInputHandlers();
|
||||||
Title = Utils.AppName;
|
Title = Utils.AppName;
|
||||||
fpsScreen = new FpsScreen( this );
|
fpsScreen = new FpsScreen( this );
|
||||||
|
@ -58,7 +58,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
|
|
||||||
/// <summary> Sets the alpha test function that is used when alpha testing is enabled. </summary>
|
/// <summary> Sets the alpha test function that is used when alpha testing is enabled. </summary>
|
||||||
public abstract void AlphaTestFunc( AlphaFunc func, float value );
|
public abstract void AlphaTestFunc( CompareFunc func, float value );
|
||||||
|
|
||||||
/// <summary> Whether alpha testing is currently enabled. </summary>
|
/// <summary> Whether alpha testing is currently enabled. </summary>
|
||||||
public abstract bool AlphaTest { set; }
|
public abstract bool AlphaTest { set; }
|
||||||
@ -80,7 +80,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public abstract void ColourMask( bool red, bool green, bool blue, bool alpha );
|
public abstract void ColourMask( bool red, bool green, bool blue, bool alpha );
|
||||||
|
|
||||||
public abstract void DepthTestFunc( DepthFunc func );
|
public abstract void DepthTestFunc( CompareFunc func );
|
||||||
|
|
||||||
/// <summary> Whether depth testing is currently enabled. </summary>
|
/// <summary> Whether depth testing is currently enabled. </summary>
|
||||||
public abstract bool DepthTest { set; }
|
public abstract bool DepthTest { set; }
|
||||||
@ -124,6 +124,9 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public abstract int InitVb<T>( T[] vertices, DrawMode mode, VertexFormat format, int count ) where T : struct;
|
public abstract int InitVb<T>( T[] vertices, DrawMode mode, VertexFormat format, int count ) where T : struct;
|
||||||
|
|
||||||
|
public abstract IndexedVbInfo InitIndexedVb<T>( T[] vertices, ushort[] indices, DrawMode mode,
|
||||||
|
VertexFormat format, int verticesCount, int indicesCount ) where T : struct;
|
||||||
|
|
||||||
public abstract void DeleteVb( int id );
|
public abstract void DeleteVb( int id );
|
||||||
|
|
||||||
public abstract void DrawVbPos3f( DrawMode mode, int id, int verticesCount );
|
public abstract void DrawVbPos3f( DrawMode mode, int id, int verticesCount );
|
||||||
@ -267,19 +270,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
ReverseSubtract = 4,
|
ReverseSubtract = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum AlphaFunc {
|
public enum CompareFunc {
|
||||||
Always = 0,
|
|
||||||
NotEqual = 1,
|
|
||||||
Never = 2,
|
|
||||||
|
|
||||||
Less = 3,
|
|
||||||
LessEqual = 4,
|
|
||||||
Equal = 5,
|
|
||||||
GreaterEqual = 6,
|
|
||||||
Greater = 7,
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum DepthFunc {
|
|
||||||
Always = 0,
|
Always = 0,
|
||||||
NotEqual = 1,
|
NotEqual = 1,
|
||||||
Never = 2,
|
Never = 2,
|
||||||
@ -318,4 +309,13 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
Modelview = 1,
|
Modelview = 1,
|
||||||
Texture = 2,
|
Texture = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct IndexedVbInfo {
|
||||||
|
public int Vb, Ib;
|
||||||
|
|
||||||
|
public IndexedVbInfo( int vb, int ib ) {
|
||||||
|
Vb = vb;
|
||||||
|
Ib = ib;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -58,7 +58,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
AlphaFunction.Lequal, AlphaFunction.Equal,
|
AlphaFunction.Lequal, AlphaFunction.Equal,
|
||||||
AlphaFunction.Gequal, AlphaFunction.Greater,
|
AlphaFunction.Gequal, AlphaFunction.Greater,
|
||||||
};
|
};
|
||||||
public override void AlphaTestFunc( AlphaFunc func, float value ) {
|
public override void AlphaTestFunc( CompareFunc func, float value ) {
|
||||||
GL.AlphaFunc( alphaFuncs[(int)func], value );
|
GL.AlphaFunc( alphaFuncs[(int)func], value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
DepthFunction.Lequal, DepthFunction.Equal,
|
DepthFunction.Lequal, DepthFunction.Equal,
|
||||||
DepthFunction.Gequal, DepthFunction.Greater,
|
DepthFunction.Gequal, DepthFunction.Greater,
|
||||||
};
|
};
|
||||||
public override void DepthTestFunc( DepthFunc func ) {
|
public override void DepthTestFunc( CompareFunc func ) {
|
||||||
GL.DepthFunc( depthFuncs[(int)func] );
|
GL.DepthFunc( depthFuncs[(int)func] );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,13 +297,56 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe int CreateDisplayList<T>( T[] vertices, DrawMode mode, VertexFormat format, int count ) where T : struct {
|
public unsafe override IndexedVbInfo InitIndexedVb<T>( T[] vertices, ushort[] indices, DrawMode mode,
|
||||||
|
VertexFormat format, int verticesCount, int indicesCount ) {
|
||||||
|
if( !useVbos ) {
|
||||||
|
// TODO: Indexed display lists
|
||||||
|
return default( IndexedVbInfo ); //return CreateDisplayList( vertices, mode, format, count );
|
||||||
|
}
|
||||||
|
int* ids = stackalloc int[2];
|
||||||
|
GL.Arb.GenBuffers( 2, ids );
|
||||||
|
int sizeInBytes = GetSizeInBytes( verticesCount, format );
|
||||||
|
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, ids[0] );
|
||||||
|
GL.Arb.BufferData( BufferTargetArb.ArrayBuffer, new IntPtr( sizeInBytes ), vertices, BufferUsageArb.StaticDraw );
|
||||||
|
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
||||||
|
|
||||||
|
sizeInBytes = indicesCount * sizeof( ushort );
|
||||||
|
GL.Arb.BindBuffer( BufferTargetArb.ElementArrayBuffer, ids[1] );
|
||||||
|
GL.Arb.BufferData( BufferTargetArb.ElementArrayBuffer, new IntPtr( sizeInBytes ), indices, BufferUsageArb.StaticDraw );
|
||||||
|
GL.Arb.BindBuffer( BufferTargetArb.ElementArrayBuffer, 0 );
|
||||||
|
return new IndexedVbInfo( ids[0], ids[1] );
|
||||||
|
}
|
||||||
|
|
||||||
|
IndexedVbInfo CreateIndexedDisplayList<T>( T[] vertices, ushort[] indices, DrawMode mode,
|
||||||
|
VertexFormat format, int verticesCount, int indicesCount ) where T : struct {
|
||||||
|
GCHandle handle;
|
||||||
|
int id = SetupDisplayListState( vertices, format, out handle );
|
||||||
|
GL.DrawElements( modeMappings[(int)mode], indicesCount, DrawElementsType.UnsignedShort, 0 );
|
||||||
|
RestoreDisplayListState( format, ref handle );
|
||||||
|
#if TRACK_RESOURCES
|
||||||
|
vbs.Add( id, Environment.StackTrace );
|
||||||
|
#endif
|
||||||
|
return new IndexedVbInfo( id, id );
|
||||||
|
}
|
||||||
|
|
||||||
|
int CreateDisplayList<T>( T[] vertices, DrawMode mode, VertexFormat format, int count ) where T : struct {
|
||||||
|
GCHandle handle;
|
||||||
|
int id = SetupDisplayListState( vertices, format, out handle );
|
||||||
|
GL.DrawArrays( modeMappings[(int)mode], 0, count );
|
||||||
|
RestoreDisplayListState( format, ref handle );
|
||||||
|
#if TRACK_RESOURCES
|
||||||
|
vbs.Add( id, Environment.StackTrace );
|
||||||
|
#endif
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe static int SetupDisplayListState<T>( T[] vertices, VertexFormat format, out GCHandle handle ) {
|
||||||
int id = GL.GenLists( 1 );
|
int id = GL.GenLists( 1 );
|
||||||
int stride = strideSizes[(int)format];
|
int stride = strideSizes[(int)format];
|
||||||
GL.NewList( id, ListMode.Compile );
|
GL.NewList( id, ListMode.Compile );
|
||||||
GL.EnableClientState( ArrayCap.VertexArray );
|
GL.EnableClientState( ArrayCap.VertexArray );
|
||||||
|
|
||||||
GCHandle handle = GCHandle.Alloc( vertices, GCHandleType.Pinned );
|
handle = GCHandle.Alloc( vertices, GCHandleType.Pinned );
|
||||||
IntPtr p = handle.AddrOfPinnedObject();
|
IntPtr p = handle.AddrOfPinnedObject();
|
||||||
GL.VertexPointer( 3, VertexPointerType.Float, stride, (IntPtr)( 0 + (byte*)p ) );
|
GL.VertexPointer( 3, VertexPointerType.Float, stride, (IntPtr)( 0 + (byte*)p ) );
|
||||||
|
|
||||||
@ -319,7 +362,10 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
GL.TexCoordPointer( 2, TexCoordPointerType.Float, stride, (IntPtr)( 12 + (byte*)p ) );
|
GL.TexCoordPointer( 2, TexCoordPointerType.Float, stride, (IntPtr)( 12 + (byte*)p ) );
|
||||||
GL.ColorPointer( 4, ColorPointerType.UnsignedByte, stride, (IntPtr)( 20 + (byte*)p ) );
|
GL.ColorPointer( 4, ColorPointerType.UnsignedByte, stride, (IntPtr)( 20 + (byte*)p ) );
|
||||||
}
|
}
|
||||||
GL.DrawArrays( modeMappings[(int)mode], 0, count );
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void RestoreDisplayListState( VertexFormat format, ref GCHandle handle ) {
|
||||||
handle.Free();
|
handle.Free();
|
||||||
|
|
||||||
GL.DisableClientState( ArrayCap.VertexArray );
|
GL.DisableClientState( ArrayCap.VertexArray );
|
||||||
@ -333,10 +379,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
GL.Color3( 1f, 1f, 1f ); // NOTE: not sure why, but display lists seem to otherwise modify global colour..
|
GL.Color3( 1f, 1f, 1f ); // NOTE: not sure why, but display lists seem to otherwise modify global colour..
|
||||||
GL.EndList();
|
GL.EndList();
|
||||||
#if TRACK_RESOURCES
|
|
||||||
vbs.Add( id, Environment.StackTrace );
|
|
||||||
#endif
|
|
||||||
return id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DeleteVb( int id ) {
|
public override void DeleteVb( int id ) {
|
||||||
|
@ -237,7 +237,7 @@ namespace ClassicalSharp {
|
|||||||
Graphics.AlphaBlending = false;
|
Graphics.AlphaBlending = false;
|
||||||
|
|
||||||
// First fill depth buffer
|
// First fill depth buffer
|
||||||
Graphics.DepthTestFunc( DepthFunc.LessEqual );
|
Graphics.DepthTestFunc( CompareFunc.LessEqual );
|
||||||
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 );
|
||||||
@ -250,7 +250,7 @@ namespace ClassicalSharp {
|
|||||||
Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] );
|
Graphics.Bind2DTexture( Window.TerrainAtlas1DTexIds[batch] );
|
||||||
RenderTranslucentBatch( batch );
|
RenderTranslucentBatch( batch );
|
||||||
}
|
}
|
||||||
Graphics.DepthTestFunc( DepthFunc.Less );
|
Graphics.DepthTestFunc( CompareFunc.Less );
|
||||||
|
|
||||||
Graphics.AlphaTest = false;
|
Graphics.AlphaTest = false;
|
||||||
Graphics.AlphaBlending = false;
|
Graphics.AlphaBlending = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user