From 345df89a45ea5b0eb6d34a59dcd54669cec0b14f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 16 May 2015 07:36:55 +1000 Subject: [PATCH] Add method to check if texture IDs and vertex buffer IDs are valid. --- GraphicsAPI/IGraphicsApi.cs | 4 ++++ GraphicsAPI/OpenGLApi.cs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/GraphicsAPI/IGraphicsApi.cs b/GraphicsAPI/IGraphicsApi.cs index 42866445e..5c16567cb 100644 --- a/GraphicsAPI/IGraphicsApi.cs +++ b/GraphicsAPI/IGraphicsApi.cs @@ -40,6 +40,8 @@ namespace ClassicalSharp.GraphicsAPI { DeleteTexture( ref texture.ID ); } + public abstract bool IsValidTexture( int texId ); + /// Whether fog is currently enabled. public abstract bool Fog { set; } @@ -123,6 +125,8 @@ namespace ClassicalSharp.GraphicsAPI { public abstract IndexedVbInfo InitIndexedVb( T[] vertices, ushort[] indices, DrawMode mode, int verticesCount, int indicesCount ) where T : struct; + public abstract bool IsValidVb( int vb ); + public abstract void DeleteVb( int id ); public abstract void DeleteIndexedVb( IndexedVbInfo id ); diff --git a/GraphicsAPI/OpenGLApi.cs b/GraphicsAPI/OpenGLApi.cs index f694f394e..c75334573 100644 --- a/GraphicsAPI/OpenGLApi.cs +++ b/GraphicsAPI/OpenGLApi.cs @@ -165,6 +165,10 @@ namespace ClassicalSharp.GraphicsAPI { texId = -1; } + public override bool IsValidTexture( int texId ) { + return GL.IsTexture( texId ); + } + public override bool Texturing { set { ToggleCap( EnableCap.Texture2D, value ); } } @@ -371,6 +375,10 @@ namespace ClassicalSharp.GraphicsAPI { GL.Arb.DeleteBuffers( 2, ref id.Vb ); } + public override bool IsValidVb( int vb ) { + return useVbos ? GL.Arb.IsBuffer( vb ) : GL.IsList( vb ); + } + public override void DrawVbPos3fTex2f( DrawMode mode, int id, int verticesCount ) { BeginVbBatch( VertexFormat.VertexPos3fTex2f ); DrawVbBatch( mode, id, verticesCount );