From 69610ef8dd65ce54cfa27e06e783cf3419dbaf13 Mon Sep 17 00:00:00 2001 From: Bart Trzynadlowski Date: Sat, 25 Feb 2012 06:36:04 +0000 Subject: [PATCH] Added a clear() method to VBORef and removed unsafe memset() clear. --- Src/Graphics/Models.cpp | 3 +-- Src/Graphics/Render3D.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Src/Graphics/Models.cpp b/Src/Graphics/Models.cpp index e490710..8c3e9ec 100644 --- a/Src/Graphics/Models.cpp +++ b/Src/Graphics/Models.cpp @@ -631,8 +631,7 @@ struct VBORef *CRender3D::BeginModel(ModelCache *Cache) Cache->curVertIdx[i] = 0; // Clear the VBO reference to 0 and clear texture references - memset(Model, 0, sizeof(VBORef) - sizeof(CTextureRefs)); - Model->texRefs.Clear(); + Model->Clear(); // Record starting index of first opaque polygon in VBO (alpha poly index will be re-set in EndModel()) Model->index[POLY_STATE_NORMAL] = Cache->vboCurOffset/(VBO_VERTEX_SIZE*sizeof(GLfloat)); diff --git a/Src/Graphics/Render3D.h b/Src/Graphics/Render3D.h index 3ce82e5..293f90e 100644 --- a/Src/Graphics/Render3D.h +++ b/Src/Graphics/Render3D.h @@ -78,6 +78,25 @@ struct VBORef UINT16 texOffset; // texture offset data for this model CTextureRefs texRefs; // unique texture references contained in this model + + /* + * Clear(): + * + * Clears the VBORef by setting all fields to 0 and clearing the texture + * references. + */ + inline void Clear(void) + { + texRefs.Clear(); + lutIdx = 0; + texOffset = 0; + nextTexOffset = NULL; + for (int i = 0; i < 2; i++) + { + index[i] = 0; + numVerts[i] = 0; + } + } }; // Display list items: model instances and viewport settings