From 138420c538c1e15ad381854c58d4869391df2a8e Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 23 Apr 2015 06:56:50 +1000 Subject: [PATCH] Make OpenGL VBO drawing simpler. --- GraphicsAPI/IGraphicsApi.cs | 7 ---- GraphicsAPI/OpenGLApi.cs | 81 ++++++++----------------------------- 2 files changed, 17 insertions(+), 71 deletions(-) diff --git a/GraphicsAPI/IGraphicsApi.cs b/GraphicsAPI/IGraphicsApi.cs index ca1f85632..9a36fb274 100644 --- a/GraphicsAPI/IGraphicsApi.cs +++ b/GraphicsAPI/IGraphicsApi.cs @@ -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 ); diff --git a/GraphicsAPI/OpenGLApi.cs b/GraphicsAPI/OpenGLApi.cs index 72e124494..d7194b30e 100644 --- a/GraphicsAPI/OpenGLApi.cs +++ b/GraphicsAPI/OpenGLApi.cs @@ -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() {