mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 23:41:09 -04:00
Inline Restoring and Setting up VBO state in OpenGLApi.
This commit is contained in:
parent
506e3b8dba
commit
c145cc2510
@ -191,14 +191,14 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
Action<DrawMode, int, int, int> drawBatchFuncTex2fCol4b;
|
Action<DrawMode, int, int, int> drawBatchFuncTex2fCol4b;
|
||||||
|
|
||||||
|
|
||||||
public override int CreateDynamicVb( VertexFormat format, int maxVertices ) {
|
public override int CreateDynamicVb( VertexFormat format, int maxVertices ) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
GL.Arb.GenBuffers( 1, out id );
|
GL.Arb.GenBuffers( 1, out id );
|
||||||
int sizeInBytes = maxVertices * strideSizes[(int)format];
|
int sizeInBytes = maxVertices * strideSizes[(int)format];
|
||||||
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, id );
|
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, id );
|
||||||
GL.Arb.BufferData( BufferTargetArb.ArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, BufferUsageArb.DynamicDraw );
|
GL.Arb.BufferData( BufferTargetArb.ArrayBuffer, new IntPtr( sizeInBytes ), IntPtr.Zero, BufferUsageArb.DynamicDraw );
|
||||||
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int InitVb<T>( T[] vertices, VertexFormat format, int count ) {
|
public override int InitVb<T>( T[] vertices, VertexFormat format, int count ) {
|
||||||
@ -269,18 +269,24 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
VertexFormat batchFormat;
|
VertexFormat batchFormat;
|
||||||
public override void BeginVbBatch( VertexFormat format ) {
|
public override void BeginVbBatch( VertexFormat format ) {
|
||||||
batchFormat = format;
|
batchFormat = format;
|
||||||
EnableClientState( format );
|
GL.EnableClientState( ArrayCap.VertexArray );
|
||||||
if( format == VertexFormat.Pos3fTex2fCol4b ) {
|
if( format == VertexFormat.Pos3fTex2fCol4b ) {
|
||||||
|
GL.EnableClientState( ArrayCap.ColorArray );
|
||||||
|
GL.EnableClientState( ArrayCap.TextureCoordArray );
|
||||||
drawBatchFunc = drawBatchFuncTex2fCol4b;
|
drawBatchFunc = drawBatchFuncTex2fCol4b;
|
||||||
} else if( format == VertexFormat.Pos3fCol4b ) {
|
|
||||||
drawBatchFunc =drawBatchFuncCol4b;
|
|
||||||
} else if( format == VertexFormat.Pos3fTex2f ) {
|
} else if( format == VertexFormat.Pos3fTex2f ) {
|
||||||
|
GL.EnableClientState( ArrayCap.TextureCoordArray );
|
||||||
drawBatchFunc = drawBatchFuncTex2f;
|
drawBatchFunc = drawBatchFuncTex2f;
|
||||||
|
} else if( format == VertexFormat.Pos3fCol4b ) {
|
||||||
|
GL.EnableClientState( ArrayCap.ColorArray );
|
||||||
|
drawBatchFunc = drawBatchFuncCol4b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void BeginIndexedVbBatch() {
|
public override void BeginIndexedVbBatch() {
|
||||||
EnableClientState( VertexFormat.Pos3fTex2fCol4b );
|
GL.EnableClientState( ArrayCap.VertexArray );
|
||||||
|
GL.EnableClientState( ArrayCap.ColorArray );
|
||||||
|
GL.EnableClientState( ArrayCap.TextureCoordArray );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void DrawVbBatch( DrawMode mode, int id, int offset, int verticesCount ) {
|
public override void DrawVbBatch( DrawMode mode, int id, int offset, int verticesCount ) {
|
||||||
@ -297,12 +303,22 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void EndVbBatch() {
|
public override void EndVbBatch() {
|
||||||
DisableClientState( batchFormat );
|
GL.DisableClientState( ArrayCap.VertexArray );
|
||||||
|
if( batchFormat == VertexFormat.Pos3fTex2fCol4b ) {
|
||||||
|
GL.DisableClientState( ArrayCap.ColorArray );
|
||||||
|
GL.DisableClientState( ArrayCap.TextureCoordArray );
|
||||||
|
} else if( batchFormat == VertexFormat.Pos3fTex2f ) {
|
||||||
|
GL.DisableClientState( ArrayCap.TextureCoordArray );
|
||||||
|
} else if( batchFormat == VertexFormat.Pos3fCol4b ) {
|
||||||
|
GL.DisableClientState( ArrayCap.ColorArray );
|
||||||
|
}
|
||||||
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EndIndexedVbBatch() {
|
public override void EndIndexedVbBatch() {
|
||||||
DisableClientState( VertexFormat.Pos3fTex2fCol4b );
|
GL.DisableClientState( ArrayCap.VertexArray );
|
||||||
|
GL.DisableClientState( ArrayCap.ColorArray );
|
||||||
|
GL.DisableClientState( ArrayCap.TextureCoordArray );
|
||||||
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
|
||||||
GL.Arb.BindBuffer( BufferTargetArb.ElementArrayBuffer, 0 );
|
GL.Arb.BindBuffer( BufferTargetArb.ElementArrayBuffer, 0 );
|
||||||
}
|
}
|
||||||
@ -328,30 +344,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
GL.TexCoordPointer( 2, TexCoordPointerType.Float, 24, new IntPtr( 16 ) );
|
GL.TexCoordPointer( 2, TexCoordPointerType.Float, 24, new IntPtr( 16 ) );
|
||||||
GL.DrawArrays( modeMappings[(int)mode], offset, verticesCount );
|
GL.DrawArrays( modeMappings[(int)mode], offset, verticesCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnableClientState( VertexFormat format ) {
|
|
||||||
GL.EnableClientState( ArrayCap.VertexArray );
|
|
||||||
if( format == VertexFormat.Pos3fCol4b ) {
|
|
||||||
GL.EnableClientState( ArrayCap.ColorArray );
|
|
||||||
} else if( format == VertexFormat.Pos3fTex2f ) {
|
|
||||||
GL.EnableClientState( ArrayCap.TextureCoordArray );
|
|
||||||
} else if( format == VertexFormat.Pos3fTex2fCol4b ) {
|
|
||||||
GL.EnableClientState( ArrayCap.ColorArray );
|
|
||||||
GL.EnableClientState( ArrayCap.TextureCoordArray );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void DisableClientState( VertexFormat format ) {
|
|
||||||
GL.DisableClientState( ArrayCap.VertexArray );
|
|
||||||
if( format == VertexFormat.Pos3fCol4b ) {
|
|
||||||
GL.DisableClientState( ArrayCap.ColorArray );
|
|
||||||
} else if( format == VertexFormat.Pos3fTex2f ) {
|
|
||||||
GL.DisableClientState( ArrayCap.TextureCoordArray );
|
|
||||||
} else if( format == VertexFormat.Pos3fTex2fCol4b ) {
|
|
||||||
GL.DisableClientState( ArrayCap.ColorArray );
|
|
||||||
GL.DisableClientState( ArrayCap.TextureCoordArray );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
@ -432,11 +424,11 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public override void BeginFrame( Game game ) {
|
public override void BeginFrame( Game game ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void EndFrame( Game game ) {
|
public override void EndFrame( Game game ) {
|
||||||
game.SwapBuffers();
|
game.SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void PrintApiSpecificInfo() {
|
public override void PrintApiSpecificInfo() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user