[D3D8 Patch] vertex shader integration + fixes - VS3 - Bis

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
 I send you a new version of my VS3 Patch. 
  Please Alexandre use this version and forget the first VS3, you will have a conflict with jason patch, thx

 this patch enable vertex shader (and not pixel as sid in my old mail) rendering into D3D8 (and correct some stupid bugs i have)

Changelog:
 - intergration with DrawPrimitive
 - remove non-esthetic c++ comments into c comments block ;)
 - more more debug
 - indent, cleanups
 - trying to use DIFFUSE and SPECULAR for vertex shader
 - many fixes
 - integration with jason texture patch

Problems:
 - very slow
 - i have problem with textures, if people can look at code ...

TODO:
 - better integrate vertex shader with draw primitive (maybe we have to splt DrawPrimitive)
 - optimize software emulation
 - hardware vertex shader program support (using auto-detect caps)
 - syntax validity of vertex shader declaration and vexter shader function code (Validate*Shader functions)
 - vertex shader compilator (in D3DX8)
 - pixel shaders

Happy Christmas
  Raphael
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+B6/Op7NA3AmQTU4RAmEEAJ9V3xxnXRJYZolvMA29PajArxQAewCdGhmA
E7jpcgrGMEm8qBqiRpio1ek=
=gBdi
-----END PGP SIGNATURE-----
Index: dlls/d3d8/d3d8_private.h
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/d3d8_private.h,v
retrieving revision 1.9
diff -u -r1.9 d3d8_private.h
--- dlls/d3d8/d3d8_private.h	23 Dec 2002 01:34:59 -0000	1.9
+++ dlls/d3d8/d3d8_private.h	24 Dec 2002 00:46:13 -0000
@@ -63,7 +63,7 @@
 #define HIGHEST_TRANSFORMSTATE 512
 #define D3DSBT_RECORDED 0xfffffffe
 
-/* Direct38 Interfaces: */
+/* Direct3D8 Interfaces: */
 typedef struct IDirect3DBaseTexture8Impl IDirect3DBaseTexture8Impl;
 typedef struct IDirect3DVolumeTexture8Impl IDirect3DVolumeTexture8Impl;
 typedef struct IDirect3D8Impl IDirect3D8Impl;
@@ -152,52 +152,64 @@
 
 } STATEBLOCK;
 
-typedef struct SHADER8Vector {
+typedef struct D3DSHADERVECTOR {
   float x;
   float y;
   float z;
   float w;
-} SHADER8Vector;
+} D3DSHADERVECTOR;
 
-typedef struct SHADER8Scalar {
+typedef struct D3DSHADERSCALAR {
   float x;
-} SHADER8Scalar;
+} D3DSHADERSCALAR;
 
-#define SHADER_MAX_CONSTANTS 96
-#define VSHADER_MAX_CONSTANTS 96
-#define PSHADER_MAX_CONSTANTS 96
-typedef SHADER8Vector SHADER8Constants[SHADER_MAX_CONSTANTS];
+#define D3D8_VSHADER_MAX_CONSTANTS 96
+#define D3D8_PSHADER_MAX_CONSTANTS 96
+typedef D3DSHADERVECTOR VSHADERCONSTANTS8[D3D8_VSHADER_MAX_CONSTANTS];
 
-typedef struct SHADER8Data {
+typedef struct SHADERDATA8 {
   /** Run Time Shader Function Constants */
   /*D3DXBUFFER* constants;*/
-  SHADER8Constants C;
+  VSHADERCONSTANTS8 C;
   /** Shader Code as char ... */
   CONST DWORD* code;
   UINT codeLength;
-} SHADER8Data;
+} SHADERDATA8;
 
 typedef struct VERTEXSHADER8 { /* TODO: Vertex Shader */
-  CONST DWORD* decl;
-  CONST DWORD* function;
+  DWORD* decl;
+  DWORD* function;
   DWORD usage; /* 0 || D3DUSAGE_SOFTWAREPROCESSING */
   UINT declLength;
   UINT functionLength;
- 
   DWORD fvf;
-
+  DWORD version;
   /* run time datas */
-  SHADER8Data* data;
+  SHADERDATA8* data;
 } VERTEXSHADER8;
 
 typedef struct PIXELSHADER8 { /* TODO: Pixel Shader */
   CONST DWORD* function;
   UINT functionLength;
-
+  DWORD version;
   /* run time datas */
-  SHADER8Data* data;
+  SHADERDATA8* data;
 } PIXELSHADER8;
 
+/** temporary here waiting for buffer code */
+typedef struct VSHADERINPUTDATA8 {
+  D3DSHADERVECTOR V[16];
+} VSHADERINPUTDATA8;
+
+/** temporary here waiting for buffer code */
+typedef struct VSHADEROUTPUTDATA8 {
+  D3DSHADERVECTOR oPos;
+  D3DSHADERVECTOR oD[2];
+  D3DSHADERVECTOR oT[4];
+  D3DSHADERVECTOR oFog;
+  D3DSHADERVECTOR oPts;
+} VSHADEROUTPUTDATA8;
+
 /*
  * External prototypes
  */
@@ -916,6 +933,6 @@
  */
 DWORD vshader_decl_parse(VERTEXSHADER8* vshader);
 DWORD vshader_program_parse(VERTEXSHADER8* vshader);
-
+BOOL  vshader_program_execute_SW(VERTEXSHADER8* vshader, VSHADERINPUTDATA8* input, VSHADEROUTPUTDATA8* output);
 
 #endif /* __WINE_D3DX8_PRIVATE_H */
Index: dlls/d3d8/d3d8.spec
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/d3d8.spec,v
retrieving revision 1.3
diff -u -r1.3 d3d8.spec
--- dlls/d3d8/d3d8.spec	4 Nov 2002 23:53:45 -0000	1.3
+++ dlls/d3d8/d3d8.spec	24 Dec 2002 00:46:13 -0000
@@ -1,5 +1,5 @@
 @ stdcall D3D8GetSWInfo() D3D8GetSWInfo
-@ stdcall DebugSetMute() DebugSetMute
+@ stdcall DebugSetMute(long) DebugSetMute
 @ stdcall Direct3DCreate8(long) Direct3DCreate8
-@ stdcall ValidatePixelShader() ValidatePixelShader
-@ stdcall ValidateVertexShader() ValidateVertexShader
+@ stdcall ValidatePixelShader(ptr ptr) ValidatePixelShader
+@ stdcall ValidateVertexShader(ptr ptr) ValidateVertexShader
Index: dlls/d3d8/device.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/device.c,v
retrieving revision 1.17
diff -u -r1.17 device.c
--- dlls/d3d8/device.c	23 Dec 2002 01:34:59 -0000	1.17
+++ dlls/d3d8/device.c	24 Dec 2002 00:46:16 -0000
@@ -53,6 +53,11 @@
     memcpy(gl_mat, (mat), 16 * sizeof(float));      \
 };
 
+#define VERTEX_SHADER(Handle) \
+  ((Handle <= VS_HIGHESTFIXEDFXF) ? ((Handle >= sizeof(VertexShaders) / sizeof(VERTEXSHADER8*)) ? NULL : VertexShaders[Handle]) : VertexShaders[Handle - VS_HIGHESTFIXEDFXF])
+
+#define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
+
 /*
  * Globals
  */
@@ -68,6 +73,7 @@
     0.0, 0.0, 0.0, 1.0
 };
 
+
 /* Routine common to the draw primitive and draw indexed primitive routines
    Doesnt use gl pointer arrays as I dont believe we can support the blending
    coordinates that way.                                                      */
@@ -89,17 +95,32 @@
 
     int vx_index;
     int NumVertexes = NumPrimitives;
+    VERTEXSHADER8* vertex_shader = NULL;
+    VSHADERINPUTDATA8 vertex_shader_input;
+    BOOL useVertexShaderFunction = FALSE;
 
     ICOM_THIS(IDirect3DDevice8Impl,iface);
 
     /* Dont understand how to handle multiple streams, but if a fixed
        FVF is passed in rather than a handle, it must use stream 0 */
-
+    
     if (This->StateBlock.VertexShader > VS_HIGHESTFIXEDFXF) {
-        FIXME("Cant handle created shaders yet\n");
-        return;
-    } else {
+      vertex_shader = VERTEX_SHADER(This->StateBlock.VertexShader);
+      if (NULL == vertex_shader) {
+	ERR("trying to use unitialised vertex shader: %lu\n", This->StateBlock.VertexShader);
+	return ;
+      }
+      if (NULL == vertex_shader->function) {
+	TRACE("vertex shader declared without program, using FVF pure mode\n");
+      } else {
+	useVertexShaderFunction = TRUE;
+      }
+      fvf = (D3DFORMAT) vertex_shader->fvf;
+      TRACE("vertex shader declared FVF: %lx\n", vertex_shader->fvf);
+      memset(&vertex_shader_input, 0, sizeof(VSHADERINPUTDATA8));
+    }
 
+    {
         int                         skip = This->StateBlock.stream_stride[0];
 
         BOOL                        normal;
@@ -107,6 +128,8 @@
         BOOL                        isPtSize;
         BOOL                        isDiffuse;
         BOOL                        isSpecular;
+	int                         numBlends;
+	BOOL                        isLastUByte4;
         int                         numTextures;
         int                         textureNo;
         const void                 *curVtx = NULL;
@@ -133,16 +156,19 @@
         normal        = fvf & D3DFVF_NORMAL;
         isRHW         = fvf & D3DFVF_XYZRHW;
         /*numBlends     = 5 - ((~fvf) & 0xe);*/  /* There must be a simpler way? */
+	numBlends     = ((fvf & D3DFVF_POSITION_MASK) >> 1) - 2; /* WARNING can be < 0 because -2 */
+	isLastUByte4  = fvf & D3DFVF_LASTBETA_UBYTE4;
         isPtSize      = fvf & D3DFVF_PSIZE;
         isDiffuse     = fvf & D3DFVF_DIFFUSE;
         isSpecular    = fvf & D3DFVF_SPECULAR;
-        numTextures =  (fvf & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
+        numTextures   = (fvf & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
 
-        TRACE("Drawing with FVF = %x, (n?%d, rhw?%d, ptSize(%d), diffuse?%d, specular?%d, numTextures=%d)\n",
-              fvf, normal, isRHW, isPtSize, isDiffuse, isSpecular, numTextures);
+
+        TRACE("Drawing with FVF = %x, (n?%d, rhw?%d, ptSize(%d), diffuse?%d, specular?%d, numTextures=%d, numBlends=%d)\n",
+              fvf, normal, isRHW, isPtSize, isDiffuse, isSpecular, numTextures, numBlends);
 
         /* If no normals, DISABLE lighting otherwise, dont touch lighing as it is 
-           set by the appropriate render state                                    */
+           set by the appropriate render state */
         if (!normal) {
             isLightingOn = glIsEnabled(GL_LIGHTING);
             glDisable(GL_LIGHTING);
@@ -151,14 +177,12 @@
 
 
         if (isRHW) {
-
             double height, width, minZ, maxZ;
-
             /*
-	         * Already transformed vertex do not need transform
-	         * matrices. Reset all matrices to identity.
-	         * Leave the default matrix in world mode.
-	        */
+	     * Already transformed vertex do not need transform
+	     * matrices. Reset all matrices to identity.
+	     * Leave the default matrix in world mode.
+	     */
             glMatrixMode(GL_PROJECTION);
             checkGLcall("glMatrixMode");
             glLoadIdentity();
@@ -174,13 +198,11 @@
             TRACE("Calling glOrtho with %f, %f, %f, %f\n", width, height, -minZ, -maxZ);
             glOrtho(0.0, width, height, 0.0, -minZ, -maxZ);
             checkGLcall("glOrtho");
-
         } else {
             glMatrixMode(GL_PROJECTION);
             checkGLcall("glMatrixMode");
             glLoadMatrixf((float *) &This->StateBlock.transforms[D3DTS_PROJECTION].u.m[0][0]);
             checkGLcall("glLoadMatrixf");
-
             glMatrixMode(GL_MODELVIEW);
             checkGLcall("glMatrixMode");
             glLoadMatrixf((float *) &This->StateBlock.transforms[D3DTS_VIEW].u.m[0][0]);
@@ -257,18 +279,51 @@
             curPos = curPos + sizeof(float);
             z = *(float *)curPos;
             curPos = curPos + sizeof(float);
-            TRACE("x,y,z=%f,%f,%f\n", x,y,z);
+            /*TRACE("x,y,z=%f,%f,%f\n", x,y,z);*/
 
+	    if (TRUE == useVertexShaderFunction) {
+	      vertex_shader_input.V[D3DVSDE_POSITION].x = x;
+	      vertex_shader_input.V[D3DVSDE_POSITION].y = y;
+	      vertex_shader_input.V[D3DVSDE_POSITION].z = z;
+	      vertex_shader_input.V[D3DVSDE_POSITION].w = 1.0f;
+	    }
             /* RHW follows, only if transformed */
             if (isRHW) {
-                rhw = *(float *)curPos;
-                curPos = curPos + sizeof(float);
-                TRACE("rhw=%f\n", rhw);
+	      rhw = *(float *)curPos;
+	      curPos = curPos + sizeof(float);
+	      /*TRACE("rhw=%f\n", rhw);*/
+	      
+	      if (TRUE == useVertexShaderFunction) {
+		vertex_shader_input.V[D3DVSDE_POSITION].w = rhw;
+	      }
             }
-
-
             /* FIXME: Skip Blending data */
-
+	    if (numBlends > 0) {
+	      UINT i;
+	      D3DSHADERVECTOR skippedBlend = { 0.0f, 0.0f, 0.0f, 0.0f };
+	      DWORD skippedBlendLastUByte4 = 0;
+	      for (i = 0; i < ((FALSE == isLastUByte4) ? numBlends : numBlends - 1); ++i) {
+		((float*)&skippedBlend)[i] =  *(float *)curPos; 
+		curPos = curPos + sizeof(float);
+	      }
+	      if (isLastUByte4) {
+		skippedBlendLastUByte4 =  *(DWORD*)curPos; 
+		curPos = curPos + sizeof(DWORD);		
+	      }
+	      
+	      if (TRUE == useVertexShaderFunction) {
+		vertex_shader_input.V[D3DVSDE_BLENDWEIGHT].x = skippedBlend.x;
+		vertex_shader_input.V[D3DVSDE_BLENDWEIGHT].y = skippedBlend.y;
+		vertex_shader_input.V[D3DVSDE_BLENDWEIGHT].z = skippedBlend.z;
+		vertex_shader_input.V[D3DVSDE_BLENDWEIGHT].w = skippedBlend.w;
+		if (isLastUByte4) {
+		  vertex_shader_input.V[D3DVSDE_BLENDINDICES].x = (float) skippedBlendLastUByte4;
+		  vertex_shader_input.V[D3DVSDE_BLENDINDICES].y = (float) skippedBlendLastUByte4;
+		  vertex_shader_input.V[D3DVSDE_BLENDINDICES].z = (float) skippedBlendLastUByte4;
+		  vertex_shader_input.V[D3DVSDE_BLENDINDICES].w = (float) skippedBlendLastUByte4;
+		}
+	      }
+	    }
             /* Vertex Normal Data (untransformed only) */
             if (normal) {
                 nx = *(float *)curPos;
@@ -277,101 +332,252 @@
                 curPos = curPos + sizeof(float);
                 nz = *(float *)curPos;
                 curPos = curPos + sizeof(float);
-                TRACE("nx,ny,nz=%f,%f,%f\n", nx,ny,nz);
-            }
-
+                /*TRACE("nx,ny,nz=%f,%f,%f\n", nx,ny,nz);*/
+            
+		if (TRUE == useVertexShaderFunction) {
+		  vertex_shader_input.V[D3DVSDE_NORMAL].x = nx;
+		  vertex_shader_input.V[D3DVSDE_NORMAL].y = ny;
+		  vertex_shader_input.V[D3DVSDE_NORMAL].z = nz;
+		  vertex_shader_input.V[D3DVSDE_NORMAL].w = 1.0f;
+		}		
+	    }
             if (isPtSize) {
                 ptSize = *(float *)curPos;
+                /*TRACE("ptSize=%f\n", ptSize);*/
                 curPos = curPos + sizeof(float);
-                TRACE("ptSize=%f\n", ptSize);
+
+		if (TRUE == useVertexShaderFunction) {
+		  vertex_shader_input.V[D3DVSDE_PSIZE].x = ptSize;
+		  vertex_shader_input.V[D3DVSDE_PSIZE].y = 0.0f;
+		  vertex_shader_input.V[D3DVSDE_PSIZE].z = 0.0f;
+		  vertex_shader_input.V[D3DVSDE_PSIZE].w = 1.0f;
+		}
             }
             if (isDiffuse) {
                 diffuseColor = *(DWORD *)curPos;
-                TRACE("diffuseColor=%lx\n", diffuseColor);
+                /*TRACE("diffuseColor=%lx\n", diffuseColor);*/
                 curPos = curPos + sizeof(DWORD);
+
+		if (TRUE == useVertexShaderFunction) {
+		  vertex_shader_input.V[D3DVSDE_DIFFUSE].x = (float) (((diffuseColor >> 16) & 0xFF) / 255.0f);
+		  vertex_shader_input.V[D3DVSDE_DIFFUSE].y = (float) (((diffuseColor >>  8) & 0xFF) / 255.0f);
+		  vertex_shader_input.V[D3DVSDE_DIFFUSE].z = (float) (((diffuseColor >>  0) & 0xFF) / 255.0f);
+		  vertex_shader_input.V[D3DVSDE_DIFFUSE].w = (float) (((diffuseColor >> 24) & 0xFF) / 255.0f);
+		}
             }
             if (isSpecular) {
                 specularColor = *(DWORD *)curPos;
-                TRACE("specularColor=%lx\n", specularColor);
+                /*TRACE("specularColor=%lx\n", specularColor);*/
                 curPos = curPos + sizeof(DWORD);
+
+		if (TRUE == useVertexShaderFunction) {
+		  vertex_shader_input.V[D3DVSDE_SPECULAR].x = (float) (((specularColor >> 16) & 0xFF) / 255.0f);
+		  vertex_shader_input.V[D3DVSDE_SPECULAR].y = (float) (((specularColor >>  8) & 0xFF) / 255.0f);
+		  vertex_shader_input.V[D3DVSDE_SPECULAR].z = (float) (((specularColor >>  0) & 0xFF) / 255.0f);
+		  vertex_shader_input.V[D3DVSDE_SPECULAR].w = (float) (((specularColor >> 24) & 0xFF) / 255.0f);
+		}
             }
 
             /* ToDo: Texture coords */
-            for (textureNo = 0;textureNo<numTextures; textureNo++) {
-
-                float s,t,r,q;
-
-                if (!(This->isMultiTexture) && textureNo>0) {
-                    FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
-                    continue;
-                }
+            for (textureNo = 0; textureNo < numTextures; ++textureNo) {
+                float s, t, r, q;
 
+                if (!(This->isMultiTexture) && textureNo > 0) {
+		  FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
+		  continue ;
+                } 
+		if (textureNo > This->TextureUnits) {
+		  FIXME("Program using more concurrent textures than this opengl implementation support\n");
+		  break ;
+		}
                 /* Query tex coords */
                 if (This->StateBlock.textures[textureNo] != NULL) {
-                    switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) This->StateBlock.textures[textureNo])) {
-                    case D3DRTYPE_TEXTURE:
-                        s = *(float *)curPos;
-                        curPos = curPos + sizeof(float);
-                        t = *(float *)curPos;
-                        curPos = curPos + sizeof(float);
-                        TRACE("tex:%d, s,t=%f,%f\n", textureNo, s,t);
-                        if (This->isMultiTexture) {
-                            glMultiTexCoord2fARB(GL_TEXTURE0_ARB + textureNo, s, t);
-                        } else {
-                            glTexCoord2f(s, t);
-                        }
-                        break;
-
-                    case D3DRTYPE_VOLUMETEXTURE:
-                        s = *(float *)curPos;
-                        curPos = curPos + sizeof(float);
-                        t = *(float *)curPos;
-                        curPos = curPos + sizeof(float);
-                        r = *(float *)curPos;
-                        curPos = curPos + sizeof(float);
-                        TRACE("tex:%d, s,t,r=%f,%f,%f\n", textureNo, s,t,r);
-                        if (This->isMultiTexture) {
-                            glMultiTexCoord3fARB(GL_TEXTURE0_ARB + textureNo, s, t, r);
-                        } else {
-                            glTexCoord3f(s, t, r);
-                        }
-                        break;
-
-                    default:
-                        r=0;q=0; /* Avoid compiler warnings, need these vars later for other textures */
-                        FIXME("Unhandled texture type\n");
-                    }
+		  switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) This->StateBlock.textures[textureNo])) {
+		  case D3DRTYPE_TEXTURE:
+		    s = *(float *)curPos;
+		    curPos = curPos + sizeof(float);
+		    t = *(float *)curPos;
+		    curPos = curPos + sizeof(float);
+		    TRACE("tex:%d, s,t=%f,%f\n", textureNo, s,t);
+
+		    if (TRUE == useVertexShaderFunction) {
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].x = s;
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].y = t;
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].z = 0.0f;
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].w = 1.0f;
+		    } else { 
+		      if (This->isMultiTexture) {
+			glMultiTexCoord2fARB(GL_TEXTURE0_ARB + textureNo, s, t);
+		      } else {
+			glTexCoord2f(s, t);
+		      }
+		    }
+		    break;
+		    
+		  case D3DRTYPE_VOLUMETEXTURE:
+		    s = *(float *)curPos;
+		    curPos = curPos + sizeof(float);
+		    t = *(float *)curPos;
+		    curPos = curPos + sizeof(float);
+		    r = *(float *)curPos;
+		    curPos = curPos + sizeof(float);
+		    TRACE("tex:%d, s,t,r=%f,%f,%f\n", textureNo, s,t,r);
+		    
+		    if (TRUE == useVertexShaderFunction) {
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].x = s;
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].y = t;
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].z = r;
+		      vertex_shader_input.V[D3DVSDE_TEXCOORD0 + textureNo].w = 1.0f;
+		    } else {
+		       if (This->isMultiTexture) {
+			 glMultiTexCoord3fARB(GL_TEXTURE0_ARB + textureNo, s, t, r);
+		       } else {
+			 glTexCoord3f(s, t, r);
+		       }
+		    }
+		    break;
+		    
+		  default:
+		    r = 0.0f; q = 0.0f; /* Avoid compiler warnings, need these vars later for other textures */
+		    FIXME("Unhandled texture type\n");
+		  }
                 } else {
-                    /* Note I have seen a program actually do this, so just hide it and continue */
-                    TRACE("Very odd - texture requested in FVF but not bound!\n");
+		  /* Note I have seen a program actually do this, so just hide it and continue */
+		  TRACE("Very odd - texture requested in FVF but not bound!\n");
                 }
 
             }
 
-            /* Handle these vertexes */
-            if (isDiffuse) {
-                glColor4f(((diffuseColor >> 16) & 0xFF) / 255.0,
-                          ((diffuseColor >>  8) & 0xFF) / 255.0,
-                          ((diffuseColor >>  0) & 0xFF) / 255.0,
-                          ((diffuseColor >> 24) & 0xFF) / 255.0);
-                TRACE("glColor4f: r,g,b,a=%f,%f,%f,%f\n", ((diffuseColor >> 16) & 0xFF) / 255.0, ((diffuseColor >>  8) & 0xFF) / 255.0,
-                       ((diffuseColor >>  0) & 0xFF) / 255.0, ((diffuseColor >> 24) & 0xFF) / 255.0);
-            }
-
-            if (normal) {
-                TRACE("Vertex: glVertex:x,y,z=%f,%f,%f  /  glNormal:nx,ny,nz=%f,%f,%f\n", x,y,z,nx,ny,nz);
+	    /** if vertex shader program specified ... using it */
+	    if (TRUE == useVertexShaderFunction) {
+	      VSHADEROUTPUTDATA8 vs_o;
+	      memset(&vs_o, 0, sizeof(VSHADEROUTPUTDATA8));
+	      vshader_program_execute_SW(vertex_shader, &vertex_shader_input, &vs_o);
+	      /*
+	      TRACE_VECTOR(vs_o.oPos);
+	      TRACE_VECTOR(vs_o.oD[0]);
+	      TRACE_VECTOR(vs_o.oT[0]);
+	      TRACE_VECTOR(vs_o.oT[1]);
+	      */
+	      x = vs_o.oPos.x;
+	      y = vs_o.oPos.y;
+	      z = vs_o.oPos.z;
+	      
+	      if (1.0f != vs_o.oPos.w || isRHW) {
+		rhw = vs_o.oPos.w;
+	      }
+	      /*TRACE_VECTOR(vs_o.oPos);*/
+	      if (isDiffuse) {
+		/*diffuseColor = D3DCOLOR_COLORVALUE(vs_o.oD[0].x, vs_o.oD[0].y, vs_o.oD[0].z, vs_o.oD[0].w);*/
+		/*TRACE_VECTOR(vs_o.oD[0]);*/
+		/*glColor4f(vs_o.oD[0].x, vs_o.oD[0].y, vs_o.oD[0].z, vs_o.oD[0].w); */
+		glMaterialfv(GL_FRONT, GL_DIFFUSE, (float*) &vs_o.oD[0]);
+		checkGLcall("glMaterialfv");
+	      }
+	      if (isSpecular) {
+		/*specularColor = D3DCOLOR_COLORVALUE(vs_o.oD[1].x, vs_o.oD[1].y, vs_o.oD[1].z, vs_o.oD[1].w);*/
+		/*TRACE_VECTOR(vs_o.oD[1]);*/
+		glMaterialfv(GL_FRONT, GL_SPECULAR, (float*) &vs_o.oD[1]);
+		checkGLcall("glMaterialfv");
+	      }
+	      /** reupdate textures coords binding using vs_o.oT[0->3] */  
+	      for (textureNo = 0; textureNo < 4/*min(numTextures, 4)*/; ++textureNo) {
+		float s, t, r, q;
+
+		if (!(This->isMultiTexture) && textureNo > 0) {
+		  FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
+		  continue ;
+                }
+		/* Query tex coords */
+                if (This->StateBlock.textures[textureNo] != NULL) {
+		  switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) This->StateBlock.textures[textureNo])) {
+		  case D3DRTYPE_TEXTURE:
+		    /*TRACE_VECTOR(vs_o.oT[textureNo]);*/
+		    s = vs_o.oT[textureNo].x;
+		    t = vs_o.oT[textureNo].y;
+		    TRACE("tex:%d, s,t=%f,%f\n", textureNo, s,t);
+		    if (This->isMultiTexture) {
+		      glMultiTexCoord2fARB(GL_TEXTURE0_ARB + textureNo, s, t);
+		      checkGLcall("glMultiTexCoord2fARB");
+		    } else {
+		      glTexCoord2f(s, t);
+		      checkGLcall("gTexCoord2f");
+		    }
+		    break;
+		    
+		  case D3DRTYPE_VOLUMETEXTURE:
+		    /*TRACE_VECTOR(vs_o.oT[textureNo]);*/
+		    s = vs_o.oT[textureNo].x;
+		    t = vs_o.oT[textureNo].y;
+		    r = vs_o.oT[textureNo].z;
+		    TRACE("tex:%d, s,t,r=%f,%f,%f\n", textureNo, s,t,r);
+		    if (This->isMultiTexture) {
+		      glMultiTexCoord3fARB(GL_TEXTURE0_ARB + textureNo, s, t, r); 
+		      checkGLcall("glMultiTexCoord2fARB");
+		    } else {
+		      glTexCoord3f(s, t, r);
+		      checkGLcall("gTexCoord3f");
+		    }
+		    break;
+		    
+		  default:
+		    /* Avoid compiler warnings, need these vars later for other textures */
+		    r = 0.0f; q = 0.0f; 
+		    FIXME("Unhandled texture type\n");
+		  }
+		}
+	      }
+
+	      if (1.0f == rhw || rhw < 0.01f) {
+		/*TRACE("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z);*/
+		glVertex3f(x, y, z);
+		checkGLcall("glVertex3f");
+	      } else {
+		/*TRACE("Vertex: glVertex:x,y,z=%f,%f,%f / rhw=%f\n", x,y,z,rhw);*/
+		glVertex4f(x / rhw, y / rhw, z / rhw, 1.0f / rhw);
+		checkGLcall("glVertex4f");
+	      }
+	    } else { 
+	      /** 
+	       * FALSE == useVertexShaderFunction 
+	       *  using std FVF code
+	       */
+
+	      /* Handle these vertexes */
+	      if (isDiffuse) {
+                /*
+		glColor4f(((diffuseColor >> 16) & 0xFF) / 255.0f,
+                          ((diffuseColor >>  8) & 0xFF) / 255.0f,
+                          ((diffuseColor >>  0) & 0xFF) / 255.0f,
+                          ((diffuseColor >> 24) & 0xFF) / 255.0f);
+		*/
+		glColor4ub((diffuseColor >> 16) & 0xFF,
+			   (diffuseColor >>  8) & 0xFF,
+			   (diffuseColor >>  0) & 0xFF,
+			   (diffuseColor >> 24) & 0xFF);
+		/*
+		TRACE("glColor4f: r,g,b,a=%f,%f,%f,%f\n", 
+		      ((diffuseColor >> 16) & 0xFF) / 255.0f, 
+		      ((diffuseColor >>  8) & 0xFF) / 255.0f,
+		      ((diffuseColor >>  0) & 0xFF) / 255.0f, 
+		      ((diffuseColor >> 24) & 0xFF) / 255.0f);
+		*/
+	      }
+	    
+	      if (normal) {
+                /*TRACE("Vertex: glVertex:x,y,z=%f,%f,%f  /  glNormal:nx,ny,nz=%f,%f,%f\n", x,y,z,nx,ny,nz);*/
                 glNormal3f(nx, ny, nz);
                 glVertex3f(x, y, z);
-
-            } else {
-                if (rhw < 0.01) {
-                    TRACE("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z);
-                    glVertex3f(x, y, z);
+	      } else {
+                if (1.0f == rhw || rhw < 0.01f) {
+		  /*TRACE("Vertex: glVertex:x,y,z=%f,%f,%f\n", x,y,z);*/
+		  glVertex3f(x, y, z);
                 } else {
-                    TRACE("Vertex: glVertex:x,y,z=%f,%f,%f / rhw=%f\n", x,y,z,rhw);
-                    glVertex4f(x / rhw, y / rhw, z / rhw, 1.0 / rhw);
+		  /*TRACE("Vertex: glVertex:x,y,z=%f,%f,%f / rhw=%f\n", x,y,z,rhw);*/
+		  glVertex4f(x / rhw, y / rhw, z / rhw, 1.0f / rhw);
                 }
-            }
+	      }
+	    }
 
             if (!isIndexed) {
                 curVtx = curVtx + skip;
@@ -411,8 +617,6 @@
         FIXME("Unhandled fmt %d\n", fmt);
         retVal = 4;
     }
-
-
     TRACE("bytes/Pxl for fmt %d = %d\n", fmt, retVal);
     return retVal;
 }
@@ -465,8 +669,6 @@
         FIXME("Unhandled fmt %d\n", fmt);
         retVal = 4;
     }
-
-
     TRACE("fmt2glType for fmt %d = %x\n", fmt, retVal);
     return retVal;
 }
@@ -551,7 +753,7 @@
     if (This->isMultiTexture) {
         glActiveTextureARB(GL_TEXTURE0_ARB + Stage);
         checkGLcall("glActiveTextureARB");
-    } else if (Stage>0) {
+    } else if (Stage > 0) {
         FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
     }
 
@@ -611,7 +813,6 @@
     return D3D_OK;
 }
 
-
 UINT     WINAPI  IDirect3DDevice8Impl_GetAvailableTextureMem(LPDIRECT3DDEVICE8 iface) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
     TRACE("(%p) : stub, emulating 32Mb for now\n", This);
@@ -1918,15 +2119,15 @@
             checkGLcall("glBlendColor");
 
             /* And now the default texture color as well */
-            for (i=0; i<This->TextureUnits; i++) {
+            for (i = 0; i < This->TextureUnits; i++) {
 
                 /* Note the D3DRS value applies to all textures, but GL has one
                    per texture, so apply it now ready to be used!               */
                 if (This->isMultiTexture) {
-                    glActiveTextureARB(GL_TEXTURE0_ARB + i);
-                    checkGLcall("Activate texture.. to update const color");
+		  glActiveTextureARB(GL_TEXTURE0_ARB + i);
+		  checkGLcall("Activate texture.. to update const color");
                 } else if (i>0) {
-                    FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
+		  FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
                 }
 
                 glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
@@ -2304,16 +2505,15 @@
         }
 
         /* Texture */
-        for (j=0; j<This->TextureUnits; j++) {
-            for (i=0; i<HIGHEST_TEXTURE_STATE; i++) {
-
-                if (pSB->Set.texture_state[j][i] && pSB->Changed.texture_state[j][i])
-                    IDirect3DDevice8Impl_SetTextureStageState(iface, j, i, pSB->texture_state[j][i]);
-            }
-
-            if (pSB->Set.textures[j] && pSB->Changed.textures[j]) {
-                IDirect3DDevice8Impl_SetTexture(iface, j, pSB->textures[j]);
-            } 
+        for (j = 0; j < This->TextureUnits; j++) {
+	  for (i = 0; i < HIGHEST_TEXTURE_STATE; i++) {
+	    if (pSB->Set.texture_state[j][i] && pSB->Changed.texture_state[j][i]) {
+	      IDirect3DDevice8Impl_SetTextureStageState(iface, j, i, pSB->texture_state[j][i]);
+	    }
+	  } 
+	  if (pSB->Set.textures[j] && pSB->Changed.textures[j]) {
+	    IDirect3DDevice8Impl_SetTexture(iface, j, pSB->textures[j]);
+	  } 
         }
 
 
@@ -2946,7 +3146,7 @@
                         glDisable(GL_TEXTURE_3D);
                         checkGLcall("Disable GL_TEXTURE_3D");
                     }
-                }
+		}
 
                 /* Now set up the operand correctly */
                 switch (Value) {
@@ -3173,27 +3373,25 @@
     }
 
     object->usage = Usage;
-    object->data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHADER8Data));
+    object->data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(SHADERDATA8));
 
     VertexShaders[i] = object;
     *pHandle = VS_HIGHESTFIXEDFXF + i;
 
-    object->decl = pDeclaration;
-    object->function = pFunction;
+    object->decl = (DWORD*) pDeclaration;
+    object->function = (DWORD*) pFunction;
 
-    /*
-    for (i = 0; 0xFFFFFFFF != pDeclaration[i]; ++i) ;
-    object->declLength = i + 1;
-    if (NULL != pFunction) {
-      for (i = 0; 0xFFFFFFFF != pFunction[i]; ++i) ;
-      object->functionLength = i + 1;
-    } else {
-      object->functionLength = 1; // no Function defined use fixed function vertex processing
-    }
-    */
     vshader_decl_parse(object);
     vshader_program_parse(object);
 
+    /* copy the function ... because it will certainly be released by application */
+    if (NULL != pFunction) {
+      object->function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->functionLength);
+      memcpy(object->function, pFunction, object->functionLength);
+    }
+    /* copy the declaration too */
+    object->decl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->declLength);
+    memcpy(object->decl, pDeclaration, object->declLength);
     return D3D_OK;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD Handle) {
@@ -3236,21 +3434,21 @@
     }
     TRACE("(%p) : freing VertexShader %p\n", This, object);
     /* TODO: check validity of object */
-    if (NULL != object->data) HeapFree(GetProcessHeap(), 0, (void *)object->data);
+    if (NULL != object->function) HeapFree(GetProcessHeap(), 0, (void *)object->function);
+    HeapFree(GetProcessHeap(), 0, (void *)object->decl);
+    HeapFree(GetProcessHeap(), 0, (void *)object->data);
     HeapFree(GetProcessHeap(), 0, (void *)object);
     VertexShaders[Handle - VS_HIGHESTFIXEDFXF] = NULL;
     return D3D_OK;
 }
 
-#define VERTEX_SHADER(Handle) ((Handle <= VS_HIGHESTFIXEDFXF) ? ((Handle >= sizeof(VertexShaders) / sizeof(VERTEXSHADER8*)) ? NULL : VertexShaders[Handle]) : VertexShaders[Handle - VS_HIGHESTFIXEDFXF])
-
 HRESULT  WINAPI  IDirect3DDevice8Impl_SetVertexShaderConstant(LPDIRECT3DDEVICE8 iface, DWORD Register, CONST void* pConstantData, DWORD ConstantCount) {
   ICOM_THIS(IDirect3DDevice8Impl,iface);
   VERTEXSHADER8* object;
   DWORD Handle = This->UpdateStateBlock->VertexShader;
 
   /* FIXME("(%p) : VertexShader_SetConstant not fully supported yet\n", This); */
-  if (Register + ConstantCount > VSHADER_MAX_CONSTANTS) {
+  if (Register + ConstantCount > D3D8_VSHADER_MAX_CONSTANTS) {
     return D3DERR_INVALIDCALL;
   }
   object = VERTEX_SHADER(Handle);
@@ -3261,7 +3459,7 @@
     FIXME("(%p) : VertexShader_SetConstant not fully supported yet\n", This);
     return D3DERR_INVALIDCALL;
   }
-  memcpy(object->data->C + Register, pConstantData, ConstantCount * sizeof(SHADER8Vector));
+  memcpy(object->data->C + Register, pConstantData, ConstantCount * sizeof(D3DSHADERVECTOR));
 
   return D3D_OK;
 }
@@ -3272,7 +3470,7 @@
 
   FIXME("(%p) : VertexShader_GetConstant not fully supported yet\n", This);
 
-  if (Register + ConstantCount > VSHADER_MAX_CONSTANTS) {
+  if (Register + ConstantCount > D3D8_VSHADER_MAX_CONSTANTS) {
     return D3DERR_INVALIDCALL;
   }
   object = VERTEX_SHADER(Handle);
@@ -3282,7 +3480,7 @@
   if (NULL == object->data) { /* temporary while datas not supported */
     return D3DERR_INVALIDCALL;
   }
-  memcpy(pConstantData, object->data->C + Register, ConstantCount * sizeof(SHADER8Vector));
+  memcpy(pConstantData, object->data->C + Register, ConstantCount * sizeof(D3DSHADERVECTOR));
 
   return D3D_OK;
 }
Index: dlls/d3d8/directx.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/directx.c,v
retrieving revision 1.9
diff -u -r1.9 directx.c
--- dlls/d3d8/directx.c	23 Dec 2002 01:34:59 -0000	1.9
+++ dlls/d3d8/directx.c	24 Dec 2002 00:46:30 -0000
@@ -159,7 +159,7 @@
         FIXME("Adapter not primary display\n");
     }
 
-    return D3D_OK;
+    return 0;
 }
 
 HRESULT  WINAPI  IDirect3D8Impl_EnumAdapterModes           (LPDIRECT3D8 iface,
@@ -195,7 +195,8 @@
 
         switch (bpp) {
         case  8: pMode->Format       = D3DFMT_R3G3B2;   break;
-        case 16: pMode->Format       = D3DFMT_A4R4G4B4; break;
+	/*case 16: pMode->Format       = D3DFMT_A4R4G4B4; break;*/
+	case 16: pMode->Format       = D3DFMT_R5G6B5;   break;
         case 24: pMode->Format       = D3DFMT_R8G8B8;   break;
         case 32: pMode->Format       = D3DFMT_A8R8G8B8; break;
         default: pMode->Format       = D3DFMT_UNKNOWN;
@@ -232,7 +233,8 @@
 
         switch (bpp) {
         case  8: pMode->Format       = D3DFMT_R3G3B2;   break;
-        case 16: pMode->Format       = D3DFMT_A4R4G4B4; break;
+	case 16: pMode->Format       = D3DFMT_R5G6B5;   break;
+	/*case 16: pMode->Format       = D3DFMT_A4R4G4B4; break;*/
         case 24: pMode->Format       = D3DFMT_R8G8B8;   break;
         case 32: pMode->Format       = D3DFMT_A8R8G8B8; break;
         default: pMode->Format       = D3DFMT_UNKNOWN;
@@ -242,7 +244,7 @@
         FIXME("Adapter not primary display\n");
     }
 
-    TRACE("returning w:%d, h:%d, ref:%d, fmt:%d\n", pMode->Width,
+    TRACE("returning w:%d, h:%d, ref:%d, fmt:%x\n", pMode->Width,
           pMode->Height, pMode->RefreshRate, pMode->Format);
     return D3D_OK;
 }
@@ -290,7 +292,7 @@
 
 
     /* NOTE: Most of the values here are complete garbage for now */
-    pCaps->DeviceType = D3DDEVTYPE_HAL;  /* Not quite true, but use h/w supported by opengl I suppose */
+    pCaps->DeviceType = (DeviceType == D3DDEVTYPE_HAL) ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF;  /* Not quite true, but use h/w supported by opengl I suppose */
     pCaps->AdapterOrdinal = Adapter;
 
     pCaps->Caps = 0;
@@ -367,7 +369,7 @@
     pCaps->MaxStreamStride = 1024;
 
     pCaps->VertexShaderVersion = 01;
-    pCaps->MaxVertexShaderConst = 1;
+    pCaps->MaxVertexShaderConst = D3D8_VSHADER_MAX_CONSTANTS;
 
     pCaps->PixelShaderVersion = 01;
     pCaps->MaxPixelShaderValue = 1.0;
@@ -466,9 +468,8 @@
 	    return D3DERR_NOTAVAILABLE;
 	  }
 	}
-
         object->glCtx = glXCreateContext(object->display, object->visInfo, NULL, GL_TRUE);
-	if (NULL == object->visInfo) {
+	if (NULL == object->glCtx) {
 	  ERR("cannot create glxContext\n"); 
 	  LEAVE_GL();
 	  return D3DERR_NOTAVAILABLE;
@@ -524,6 +525,8 @@
     */
 
     ENTER_GL();
+
+    /*TRACE("hereeee. %x %x %x\n", object->display, object->win, object->glCtx);*/
     if (glXMakeCurrent(object->display, object->win, object->glCtx) == False) {
       ERR("Error in setting current context (context %p drawable %ld)!\n", object->glCtx, object->win);
     }
@@ -555,26 +558,26 @@
     if (NULL == GL_Extensions) {
       ERR("   GL_Extensions returns NULL\n");      
     } else {
-      while (*GL_Extensions!=0x00) {
+      while (*GL_Extensions != 0x00) {
         const char *Start = GL_Extensions;
         char ThisExtn[256];
 
         memset(ThisExtn, 0x00, sizeof(ThisExtn));
-        while (*GL_Extensions!=' ' && *GL_Extensions!=0x00) {
-            GL_Extensions++;
+        while (*GL_Extensions != ' ' && *GL_Extensions != 0x00) {
+	  GL_Extensions++;
         }
-        memcpy(ThisExtn, Start, (GL_Extensions-Start));
+        memcpy(ThisExtn, Start, (GL_Extensions - Start));
         TRACE ("   %s\n", ThisExtn);
 
-        if (strcmp(ThisExtn, "GL_ARB_multitexture")==0) {
-            GLint gl_max_texture_units_arb;
-            glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max_texture_units_arb);
-            object->isMultiTexture = TRUE;
-            object->TextureUnits   = min(8, gl_max_texture_units_arb);
-            TRACE("FOUND: Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max_texture_units_arb);
+        if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
+	  GLint gl_max_texture_units_arb;
+	  glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max_texture_units_arb);
+	  object->isMultiTexture = TRUE;
+	  object->TextureUnits   = min(8, gl_max_texture_units_arb);
+	  TRACE("FOUND: Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max_texture_units_arb);
         }
 
-        if (*GL_Extensions==' ') GL_Extensions++;
+        if (*GL_Extensions == ' ') GL_Extensions++;
       }
     }
 
@@ -584,17 +587,17 @@
     if (NULL == GLX_Extensions) {
       ERR("   GLX_Extensions returns NULL\n");      
     } else {
-      while (*GLX_Extensions!=0x00) {
+      while (*GLX_Extensions != 0x00) {
         const char *Start = GLX_Extensions;
         char ThisExtn[256];
-
+	
         memset(ThisExtn, 0x00, sizeof(ThisExtn));
-        while (*GLX_Extensions!=' ' && *GLX_Extensions!=0x00) {
-            GLX_Extensions++;
+        while (*GLX_Extensions != ' ' && *GLX_Extensions != 0x00) {
+	  GLX_Extensions++;
         }
-        memcpy(ThisExtn, Start, (GLX_Extensions-Start));
+        memcpy(ThisExtn, Start, (GLX_Extensions - Start));
         TRACE ("   %s\n", ThisExtn);
-        if (*GLX_Extensions==' ') GLX_Extensions++;
+        if (*GLX_Extensions == ' ') GLX_Extensions++;
       }
     }
 
Index: dlls/d3d8/shader.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/shader.c,v
retrieving revision 1.2
diff -u -r1.2 shader.c
--- dlls/d3d8/shader.c	18 Dec 2002 05:05:41 -0000	1.2
+++ dlls/d3d8/shader.c	24 Dec 2002 00:46:55 -0000
@@ -30,163 +30,214 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
-typedef void (*shader_fct0_t)(void);
-typedef void (*shader_fct1_t)(SHADER8Vector*);
-typedef void (*shader_fct2_t)(SHADER8Vector*,SHADER8Vector*);
-typedef void (*shader_fct3_t)(SHADER8Vector*,SHADER8Vector*,SHADER8Vector*);
-typedef void (*shader_fct4_t)(SHADER8Vector*,SHADER8Vector*,SHADER8Vector*,SHADER8Vector*);
-
-/*
-typedef union shader_fct {
-  shader_fct0_t fct0;
-  shader_fct1_t fct1;
-  shader_fct2_t fct2;
-  shader_fct3_t fct3;
-  shader_fct4_t fct4;
-} shader_fct;
-*/
-typedef void (*shader_fct)();
-
-typedef struct shader_opcode {
-  CONST BYTE  opcode;
-  const char* name;
-  CONST UINT  num_params;
-  shader_fct  soft_fct;
-  /*
-  union {
-    shader_fct0_t fct0;
-    shader_fct1_t fct1;
-    shader_fct2_t fct2;
-    shader_fct3_t fct3;
-    shader_fct4_t fct4;
-  } shader_fct;
-  */
-} shader_opcode;
+/**
+ * DirectX9 SDK download
+ *  http://msdn.microsoft.com/library/default.asp?url=/downloads/list/directx.asp
+ *
+ * Exploring D3DX
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx07162002.asp
+ *
+ * Using Vertex Shaders
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx02192001.asp
+ *
+ * Dx9 New
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/whatsnew.asp
+ *
+ * Dx9 Shaders
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/VertexShader2_0.asp
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader2_0/Instructions/Instructions.asp
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexDeclaration/VertexDeclaration.asp
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/Shaders/VertexShader3_0/VertexShader3_0.asp
+ *
+ * Dx9 D3DX
+ *  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/programmingguide/advancedtopics/VertexPipe/matrixstack/matrixstack.asp
+ *
+ * FVF
+ *  http://msdn.microsoft.com/library/en-us/directx9_c/directx/graphics/programmingguide/GettingStarted/VertexFormats/vformats.asp
+ */
+
+typedef void (*shader_fct_t)();
 
-typedef struct vshader_input_data {
-  /*SHADER8Vector V[16];//0-15*/
-  SHADER8Vector V[16];
-} vshader_input_data;
-
-typedef struct vshader_output_data {
-  SHADER8Vector oPos;
-  /*SHADER8Vector oD[2];//0-1*/
-  SHADER8Vector oD[2];
-  /*SHADER8Vector oT[4];//0-3*/
-  SHADER8Vector oT[4];
-  /*SHADER8Scalar oFog;*/
-  /*SHADER8Scalar oPts;*/
-  SHADER8Vector oFog;
-  SHADER8Vector oPts;
-} vshader_output_data;
+typedef struct SHADER_OPCODE {
+  CONST BYTE    opcode;
+  const char*   name;
+  CONST UINT    num_params;
+  shader_fct_t  soft_fct;
+} SHADER_OPCODE;
+
+/** Vertex Shader Declaration data types tokens */
+static CONST char* VertexShaderDeclDataTypes [] = {
+  "D3DVSDT_FLOAT1",
+  "D3DVSDT_FLOAT2",
+  "D3DVSDT_FLOAT3",
+  "D3DVSDT_FLOAT4",
+  "D3DVSDT_D3DCOLOR",
+  "D3DVSDT_UBYTE4",
+  "D3DVSDT_SHORT2",
+  "D3DVSDT_SHORT4",
+  NULL
+};
+
+static CONST char* VertexShaderDeclRegister [] = {
+  "D3DVSDE_POSITION",
+  "D3DVSDE_BLENDWEIGHT",
+  "D3DVSDE_BLENDINDICES",
+  "D3DVSDE_NORMAL",
+  "D3DVSDE_PSIZE",
+  "D3DVSDE_DIFFUSE",
+  "D3DVSDE_SPECULAR",
+  "D3DVSDE_TEXCOORD0",
+  "D3DVSDE_TEXCOORD1",
+  "D3DVSDE_TEXCOORD2",
+  "D3DVSDE_TEXCOORD3",
+  "D3DVSDE_TEXCOORD4",
+  "D3DVSDE_TEXCOORD5",
+  "D3DVSDE_TEXCOORD6",
+  "D3DVSDE_TEXCOORD7",
+  "D3DVSDE_POSITION2",
+  "D3DVSDE_NORMAL2",
+  NULL
+};
 
 /*******************************
  * vshader functions software VM
  */
 
-void vshader_add(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_add(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = s0->x + s1->x;
   d->y = s0->y + s1->y;
   d->z = s0->z + s1->z;
   d->w = s0->w + s1->w;
 }
 
-void vshader_dp3(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_dp3(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = d->y = d->z = d->w = s0->x * s1->x + s0->y * s1->y + s0->z * s1->z;
 }
 
-void vshader_dp4(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_dp4(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = d->y = d->z = d->w = s0->x * s1->x + s0->y * s1->y + s0->z * s1->z + s0->w * s1->w;
+
+  /*
+  DPRINTF("executing dp4: s0=(%f, %f, %f, %f) s1=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
+	  s0->x, s0->y, s0->z, s0->w, s1->x, s1->y, s1->z, s1->w, d->x, d->y, d->z, d->w);
+  */
 }
 
-void vshader_dst(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
-  d->x = 1;
+void vshader_dst(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
+  d->x = 1.0f;
   d->y = s0->y * s1->y;
   d->z = s0->z;
   d->w = s1->w;
+
+  /*
+  DPRINTF("executing dst: s0=(%f, %f, %f, %f) s1=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
+	  s0->x, s0->y, s0->z, s0->w, s1->x, s1->y, s1->z, s1->w, d->x, d->y, d->z, d->w);
+  */
 }
 
-void vshader_expp(SHADER8Vector* d, SHADER8Vector* s0) {
+void vshader_expp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   float tmp_f = floorf(s0->w);
-  d->x = pow(2, tmp_f);
+  d->x = powf(2.0f, tmp_f);
   d->y = s0->w - tmp_f;
-  d->z = pow(2, s0->w);
-  d->w = 1;
+  d->z = powf(2.0f, s0->w);
+  d->w = 1.0f;
+
+  /*
+  DPRINTF("executing exp: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
+          s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w);
+  */
 }
 
-void vshader_lit(SHADER8Vector* d, SHADER8Vector* s0) {
-  d->x = 1;
-  d->y = (0 < s0->x) ? s0->x : 0;
-  d->z = (0 < s0->x && 0 < s0->y) ? pow(s0->y, s0->w) : 0;
-  d->w = 1;
+void vshader_lit(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
+  d->x = 1.0f;
+  d->y = (0.0f < s0->x) ? s0->x : 0.0f;
+  d->z = (0.0f < s0->x && 0.0f < s0->y) ? powf(s0->y, s0->w) : 0.0f;
+  d->w = 1.0f;
+
+  /*
+  DPRINTF("executing lit: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
+	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w);
+  */
 }
 
-void vshader_logp(SHADER8Vector* d, SHADER8Vector* s0) {
-  d->x = d->y = d->z = d->w = (0 != s0->w) ? log(fabsf(s0->w))/log(2) : HUGE;
+void vshader_logp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
+  float tmp_f = fabsf(s0->w); 
+  d->x = d->y = d->z = d->w = (0.0f != tmp_f) ? logf(tmp_f) / logf(2.0f) : -HUGE;
 }
 
-void vshader_mad(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1, SHADER8Vector* s2) {
+void vshader_mad(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1, D3DSHADERVECTOR* s2) {
   d->x = s0->x * s1->x + s2->x;
   d->y = s0->y * s1->y + s2->y;
   d->z = s0->z * s1->z + s2->z;
   d->w = s0->w * s1->w + s2->w;
 }
 
-void vshader_max(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_max(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = (s0->x >= s1->x) ? s0->x : s1->x;
   d->y = (s0->y >= s1->y) ? s0->y : s1->y;
   d->z = (s0->z >= s1->z) ? s0->z : s1->z;
   d->w = (s0->w >= s1->w) ? s0->w : s1->w;
 }
 
-void vshader_min(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_min(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = (s0->x < s1->x) ? s0->x : s1->x;
   d->y = (s0->y < s1->y) ? s0->y : s1->y;
   d->z = (s0->z < s1->z) ? s0->z : s1->z;
   d->w = (s0->w < s1->w) ? s0->w : s1->w;
 }
 
-void vshader_mov(SHADER8Vector* d, SHADER8Vector* s0) {
+void vshader_mov(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
   d->x = s0->x;
   d->y = s0->y;
   d->z = s0->z;
   d->w = s0->w;
+
+  /*
+  DPRINTF("executing mov: s0=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
+	  s0->x, s0->y, s0->z, s0->w, d->x, d->y, d->z, d->w);
+  */
 }
 
-void vshader_mul(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_mul(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = s0->x * s1->x;
   d->y = s0->y * s1->y;
   d->z = s0->z * s1->z;
   d->w = s0->w * s1->w;
+
+  /*
+  DPRINTF("executing mul: s0=(%f, %f, %f, %f) s1=(%f, %f, %f, %f) => d=(%f, %f, %f, %f)\n",
+          s0->x, s0->y, s0->z, s0->w, s1->x, s1->y, s1->z, s1->w, d->x, d->y, d->z, d->w);
+  */
 }
 
 void vshader_nop(void) {
   /* NOPPPP ahhh too easy ;) */
 }
 
-void vshader_rcp(SHADER8Vector* d, SHADER8Vector* s0) {
-  d->x = d->y = d->z = d->w = (0 == s0->w) ? HUGE : 1 / s0->w;
+void vshader_rcp(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
+  d->x = d->y = d->z = d->w = (0.0f == s0->w) ? HUGE : 1.0f / s0->w;
 }
 
-void vshader_rsq(SHADER8Vector* d, SHADER8Vector* s0) {
-  d->x = d->y = d->z = d->w = (0 == s0->w) ? HUGE : 1 / sqrt(fabsf(s0->w));
+void vshader_rsq(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0) {
+  float tmp_f = fabsf(s0->w);
+  d->x = d->y = d->z = d->w = (0.0f == tmp_f) ? HUGE : ((1.0f != tmp_f) ? 1.0f / sqrtf(tmp_f) : 1.0f);
 }
 
-void vshader_sge(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
-  d->x = (s0->x >= s1->x) ? 1 : 0;
-  d->y = (s0->y >= s1->y) ? 1 : 0;
-  d->z = (s0->z >= s1->z) ? 1 : 0;
-  d->w = (s0->w >= s1->w) ? 1 : 0;
+void vshader_sge(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
+  d->x = (s0->x >= s1->x) ? 1.0f : 0.0f;
+  d->y = (s0->y >= s1->y) ? 1.0f : 0.0f;
+  d->z = (s0->z >= s1->z) ? 1.0f : 0.0f;
+  d->w = (s0->w >= s1->w) ? 1.0f : 0.0f;
 }
 
-void vshader_slt(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
-  d->x = (s0->x < s1->x) ? 1 : 0;
-  d->y = (s0->y < s1->y) ? 1 : 0;
-  d->z = (s0->z < s1->z) ? 1 : 0;
-  d->w = (s0->w < s1->w) ? 1 : 0;
+void vshader_slt(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
+  d->x = (s0->x < s1->x) ? 1.0f : 0.0f;
+  d->y = (s0->y < s1->y) ? 1.0f : 0.0f;
+  d->z = (s0->z < s1->z) ? 1.0f : 0.0f;
+  d->w = (s0->w < s1->w) ? 1.0f : 0.0f;
 }
 
-void vshader_sub(SHADER8Vector* d, SHADER8Vector* s0, SHADER8Vector* s1) {
+void vshader_sub(D3DSHADERVECTOR* d, D3DSHADERVECTOR* s0, D3DSHADERVECTOR* s1) {
   d->x = s0->x - s1->x;
   d->y = s0->y - s1->y;
   d->z = s0->z - s1->z;
@@ -195,10 +246,8 @@
 
 /**
  * log, exp, frc, m*x* seems to be macros ins ... to see
- *
- * @TODO: find this fucking really opcodes values
  */
-static CONST shader_opcode vshader_ins [] = {
+static CONST SHADER_OPCODE vshader_ins [] = {
   {D3DSIO_MOV,  "mov",  2, vshader_mov},
   {D3DSIO_MAX,  "max",  3, vshader_max},
   {D3DSIO_MIN,  "min",  3, vshader_min},
@@ -221,8 +270,9 @@
 };
 
 
-const shader_opcode* vshader_program_get_opcode(const DWORD code) {
+const SHADER_OPCODE* vshader_program_get_opcode(const DWORD code) {
   DWORD i = 0;
+  /** TODO: use dichotomic search */
   while (NULL != vshader_ins[i].name) {
     if ((code & D3DSI_OPCODE_MASK) == vshader_ins[i].opcode) {
       return &vshader_ins[i];
@@ -307,7 +357,7 @@
  */
 DWORD vshader_program_parse(VERTEXSHADER8* vshader) {
   const DWORD* pToken = vshader->function;
-  const shader_opcode* curOpcode = NULL;
+  const SHADER_OPCODE* curOpcode = NULL;
   DWORD len = 0;  
   DWORD i;
 
@@ -339,7 +389,7 @@
 	DPRINTF("\n");
       }
     }
-    vshader->functionLength = len * sizeof(DWORD);
+    vshader->functionLength = (len + 1) * sizeof(DWORD);
   } else {
     vshader->functionLength = 1; /* no Function defined use fixed function vertex processing */
   }
@@ -347,8 +397,8 @@
 }
 
 BOOL vshader_program_execute_HAL(VERTEXSHADER8* vshader,
-				 const vshader_input_data* input,
-				 vshader_output_data* output) {
+				 VSHADERINPUTDATA8* input,
+				 VSHADEROUTPUTDATA8* output) {
   /** 
    * TODO: use the NV_vertex_program (or 1_1) extension 
    *  and specifics vendors (ARB_vertex_program??) variants for it 
@@ -356,51 +406,73 @@
   return TRUE;
 }
 
+#define TRACE_VECTOR(name) DPRINTF( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w)
+
 BOOL vshader_program_execute_SW(VERTEXSHADER8* vshader,
-				vshader_input_data* input,
-				vshader_output_data* output) {
+				VSHADERINPUTDATA8* input,
+				VSHADEROUTPUTDATA8* output) {
   /** Vertex Shader Temporary Registers */
-  SHADER8Vector R[12];
-  /*SHADER8Scalar A0;*/
-  SHADER8Vector A[1];
+  D3DSHADERVECTOR R[12];
+  memset(R, 0, 12 * sizeof(D3DSHADERVECTOR));
+  /*D3DSHADERSCALAR A0;*/
+  D3DSHADERVECTOR A[1];
   /** temporary Vector for modifier management */
-  SHADER8Vector d;
-  SHADER8Vector s[3];
+  D3DSHADERVECTOR d;
+  D3DSHADERVECTOR s[3];
   /** parser datas */
   const DWORD* pToken = vshader->function;
-  const shader_opcode* curOpcode = NULL;
+  const SHADER_OPCODE* curOpcode = NULL;
   /** functions parameters */
-  SHADER8Vector* p[4];
-  SHADER8Vector* p_send[4];
-
+  D3DSHADERVECTOR* p[4];
+  D3DSHADERVECTOR* p_send[4];
   DWORD i;
 
+  /* vshader_program_parse(vshader); */
+  /*
+  TRACE_VECTOR(vshader->data->C[0]);
+  TRACE_VECTOR(vshader->data->C[1]);
+  TRACE_VECTOR(vshader->data->C[2]);
+  TRACE_VECTOR(vshader->data->C[3]);
+  TRACE_VECTOR(vshader->data->C[4]);
+  TRACE_VECTOR(vshader->data->C[5]);
+  TRACE_VECTOR(input->V[D3DVSDE_POSITION]);
+  TRACE_VECTOR(input->V[D3DVSDE_BLENDWEIGHT]);
+  TRACE_VECTOR(input->V[D3DVSDE_BLENDINDICES]);
+  TRACE_VECTOR(input->V[D3DVSDE_NORMAL]);
+  TRACE_VECTOR(input->V[D3DVSDE_PSIZE]);
+  TRACE_VECTOR(input->V[D3DVSDE_DIFFUSE]);
+  TRACE_VECTOR(input->V[D3DVSDE_SPECULAR]);
+  TRACE_VECTOR(input->V[D3DVSDE_TEXCOORD0]);
+  TRACE_VECTOR(input->V[D3DVSDE_TEXCOORD1]);
+  */
+
   /* the first dword is the version tag */
   /* TODO: parse it */
   
-  ++pToken;
   while (D3DVS_END() != *pToken) {
     curOpcode = vshader_program_get_opcode(*pToken);
     ++pToken;
     if (NULL == curOpcode) {
       /* unkown current opcode ... */
       while (*pToken & 0x80000000) {
-	DPRINTF("unrecognized opcode: %08lX\n", *pToken);
+	DPRINTF("unrecognized opcode: pos=%d token=%08lX\n", pToken - vshader->function, *pToken);
 	++pToken;
       }
       /*return FALSE;*/
     } else {     
-      if (curOpcode->num_params > 0) {
-	
+      if (curOpcode->num_params > 0) {	
+	/*DPRINTF(">> execting opcode: pos=%d opcode_name=%s token=%08lX\n", pToken - vshader->function, curOpcode->name, *pToken);*/
 	for (i = 0; i < curOpcode->num_params; ++i) {
 	  DWORD reg = pToken[i] & 0x00001FFF;
 	  DWORD regtype = ((pToken[i] & D3DSP_REGTYPE_MASK) >> D3DSP_REGTYPE_SHIFT);
 
 	  switch (regtype << D3DSP_REGTYPE_SHIFT) {
 	  case D3DSPR_TEMP:
+	    /*DPRINTF("p[%d]=R[%d]\n", i, reg);*/
 	    p[i] = &R[reg];
 	    break;
 	  case D3DSPR_INPUT:
+	    /*DPRINTF("p[%d]=V[%s]\n", i, VertexShaderDeclRegister[reg]);*/
 	    p[i] = &input->V[reg];
 	    break;
 	  case D3DSPR_CONST:
@@ -411,8 +483,11 @@
 	    }
 	    break;
 	  case D3DSPR_ADDR: /*case D3DSPR_TEXTURE:*/
-	    if (0 != reg)
-	      ERR("cannot handle address registers != a0");
+	    if (0 != reg) {
+	      ERR("cannot handle address registers != a0, forcing use of a0\n");
+	      reg = 0;
+	    }
+	    /*DPRINTF("p[%d]=A[%d]\n", i, reg);*/
 	    p[i] = &A[reg];
 	    break;
 	  case D3DSPR_RASTOUT:
@@ -429,29 +504,35 @@
 	    }
 	    break;
 	  case D3DSPR_ATTROUT:
+	    /*DPRINTF("p[%d]=oD[%d]\n", i, reg);*/
 	    p[i] = &output->oD[reg];
 	    break;
 	  case D3DSPR_TEXCRDOUT:
+	    /*DPRINTF("p[%d]=oT[%d]\n", i, reg);*/
 	    p[i] = &output->oT[reg];
 	    break;
 	  default:
 	    break;
 	  }
 	  
-	  if (i > 1) { /* input reg */
+	  if (i > 0) { /* input reg */
 	    DWORD swizzle = (pToken[i] & D3DVS_SWIZZLE_MASK) >> D3DVS_SWIZZLE_SHIFT;
-	    DWORD swizzle_x = swizzle & 0x03;
-	    DWORD swizzle_y = (swizzle >> 2) & 0x03;
-	    DWORD swizzle_z = (swizzle >> 4) & 0x03;
-	    DWORD swizzle_w = (swizzle >> 6) & 0x03;
-	    if ((D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) == swizzle) {
+	    UINT isNegative = ((*pToken & D3DSP_SRCMOD_MASK) == D3DSPSM_NEG);
+
+	    if (!isNegative && (D3DVS_NOSWIZZLE >> D3DVS_SWIZZLE_SHIFT) == swizzle) {
+	      /*DPRINTF("p[%d] not swizzled\n", i);*/
 	      p_send[i] = p[i];
 	    } else {
+	      DWORD swizzle_x = swizzle & 0x03;
+	      DWORD swizzle_y = (swizzle >> 2) & 0x03;
+	      DWORD swizzle_z = (swizzle >> 4) & 0x03;
+	      DWORD swizzle_w = (swizzle >> 6) & 0x03;
+	      /*DPRINTF("p[%d] swizzled\n", i);*/
 	      float* tt = (float*) p[i];
-	      s[i].x = tt[swizzle_x];
-	      s[i].y = tt[swizzle_y];
-	      s[i].z = tt[swizzle_z];
-	      s[i].w = tt[swizzle_w];
+	      s[i].x = (isNegative) ? -tt[swizzle_x] : tt[swizzle_x];
+	      s[i].y = (isNegative) ? -tt[swizzle_y] : tt[swizzle_y];
+	      s[i].z = (isNegative) ? -tt[swizzle_z] : tt[swizzle_z];
+	      s[i].w = (isNegative) ? -tt[swizzle_w] : tt[swizzle_w];
 	      p_send[i] = &s[i];
 	    }
 	  } else { /* output reg */
@@ -492,6 +573,19 @@
 	if (pToken[0] & D3DSP_WRITEMASK_3) p[0]->w = d.w; 
       }
       
+      /*
+      TRACE_VECTOR(output->oPos);
+      TRACE_VECTOR(output->oD[0]);
+      TRACE_VECTOR(output->oD[1]);
+      TRACE_VECTOR(output->oT[0]);
+      TRACE_VECTOR(output->oT[1]);
+      TRACE_VECTOR(R[0]);
+      TRACE_VECTOR(R[1]);
+      TRACE_VECTOR(R[2]);
+      TRACE_VECTOR(R[3]);
+      TRACE_VECTOR(R[4]);
+      */
+
       /* to next opcode token */
       pToken += curOpcode->num_params;
     }
@@ -503,41 +597,6 @@
  * Vertex Shader Declaration Parser First draft ...
  */
 
-/** Vertex Shader Declaration data types tokens */
-static CONST char* VertexShaderDeclDataTypes [] = {
-  "D3DVSDT_FLOAT1",
-  "D3DVSDT_FLOAT2",
-  "D3DVSDT_FLOAT3",
-  "D3DVSDT_FLOAT4",
-  "D3DVSDT_D3DCOLOR",
-  "D3DVSDT_UBYTE4",
-  "D3DVSDT_SHORT2",
-  "D3DVSDT_SHORT4",
-  NULL
-};
-
-static CONST char* VertexShaderDeclRegister [] = {
-  "D3DVSDE_POSITION",
-  "D3DVSDE_BLENDWEIGHT",
-  "D3DVSDE_BLENDINDICES",
-  "D3DVSDE_NORMAL",
-  "D3DVSDE_PSIZE",
-  "D3DVSDE_DIFFUSE",
-  "D3DVSDE_SPECULAR",
-  "D3DVSDE_TEXCOORD0",
-  "D3DVSDE_TEXCOORD1",
-  "D3DVSDE_TEXCOORD2",
-  "D3DVSDE_TEXCOORD3",
-  "D3DVSDE_TEXCOORD4",
-  "D3DVSDE_TEXCOORD5",
-  "D3DVSDE_TEXCOORD6",
-  "D3DVSDE_TEXCOORD7",
-  "D3DVSDE_POSITION2",
-  "D3DVSDE_NORMAL2",
-  NULL
-};
-
-
 /** todo check decl validity */
 DWORD vshader_decl_parse_token(const DWORD* pToken) {
   const DWORD token = *pToken;
@@ -622,6 +681,7 @@
   DWORD token;
   DWORD tokenlen;
   DWORD tokentype;
+  DWORD tex = D3DFVF_TEX0;
 
   while (D3DVSD_END() != *pToken) {
     token = *pToken;
@@ -632,55 +692,108 @@
     if (D3DVSD_TOKEN_STREAMDATA == tokentype && 0 == (0x10000000 & tokentype)) {
       DWORD type = ((token & D3DVSD_DATATYPEMASK)  >> D3DVSD_DATATYPESHIFT);
       DWORD reg  = ((token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
+
       switch (reg) {
-      case D3DVSDE_POSITION:     fvf |= D3DFVF_XYZ;             break;
+      case D3DVSDE_POSITION:     
+	switch (type) {
+	case D3DVSDT_FLOAT3:     fvf |= D3DFVF_XYZ;             break;
+	case D3DVSDT_FLOAT4:     fvf |= D3DFVF_XYZRHW;          break;
+	default: /** errooooorr what to do ? */
+	  ERR("Error in VertexShader declaration of D3DVSDE_POSITION register: unsupported type %lu\n", type);	  
+	}
+	break;
+
       case D3DVSDE_BLENDWEIGHT:
 	switch (type) {
 	case D3DVSDT_FLOAT1:     fvf |= D3DFVF_XYZB1;           break;
 	case D3DVSDT_FLOAT2:     fvf |= D3DFVF_XYZB2;           break;
 	case D3DVSDT_FLOAT3:     fvf |= D3DFVF_XYZB3;           break;
 	case D3DVSDT_FLOAT4:     fvf |= D3DFVF_XYZB4;           break;
-	default:
-	  /** errooooorr what to do ? */
+	default: /** errooooorr what to do ? */
 	  ERR("Error in VertexShader declaration of D3DVSDE_BLENDWEIGHT register: unsupported type %lu\n", type);
 	}
 	break;
 
-      case D3DVSDE_BLENDINDICES: fvf |= D3DFVF_LASTBETA_UBYTE4; break;
-      case D3DVSDE_NORMAL:       fvf |= D3DFVF_NORMAL;          break;
-      case D3DVSDE_PSIZE:        fvf |= D3DFVF_PSIZE;           break;
-      case D3DVSDE_DIFFUSE:      fvf |= D3DFVF_DIFFUSE;         break;
-      case D3DVSDE_SPECULAR:     fvf |= D3DFVF_SPECULAR;        break;
-      case D3DVSDE_TEXCOORD0:    fvf |= D3DFVF_TEX1;            break;
-      case D3DVSDE_TEXCOORD1:    fvf |= D3DFVF_TEX2;            break;
-      case D3DVSDE_TEXCOORD2:    fvf |= D3DFVF_TEX3;            break;
-      case D3DVSDE_TEXCOORD3:    fvf |= D3DFVF_TEX4;            break;
-      case D3DVSDE_TEXCOORD4:    fvf |= D3DFVF_TEX5;            break;
-      case D3DVSDE_TEXCOORD5:    fvf |= D3DFVF_TEX6;            break;
-      case D3DVSDE_TEXCOORD6:    fvf |= D3DFVF_TEX7;            break;
-      case D3DVSDE_TEXCOORD7:    fvf |= D3DFVF_TEX8;            break;
+      case D3DVSDE_BLENDINDICES: /* seem to be B5 as said in MSDN Dx9SDK ??  */
+	switch (type) {
+	case D3DVSDT_UBYTE4:     fvf |= D3DFVF_LASTBETA_UBYTE4;           break;
+	default: /** errooooorr what to do ? */
+	  ERR("Error in VertexShader declaration of D3DVSDE_BLENDINDINCES register: unsupported type %lu\n", type);
+	}
+	break; 
+
+      case D3DVSDE_NORMAL: /* TODO: only FLOAT3 supported ... another choice possible ? */
+	switch (type) {
+	case D3DVSDT_FLOAT3:     fvf |= D3DFVF_NORMAL;          break;
+	default: /** errooooorr what to do ? */
+	  ERR("Error in VertexShader declaration of D3DVSDE_NORMAL register: unsupported type %lu\n", type);
+	}
+	break; 
+
+      case D3DVSDE_PSIZE:  /* TODO: only FLOAT1 supported ... another choice possible ? */
+	switch (type) {
+        case D3DVSDT_FLOAT1:     fvf |= D3DFVF_PSIZE;           break;
+	default: /** errooooorr what to do ? */
+	  ERR("Error in VertexShader declaration of D3DVSDE_PSIZE register: unsupported type %lu\n", type);
+	}
+	break;
+
+      case D3DVSDE_DIFFUSE:  /* TODO: only D3DCOLOR supported */
+	switch (type) {
+	case D3DVSDT_D3DCOLOR:   fvf |= D3DFVF_DIFFUSE;         break;
+	default: /** errooooorr what to do ? */
+	  ERR("Error in VertexShader declaration of D3DVSDE_DIFFUSE register: unsupported type %lu\n", type);
+	}
+	break;
+
+      case D3DVSDE_SPECULAR:  /* TODO: only D3DCOLOR supported */
+	switch (type) {
+	case D3DVSDT_D3DCOLOR:	 fvf |= D3DFVF_SPECULAR;        break;
+	default: /** errooooorr what to do ? */
+	  ERR("Error in VertexShader declaration of D3DVSDE_SPECULAR register: unsupported type %lu\n", type);
+	}
+	break;
+
+	/**
+	 * TODO: for TEX* only FLOAT2 supported
+	 *  by default using texture type info
+	 */
+      case D3DVSDE_TEXCOORD0:    tex = max(tex, D3DFVF_TEX1);   break; 
+      case D3DVSDE_TEXCOORD1:    tex = max(tex, D3DFVF_TEX2);   break;
+      case D3DVSDE_TEXCOORD2:    tex = max(tex, D3DFVF_TEX3);   break;
+      case D3DVSDE_TEXCOORD3:    tex = max(tex, D3DFVF_TEX4);   break;
+      case D3DVSDE_TEXCOORD4:    tex = max(tex, D3DFVF_TEX5);   break;
+      case D3DVSDE_TEXCOORD5:    tex = max(tex, D3DFVF_TEX6);   break;
+      case D3DVSDE_TEXCOORD6:    tex = max(tex, D3DFVF_TEX7);   break;
+      case D3DVSDE_TEXCOORD7:    tex = max(tex, D3DFVF_TEX8);   break;
       case D3DVSDE_POSITION2:   /* maybe D3DFVF_XYZRHW instead D3DFVF_XYZ (of D3DVDE_POSITION) ... to see */
       case D3DVSDE_NORMAL2:     /* FIXME i don't know what to do here ;( */
 	FIXME("[%lu] registers in VertexShader declaration not supported yet (token:0x%08lx)\n", reg, token);
 	break;
       }
+      /*TRACE("VertexShader declaration define %x as current FVF\n", fvf);*/
     }
     len += tokenlen;
     pToken += tokenlen;
   }
+  if (tex > 0) {
+    /*TRACE("VertexShader declaration define %x as texture level\n", tex);*/
+    fvf |= tex;
+  }   
   /* here D3DVSD_END() */
   len += vshader_decl_parse_token(pToken);
-  if (NULL == vshader->function) vshader->fvf = fvf;
+  vshader->fvf = fvf;
   vshader->declLength = len * sizeof(DWORD);
   return len * sizeof(DWORD);
 }
 
-HRESULT WINAPI ValidateVertexShader(void) {
-  FIXME("(void): stub\n");
-  return 0;
+BOOL WINAPI ValidateVertexShader(LPVOID what, LPVOID toto) {
+  FIXME("(void): stub: %p\n", what);
+  return TRUE;
 }
 
-HRESULT WINAPI ValidatePixelShader(void) {
-  FIXME("(void): stub\n");
-  return 0;
+BOOL WINAPI ValidatePixelShader(LPVOID what, LPVOID toto) {
+  FIXME("(void): stub: %p\n", what);
+  return TRUE;
 }
+
Index: include/d3d8.h
===================================================================
RCS file: /home/wine/wine/include/d3d8.h,v
retrieving revision 1.3
diff -u -r1.3 d3d8.h
--- include/d3d8.h	17 Dec 2002 01:15:15 -0000	1.3
+++ include/d3d8.h	24 Dec 2002 00:47:47 -0000
@@ -63,41 +63,41 @@
 /*****************************************************************************
  * Predeclare the interfaces
  */
-DEFINE_GUID(IID_IDirect3D8,             0x1DD9E8DA,0x1C77,0x4D40,0xB0,0xCF,0x98,0xFE,0xFD,0xFF,0x95,0x12);
-typedef struct IDirect3D8              IDirect3D8, *LPDIRECT3D8;
+DEFINE_GUID(IID_IDirect3D8,              0x1DD9E8DA,0x1C77,0x4D40,0xB0,0xCF,0x98,0xFE,0xFD,0xFF,0x95,0x12);
+typedef struct IDirect3D8                IDirect3D8, *LPDIRECT3D8;
 
-DEFINE_GUID(IID_IDirect3DDevice8,       0X7385E5DF,0X8FE8,0X41D5,0X86,0XB6,0XD7,0XB4,0X85,0X47,0XB6,0XCF);
-typedef struct IDirect3DDevice8        IDirect3DDevice8, *LPDIRECT3DDEVICE8;
+DEFINE_GUID(IID_IDirect3DDevice8,        0x7385E5DF,0x8FE8,0x41D5,0x86,0xB6,0xD7,0xB4,0x85,0x47,0xB6,0xCF);
+typedef struct IDirect3DDevice8          IDirect3DDevice8, *LPDIRECT3DDEVICE8;
 
-DEFINE_GUID(IID_IDirect3DResource8,     0X1B36BB7B,0X09B7,0X410A,0XB4,0X45,0X7D,0X14,0X30,0XD7,0XB3,0X3F);
-typedef struct IDirect3DResource8      IDirect3DResource8, *LPDIRECT3DRESOURCE8, *PDIRECT3DRESOURCE8;
+DEFINE_GUID(IID_IDirect3DResource8,      0x1B36BB7B,0x09B7,0x410A,0xB4,0x45,0x7D,0x14,0x30,0xD7,0xB3,0x3F);
+typedef struct IDirect3DResource8        IDirect3DResource8, *LPDIRECT3DRESOURCE8, *PDIRECT3DRESOURCE8;
 
-DEFINE_GUID(IID_IDirect3DVertexBuffer8, 0X8AEEEAC7,0X05F9,0X44D4,0XB5,0X91,0X00,0X0B,0X0D,0XF1,0XCB,0X95);
-typedef struct IDirect3DVertexBuffer8  IDirect3DVertexBuffer8, *LPDIRECT3DVERTEXBUFFER8, *PDIRECT3DVERTEXBUFFER8;
+DEFINE_GUID(IID_IDirect3DVertexBuffer8,  0x8AEEEAC7,0x05F9,0x44D4,0xB5,0x91,0x00,0x0B,0x0D,0xF1,0xCB,0x95);
+typedef struct IDirect3DVertexBuffer8    IDirect3DVertexBuffer8, *LPDIRECT3DVERTEXBUFFER8, *PDIRECT3DVERTEXBUFFER8;
 
-DEFINE_GUID(IID_IDirect3DVolume8,       0XBD7349F5,0X14F1,0X42E4,0X9C,0X79,0X97,0X23,0X80,0XDB,0X40,0XC0);
-typedef struct IDirect3DVolume8        IDirect3DVolume8, *LPDIRECT3DVOLUME8, *PDIRECT3DVOLUME8;
+DEFINE_GUID(IID_IDirect3DVolume8,        0xBD7349F5,0x14F1,0x42E4,0x9C,0x79,0x97,0x23,0x80,0xDB,0x40,0xC0);
+typedef struct IDirect3DVolume8          IDirect3DVolume8, *LPDIRECT3DVOLUME8, *PDIRECT3DVOLUME8;
 
-DEFINE_GUID(IID_IDirect3DSwapChain8,    0X928C088B,0X76B9,0X4C6B,0XA5,0X36,0XA5,0X90,0X85,0X38,0X76,0XCD);
-typedef struct IDirect3DSwapChain8     IDirect3DSwapChain8, *LPDIRECT3DSWAPCHAIN8, *PDIRECT3DSWAPCHAIN8;
+DEFINE_GUID(IID_IDirect3DSwapChain8,     0x928C088B,0x76B9,0x4C6B,0xA5,0x36,0xA5,0x90,0x85,0x38,0x76,0xCD);
+typedef struct IDirect3DSwapChain8       IDirect3DSwapChain8, *LPDIRECT3DSWAPCHAIN8, *PDIRECT3DSWAPCHAIN8;
 
-DEFINE_GUID(IID_IDirect3DSurface8,      0XB96EEBCA,0XB326,0X4EA5,0X88,0X2F,0X2F,0XF5,0XBA,0XE0,0X21,0XDD);
-typedef struct IDirect3DSurface8       IDirect3DSurface8, *LPDIRECT3DSURFACE8, *PDIRECT3DSURFACE8;
+DEFINE_GUID(IID_IDirect3DSurface8,       0xB96EEBCA,0xB326,0x4EA5,0x88,0x2F,0x2F,0xF5,0xBA,0xE0,0x21,0xDD);
+typedef struct IDirect3DSurface8         IDirect3DSurface8, *LPDIRECT3DSURFACE8, *PDIRECT3DSURFACE8;
 
-DEFINE_GUID(IID_IDirect3DIndexBuffer8,  0X0E689C9A,0X053D,0X44A0,0X9D,0X92,0XDB,0X0E,0X3D,0X75,0X0F,0X86);
-typedef struct IDirect3DIndexBuffer8   IDirect3DIndexBuffer8, *LPDIRECT3DINDEXBUFFER8, *PDIRECT3DINDEXBUFFER8;
+DEFINE_GUID(IID_IDirect3DIndexBuffer8,   0x0E689C9A,0x053D,0x44A0,0x9D,0x92,0xDB,0x0E,0x3D,0x75,0x0F,0x86);
+typedef struct IDirect3DIndexBuffer8     IDirect3DIndexBuffer8, *LPDIRECT3DINDEXBUFFER8, *PDIRECT3DINDEXBUFFER8;
 
-DEFINE_GUID(IID_IDirect3DBaseTexture8,  0XB4211CFA,0X51B9,0X4A9F,0XAB,0X78,0XDB,0X99,0XB2,0XBB,0X67,0X8E);
-typedef struct IDirect3DBaseTexture8   IDirect3DBaseTexture8, *LPDIRECT3DBASETEXTURE8, *PDIRECT3DBASETEXTURE8;
+DEFINE_GUID(IID_IDirect3DBaseTexture8,   0xB4211CFA,0x51B9,0x4A9F,0xAB,0x78,0xDB,0x99,0xB2,0xBB,0x67,0x8E);
+typedef struct IDirect3DBaseTexture8     IDirect3DBaseTexture8, *LPDIRECT3DBASETEXTURE8, *PDIRECT3DBASETEXTURE8;
 
-DEFINE_GUID(IID_IDirect3DTexture8,      0XE4CDD575,0X2866,0X4F01,0XB1,0X2E,0X7E,0XEC,0XE1,0XEC,0X93,0X58);
-typedef struct IDirect3DTexture8       IDirect3DTexture8, *LPDIRECT3DTEXTURE8, *PDIRECT3DTEXTURE8;
+DEFINE_GUID(IID_IDirect3DTexture8,       0xE4CDD575,0x2866,0x4F01,0xB1,0x2E,0x7E,0xEC,0xE1,0xEC,0x93,0x58);
+typedef struct IDirect3DTexture8         IDirect3DTexture8, *LPDIRECT3DTEXTURE8, *PDIRECT3DTEXTURE8;
 
-DEFINE_GUID(IID_IDirect3DCubeTexture8,  0X3EE5B968,0X2ACA,0X4C34,0X8B,0XB5,0X7E,0X0C,0X3D,0X19,0XB7,0X50);
-typedef struct IDirect3DCubeTexture8   IDirect3DCubeTexture8, *LPDIRECT3DCUBETEXTURE8, *PDIRECT3DCUBETEXTURE8;
+DEFINE_GUID(IID_IDirect3DCubeTexture8,   0x3EE5B968,0x2ACA,0x4C34,0x8B,0xB5,0x7E,0x0C,0x3D,0x19,0xB7,0x50);
+typedef struct IDirect3DCubeTexture8     IDirect3DCubeTexture8, *LPDIRECT3DCUBETEXTURE8, *PDIRECT3DCUBETEXTURE8;
 
-DEFINE_GUID(IID_IDirect3DVolumeTexture8,0X4B8AAAFA,0X140F,0X42BA,0X91,0X31,0X59,0X7E,0XAF,0XAA,0X2E,0XAD);
-typedef struct IDirect3DVolumeTexture8 IDirect3DVolumeTexture8, *LPDIRECT3DVOLUMETEXTURE8, *PDIRECT3DVOLUMETEXTURE8;
+DEFINE_GUID(IID_IDirect3DVolumeTexture8, 0x4B8AAAFA,0x140F,0x42BA,0x91,0x31,0x59,0x7E,0xAF,0xAA,0x2E,0xAD);
+typedef struct IDirect3DVolumeTexture8   IDirect3DVolumeTexture8, *LPDIRECT3DVOLUMETEXTURE8, *PDIRECT3DVOLUMETEXTURE8;
 
 /*****************************************************************************
  * IDirect3D8 interface
@@ -728,7 +728,15 @@
 #define IDirect3DVolumeTexture8_UnlockBox(p,a)               ICOM_CALL1(UnlockBox,p,a)
 #define IDirect3DVolumeTexture8_AddDirtyBox(p,a)             ICOM_CALL1(AddDirtyBox,p,a)
 
+#ifdef __cplusplus
+extern "C" {
+#endif  /* defined(__cplusplus) */
+
 /* Define the main entrypoint as well */
 IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif /* defined(__cplusplus) */
 
 #endif /* __WINE_D3D8_H */
Index: include/d3d8types.h
===================================================================
RCS file: /home/wine/wine/include/d3d8types.h,v
retrieving revision 1.5
diff -u -r1.5 d3d8types.h
--- include/d3d8types.h	18 Dec 2002 05:04:43 -0000	1.5
+++ include/d3d8types.h	24 Dec 2002 00:47:48 -0000
@@ -250,7 +250,7 @@
 #define D3DVSD_EXTINFOMASK       (0xFFFFFF << D3DVSD_EXTINFOSHIFT)
 #define D3DVSD_STREAMNUMBERMASK  (0xF      << D3DVSD_STREAMNUMBERSHIFT)
 #define D3DVSD_VERTEXREGMASK     (0x1F     << D3DVSD_VERTEXREGSHIFT)
-#define D3DVSD_CONSTRSMASK       (0x1FFF   << D3DVSD_CONSTREGSHIFT)
+#define D3DVSD_CONSTRSMASK       (0x1FFF   << D3DVSD_CONSTRSSHIFT)
 #define D3DVSD_DATATYPEMASK      (0xF      << D3DVSD_DATATYPESHIFT)
 #define D3DVSD_SKIPCOUNTMASK     (0xF      << D3DVSD_SKIPCOUNTSHIFT)
 #define D3DVSD_EXTCOUNTMASK      (0x1F     << D3DVSD_EXTCOUNTSHIFT)

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux