WINED3D: Disable vertex arrays after we're done drawing from them

H. Verbeet hverbeet at gmail.com
Thu Aug 3 14:53:16 CDT 2006


After drawing from a vertex array we should disable them, to prevent
the next draw calls from potentially reading past their ends. This
also moves the disabling of vertex attrib arrays (for shaders) into
its own function.
-------------- next part --------------
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index ab6162c..e337789 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -794,6 +794,27 @@ static void draw_vertex(IWineD3DDevice *
 }
 #endif /* TODO: Software shaders */
 
+/* This should match any arrays loaded in loadNumberedArrays. */
+/* TODO: Only load / unload arrays if we have to. */
+static void unloadNumberedArrays(IWineD3DDevice *iface) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+
+    /* disable any attribs (this is the same for both GLSL and ARB modes) */
+    GLint maxAttribs;
+    int i;
+
+    /* Leave all the attribs disabled */
+    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &maxAttribs);
+    /* MESA does not support it right not */
+    if (glGetError() != GL_NO_ERROR)
+        maxAttribs = 16;
+    for (i = 0; i < maxAttribs; ++i) {
+        GL_EXTCALL(glDisableVertexAttribArrayARB(i));
+        checkGLcall("glDisableVertexAttribArrayARB(reg);");
+    }
+}
+
+/* TODO: Only load / unload arrays if we have to. */
 static void loadNumberedArrays(
     IWineD3DDevice *iface,
     IWineD3DVertexShader *shader,
@@ -825,6 +846,25 @@ static void loadNumberedArrays(
    }
 }
 
+/* This should match any arrays loaded in loadVertexData. */
+/* TODO: Only load / unload arrays if we have to. */
+static void unloadVertexData(IWineD3DDevice *iface) {
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    int texture_idx;
+
+    glDisableClientState(GL_VERTEX_ARRAY);
+    glDisableClientState(GL_NORMAL_ARRAY);
+    glDisableClientState(GL_COLOR_ARRAY);
+    if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+        glDisableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
+    }
+    for (texture_idx = 0; texture_idx < GL_LIMITS(textures); ++texture_idx) {
+        glClientActiveTextureARB(GL_TEXTURE0_ARB + texture_idx);
+        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+    }
+}
+
+/* TODO: Only load / unload arrays if we have to. */
 static void loadVertexData(IWineD3DDevice *iface, WineDirect3DVertexStridedData *sd) {
     unsigned int textureNo   = 0;
     unsigned int texture_idx = 0;
@@ -1814,21 +1854,12 @@ #undef BUFFER_OR_DATA
 
     /* Cleanup vertex program */
     if (useVertexShaderFunction) {
-        /* disable any attribs (this is the same for both GLSL and ARB modes) */
-        GLint maxAttribs;
-        int i;
-        /* Leave all the attribs disabled */
-        glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &maxAttribs);
-        /* MESA does not support it right not */
-        if (glGetError() != GL_NO_ERROR)
-            maxAttribs = 16;
-        for (i = 0; i < maxAttribs; ++i) {
-            GL_EXTCALL(glDisableVertexAttribArrayARB(i));
-            checkGLcall("glDisableVertexAttribArrayARB(reg);");
-        }
+        unloadNumberedArrays(iface);
 
         if (wined3d_settings.vs_selected_mode == SHADER_ARB)
             glDisable(GL_VERTEX_PROGRAM_ARB);
+    } else {
+        unloadVertexData(iface);
     }
 
     /* Cleanup fragment program */


More information about the wine-patches mailing list