From 7363211f3921b92ba12b91d40cab33f1ebc5ec56 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 25 Apr 2015 08:23:20 +1000 Subject: [PATCH] reduce VBO drawing overhead. --- GraphicsAPI/OpenGLApi.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/GraphicsAPI/OpenGLApi.cs b/GraphicsAPI/OpenGLApi.cs index 979ec339c..b8aaa78ff 100644 --- a/GraphicsAPI/OpenGLApi.cs +++ b/GraphicsAPI/OpenGLApi.cs @@ -29,9 +29,7 @@ namespace ClassicalSharp.GraphicsAPI { string extensions = GL.GetString( StringName.Extensions ); nonPow2 = extensions.Contains( nonPow2Ext ); useVbos = extensions.Contains( vboExt ); - if( useVbos ) { - SetupVb(); - } else { + if( !useVbos ) { Utils.LogWarning( "Unable to use OpenGL VBOs, you may experience reduced performance." ); } } @@ -271,14 +269,7 @@ namespace ClassicalSharp.GraphicsAPI { #if TRACK_RESOURCES Dictionary vbs = new Dictionary(); #endif - Action[] drawBatchFuncs; Action drawBatchFunc; - void SetupVb() { - drawBatchFuncs = new Action[3]; - drawBatchFuncs[0] = (mode, id, count) => DrawVbPos3fTex2fFast( mode, id, count ); - drawBatchFuncs[1] = (mode, id, count) => DrawVbPos3fCol4bFast( mode, id, count ); - drawBatchFuncs[2] = (mode, id, count) => DrawVbPos3fTex2fCol4bFast( mode, id, count ); - } public override int InitVb( T[] vertices, DrawMode mode, VertexFormat format, int count ) { if( !useVbos ) { @@ -399,7 +390,13 @@ namespace ClassicalSharp.GraphicsAPI { if( !useVbos ) return; batchFormat = format; EnableClientState( format ); - drawBatchFunc = drawBatchFuncs[(int)batchFormat]; + if( format == VertexFormat.VertexPos3fTex2fCol4b ) { + drawBatchFunc = DrawVbPos3fTex2fCol4bFast; + } else if( format == VertexFormat.VertexPos3fCol4b ) { + drawBatchFunc = DrawVbPos3fCol4bFast; + } else if( format == VertexFormat.VertexPos3fTex2f ) { + drawBatchFunc = DrawVbPos3fTex2fFast; + } } public override void BeginIndexedVbBatch() {