Make OpenGL VBO drawing simpler.

This commit is contained in:
UnknownShadow200 2015-04-23 06:56:50 +10:00
parent 1eaab6fcdd
commit 138420c538
2 changed files with 17 additions and 71 deletions

View File

@ -126,13 +126,6 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract void DeleteVb( int id );
public virtual void DrawVb( DrawMode mode, int id, int verticesCount, VertexFormat format ) {
if( format == VertexFormat.VertexPos3f ) DrawVbPos3f( mode, id, verticesCount );
else if( format == VertexFormat.VertexPos3fTex2f ) DrawVbPos3fTex2f( mode, id, verticesCount );
else if( format == VertexFormat.VertexPos3fCol4b ) DrawVbPos3fCol4b( mode, id, verticesCount );
else if( format == VertexFormat.VertexPos3fTex2fCol4b ) DrawVbPos3fTex2fCol4b( mode, id, verticesCount );
}
public abstract void DrawVbPos3f( DrawMode mode, int id, int verticesCount );
public abstract void DrawVbPos3fTex2f( DrawMode mode, int id, int verticesCount );

View File

@ -111,8 +111,8 @@ namespace ClassicalSharp.GraphicsAPI {
GL.Fog( FogParameter.FogStart, value );
}
public override bool FaceCulling {
set { ToggleCap( EnableCap.CullFace, value ); }
public override bool FaceCulling {
set { ToggleCap( EnableCap.CullFace, value ); }
}
@ -352,75 +352,27 @@ namespace ClassicalSharp.GraphicsAPI {
}
public override void DrawVbPos3f( DrawMode mode, int id, int verticesCount ) {
if( !useVbos ) {
GL.CallList( id );
return;
}
GL.EnableClientState( ArrayCap.VertexArray );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, id );
GL.VertexPointer( 3, VertexPointerType.Float, 12, new IntPtr( 0 ) );
GL.DrawArrays( modeMappings[(int)mode], 0, verticesCount );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
GL.DisableClientState( ArrayCap.VertexArray );
BeginVbBatch( VertexFormat.VertexPos3f );
DrawVbBatch( mode, id, verticesCount );
EndVbBatch();
}
public override void DrawVbPos3fTex2f( DrawMode mode, int id, int verticesCount ) {
if( !useVbos ) {
GL.CallList( id );
return;
}
GL.EnableClientState( ArrayCap.VertexArray );
GL.EnableClientState( ArrayCap.TextureCoordArray );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, id );
GL.VertexPointer( 3, VertexPointerType.Float, 20, new IntPtr( 0 ) );
GL.TexCoordPointer( 2, TexCoordPointerType.Float, 20, new IntPtr( 12 ) );
GL.DrawArrays( modeMappings[(int)mode], 0, verticesCount );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
GL.DisableClientState( ArrayCap.VertexArray );
GL.DisableClientState( ArrayCap.TextureCoordArray );
BeginVbBatch( VertexFormat.VertexPos3fTex2f );
DrawVbBatch( mode, id, verticesCount );
EndVbBatch();
}
public override void DrawVbPos3fCol4b( DrawMode mode, int id, int verticesCount ) {
if( !useVbos ) {
GL.CallList( id );
return;
}
GL.EnableClientState( ArrayCap.VertexArray );
GL.EnableClientState( ArrayCap.ColorArray );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, id );
GL.VertexPointer( 3, VertexPointerType.Float, 16, new IntPtr( 0 ) );
GL.ColorPointer( 4, ColorPointerType.UnsignedByte, 16, new IntPtr( 12 ) );
GL.DrawArrays( modeMappings[(int)mode], 0, verticesCount );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
GL.DisableClientState( ArrayCap.VertexArray );
GL.DisableClientState( ArrayCap.ColorArray );
BeginVbBatch( VertexFormat.VertexPos3fCol4b );
DrawVbBatch( mode, id, verticesCount );
EndVbBatch();
}
public override void DrawVbPos3fTex2fCol4b( DrawMode mode, int id, int verticesCount ) {
if( !useVbos ) {
GL.CallList( id );
return;
}
GL.EnableClientState( ArrayCap.VertexArray );
GL.EnableClientState( ArrayCap.TextureCoordArray );
GL.EnableClientState( ArrayCap.ColorArray );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, id );
GL.VertexPointer( 3, VertexPointerType.Float, 24, new IntPtr( 0 ) );
GL.TexCoordPointer( 2, TexCoordPointerType.Float, 24, new IntPtr( 12 ) );
GL.ColorPointer( 4, ColorPointerType.UnsignedByte, 24, new IntPtr( 20 ) );
GL.DrawArrays( modeMappings[(int)mode], 0, verticesCount );
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
GL.DisableClientState( ArrayCap.VertexArray );
GL.DisableClientState( ArrayCap.TextureCoordArray );
GL.DisableClientState( ArrayCap.ColorArray );
BeginVbBatch( VertexFormat.VertexPos3fTex2fCol4b );
DrawVbBatch( mode, id, verticesCount );
EndVbBatch();
}
VertexFormat batchFormat;
@ -462,6 +414,7 @@ namespace ClassicalSharp.GraphicsAPI {
GL.DisableClientState( ArrayCap.ColorArray );
GL.DisableClientState( ArrayCap.TextureCoordArray );
}
GL.Arb.BindBuffer( BufferTargetArb.ArrayBuffer, 0 );
}
void DrawVbPos3fFast( DrawMode mode, int id, int verticesCount ) {
@ -599,8 +552,8 @@ namespace ClassicalSharp.GraphicsAPI {
}
}
public override void OnWindowResize( int newWidth, int newHeight ) {
GL.Viewport( 0, 0, newWidth, newHeight );
public override void OnWindowResize( int newWidth, int newHeight ) {
GL.Viewport( 0, 0, newWidth, newHeight );
}
public Color4 GetCol() {