[dx71] d3d8 Fast mode fixes

Ann and Jason Edmeades us at the-edmeades.demon.co.uk
Sun Jul 20 10:11:45 CDT 2003


Thanks to Lucho again for pointing out problems with the fast mode case
which caused traps,  and in my misinterpretation of some of the
transform flags. This fix also resolves the problem with the white ship
in the UT2 demo, so I have put back support for fast mode - Raphael, if
you have any problems, let me know.

Changelog
Disable client texture states when not in use (fast mode) otherwise
traps occur!
Correct number of texture coords supplied in both fast and slow mode
Dont supply a default colour of white when diffuse mode is disabled
Reenable fast mode

Jason

[Note: The removing of the default diffuse to be white may be a
temporary fix]
-------------- next part --------------
Index: dlls/d3d8/drawprim.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/drawprim.c,v
retrieving revision 1.6
diff -u -r1.6 drawprim.c
--- dlls/d3d8/drawprim.c	19 Jul 2003 03:02:42 -0000	1.6
+++ dlls/d3d8/drawprim.c	20 Jul 2003 14:53:01 -0000
@@ -679,8 +679,6 @@
 
         glDisableClientState(GL_COLOR_ARRAY);
         checkGLcall("glDisableClientState(GL_COLOR_ARRAY)");
-        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-        checkGLcall("glColor4f(1, 1, 1, 1)");
     }
 
     /* Specular Colour ------------------------------------------*/
@@ -734,58 +732,58 @@
     /* Texture coords -------------------------------------------*/
     for (textureNo = 0; textureNo < GL_LIMITS(textures); ++textureNo) {
 
-        if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0) {
-            FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
-            continue ;
-        }
+        /* Select the correct texture stage */
+#if defined(GL_VERSION_1_3)
+        glClientActiveTexture(GL_TEXTURE0 + textureNo);
+#else
+        glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
+#endif
 
         /* Query tex coords */
         if (This->StateBlock->textures[textureNo] != NULL) {
             int coordIdx = This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXCOORDINDEX];
 
+            if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0) {
+                FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
+                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+                glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1);
+                continue;
+            }
+
             if (coordIdx > 7) {
                 VTRACE(("tex: %d - Skip tex coords, as being system generated\n", textureNo));
+                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+                glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1);
             } else if (sd->u.s.texCoords[coordIdx].lpData == NULL) {
                 VTRACE(("Bound texture but no texture coordinates supplied, so skipping\n"));
+                glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+                glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1);
             } else {
-                int coordsToUse = sd->u.s.texCoords[coordIdx].dwType + 1; /* 0 == D3DVSDT_FLOAT1 etc */
-                int numFloats = coordsToUse;
-#if defined(GL_VERSION_1_3)
-                glClientActiveTexture(GL_TEXTURE0 + textureNo);
-#else
-                glClientActiveTextureARB(GL_TEXTURE0_ARB + textureNo);
-#endif
-                /* If texture transform flags in effect, values passed through to vertex
-                   depend on the D3DTSS_TEXTURETRANSFORMFLAGS */
-                if (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] != D3DTTFF_DISABLE) {
-
-                    /* This indicates how many coords to use regardless of the
-                       texture type. However, d3d/opengl fill in the rest appropriately */
-                    coordsToUse = This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] & ~D3DTTFF_PROJECTED;
-
-                    /* BUT - Projected is more 'fun' - Cant be done for ptr mode.
-                       Probably should scan enabled texture units and drop back to
-                       slow mode if found? */
-                    if (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED) {
-                        FIXME("Cannot handle projected transform state in fast mode\n");
-                    }
 
-                    /* coordsToUse maps to D3DTTFF_COUNT1,2,3,4 == 1,2,3,4 which is correct */
-                }
-                if (numFloats == 0) {
-                    FIXME("Skipping as invalid request - numfloats=%d, coordIdx=%d\n", numFloats, coordIdx);
-                    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-                    checkGLcall("glDisableClientState(GL_TEXTURE_COORD_ARRAY);");
-                } else {
-                    VTRACE(("tex: %d, ptr=%p, numcoords=%d\n", textureNo, sd->u.s.texCoords[coordIdx].lpData, numFloats));
-                    glTexCoordPointer(numFloats, GL_FLOAT, sd->u.s.texCoords[coordIdx].dwStride, sd->u.s.texCoords[coordIdx].lpData);
-                    checkGLcall("glTexCoordPointer(x, ...)");
-                    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-                    checkGLcall("glEnableClientState(GL_TEXTURE_COORD_ARRAY);");
-                }
-            }
-        }
-    }
+                /* The coords to supply depend completely on the fvf / vertex shader */
+                GLint size;
+                GLenum type;
+
+                switch (sd->u.s.texCoords[coordIdx].dwType) {
+    		case D3DVSDT_FLOAT1: size = 1, type = GL_FLOAT; break;
+    		case D3DVSDT_FLOAT2: size = 2, type = GL_FLOAT; break;
+    		case D3DVSDT_FLOAT3: size = 3, type = GL_FLOAT; break;
+    		case D3DVSDT_FLOAT4: size = 4, type = GL_FLOAT; break;
+    		case D3DVSDT_SHORT2: size = 2, type = GL_SHORT; break;
+    		case D3DVSDT_SHORT4: size = 4, type = GL_SHORT; break;
+    		case D3DVSDT_UBYTE4: size = 4, type = GL_UNSIGNED_BYTE; break;
+    		default: FIXME("Unrecognized data type %ld\n", sd->u.s.texCoords[coordIdx].dwType);
+                      size = 4; type = GL_UNSIGNED_BYTE;
+    		}
+
+    		glTexCoordPointer(size, type, sd->u.s.texCoords[coordIdx].dwStride, sd->u.s.texCoords[coordIdx].lpData);
+    		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+    	    }
+    	} else {
+    	    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+    	    glMultiTexCoord4fARB(GL_TEXTURE0_ARB + textureNo, 0, 0, 0, 1);
+    	}
+    } 
 
     /* Ok, Work out which primitive is requested and how many vertexes that 
        will be                                                              */
@@ -795,23 +793,14 @@
     if (idxData != NULL) {
 
         TRACE("glElements(%x, %d, %ld, ...)\n", glPrimType, NumVertexes, minIndex);
-        if (idxSize==2) {
 #if 1  /* FIXME: Want to use DrawRangeElements, but wrong calculation! */
-            glDrawElements(glPrimType, NumVertexes, GL_UNSIGNED_SHORT,
-                           (char *)idxData+(2 * startIdx));
+        glDrawElements(glPrimType, NumVertexes, idxSize==2?GL_UNSIGNED_SHORT:GL_UNSIGNED_INT,
+                      (char *)idxData+(idxSize * startIdx));
 #else
-            glDrawRangeElements(glPrimType, minIndex, minIndex+NumVertexes-1, NumVertexes, 
-                                GL_UNSIGNED_SHORT, (char *)idxData+(2 * startIdx));
+        glDrawRangeElements(glPrimType, minIndex, minIndex+NumVertexes-1, NumVertexes, 
+                      idxSize==2?GL_UNSIGNED_SHORT:GL_UNSIGNED_INT, 
+                      (char *)idxData+(idxSize * startIdx));
 #endif
-        } else {
-#if 1  /* FIXME: Want to use DrawRangeElements, but wrong calculation! */
-            glDrawElements(glPrimType, NumVertexes, GL_UNSIGNED_INT,
-                           (char *)idxData+(4 * startIdx));
-#else
-            glDrawRangeElements(glPrimType, minIndex, minIndex+NumVertexes-1, NumVertexes, 
-                                GL_UNSIGNED_INT, (char *)idxData+(2 * startIdx));
-#endif
-        }
         checkGLcall("glDrawRangeElements");
 
     } else {
@@ -968,23 +957,19 @@
 
                     int coordsToUse = sd->u.s.texCoords[coordIdx].dwType + 1; /* 0 == D3DVSDT_FLOAT1 etc */
 
-                    /* If texture transform flags in effect, values passed through to vertex
-                       depend on the D3DTSS_TEXTURETRANSFORMFLAGS */
-                    if (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] != D3DTTFF_DISABLE) {
-
-                        /* This indicates how many coords to use regardless of the
-                           texture type. However, d3d/opengl fill in the rest appropriately */
-                        coordsToUse = This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] & ~D3DTTFF_PROJECTED;
-
-                        switch (coordsToUse) {
-                        case 4: q = ptrToCoords[3]; /* drop through */
-                        case 3: r = ptrToCoords[2]; /* drop through */
-                        case 2: t = ptrToCoords[1]; /* drop through */
-                        case 1: s = ptrToCoords[0]; 
-                        }
+                    /* The coords to supply depend completely on the fvf / vertex shader */
+                    switch (coordsToUse) {
+                    case 4: q = ptrToCoords[3]; /* drop through */
+                    case 3: r = ptrToCoords[2]; /* drop through */
+                    case 2: t = ptrToCoords[1]; /* drop through */
+                    case 1: s = ptrToCoords[0]; 
+                    }
+
+                    /* Projected is more 'fun' - Move the last coord to the 'q'
+                          parameter (see comments under D3DTSS_TEXTURETRANSFORMFLAGS */
+                    if ((This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] != D3DTTFF_DISABLE) &&
+                        (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED)) {
 
-                        /* BUT - Projected is more 'fun' - Move the last coord to the 'q'
-                           parameter (see comments under D3DTSS_TEXTURETRANSFORMFLAGS */
                         if (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED) {
                             switch (coordsToUse) {
                             case 0:  /* Drop Through */
@@ -1008,13 +993,6 @@
                                       This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] & D3DTTFF_PROJECTED);
                             }
                         }
-                    } else {
-                        switch (coordsToUse) {
-                        case 4: q = ptrToCoords[3]; /* drop through */
-                        case 3: r = ptrToCoords[2]; /* drop through */
-                        case 2: t = ptrToCoords[1]; /* drop through */
-                        case 1: s = ptrToCoords[0]; 
-                        }
                     }
 
                     switch (coordsToUse) {   /* Supply the provided texture coords */
@@ -1327,8 +1305,7 @@
         drawStridedSoftwareVS(iface, &dataLocations, PrimitiveType, NumPrimitives, 
                         idxData, idxSize, minIndex, StartIdx);            
 
-    } else if (TRUE ||
-	       (dataLocations.u.s.pSize.lpData        != NULL) || 
+    } else if ((dataLocations.u.s.pSize.lpData        != NULL) || 
                (dataLocations.u.s.diffuse.lpData      != NULL) || 
                (dataLocations.u.s.blendWeights.lpData != NULL)) {
 


More information about the wine-patches mailing list