[dx37] come back

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

 



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

Hi,

i'm back again (only a 4 days break).
This patch inlcude the beginnig of merge of my 4 prototypes tree.

Changelog:
- -  implemented render to surfaces (and render to new rendertargets) using glx 
pbuffers (with a usefull debug code to display rendered surface into window 
drawable)
- - better cubetextures
- - splitted utilities functions into utils.c and added more
- - more readable debug again
- - a better caps code (not perfect but i'll use glx code later)
- - use of the new caps code
- - begin of UpdateTexture
- - begin of Cursor support
- - cleaning most of deprecated #if 0/#endif
- - correct some lockable/unlockable behavior
- - correct some returns code

Now, i have to take some days to read my huge list of late mails ;)

Regards,
Raphael

PS: lionel can you send an updated version of dinput patch ? else i'll try to 
send it.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+zVJZp7NA3AmQTU4RAi2/AJ42dPqT2qzymvVCTa1HYuswFCcnvgCfQsCh
o6rEegcQePdc9tZeKx9esu8=
=DsrQ
-----END PGP SIGNATURE-----
Index: basetexture.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/basetexture.c,v
retrieving revision 1.6
diff -u -r1.6 basetexture.c
--- basetexture.c	17 May 2003 18:33:02 -0000	1.6
+++ basetexture.c	22 May 2003 22:24:10 -0000
@@ -123,6 +123,21 @@
     return 0;
 }
 
+BOOL WINAPI IDirect3DBaseTexture8Impl_IsDirty(LPDIRECT3DBASETEXTURE8 iface) {
+    ICOM_THIS(IDirect3DBaseTexture8Impl,iface);
+    return This->Dirty;
+}
+
+BOOL WINAPI IDirect3DBaseTexture8Impl_SetDirty(LPDIRECT3DBASETEXTURE8 iface, BOOL dirty) {
+    BOOL old;
+    ICOM_THIS(IDirect3DBaseTexture8Impl,iface);
+    
+    old = This->Dirty;
+    This->Dirty = dirty;
+    return old;
+}
+
+
 ICOM_VTABLE(IDirect3DBaseTexture8) Direct3DBaseTexture8_Vtbl =
 {
     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
Index: cubetexture.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/cubetexture.c,v
retrieving revision 1.8
diff -u -r1.8 cubetexture.c
--- cubetexture.c	17 May 2003 18:33:02 -0000	1.8
+++ cubetexture.c	22 May 2003 22:24:10 -0000
@@ -140,7 +140,7 @@
       if (i == 0 && This->surfaces[0][i]->textureName != 0 && This->Dirty == FALSE) {
 	glEnable(GL_TEXTURE_CUBE_MAP_ARB);
 #if defined(GL_VERSION_1_3)
-	glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][i]->textureName);
+	glBindTexture(GL_TEXTURE_CUBE_MAP, This->surfaces[0][i]->textureName);
 #else
         glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->surfaces[0][i]->textureName);
 #endif
@@ -173,10 +173,17 @@
 	}
 	
 	for (j = 0; j < 6; j++) {
-	  TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, glFmt=%x, glType=%lx, Mem=%p\n",
-		cube_targets[j], i, fmt2glintFmt(This->format), 
-		This->surfaces[j][i]->myDesc.Width, This->surfaces[j][i]->myDesc.Height, 
-		0, fmt2glFmt(This->format), fmt2glType(This->format),
+	  IDirect3DSurface8Impl_CreateGLTexture((LPDIRECT3DSURFACE8) This->surfaces[j][i], cube_targets[j], i); 
+#if 0
+	  TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, glFmt=%x, glType=%x, Mem=%p\n",
+		cube_targets[j], 
+		i, 
+		fmt2glintFmt(This->format), 
+		This->surfaces[j][i]->myDesc.Width, 
+		This->surfaces[j][i]->myDesc.Height, 
+		0, 
+		fmt2glFmt(This->format), 
+		fmt2glType(This->format),
 		This->surfaces[j][i]->allocatedMemory);
 	  glTexImage2D(cube_targets[j],
 		       i,
@@ -188,6 +195,7 @@
 		       fmt2glType(This->format),
 		       This->surfaces[j][i]->allocatedMemory);
 	  checkGLcall("glTexImage2D");
+#endif
 	}
 	/* Removed glTexParameterf now TextureStageStates are initialized at startup */
 	This->Dirty = FALSE;
Index: device.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/device.c,v
retrieving revision 1.59
diff -u -r1.59 device.c
--- device.c	22 May 2003 03:35:24 -0000	1.59
+++ device.c	22 May 2003 22:24:16 -0000
@@ -78,122 +78,6 @@
 
 #define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
 
-const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
-  switch (devtype) {
-#define DEVTYPE_TO_STR(dev) case dev: return #dev
-    DEVTYPE_TO_STR(D3DDEVTYPE_HAL);
-    DEVTYPE_TO_STR(D3DDEVTYPE_REF);
-    DEVTYPE_TO_STR(D3DDEVTYPE_SW);    
-#undef DEVTYPE_TO_STR
-  default:
-    FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
-    return "unrecognized";
-  }
-}
-
-const char* debug_d3dusage(DWORD usage) {
-  switch (usage) {
-#define D3DUSAGE_TO_STR(u) case u: return #u
-    D3DUSAGE_TO_STR(D3DUSAGE_RENDERTARGET);
-    D3DUSAGE_TO_STR(D3DUSAGE_DEPTHSTENCIL);
-    D3DUSAGE_TO_STR(D3DUSAGE_WRITEONLY);
-    D3DUSAGE_TO_STR(D3DUSAGE_SOFTWAREPROCESSING);
-    D3DUSAGE_TO_STR(D3DUSAGE_DONOTCLIP);
-    D3DUSAGE_TO_STR(D3DUSAGE_POINTS);
-    D3DUSAGE_TO_STR(D3DUSAGE_RTPATCHES);
-    D3DUSAGE_TO_STR(D3DUSAGE_NPATCHES);
-    D3DUSAGE_TO_STR(D3DUSAGE_DYNAMIC);
-#undef D3DUSAGE_TO_STR
-  case 0: return "none";
-  default:
-    FIXME("Unrecognized %lu Usage!\n", usage);
-    return "unrecognized";
-  }
-}
-
-const char* debug_d3dformat(D3DFORMAT fmt) {
-  switch (fmt) {
-#define FMT_TO_STR(fmt) case fmt: return #fmt
-    FMT_TO_STR(D3DFMT_UNKNOWN);
-    FMT_TO_STR(D3DFMT_R8G8B8);
-    FMT_TO_STR(D3DFMT_A8R8G8B8);
-    FMT_TO_STR(D3DFMT_X8R8G8B8);
-    FMT_TO_STR(D3DFMT_R5G6B5);
-    FMT_TO_STR(D3DFMT_X1R5G5B5);
-    FMT_TO_STR(D3DFMT_A1R5G5B5);
-    FMT_TO_STR(D3DFMT_A4R4G4B4);
-    FMT_TO_STR(D3DFMT_R3G3B2);
-    FMT_TO_STR(D3DFMT_A8);
-    FMT_TO_STR(D3DFMT_A8R3G3B2);
-    FMT_TO_STR(D3DFMT_X4R4G4B4);
-    FMT_TO_STR(D3DFMT_A8P8);
-    FMT_TO_STR(D3DFMT_P8);
-    FMT_TO_STR(D3DFMT_L8);
-    FMT_TO_STR(D3DFMT_A8L8);
-    FMT_TO_STR(D3DFMT_A4L4);
-    FMT_TO_STR(D3DFMT_V8U8);
-    FMT_TO_STR(D3DFMT_L6V5U5);
-    FMT_TO_STR(D3DFMT_X8L8V8U8);
-    FMT_TO_STR(D3DFMT_Q8W8V8U8);
-    FMT_TO_STR(D3DFMT_V16U16);
-    FMT_TO_STR(D3DFMT_W11V11U10);
-    FMT_TO_STR(D3DFMT_UYVY);
-    FMT_TO_STR(D3DFMT_YUY2);
-    FMT_TO_STR(D3DFMT_DXT1);
-    FMT_TO_STR(D3DFMT_DXT2);
-    FMT_TO_STR(D3DFMT_DXT3);
-    FMT_TO_STR(D3DFMT_DXT4);
-    FMT_TO_STR(D3DFMT_DXT5);
-    FMT_TO_STR(D3DFMT_D16_LOCKABLE);
-    FMT_TO_STR(D3DFMT_D32);
-    FMT_TO_STR(D3DFMT_D15S1);
-    FMT_TO_STR(D3DFMT_D24S8);
-    FMT_TO_STR(D3DFMT_D16);
-    FMT_TO_STR(D3DFMT_D24X8);
-    FMT_TO_STR(D3DFMT_D24X4S4);
-    FMT_TO_STR(D3DFMT_VERTEXDATA);
-    FMT_TO_STR(D3DFMT_INDEX16);
-    FMT_TO_STR(D3DFMT_INDEX32);
-#undef FMT_TO_STR
-  default:
-    FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
-    return "unrecognized";
-  }
-}
-
-const char* debug_d3dressourcetype(D3DRESOURCETYPE res) {
-  switch (res) {
-#define RES_TO_STR(res) case res: return #res;
-    RES_TO_STR(D3DRTYPE_SURFACE);
-    RES_TO_STR(D3DRTYPE_VOLUME);
-    RES_TO_STR(D3DRTYPE_TEXTURE);
-    RES_TO_STR(D3DRTYPE_VOLUMETEXTURE);
-    RES_TO_STR(D3DRTYPE_CUBETEXTURE);
-    RES_TO_STR(D3DRTYPE_VERTEXBUFFER);
-    RES_TO_STR(D3DRTYPE_INDEXBUFFER);
-#undef  RES_TO_STR
-  default:
-    FIXME("Unrecognized %u D3DRESOURCETYPE!\n", res);
-    return "unrecognized";
-  }
-}
-
-const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
-  switch (PrimitiveType) {
-#define PRIM_TO_STR(prim) case prim: return #prim;
-    PRIM_TO_STR(D3DPT_POINTLIST);
-    PRIM_TO_STR(D3DPT_LINELIST);
-    PRIM_TO_STR(D3DPT_LINESTRIP);
-    PRIM_TO_STR(D3DPT_TRIANGLELIST);
-    PRIM_TO_STR(D3DPT_TRIANGLESTRIP);
-    PRIM_TO_STR(D3DPT_TRIANGLEFAN);
-#undef  PRIM_TO_STR
-  default:
-    FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
-    return "unrecognized";
-  }
-}
-
 /* Routine common to the draw primitive and draw indexed primitive routines */
 void DrawPrimitiveI(LPDIRECT3DDEVICE8 iface,
                     int PrimitiveType,
@@ -346,6 +230,12 @@
 	    glOrtho(X, X + width, Y + height, Y, -minZ, -maxZ);
             checkGLcall("glOrtho");
         } else {
+	    double X, Y, height, width;
+	    X = This->StateBlock->viewport.X;
+	    Y = This->StateBlock->viewport.Y;
+            height = This->StateBlock->viewport.Height;
+            width = This->StateBlock->viewport.Width;
+
             glMatrixMode(GL_MODELVIEW);
             checkGLcall("glMatrixMode");
             glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_VIEW].u.m[0][0]);
@@ -353,6 +243,18 @@
             glMultMatrixf((float *) &This->StateBlock->transforms[D3DTS_WORLDMATRIX(0)].u.m[0][0]);
             checkGLcall("glMultMatrixf");
 
+#if 0
+	    /**
+	     * OpenGL seems to map font between pixels
+	     *  well with this it seems better but not perfect
+	     *  anyone have a better idea ?
+	     */
+	    glTranslatef(0.8f / width, -0.8f / height, 0.0f);
+	    /**
+	     *
+	     */
+#endif
+
             glMatrixMode(GL_PROJECTION);
             checkGLcall("glMatrixMode");
             glLoadMatrixf((float *) &This->StateBlock->transforms[D3DTS_PROJECTION].u.m[0][0]);
@@ -529,9 +431,9 @@
                 }
 
                 /* Now use the appropriate set of texture indexes */
-                for (textureNo = 0; textureNo < This->TextureUnits; ++textureNo) {
+                for (textureNo = 0; textureNo < GL_LIMITS(textures); ++textureNo) {
 
-                    if (!(This->isMultiTexture) && textureNo > 0) {
+                    if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0) {
                         FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
                         continue ;
                     }
@@ -552,7 +454,7 @@
 
                             /* If texture transform flags in effect, values passed through to vertex
                                depend on the D3DTSS_TEXTURETRANSFORMFLAGS */
-                            if (coordsToUse>0 && 
+                            if (coordsToUse > 0 && 
                                 This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXTURETRANSFORMFLAGS] != D3DTTFF_DISABLE) 
                             {
                                /* This indicates how many coords to use regardless of the
@@ -589,7 +491,7 @@
                             switch (coordsToUse) {   /* Supply the provided texture coords */
                             case D3DFVF_TEXTUREFORMAT1:
                                 VTRACE(("tex:%d, s=%f\n", textureNo, s[coordIdx]));
-                                if (This->isMultiTexture) {
+                                if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                                     glMultiTexCoord1f(GL_TEXTURE0 + textureNo, s[coordIdx]);
 #else
@@ -601,7 +503,7 @@
                                 break;
                             case D3DFVF_TEXTUREFORMAT2:
                                 VTRACE(("tex:%d, s=%f, t=%f\n", textureNo, s[coordIdx], t[coordIdx]));
-                                if (This->isMultiTexture) {
+                                if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                                     glMultiTexCoord2f(GL_TEXTURE0 + textureNo, s[coordIdx], t[coordIdx]);
 #else
@@ -613,7 +515,7 @@
                                 break;
                             case D3DFVF_TEXTUREFORMAT3:
                                 VTRACE(("tex:%d, s=%f, t=%f, r=%f\n", textureNo, s[coordIdx], t[coordIdx], r[coordIdx]));
-                                if (This->isMultiTexture) {
+                                if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                                     glMultiTexCoord3f(GL_TEXTURE0 + textureNo, s[coordIdx], t[coordIdx], r[coordIdx]);
 #else
@@ -625,7 +527,7 @@
                                 break;
                             case D3DFVF_TEXTUREFORMAT4:
                                 VTRACE(("tex:%d, s=%f, t=%f, r=%f, q=%f\n", textureNo, s[coordIdx], t[coordIdx], r[coordIdx], q[coordIdx]));
-                                if (This->isMultiTexture) {
+                                if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                                     glMultiTexCoord4f(GL_TEXTURE0 + textureNo, s[coordIdx], t[coordIdx], r[coordIdx], q[coordIdx]);
 #else
@@ -696,18 +598,18 @@
 #if defined(GL_VERSION_1_4)
 		    glSecondaryColor3fv((float*) &vertex_shader->output.oD[1]);
 		    checkGLcall("glSecondaryColor3fv");
-#else
-		    if (checkGLSupport(EXT_SECONDARY_COLOR)) {
-		      /*specularColor = D3DCOLOR_COLORVALUE(vertex_shader->output.oD[1]);*/
-		      /*GLExtCall(glSecondaryColor3fvEXT)((float*) &vertex_shader->output.oD[1]);*/
-		      /*checkGLcall("glSecondaryColor3fvEXT");*/
+#elif defined(GL_EXT_secondary_color)
+		    if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+		      /*specularColor = D3DCOLORTOCOLORVALUE(vertex_shader->output.oD[1]);*/
+		      glSecondaryColor3fvEXT((float*) &vertex_shader->output.oD[1]);
+		      checkGLcall("glSecondaryColor3fvEXT");
 		    }
 #endif
                     /** reupdate textures coords binding using vertex_shader->output.oT[0->3] */
                     for (textureNo = 0; textureNo < 4; ++textureNo) {
                         float s, t, r, q;
 
-                        if (!(This->isMultiTexture) && textureNo > 0) {
+                        if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0) {
                             FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
                             continue ;
                         }
@@ -722,7 +624,7 @@
                                 if (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXCOORDINDEX] > 7) {
                                     VTRACE(("Skip tex coords, as being system generated\n"));
                                 } else {
-                                    if (This->isMultiTexture) {
+                                    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                                         glMultiTexCoord2f(GL_TEXTURE0 + textureNo, s, t);
 #else
@@ -745,7 +647,7 @@
                                 if (This->UpdateStateBlock->texture_state[textureNo][D3DTSS_TEXCOORDINDEX] > 7) {
                                     VTRACE(("Skip tex coords, as being system generated\n"));
                                 } else {
-                                    if (This->isMultiTexture) {
+                                    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                                         glMultiTexCoord3f(GL_TEXTURE0 + textureNo, s, t, r); 
 #else
@@ -846,30 +748,34 @@
                /* no such functionality in the fixed function GL pipeline */
                /* FIXME: Wont get here as will drop to slow method        */
    	       /* FIXME("Cannot handle blending data here in openGl\n");*/
-	       if (checkGLSupport(ARB_VERTEX_BLEND)) {
-		  FIXME("TODO\n");
-	       } else if (checkGLSupport(EXT_VERTEX_WEIGHTING)) {
-		  FIXME("TODO\n");
+#if 0
+	       if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
+		 /*FIXME("TODO\n");*/
+	       } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
+		 /*FIXME("TODO\n");*/
 		  /*
 		  GLExtCall(glVertexWeightPointerEXT)(numBlends, GL_FLOAT, skip, curPos); 
 		  checkGLcall("glVertexWeightPointerEXT(numBlends, ...)");
 		  glEnableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT);
 		  checkGLcall("glEnableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT)");
 		  */
-		  curPos += numBlends * sizeof(float);
 	       } else {
 		  FIXME("unsupported blending in openGl\n");
 	       }
+#endif
+	       curPos += numBlends * sizeof(float);
             } else {
-	       if (checkGLSupport(ARB_VERTEX_BLEND)) {
+#if 0
+	       if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
 		  FIXME("TODO\n");
-	       } else if (checkGLSupport(EXT_VERTEX_WEIGHTING)) {
+	       } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
 		  FIXME("TODO\n");
 		  /*
 		  glDisableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT);
 		  checkGLcall("glDisableClientState(GL_VERTEX_WEIGHT_ARRAY_EXT)");
 		  */
 	       }
+#endif
 	    }
 
  
@@ -914,14 +820,14 @@
                 checkGLcall("glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, skip, curPos)");
                 glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
                 checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY)");
-#else
-# if 0
+#elif defined(GL_EXT_secondary_color)
                 /* FIXME: check for GL_EXT_secondary_color */
-                glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, skip, curPos);
-                checkGLcall("glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, skip, curPos)");
-                glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
-                checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
-# endif
+		if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+		  glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, skip, curPos);
+		  checkGLcall("glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, skip, curPos)");
+		  glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
+		  checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
+		}
 #endif
                 curPos += sizeof(DWORD);
             } else {
@@ -971,9 +877,9 @@
             }
 
             /* Now use the appropriate set of texture indexes */
-            for (textureNo = 0; textureNo < This->TextureUnits; ++textureNo) {
+            for (textureNo = 0; textureNo < GL_LIMITS(textures); ++textureNo) {
 
-                if (!(This->isMultiTexture) && textureNo > 0) {
+                if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0) {
                     FIXME("Program using multiple concurrent textures which this opengl implementation doesnt support\n");
                     continue ;
                 }
@@ -1079,167 +985,6 @@
     TRACE("glEnd\n");
 }
 
-/*
- * Simple utility routines used for dx -> gl mapping of byte formats
- */
-SHORT bytesPerPixel(D3DFORMAT fmt) {
-    SHORT retVal;
-
-    switch (fmt) {
-    /* color buffer */
-    case D3DFMT_P8:               retVal = 1; break;
-    case D3DFMT_A4R4G4B4:         retVal = 2; break;
-    case D3DFMT_R5G6B5:           retVal = 2; break;
-    case D3DFMT_X1R5G5B5:         retVal = 2; break;
-    case D3DFMT_A1R5G5B5:         retVal = 2; break;
-    case D3DFMT_R8G8B8:           retVal = 3; break;
-    case D3DFMT_X8R8G8B8:         retVal = 4; break;
-    case D3DFMT_A8R8G8B8:         retVal = 4; break;
-    /* depth/stencil buffer */
-    case D3DFMT_D16_LOCKABLE:     retVal = 2; break;
-    case D3DFMT_D16:              retVal = 2; break;
-    case D3DFMT_D15S1:            retVal = 2; break;
-    case D3DFMT_D24X4S4:          retVal = 4; break;
-    case D3DFMT_D24S8:            retVal = 4; break;
-    case D3DFMT_D24X8:            retVal = 4; break;
-    case D3DFMT_D32:              retVal = 4; break;
-    /* unknown */				  
-    case D3DFMT_UNKNOWN:
-      /* Guess at the highest value of the above */
-      TRACE("D3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
-      retVal = 4;
-      break;
-
-    default:
-      FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
-      retVal = 4;
-    }
-    TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
-    return retVal;
-}
-
-GLint fmt2glintFmt(D3DFORMAT fmt) {
-    GLint retVal;
-
-    switch (fmt) {
-    case D3DFMT_A4R4G4B4:         retVal = GL_RGBA4; break;
-    case D3DFMT_A8R8G8B8:         retVal = GL_RGBA8; break;
-    case D3DFMT_X8R8G8B8:         retVal = GL_RGB8; break;
-    case D3DFMT_R8G8B8:           retVal = GL_RGB8; break;
-    case D3DFMT_R5G6B5:           retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
-    case D3DFMT_A1R5G5B5:         retVal = GL_RGB5_A1; break;
-    default:
-        FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
-        retVal = GL_RGB8;
-    }
-    TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
-    return retVal;
-}
-GLenum fmt2glFmt(D3DFORMAT fmt) {
-    GLenum retVal;
-
-    switch (fmt) {
-    case D3DFMT_A4R4G4B4:         retVal = GL_BGRA; break;
-    case D3DFMT_A8R8G8B8:         retVal = GL_BGRA; break;
-    case D3DFMT_X8R8G8B8:         retVal = GL_BGRA; break;
-    case D3DFMT_R8G8B8:           retVal = GL_BGR; break;
-    case D3DFMT_R5G6B5:           retVal = GL_RGB; break;
-    case D3DFMT_A1R5G5B5:         retVal = GL_BGRA; break;
-    default:
-        FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
-        retVal = GL_BGR;
-    }
-    TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
-    return retVal;
-}
-DWORD fmt2glType(D3DFORMAT fmt) {
-    GLenum retVal;
-
-    switch (fmt) {
-    case D3DFMT_A4R4G4B4:         retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
-    case D3DFMT_A8R8G8B8:         retVal = GL_UNSIGNED_BYTE; break;
-    case D3DFMT_X8R8G8B8:         retVal = GL_UNSIGNED_BYTE; break;
-    case D3DFMT_R5G6B5:           retVal = GL_UNSIGNED_SHORT_5_6_5; break;
-    case D3DFMT_R8G8B8:           retVal = GL_UNSIGNED_BYTE; break;
-    case D3DFMT_A1R5G5B5:         retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
-    default:
-        FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
-        retVal = GL_UNSIGNED_BYTE;
-    }
-    TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
-    return retVal;
-}
-
-int SOURCEx_RGB_EXT(DWORD arg) {
-    switch(arg) {
-    case D3DTSS_COLORARG0: return GL_SOURCE2_RGB_EXT;
-    case D3DTSS_COLORARG1: return GL_SOURCE0_RGB_EXT;
-    case D3DTSS_COLORARG2: return GL_SOURCE1_RGB_EXT;
-    case D3DTSS_ALPHAARG0:
-    case D3DTSS_ALPHAARG1:
-    case D3DTSS_ALPHAARG2:
-    default:
-        FIXME("Invalid arg %ld\n", arg);
-        return GL_SOURCE0_RGB_EXT;
-    }
-}
-int OPERANDx_RGB_EXT(DWORD arg) {
-    switch(arg) {
-    case D3DTSS_COLORARG0: return GL_OPERAND2_RGB_EXT;
-    case D3DTSS_COLORARG1: return GL_OPERAND0_RGB_EXT;
-    case D3DTSS_COLORARG2: return GL_OPERAND1_RGB_EXT;
-    case D3DTSS_ALPHAARG0:
-    case D3DTSS_ALPHAARG1:
-    case D3DTSS_ALPHAARG2:
-    default:
-        FIXME("Invalid arg %ld\n", arg);
-        return GL_OPERAND0_RGB_EXT;
-    }
-}
-int SOURCEx_ALPHA_EXT(DWORD arg) {
-    switch(arg) {
-    case D3DTSS_ALPHAARG0:  return GL_SOURCE2_ALPHA_EXT;
-    case D3DTSS_ALPHAARG1:  return GL_SOURCE0_ALPHA_EXT;
-    case D3DTSS_ALPHAARG2:  return GL_SOURCE1_ALPHA_EXT;
-    case D3DTSS_COLORARG0:
-    case D3DTSS_COLORARG1:
-    case D3DTSS_COLORARG2:
-    default:
-        FIXME("Invalid arg %ld\n", arg);
-        return GL_SOURCE0_ALPHA_EXT;
-    }
-}
-int OPERANDx_ALPHA_EXT(DWORD arg) {
-    switch(arg) {
-    case D3DTSS_ALPHAARG0:  return GL_OPERAND2_ALPHA_EXT;
-    case D3DTSS_ALPHAARG1:  return GL_OPERAND0_ALPHA_EXT;
-    case D3DTSS_ALPHAARG2:  return GL_OPERAND1_ALPHA_EXT;
-    case D3DTSS_COLORARG0:
-    case D3DTSS_COLORARG1:
-    case D3DTSS_COLORARG2:
-    default:
-        FIXME("Invalid arg %ld\n", arg);
-        return GL_OPERAND0_ALPHA_EXT;
-    }
-}
-GLenum StencilOp(DWORD op) {
-    switch(op) {                
-    case D3DSTENCILOP_KEEP    : return GL_KEEP;
-    case D3DSTENCILOP_ZERO    : return GL_ZERO;
-    case D3DSTENCILOP_REPLACE : return GL_REPLACE;
-    case D3DSTENCILOP_INCRSAT : return GL_INCR;
-    case D3DSTENCILOP_DECRSAT : return GL_DECR;
-    case D3DSTENCILOP_INVERT  : return GL_INVERT;
-    case D3DSTENCILOP_INCR    : FIXME("Unsupported stencil op D3DSTENCILOP_INCR\n");
-                                return GL_INCR; /* Fixme - needs to support wrap */
-    case D3DSTENCILOP_DECR    : FIXME("Unsupported stencil op D3DSTENCILOP_DECR\n");
-                                return GL_DECR; /* Fixme - needs to support wrap */
-    default:
-        FIXME("Invalid stencil op %ld\n", op);
-        return GL_ALWAYS;
-    }
-}
-
 /**
  * @nodoc: todo
  */
@@ -1305,7 +1050,6 @@
   }
 }
 
-
 /* Apply the current values to the specified texture stage */
 void setupTextureStates(LPDIRECT3DDEVICE8 iface, DWORD Stage) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
@@ -1313,7 +1057,7 @@
     float col[4];
 
     /* Make appropriate texture active */
-    if (This->isMultiTexture) {
+    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
         glActiveTexture(GL_TEXTURE0 + Stage);
 #else
@@ -1330,13 +1074,8 @@
     }
 
     /* Note the D3DRS value applies to all textures, but GL has one
-       per texture, so apply it now ready to be used!               */
-#if 0
-    col[0] = ((This->StateBlock->renderstate[D3DRS_TEXTUREFACTOR]>> 16) & 0xFF) / 255.0;
-    col[1] = ((This->StateBlock->renderstate[D3DRS_TEXTUREFACTOR] >> 8 ) & 0xFF) / 255.0;
-    col[2] = ((This->StateBlock->renderstate[D3DRS_TEXTUREFACTOR] >> 0 ) & 0xFF) / 255.0;
-    col[3] = ((This->StateBlock->renderstate[D3DRS_TEXTUREFACTOR] >> 24 ) & 0xFF) / 255.0;
-#endif
+     *  per texture, so apply it now ready to be used!
+     */
     D3DCOLORTOGLFLOAT4(This->StateBlock->renderstate[D3DRS_TEXTUREFACTOR], col);
     glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, &col[0]);
     checkGLcall("glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);");
@@ -1371,7 +1110,8 @@
     ULONG ref = --This->ref;
     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
     if (ref == 0) {
-        HeapFree(GetProcessHeap(), 0, This);
+      IDirect3DDevice8Impl_CleanRender(iface);
+      HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
 }
@@ -1447,20 +1187,39 @@
     return D3D_OK;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap) {
+    IDirect3DSurface8Impl* pSur = (IDirect3DSurface8Impl*) pCursorBitmap;
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);    return D3D_OK;
+    TRACE("(%p) : Spot Pos(%u,%u)\n", This, XHotSpot, YHotSpot);
+
+    if (D3DFMT_A8R8G8B8 != pSur->myDesc.Format) {
+      ERR("(%p) : surface(%p) have a invalid format\n", This, pCursorBitmap);
+      return D3DERR_INVALIDCALL;
+    }
+    if (32 != pSur->myDesc.Height || 32 != pSur->myDesc.Width) {
+      ERR("(%p) : surface(%p) have a invalid size\n", This, pCursorBitmap);
+      return D3DERR_INVALIDCALL;
+    }
+
+    This->xHotSpot = XHotSpot;
+    This->yHotSpot = YHotSpot;
+    return D3D_OK;
 }
-void     WINAPI  IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace,DWORD Flags) {
+void     WINAPI  IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);    return;
+    TRACE("(%p) : SetPos to (%u,%u)\n", This, XScreenSpace, YScreenSpace);
+    This->xScreenSpace = XScreenSpace;
+    This->yScreenSpace = YScreenSpace;
+    return;
 }
 BOOL     WINAPI  IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);    return D3D_OK;
+    TRACE("(%p) : visible(%d)\n", This, bShow); 
+    This->bCursorVisible = bShow;
+    return D3D_OK;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);    
+    FIXME("(%p) : stub\n", This);
     *pSwapChain = NULL;
     return D3D_OK;
 }
@@ -1474,7 +1233,7 @@
 
     ENTER_GL();
 
-    glXSwapBuffers(This->display, This->win);
+    glXSwapBuffers(This->display, This->drawable);
     checkGLcall("glXSwapBuffers");
 
     LEAVE_GL();
@@ -1501,16 +1260,18 @@
     FIXME("(%p) : stub\n", This);    
     return D3D_OK;
 }
-void     WINAPI  IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags,CONST D3DGAMMARAMP* pRamp) {
+void     WINAPI  IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);    return;
+    FIXME("(%p) : stub\n", This);
+    return;
 }
 void     WINAPI  IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);    return;
+    FIXME("(%p) : stub\n", This);
+    return;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
-                                                    D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture8** ppTexture) {
+                                                    D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8** ppTexture) {
     IDirect3DTexture8Impl *object;
     int i;
     UINT tmpW;
@@ -1523,7 +1284,6 @@
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
     object->lpVtbl = &Direct3DTexture8_Vtbl;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->device);*/
     object->ResourceType = D3DRTYPE_TEXTURE;
     object->ref = 1;
     object->width = Width;
@@ -1532,7 +1292,6 @@
     object->usage = Usage;
     object->format = Format;
 
-
     /* Calculate levels for mip mapping */
     if (Levels == 0) {
         object->levels++;
@@ -1553,9 +1312,15 @@
     {
         IDirect3DDevice8Impl_CreateImageSurface(iface, tmpW, tmpH, Format, (LPDIRECT3DSURFACE8*) &object->surfaces[i]);
         object->surfaces[i]->Container = (IUnknown*) object;
-	/*IUnknown_AddRef(object->surfaces[i]->Container);*/
         object->surfaces[i]->myDesc.Usage = Usage;
-        object->surfaces[i]->myDesc.Pool = Pool ;
+        object->surfaces[i]->myDesc.Pool = Pool;
+	/** 
+	 * As writen in msdn in IDirect3DTexture8::LockRect
+	 *  Textures created in D3DPOOL_DEFAULT are not lockable.
+	 */
+	if (D3DPOOL_DEFAULT == Pool) {
+	  object->surfaces[i]->lockable = FALSE;
+	}
 
         TRACE("Created surface level %d @ %p, memory at %p\n", i, object->surfaces[i], object->surfaces[i]->allocatedMemory);
         tmpW = max(1, tmpW / 2);
@@ -1565,7 +1330,9 @@
     *ppTexture = (LPDIRECT3DTEXTURE8) object;
     return D3D_OK;
 }
-HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface, UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture8** ppVolumeTexture) {
+HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface, 
+                                                          UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, 
+                                                          D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
 
     IDirect3DVolumeTexture8Impl *object;
     int i;
@@ -1581,7 +1348,6 @@
     object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
     object->ResourceType = D3DRTYPE_VOLUMETEXTURE;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ref = 1;
 
     object->width = Width;
@@ -1613,7 +1379,7 @@
 
     for (i = 0; i < object->levels; i++) 
     {
-        IDirect3DVolume8Impl *volume;
+        IDirect3DVolume8Impl* volume;
 
         /* Create the volume - No entry point for this seperately?? */
         volume  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolume8Impl));
@@ -1621,10 +1387,8 @@
 
         volume->lpVtbl = &Direct3DVolume8_Vtbl;
         volume->Device = This;
-	/*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) volume->Device);*/
         volume->ResourceType = D3DRTYPE_VOLUME;
         volume->Container = (IUnknown*) object;
-	/*IUnknown_AddRef(volume->Container);*/	
         volume->ref = 1;
 
         volume->myDesc.Width  = Width;
@@ -1634,12 +1398,13 @@
         volume->myDesc.Type   = D3DRTYPE_VOLUME;
         volume->myDesc.Pool   = Pool;
         volume->myDesc.Usage  = Usage;
-        volume->bytesPerPixel   = bytesPerPixel(Format);
+        volume->bytesPerPixel   = D3DFmtGetBpp(Format);
         volume->myDesc.Size     = (Width * volume->bytesPerPixel) * Height * Depth;
         volume->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, volume->myDesc.Size);
 
-        TRACE("(%p) : Volume at w(%d) h(%d) d(%d) fmt(%u,%s) surf@%p, surfmem@%p, %d bytes\n", This, Width, Height, Depth, Format, debug_d3dformat(Format),
-                  volume, volume->allocatedMemory, volume->myDesc.Size);
+        TRACE("(%p) : Volume at w(%d) h(%d) d(%d) fmt(%u,%s) surf@%p, surfmem@%p, %d bytes\n", 
+              This, Width, Height, Depth, Format, debug_d3dformat(Format),
+              volume, volume->allocatedMemory, volume->myDesc.Size);
 
         tmpW = max(1, tmpW / 2);
         tmpH = max(1, tmpH / 2);
@@ -1649,7 +1414,8 @@
     *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
     return D3D_OK;
 }
-HRESULT  WINAPI  IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
+HRESULT  WINAPI  IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage, 
+                                                        D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
 
     IDirect3DCubeTexture8Impl *object;
     ICOM_THIS(IDirect3DDevice8Impl,iface);
@@ -1662,7 +1428,6 @@
     object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
     object->ref = 1;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ResourceType = D3DRTYPE_CUBETEXTURE;
 
     object->edgeLength = EdgeLength;
@@ -1688,10 +1453,15 @@
         for (j = 0; j < 6; j++) {
            IDirect3DDevice8Impl_CreateImageSurface(iface, tmpW, tmpW, Format, (LPDIRECT3DSURFACE8*) &object->surfaces[j][i]);
            object->surfaces[j][i]->Container = (IUnknown*) object;
-	   /*IUnknown_AddRef(object->surfaces[j][i]->Container);*/
            object->surfaces[j][i]->myDesc.Usage = Usage;
            object->surfaces[j][i]->myDesc.Pool = Pool;
-	   /*object->surfaces[j][i]->myDesc.Format = Format;*/
+	   /** 
+	    * As writen in msdn in IDirect3DCubeTexture8::LockRect
+	    *  Textures created in D3DPOOL_DEFAULT are not lockable.
+	    */
+	   if (D3DPOOL_DEFAULT == Pool) {
+	     object->surfaces[j][i]->lockable = FALSE;
+	   }
 
            TRACE("Created surface level %d @ %p, memory at %p\n", i, object->surfaces[j][i], object->surfaces[j][i]->allocatedMemory);
            tmpW = max(1, tmpW / 2);
@@ -1711,7 +1481,6 @@
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
     object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ResourceType = D3DRTYPE_VERTEXBUFFER;
     object->ref = 1;
     object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
@@ -1736,7 +1505,6 @@
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DIndexBuffer8Impl));
     object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ref = 1;
     object->ResourceType = D3DRTYPE_INDEXBUFFER;
 
@@ -1756,7 +1524,6 @@
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
     IDirect3DSurface8Impl *object;
-
     ICOM_THIS(IDirect3DDevice8Impl,iface);
     
     object  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
@@ -1767,10 +1534,8 @@
     *ppSurface = (LPDIRECT3DSURFACE8) object;
     object->lpVtbl = &Direct3DSurface8_Vtbl;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ResourceType = D3DRTYPE_SURFACE;
     object->Container = (IUnknown*) This;
-    /*IUnknown_AddRef(object->Container);*/
 
     object->ref = 1;
     object->myDesc.Width  = Width;
@@ -1780,12 +1545,12 @@
     object->myDesc.Usage = D3DUSAGE_RENDERTARGET;
     object->myDesc.Pool = D3DPOOL_DEFAULT;
     object->myDesc.MultiSampleType = MultiSample;
-    object->bytesPerPixel = bytesPerPixel(Format);
+    object->bytesPerPixel = D3DFmtGetBpp(Format);
     object->myDesc.Size = (Width * object->bytesPerPixel) * Height;
     object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->myDesc.Size);
     object->lockable = Lockable;
     object->locked = FALSE;
-
+    
     TRACE("(%p) : w(%d) h(%d) fmt(%d,%s) lockable(%d) surf@%p, surfmem@%p, %d bytes\n", This, Width, Height, Format, debug_d3dformat(Format), Lockable, *ppSurface, object->allocatedMemory, object->myDesc.Size);
     return D3D_OK;
 }
@@ -1802,10 +1567,8 @@
     *ppSurface = (LPDIRECT3DSURFACE8) object;
     object->lpVtbl = &Direct3DSurface8_Vtbl;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ResourceType = D3DRTYPE_SURFACE;
     object->Container = (IUnknown*) This;
-    /*IUnknown_AddRef(object->Container);*/
 
     object->ref = 1;
     object->myDesc.Width  = Width;
@@ -1815,12 +1578,12 @@
     object->myDesc.Usage = D3DUSAGE_DEPTHSTENCIL;
     object->myDesc.Pool = D3DPOOL_DEFAULT;
     object->myDesc.MultiSampleType = MultiSample;
-    object->bytesPerPixel = bytesPerPixel(Format);
+    object->bytesPerPixel = D3DFmtGetBpp(Format);
     object->myDesc.Size = (Width * object->bytesPerPixel) * Height;
     object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->myDesc.Size);
     object->lockable = (D3DFMT_D16_LOCKABLE == Format) ? TRUE : FALSE;
     object->locked = FALSE;
-
+        
     TRACE("(%p) : w(%d) h(%d) fmt(%d,%s) surf@%p, surfmem@%p, %d bytes\n", This, Width, Height, Format, debug_d3dformat(Format), *ppSurface, object->allocatedMemory, object->myDesc.Size);
     return D3D_OK;
 }
@@ -1833,10 +1596,8 @@
     *ppSurface = (LPDIRECT3DSURFACE8) object;
     object->lpVtbl = &Direct3DSurface8_Vtbl;
     object->Device = This;
-    /*IDirect3DDevice8Impl_AddRef((LPDIRECT3DDEVICE8) object->Device);*/
     object->ResourceType = D3DRTYPE_SURFACE;
     object->Container = (IUnknown*) This;
-    /*IUnknown_AddRef(object->Container);*/
 
     object->ref = 1;
     object->myDesc.Width  = Width;
@@ -1845,7 +1606,7 @@
     object->myDesc.Type = D3DRTYPE_SURFACE;
     object->myDesc.Usage = 0;
     object->myDesc.Pool = D3DPOOL_SYSTEMMEM;
-    object->bytesPerPixel = bytesPerPixel(Format);
+    object->bytesPerPixel = D3DFmtGetBpp(Format);
     object->myDesc.Size = (Width * object->bytesPerPixel) * Height;
     object->allocatedMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->myDesc.Size);
     object->lockable = TRUE;
@@ -1854,10 +1615,11 @@
     TRACE("(%p) : w(%d) h(%d) fmt(%d,%s) surf@%p, surfmem@%p, %d bytes\n", This, Width, Height, Format, debug_d3dformat(Format), *ppSurface, object->allocatedMemory, object->myDesc.Size);
     return D3D_OK;
 }
-HRESULT  WINAPI  IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pSourceSurface,CONST RECT* pSourceRectsArray,UINT cRects,
-                                                IDirect3DSurface8* pDestinationSurface,CONST POINT* pDestPointsArray) {
+HRESULT  WINAPI  IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, 
+                                                IDirect3DSurface8* pSourceSurface, CONST RECT* pSourceRectsArray, UINT cRects,
+                                                IDirect3DSurface8* pDestinationSurface, CONST POINT* pDestPointsArray) {
 
-    HRESULT rc      = D3D_OK;
+    HRESULT rc = D3D_OK;
     IDirect3DBaseTexture8* texture = NULL;
 
 
@@ -1865,13 +1627,15 @@
     IDirect3DSurface8Impl* dst = (IDirect3DSurface8Impl*) pDestinationSurface;
 
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    TRACE("(%p) srcsur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", This,
+    TRACE("(%p) pSrcSur=%p, pSourceRects=%p, cRects=%d, pDstSur=%p, pDestPtsArr=%p\n", This,
           pSourceSurface, pSourceRectsArray, cRects, pDestinationSurface, pDestPointsArray);
 
     /* Note: Not sure about the d3dfmt_unknown bit, but seems to avoid a problem inside
          a sample and doesnt seem to break anything as far as I can tell               */
     if (src->myDesc.Format != dst->myDesc.Format && (dst->myDesc.Format != D3DFMT_UNKNOWN)) {
-        TRACE("Formats do not match %x / %x\n", src->myDesc.Format, dst->myDesc.Format);
+        TRACE("Formats do not match (%x,%s) / (%x,%s)\n", 
+               src->myDesc.Format, debug_d3dformat(src->myDesc.Format), 
+               dst->myDesc.Format, debug_d3dformat(dst->myDesc.Format));
         rc = D3DERR_INVALIDCALL;
 
     } else if (dst->myDesc.Format == D3DFMT_UNKNOWN) {
@@ -1881,23 +1645,10 @@
         /* Convert container as well */
         IDirect3DSurface8Impl_GetContainer((LPDIRECT3DSURFACE8) dst, &IID_IDirect3DBaseTexture8, (void**) &texture); /* FIXME: Which refid? */
         if (texture != NULL) {
-
-            switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) texture)) {
-            case D3DRTYPE_TEXTURE:
-                ((IDirect3DTexture8Impl *)texture)->format = src->myDesc.Format;
-                break;
-            case D3DRTYPE_VOLUMETEXTURE:
-                ((IDirect3DVolumeTexture8Impl *)texture)->format = src->myDesc.Format;
-                break;
-            case D3DRTYPE_CUBETEXTURE:
-                ((IDirect3DCubeTexture8Impl *)texture)->format = src->myDesc.Format;
-                break;
-            default:
-                FIXME("Unhandled texture type\n");
-            }
-
+            ((IDirect3DBaseTexture8Impl*) texture)->format = src->myDesc.Format;
 	    /** Releasing texture after GetContainer */
-	    IDirect3DBaseTexture8_Release(texture);   
+	    IDirect3DBaseTexture8_Release(texture);
+	    texture = NULL;
         }
     }
 
@@ -1916,7 +1667,7 @@
 	memcpy(lrDst.pBits, lrSrc.pBits, src->myDesc.Size);
  
         IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) src);
-        IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) dst);
+        rc = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) dst);
         TRACE("Unlocked src and dst\n");
 
       } else {
@@ -1930,15 +1681,7 @@
 
       if (NULL != pSourceRectsArray && NULL != pDestPointsArray) {
 
-        int bytesPerPixel = ((IDirect3DSurface8Impl *)pSourceSurface)->bytesPerPixel;
-#if 0
-	int pitchFrom     = ((IDirect3DSurface8Impl *)pSourceSurface)->myDesc.Width * bytesPerPixel;
-        int pitchTo       = ((IDirect3DSurface8Impl *)pDestinationSurface)->myDesc.Width * bytesPerPixel;
-        char *copyfrom = ((IDirect3DSurface8Impl *)pSourceSurface)->allocatedMemory;
-        char *copyto   = ((IDirect3DSurface8Impl *)pDestinationSurface)->allocatedMemory;
-        char *from;
-        char *to;
-#endif
+        int bytesPerPixel = ((IDirect3DSurface8Impl*) pSourceSurface)->bytesPerPixel;
         int i;
         /* Copy rect by rect */
         for (i = 0; i < cRects; i++) {
@@ -1976,7 +1719,7 @@
 	    }
 
             IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) src);
-            IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) dst);
+            rc = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) dst);
             TRACE("Unlocked src and dst\n");
         }
       
@@ -1988,44 +1731,76 @@
       }
     }
 
-    /* Set dirty */
-    if (rc == D3D_OK) {
-        IDirect3DSurface8Impl_GetContainer((LPDIRECT3DSURFACE8) dst, &IID_IDirect3DBaseTexture8, (void**) &texture); /* FIXME: Which refid? */
-        if (texture != NULL) {
-
-            switch (IDirect3DBaseTexture8Impl_GetType((LPDIRECT3DBASETEXTURE8) texture)) {
-            case D3DRTYPE_TEXTURE:
-                {
-                    IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)texture;
-                    pTexture->Dirty = TRUE;
-                }
-                break;
-            case D3DRTYPE_VOLUMETEXTURE:
-                {
-                    IDirect3DVolumeTexture8Impl *pTexture = (IDirect3DVolumeTexture8Impl *)texture;
-                    pTexture->Dirty = TRUE;
-                }
-                break;
-            case D3DRTYPE_CUBETEXTURE:
-                {
-                    IDirect3DCubeTexture8Impl *pTexture = (IDirect3DCubeTexture8Impl *)texture;
-                    pTexture->Dirty = TRUE;
-                }
-                break;
-            default:
-                FIXME("Unhandled texture type\n");
-            }
-
-	    /** Releasing texture after GetContainer */
-	    IDirect3DBaseTexture8_Release(texture);
-        }
-    }
-
-    return D3D_OK;
+    return rc;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture) {
+    IDirect3DBaseTexture8Impl* src = (IDirect3DBaseTexture8Impl*) pSourceTexture;
+    IDirect3DBaseTexture8Impl* dst = (IDirect3DBaseTexture8Impl*) pDestinationTexture;
+    D3DRESOURCETYPE srcType;
+    D3DRESOURCETYPE dstType;
+
     ICOM_THIS(IDirect3DDevice8Impl,iface);
-    FIXME("(%p) : stub\n", This);
+    TRACE("(%p) : first try\n", This);
+
+    srcType = IDirect3DBaseTexture8Impl_GetType(pSourceTexture);
+    dstType = IDirect3DBaseTexture8Impl_GetType(pDestinationTexture);
+
+    if (srcType != dstType) {
+      return D3DERR_INVALIDCALL;
+    }
+    if (D3DPOOL_SYSTEMMEM != IDirect3DResource8Impl_GetPool((LPDIRECT3DRESOURCE8) src)) {
+      return D3DERR_INVALIDCALL;
+    }
+    if (D3DPOOL_DEFAULT != IDirect3DResource8Impl_GetPool((LPDIRECT3DRESOURCE8) dst)) {
+      return D3DERR_INVALIDCALL;
+    }
+    if (IDirect3DBaseTexture8Impl_IsDirty(pSourceTexture)) {
+      /** Only copy Dirty textures */
+      DWORD srcLevelCnt = IDirect3DBaseTexture8Impl_GetLevelCount(pSourceTexture);
+      DWORD dstLevelCnt = IDirect3DBaseTexture8Impl_GetLevelCount(pDestinationTexture);
+      DWORD skipLevels = (dstLevelCnt < srcLevelCnt) ? srcLevelCnt - dstLevelCnt : 0;
+      UINT i, j;
+
+      for (i = skipLevels; i < srcLevelCnt; ++i) {
+	HRESULT hr;
+
+	switch (srcType) { 
+	case D3DRTYPE_TEXTURE:
+	  {
+	    IDirect3DSurface8* srcSur = NULL;
+	    IDirect3DSurface8* dstSur = NULL;
+	    hr = IDirect3DTexture8Impl_GetSurfaceLevel((LPDIRECT3DTEXTURE8) src, i, &srcSur);
+	    hr = IDirect3DTexture8Impl_GetSurfaceLevel((LPDIRECT3DTEXTURE8) dst, i - skipLevels, &dstSur);
+	    /*IDirect3DDevice8_CopyRects*/
+	    IDirect3DSurface8Impl_Release(srcSur);
+	    IDirect3DSurface8Impl_Release(dstSur);
+	  }
+	  break;
+	case D3DRTYPE_VOLUMETEXTURE:
+	  {
+	    FIXME("D3DRTYPE_VOLUMETEXTURE reload currently not implemented\n");
+	  }
+	  break;
+	case D3DRTYPE_CUBETEXTURE:
+	  {
+	    IDirect3DSurface8* srcSur = NULL;
+	    IDirect3DSurface8* dstSur = NULL;
+	    for (j = 0; j < 5; ++j) {
+	      hr = IDirect3DCubeTexture8Impl_GetCubeMapSurface((LPDIRECT3DCUBETEXTURE8) src, j, i, &srcSur);
+	      hr = IDirect3DCubeTexture8Impl_GetCubeMapSurface((LPDIRECT3DCUBETEXTURE8) dst, j, i - skipLevels, &srcSur);
+	      /*IDirect3DDevice8_CopyRects*/
+	      IDirect3DSurface8Impl_Release(srcSur);
+	      IDirect3DSurface8Impl_Release(dstSur);
+	    }
+	  }
+	  break;
+	default:
+	  break;
+	}
+      }
+      IDirect3DBaseTexture8Impl_SetDirty(pSourceTexture, FALSE);
+    }
+    
     return D3D_OK;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface) {
@@ -2089,10 +1864,6 @@
 	vcheckGLcall("glReadPixels");
       }
     }
-    /*
-    glReadPixels(0, 0, This->PresentParms.BackBufferWidth, This->PresentParms.BackBufferHeight,
-		 GL_BGRA, GL_UNSIGNED_BYTE, lockedRect.pBits);
-    */
     glPixelStorei(GL_PACK_SWAP_BYTES, prev_store);
     vcheckGLcall("glPixelStorei");
     glReadBuffer(prev_read);
@@ -2104,34 +1875,47 @@
     return hr;
 }
 HRESULT  WINAPI  IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil) {
+    HRESULT hr;
+
     ICOM_THIS(IDirect3DDevice8Impl,iface);
 
-    if ((IDirect3DSurface8Impl*) pRenderTarget == This->frontBuffer && (IDirect3DSurface8Impl*) pNewZStencil == This->depthStencilBuffer) {
+    if ((IDirect3DSurface8Impl*) pRenderTarget == This->renderTarget && (IDirect3DSurface8Impl*) pNewZStencil == This->stencilBufferTarget) {
       TRACE("Trying to do a NOP SetRenderTarget operation\n");
       return D3D_OK;
     }
-    
-    FIXME("(%p) : invalid stub expect crash newRender@%p newZStencil@%p\n", This, pRenderTarget, pNewZStencil);
 
-    return D3D_OK;
+    IDirect3DDevice8Impl_CleanRender(iface);
+
+    if ((IDirect3DSurface8Impl*) pRenderTarget == This->frontBuffer && (IDirect3DSurface8Impl*) pNewZStencil == This->depthStencilBuffer) {
+      TRACE("retoring SetRenderTarget defaults\n");
+      return D3D_OK;
+    }
+
+    TRACE("(%p) : expect crash newRender@%p newZStencil@%p\n", This, pRenderTarget, pNewZStencil);
+
+    hr = IDirect3DDevice8Impl_ActiveRender(iface, pRenderTarget, pNewZStencil);
+    
+    return hr;
 }
+
 HRESULT  WINAPI  IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
 
-    TRACE("(%p)->(%p)\n", This, This->frontBuffer);
+    TRACE("(%p)->(%p) default(%p)\n", This, This->renderTarget, This->frontBuffer);
     
-    *ppRenderTarget = (LPDIRECT3DSURFACE8) This->frontBuffer;
+    *ppRenderTarget = (LPDIRECT3DSURFACE8) This->renderTarget;
     IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) *ppRenderTarget);
     
     return D3D_OK;
 }
+
 HRESULT  WINAPI  IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface) {
     ICOM_THIS(IDirect3DDevice8Impl,iface);
 
-    TRACE("(%p)->(%p)\n", This, ppZStencilSurface);
+    TRACE("(%p)->(%p) default(%p)\n", This, This->stencilBufferTarget, This->depthStencilBuffer);
     
     /* Note inc ref on returned surface */
-    *ppZStencilSurface = (LPDIRECT3DSURFACE8) This->depthStencilBuffer;
+    *ppZStencilSurface = (LPDIRECT3DSURFACE8) This->stencilBufferTarget;
     IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) *ppZStencilSurface);
 
     return D3D_OK;
@@ -2155,6 +1939,17 @@
     printf("Hit Enter ...\n");
     getchar(); */
 
+    if (This->frontBuffer != This->renderTarget) {
+      IDirect3DBaseTexture8* cont = NULL;
+      HRESULT hr;
+      hr = IDirect3DSurface8_GetContainer((LPDIRECT3DSURFACE8) This->renderTarget, &IID_IDirect3DBaseTexture8, (void**) &cont);
+      if (SUCCEEDED(hr) && NULL != cont) {
+	IDirect3DBaseTexture8_PreLoad(cont);
+	IDirect3DBaseTexture8_Release(cont);
+	cont = NULL;
+      }
+    }
+
     LEAVE_GL();
     return D3D_OK;
 }
@@ -2334,11 +2129,13 @@
        */
       /** store it */
       conv_mat(lpmatrix, &This->StateBlock->transforms[d3dts]);
-      if (checkGLSupport(ARB_VERTEX_BLEND)) {
+#if 0
+      if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
           FIXME("TODO\n");
-      } else if (checkGLSupport(EXT_VERTEX_WEIGHTING)) {
+      } else if (GL_SUPPORT(EXT_VERTEX_WEIGHTING)) {
           FIXME("TODO\n");
       }
+#endif
     }
 
     /*
@@ -2372,7 +2169,7 @@
               enabled, since the call to enable it will not reset the position.             */
 
            /* Reset lights */
-           for (k = 0; k < This->maxLights; k++) {
+           for (k = 0; k < GL_LIMITS(lights); k++) {
                glLightfv(GL_LIGHT0 + k, GL_POSITION,       &This->lightPosn[k][0]);
                checkGLcall("glLightfv posn");
                glLightfv(GL_LIGHT0 + k, GL_SPOT_DIRECTION, &This->lightDirn[k][0]);
@@ -2380,13 +2177,13 @@
            }
 
            /* Reset Clipping Planes if clipping is enabled */
-           for (k = 0; k < This->clipPlanes; k++) {
+           for (k = 0; k < GL_LIMITS(clipplanes); k++) {
                glClipPlane(GL_CLIP_PLANE0 + k, This->StateBlock->clipplane[k]);
                checkGLcall("glClipPlane");
            }
 
            /* Reapply texture transforms as based off modelview when applied */
-           for (Stage = 0; Stage < This->TextureUnits; Stage++) {
+           for (Stage = 0; Stage < GL_LIMITS(textures); Stage++) {
 
                /* Only applicable if the transforms are not disabled */
                if (This->UpdateStateBlock->texture_state[Stage][D3DTSS_TEXTURETRANSFORMFLAGS] != D3DTTFF_DISABLE) 
@@ -2660,7 +2457,7 @@
     ICOM_THIS(IDirect3DDevice8Impl,iface);
     TRACE("(%p) : Idx(%ld), pLight(%p)\n", This, Index, pLight);
 
-    if (Index >= This->maxLights) {
+    if (Index >= GL_LIMITS(lights)) {
         TRACE("Cannot handle more lights than device supports\n");
         return D3DERR_INVALIDCALL;
     }
@@ -2801,7 +2598,7 @@
     ICOM_THIS(IDirect3DDevice8Impl,iface);
     TRACE("(%p) : Idx(%ld), pLight(%p)\n", This, Index, pLight);
     
-    if (Index >= This->maxLights) {
+    if (Index >= GL_LIMITS(lights)) {
         TRACE("Cannot handle more lights than device supports\n");
         return D3DERR_INVALIDCALL;
     }
@@ -2813,7 +2610,7 @@
     ICOM_THIS(IDirect3DDevice8Impl,iface);
     TRACE("(%p) : Idx(%ld), enable? %d\n", This, Index, Enable);
 
-    if (Index >= This->maxLights) {
+    if (Index >= GL_LIMITS(lights)) {
         TRACE("Cannot handle more lights than device supports\n");
         return D3DERR_INVALIDCALL;
     }
@@ -2841,7 +2638,7 @@
     ICOM_THIS(IDirect3DDevice8Impl,iface);
     TRACE("(%p) : for idx(%ld)\n", This, Index);
 
-    if (Index >= This->maxLights) {
+    if (Index >= GL_LIMITS(lights)) {
         TRACE("Cannot handle more lights than device supports\n");
         return D3DERR_INVALIDCALL;
     }
@@ -2854,7 +2651,7 @@
     TRACE("(%p) : for idx %ld, %p\n", This, Index, pPlane);
 
     /* Validate Index */
-    if (Index >= This->clipPlanes ) {
+    if (Index >= GL_LIMITS(clipplanes)) {
         TRACE("Application has requested clipplane this device doesnt support\n");
         return D3DERR_INVALIDCALL;
     }
@@ -2893,7 +2690,7 @@
     TRACE("(%p) : for idx %ld\n", This, Index);
 
     /* Validate Index */
-    if (Index >= This->clipPlanes ) {
+    if (Index >= GL_LIMITS(clipplanes)) {
         TRACE("Application has requested clipplane this device doesnt support\n");
         return D3DERR_INVALIDCALL;
     }
@@ -3226,23 +3023,17 @@
             /* Note the texture color applies to all textures whereas 
                GL_TEXTURE_ENV_COLOR applies to active only */
             float col[4];
-#if 0
-            col[0] = ((Value >> 16) & 0xFF) / 255.0f;
-            col[1] = ((Value >>  8) & 0xFF) / 255.0f;
-            col[2] = ((Value >>  0) & 0xFF) / 255.0f;
-            col[3] = ((Value >> 24) & 0xFF) / 255.0f;
-#endif
 	    D3DCOLORTOGLFLOAT4(Value, col);
             /* Set the default alpha blend color */
             glBlendColor(col[0], col[1], col[2], col[3]);
             checkGLcall("glBlendColor");
 
             /* And now the default texture color as well */
-            for (i = 0; i < This->TextureUnits; i++) {
+            for (i = 0; i < GL_LIMITS(textures); 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) {
+                if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
                     glActiveTexture(GL_TEXTURE0 + i);
 #else
@@ -3262,10 +3053,10 @@
     case D3DRS_SPECULARENABLE            : 
         {
             if (Value) {
-                glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);
+                glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
                 checkGLcall("glLightModel (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SEPARATE_SPECULAR_COLOR);");
             } else {
-                glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR);
+                glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
                 checkGLcall("glLightModel (GL_LIGHT_MODEL_COLOR_CONTROL,GL_SINGLE_COLOR);");
             }
         }
@@ -3420,12 +3211,6 @@
     case D3DRS_FOGCOLOR                  :
         {
             float col[4];
-#if 0
-            col[0] = ((Value >> 16) & 0xFF) / 255.0f;
-            col[1] = ((Value >>  8) & 0xFF) / 255.0f;
-            col[2] = ((Value >>  0) & 0xFF) / 255.0f;
-            col[3] = ((Value >> 24) & 0xFF) / 255.0f;
-#endif
 	    D3DCOLORTOGLFLOAT4(Value, col);
             /* Set the default alpha blend color */
             glFogfv(GL_FOG_COLOR, &col[0]);
@@ -3466,7 +3251,8 @@
 
     case D3DRS_FOGDENSITY                :
         {
-            glFogf(GL_FOG_DENSITY, (float) Value);
+            float *f = (float*) &Value;
+            glFogfv(GL_FOG_DENSITY, f);
             checkGLcall("glFogf(GL_FOG_DENSITY, (float) Value)");
         }
         break;
@@ -3491,7 +3277,6 @@
         }
 	break;
 
-
     case D3DRS_COLORVERTEX               :
     case D3DRS_DIFFUSEMATERIALSOURCE     :
     case D3DRS_SPECULARMATERIALSOURCE    :
@@ -3542,12 +3327,151 @@
         }
         break; 
 
-        /* Unhandled yet...! */
     case D3DRS_LINEPATTERN               :
+        {
+            D3DLINEPATTERN *pattern = (D3DLINEPATTERN *)&Value;
+            TRACE("Line pattern: repeat %d bits %x\n", pattern->wRepeatFactor, pattern->wLinePattern);
+
+            if (pattern->wRepeatFactor) {
+                glLineStipple(pattern->wRepeatFactor, pattern->wLinePattern);
+                checkGLcall("glLineStipple(repeat, linepattern)\n");
+                glEnable(GL_LINE_STIPPLE);
+                checkGLcall("glEnable(GL_LINE_STIPPLE);\n");
+            } else {
+                glDisable(GL_LINE_STIPPLE);
+                checkGLcall("glDisable(GL_LINE_STIPPLE);\n");
+            }
+        }
+        break;
+
+    case D3DRS_ZBIAS                     :
+        {
+            if (Value) {
+                TRACE("ZBias value %f\n", *((float*)&Value));
+                glPolygonOffset(0, -*((float*)&Value));
+                checkGLcall("glPolygonOffset(0, -Value)");
+                glEnable(GL_POLYGON_OFFSET_FILL);
+                checkGLcall("glEnable(GL_POLYGON_OFFSET_FILL);");
+                glEnable(GL_POLYGON_OFFSET_LINE);
+                checkGLcall("glEnable(GL_POLYGON_OFFSET_LINE);");
+                glEnable(GL_POLYGON_OFFSET_POINT);
+                checkGLcall("glEnable(GL_POLYGON_OFFSET_POINT);");
+            } else {
+                glDisable(GL_POLYGON_OFFSET_FILL);
+                checkGLcall("glDisable(GL_POLYGON_OFFSET_FILL);");
+                glDisable(GL_POLYGON_OFFSET_LINE);
+                checkGLcall("glDisable(GL_POLYGON_OFFSET_LINE);");
+                glDisable(GL_POLYGON_OFFSET_POINT);
+                checkGLcall("glDisable(GL_POLYGON_OFFSET_POINT);");
+            }
+        }
+        break;
+
+    case D3DRS_NORMALIZENORMALS          :
+        if (Value) {
+            glEnable(GL_NORMALIZE);
+            checkGLcall("glEnable(GL_NORMALIZE);");
+        } else {
+            glDisable(GL_NORMALIZE);
+            checkGLcall("glDisable(GL_NORMALIZE);");
+        }
+        break;
+
+    case D3DRS_POINTSIZE                 :
+        TRACE("Set point size to %f\n", *((float*)&Value));
+        glPointSize(*((float*)&Value));
+        checkGLcall("glPointSize(...);\n");
+        break;
+
+    case D3DRS_POINTSIZE_MIN             :
+#if defined(GL_VERSION_1_4)
+        glPointParameterf(GL_POINT_SIZE_MIN, *((float*)&Value));
+        checkGLcall("glPointParameterf(...);\n");
+#elif defined(GL_EXT_point_parameters)
+        glPointParameterfEXT(GL_POINT_SIZE_MIN_EXT, *((float*)&Value));
+        checkGLcall("glPointParameterfEXT(...);\n");
+#elif defined(GL_ARB_point_parameters)
+        glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, *((float*)&Value));
+        checkGLcall("glPointParameterfARB(...);\n");
+#else
+        FIXME("D3DRS_POINTSIZE_MIN not supported on this opengl\n");
+#endif
+        break;
+
+    case D3DRS_POINTSIZE_MAX             :
+#if defined(GL_VERSION_1_4)
+        glPointParameterf(GL_POINT_SIZE_MAX, *((float*)&Value));
+        checkGLcall("glPointParameterf(...);\n");
+#elif defined(GL_EXT_point_parameters)
+        glPointParameterfEXT(GL_POINT_SIZE_MAX_EXT, *((float*)&Value));
+        checkGLcall("glPointParameterfEXT(...);\n");
+#elif defined(GL_ARB_point_parameters)
+        glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, *((float*)&Value));
+        checkGLcall("glPointParameterfARB(...);\n");
+#else
+        FIXME("D3DRS_POINTSIZE_MAX not supported on this opengl\n");
+#endif
+        break;
+
+    case D3DRS_POINTSCALE_A              :
+    case D3DRS_POINTSCALE_B              :
+    case D3DRS_POINTSCALE_C              :
+    case D3DRS_POINTSCALEENABLE          :
+        {
+            /* If enabled, supply the parameters, otherwise fall back to defaults */
+            if (This->StateBlock->renderstate[D3DRS_POINTSCALEENABLE]) {
+                GLfloat att[3] = {1.0, 0.0, 0.0};
+                att[0] = *((float*)&This->StateBlock->renderstate[D3DRS_POINTSCALE_A]);
+                att[1] = *((float*)&This->StateBlock->renderstate[D3DRS_POINTSCALE_B]);
+                att[2] = *((float*)&This->StateBlock->renderstate[D3DRS_POINTSCALE_C]);
+
+#if defined(GL_VERSION_1_4)
+                glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att);
+                checkGLcall("glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, ...);\n");
+#elif defined(GL_EXT_point_parameters)
+                glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, att);
+                checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...);\n");
+#elif defined(GL_ARB_point_parameters)
+                glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, att);        
+                checkGLcall("glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, ...);\n");
+#else
+                TRACE("D3DRS_POINTSCALEENABLE not supported on this opengl\n");
+#endif
+            } else {
+                GLfloat att[3] = {1.0, 0.0, 0.0};
+#if defined(GL_VERSION_1_4)
+                glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, att);
+                checkGLcall("glPointParameterfv(GL_POINT_DISTANCE_ATTENUATION, ...);\n");
+#elif defined(GL_EXT_point_parameters)
+                glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, att);
+                checkGLcall("glPointParameterfvEXT(GL_DISTANCE_ATTENUATION_EXT, ...);\n");
+#elif defined(GL_ARB_point_parameters)
+                glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, att);        
+                checkGLcall("glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, ...);\n");
+#else
+                TRACE("D3DRS_POINTSCALEENABLE not supported, but not on either\n");
+#endif
+            }
+            break;
+        }
+
+    case D3DRS_COLORWRITEENABLE          :
+        TRACE("Color mask: r(%d) g(%d) b(%d) a(%d)\n", 
+                    Value & D3DCOLORWRITEENABLE_RED?1:0,
+                    Value & D3DCOLORWRITEENABLE_GREEN?1:0,
+                    Value & D3DCOLORWRITEENABLE_BLUE?1:0,
+                    Value & D3DCOLORWRITEENABLE_ALPHA?1:0); 
+		glColorMask(Value & D3DCOLORWRITEENABLE_RED, 
+                    Value & D3DCOLORWRITEENABLE_GREEN,
+		            Value & D3DCOLORWRITEENABLE_BLUE, 
+                    Value & D3DCOLORWRITEENABLE_ALPHA);
+        checkGLcall("glColorMask(...)\n");
+		break;
+
+        /* Unhandled yet...! */
     case D3DRS_LASTPIXEL                 :
     case D3DRS_ZVISIBLE                  :
     case D3DRS_EDGEANTIALIAS             :
-    case D3DRS_ZBIAS                     :
     case D3DRS_RANGEFOGENABLE            :
     case D3DRS_WRAP0                     :
     case D3DRS_WRAP1                     :
@@ -3559,22 +3483,13 @@
     case D3DRS_WRAP7                     :
     case D3DRS_FOGVERTEXMODE             :
     case D3DRS_LOCALVIEWER               :
-    case D3DRS_NORMALIZENORMALS          :
     case D3DRS_SOFTWAREVERTEXPROCESSING  :
-    case D3DRS_POINTSIZE                 :
-    case D3DRS_POINTSIZE_MIN             :
     case D3DRS_POINTSPRITEENABLE         :
-    case D3DRS_POINTSCALEENABLE          :
-    case D3DRS_POINTSCALE_A              :
-    case D3DRS_POINTSCALE_B              :
-    case D3DRS_POINTSCALE_C              :
     case D3DRS_MULTISAMPLEANTIALIAS      :
     case D3DRS_MULTISAMPLEMASK           :
     case D3DRS_PATCHEDGESTYLE            :
     case D3DRS_PATCHSEGMENTS             :
     case D3DRS_DEBUGMONITORTOKEN         :
-    case D3DRS_POINTSIZE_MAX             :
-    case D3DRS_COLORWRITEENABLE          :
     case D3DRS_POSITIONORDER             :
     case D3DRS_NORMALORDER               :
         /*Put back later: FIXME("(%p)->(%d,%ld) not handled yet\n", This, State, Value); */
@@ -3676,7 +3591,7 @@
     TRACE("(%p) : Stage(%ld), Texture (%p)\n", This, Stage, pTexture);
 
     /* Reject invalid texture units */
-    if (Stage >= This->TextureUnits) {
+    if (Stage >= GL_LIMITS(textures)) {
         TRACE("Attempt to access invalid texture rejected\n");
         return D3DERR_INVALIDCALL;
     }
@@ -3692,7 +3607,7 @@
     }
 
     /* Make appropriate texture active */
-    if (This->isMultiTexture) {
+    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
         glActiveTexture(GL_TEXTURE0 + Stage);
 #else
@@ -3721,7 +3636,6 @@
               TRACE("Skipping setting texture as old == new\n");
               reapplyStates = FALSE;
           } else {
-
             /* Standard 2D texture */
             TRACE("Standard 2d texture\n");
             This->UpdateStateBlock->textureDimensions[Stage] = GL_TEXTURE_2D;
@@ -3730,76 +3644,19 @@
             IDirect3DTexture8Impl_PreLoad((LPDIRECT3DTEXTURE8) pTexture);
           }
         } else if (textureType == D3DRTYPE_VOLUMETEXTURE) {
-#if 0
-            IDirect3DVolumeTexture8Impl *pTexture2 = (IDirect3DVolumeTexture8Impl *) pTexture;
-            int i;
-#endif
-
             /* Standard 3D (volume) texture */
             TRACE("Standard 3d texture\n");
             This->UpdateStateBlock->textureDimensions[Stage] = GL_TEXTURE_3D;
 
             /* Load up the texture now */
 	    IDirect3DVolumeTexture8Impl_PreLoad((LPDIRECT3DVOLUMETEXTURE8) pTexture);
-
-#if 0
-            for (i=0; i<pTexture2->levels; i++) 
-            {
-
-                if (i==0 && pTexture2->volumes[i]->textureName != 0 && pTexture2->Dirty == FALSE) {
-                    glBindTexture(GL_TEXTURE_3D, pTexture2->volumes[i]->textureName);
-                    checkGLcall("glBindTexture");
-                    TRACE("Texture %p given name %d\n", pTexture2->volumes[i], pTexture2->volumes[i]->textureName);
-
-                    /* No need to walk through all mip-map levels, since already all assigned */
-                    i = pTexture2->levels;
-                } else {
-                    if (i==0) {
-
-                        if (pTexture2->volumes[i]->textureName == 0) {
-                            glGenTextures(1, &pTexture2->volumes[i]->textureName);
-                            checkGLcall("glGenTextures");
-                            TRACE("Texture %p given name %d\n", pTexture2->volumes[i], pTexture2->volumes[i]->textureName);
-                        }
-
-                        glBindTexture(GL_TEXTURE_3D, pTexture2->volumes[i]->textureName);
-                        checkGLcall("glBindTexture");
-
-                        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, pTexture2->levels-1); 
-                        checkGLcall("glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, pTexture2->levels-1)");
-                    }
-
-                    TRACE("Calling glTexImage3D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%lx, Mem=%p\n",
-                          GL_TEXTURE_3D, i, fmt2glintFmt(pTexture2->format), pTexture2->volumes[i]->myDesc.Width,
-                          pTexture2->volumes[i]->myDesc.Height, pTexture2->volumes[i]->myDesc.Depth,
-                          0, fmt2glFmt(pTexture2->format),fmt2glType(pTexture2->format),
-                          pTexture2->volumes[i]->allocatedMemory);
-                    glTexImage3D(GL_TEXTURE_3D, i,
-                                 fmt2glintFmt(pTexture2->format),
-                                 pTexture2->volumes[i]->myDesc.Width,
-                                 pTexture2->volumes[i]->myDesc.Height,
-                                 pTexture2->volumes[i]->myDesc.Depth,
-                                 0,
-                                 fmt2glFmt(pTexture2->format),
-                                 fmt2glType(pTexture2->format),
-                                 pTexture2->volumes[i]->allocatedMemory
-                                );
-                    checkGLcall("glTexImage3D");
-
-                    /* Removed glTexParameterf now TextureStageStates are initialized at startup */
-                    pTexture2->Dirty = FALSE;
-                }
-            }
-#endif
-
         } else if (textureType == D3DRTYPE_CUBETEXTURE) {
-	  /* Standard Cube texture */
-	  FIXME("Standard Cube texture\n");
-	  
-	  This->UpdateStateBlock->textureDimensions[Stage] = GL_TEXTURE_CUBE_MAP_ARB;
+	    /* Standard Cube texture */
+	    TRACE("Standard Cube texture\n");
+	    This->UpdateStateBlock->textureDimensions[Stage] = GL_TEXTURE_CUBE_MAP_ARB;
 
-	  /* Load up the texture now */
-	  IDirect3DCubeTexture8Impl_PreLoad((LPDIRECT3DCUBETEXTURE8) pTexture);
+	    /* Load up the texture now */
+	    IDirect3DCubeTexture8Impl_PreLoad((LPDIRECT3DCUBETEXTURE8) pTexture);
 	} else {
             FIXME("(%p) : Incorrect type for a texture : (%d,%s)\n", This, textureType, debug_d3dressourcetype(textureType));
         }
@@ -3835,7 +3692,7 @@
     TRACE("(%p) : stub, Stage=%ld, Type=%d, Value=%ld\n", This, Stage, Type, Value);
 
     /* Reject invalid texture units */
-    if (Stage >= This->TextureUnits) {
+    if (Stage >= GL_LIMITS(textures)) {
         TRACE("Attempt to access invalid texture rejected\n");
         return D3DERR_INVALIDCALL;
     }
@@ -3852,7 +3709,7 @@
 
     /* Make appropriate texture active */
     VTRACE(("Activating appropriate texture state %ld\n", Stage));
-    if (This->isMultiTexture) {
+    if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
         glActiveTexture(GL_TEXTURE0 + Stage);
         vcheckGLcall("glActiveTexture");
@@ -4108,7 +3965,7 @@
 
                 case D3DTOP_DOTPRODUCT3               :
 #if defined(GL_VERSION_1_3)
-                    if (This->isDot3) {
+                    if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3)) {
                         glTexEnvi(GL_TEXTURE_ENV, Parm, GL_DOT3_RGBA);
                         checkGLcall("glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_DOT3_RGBA);");
                         break;
@@ -4199,12 +4056,6 @@
     case D3DTSS_BORDERCOLOR           :
         {
             float col[4];
-#if 0
-            col[0] = ((Value >> 16) & 0xFF) / 255.0;
-            col[1] = ((Value >>  8) & 0xFF) / 255.0;
-            col[2] = ((Value >>  0) & 0xFF) / 255.0;
-            col[3] = ((Value >> 24) & 0xFF) / 255.0;
-#endif
 	    D3DCOLORTOGLFLOAT4(Value, col);
             TRACE("Setting border color for %x to %lx\n", This->StateBlock->textureDimensions[Stage], Value); 
             glTexParameterfv(This->StateBlock->textureDimensions[Stage], GL_TEXTURE_BORDER_COLOR, &col[0]);
@@ -4432,13 +4283,17 @@
     FIXME("(%p) : Setting to (%u)\n", This, PaletteNumber);
     This->currentPalette = PaletteNumber;
 #if defined(GL_EXT_paletted_texture)
-    glColorTableEXT(GL_TEXTURE_2D,    /* target */
-		    GL_RGBA,          /* internal format */
-		    256,              /* table size */
-		    GL_RGBA,          /* table format */
-		    GL_UNSIGNED_BYTE, /* table type */
-		    &This->palettes[PaletteNumber]);
-    checkGLcall("glColorTableEXT");
+    if (GL_SUPPORT(EXT_PALETTED_TEXTURE)) {
+      glColorTableEXT(GL_TEXTURE_2D,    /* target */
+		      GL_RGBA,          /* internal format */
+		      256,              /* table size */
+		      GL_RGBA,          /* table format */
+		      GL_UNSIGNED_BYTE, /* table type */
+		      &This->palettes[PaletteNumber]);
+      checkGLcall("glColorTableEXT");
+    } else {
+      /* Delayed palette handling ... waiting for software emulation into preload code */
+    }
 #endif
     return D3D_OK;
 }
@@ -4984,3 +4839,224 @@
     IDirect3DDevice8Impl_DrawTriPatch,
     IDirect3DDevice8Impl_DeletePatch
 };
+
+HRESULT WINAPI IDirect3DDevice8Impl_CleanRender(LPDIRECT3DDEVICE8 iface) {
+  ICOM_THIS(IDirect3DDevice8Impl,iface);
+#if defined(GL_VERSION_1_3) /* @see comments on ActiveRender */
+#if 0
+  if (This->glCtx != This->render_ctx) {
+    glXDestroyContext(This->display, This->render_ctx);
+    This->render_ctx = This->glCtx;
+  }
+#endif
+  if (This->win != This->drawable) {
+    glXDestroyPbuffer(This->display, This->drawable);
+    This->drawable = This->win;
+  }
+#endif
+  return D3D_OK;
+}
+
+HRESULT WINAPI IDirect3DDevice8Impl_ActiveRender(LPDIRECT3DDEVICE8 iface,
+						IDirect3DSurface8* RenderSurface, 
+						IDirect3DSurface8* StencilSurface) {
+
+  /**
+   * Currently only active for GLX >= 1.3
+   * for others versions we'll have to use GLXPixmaps
+   *
+   * normally we must test GLX_VERSION_1_3 but nvidia headers are not correct
+   * as they implements GLX 1.3 but only define GLX_VERSION_1_2
+   * so only check OpenGL version
+   */
+#if defined(GL_VERSION_1_3) 
+
+  GLXFBConfig* cfgs = NULL;
+  int nCfgs = 0;
+  int attribs[256];
+  int nAttribs = 0;
+  D3DFORMAT BackBufferFormat = ((IDirect3DSurface8Impl*) RenderSurface)->myDesc.Format;
+  D3DFORMAT StencilBufferFormat = ((IDirect3DSurface8Impl*) StencilSurface)->myDesc.Format;
+  UINT Width = ((IDirect3DSurface8Impl*) RenderSurface)->myDesc.Width;
+  UINT Height = ((IDirect3DSurface8Impl*) RenderSurface)->myDesc.Height;
+  IDirect3DSurface8Impl* tmp;
+
+  ICOM_THIS(IDirect3DDevice8Impl,iface);
+ 
+#define PUSH1(att)        attribs[nAttribs++] = (att); 
+#define PUSH2(att,value)  attribs[nAttribs++] = (att); attribs[nAttribs++] = (value);
+
+  PUSH2(GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_WINDOW | GLX_PBUFFER_BIT);
+  PUSH2(GLX_X_RENDERABLE,  TRUE);
+  PUSH2(GLX_DOUBLEBUFFER, TRUE);
+  
+  switch (BackBufferFormat) {
+    /* color buffer */
+  case D3DFMT_P8:
+    PUSH2(GLX_RENDER_TYPE,  GLX_COLOR_INDEX_BIT);
+    PUSH2(GLX_BUFFER_SIZE,  8);
+    PUSH2(GLX_DOUBLEBUFFER, TRUE);
+    break;
+    
+  case D3DFMT_R3G3B2:
+    PUSH2(GLX_RENDER_TYPE,  GLX_RGBA_BIT);
+    PUSH2(GLX_RED_SIZE,     3);
+    PUSH2(GLX_GREEN_SIZE,   3);
+    PUSH2(GLX_BLUE_SIZE,    2);
+    break;
+    
+  case D3DFMT_A1R5G5B5:
+    PUSH2(GLX_ALPHA_SIZE,   1);
+  case D3DFMT_X1R5G5B5:
+    PUSH2(GLX_RED_SIZE,     5);
+    PUSH2(GLX_GREEN_SIZE,   5);
+    PUSH2(GLX_BLUE_SIZE,    5);
+    break;
+    
+  case D3DFMT_R5G6B5:
+    PUSH2(GLX_RED_SIZE,     5);
+    PUSH2(GLX_GREEN_SIZE,   6);
+    PUSH2(GLX_BLUE_SIZE,    5);
+    break;
+    
+  case D3DFMT_A4R4G4B4:
+    PUSH2(GLX_ALPHA_SIZE,   4);
+  case D3DFMT_X4R4G4B4:
+    PUSH2(GLX_RED_SIZE,     4);
+    PUSH2(GLX_GREEN_SIZE,   4);
+    PUSH2(GLX_BLUE_SIZE,    4);
+    break;
+    
+  case D3DFMT_A8R8G8B8:
+    PUSH2(GLX_ALPHA_SIZE,   8);
+  case D3DFMT_R8G8B8:
+  case D3DFMT_X8R8G8B8:
+    PUSH2(GLX_RED_SIZE,     8);
+    PUSH2(GLX_GREEN_SIZE,   8);
+    PUSH2(GLX_BLUE_SIZE,    8);
+    break;
+
+  default:
+    break;
+  }
+   
+  switch (StencilBufferFormat) { 
+  case D3DFMT_D16_LOCKABLE:
+  case D3DFMT_D16:
+    PUSH2(GLX_DEPTH_SIZE,   16);
+    break;
+    
+  case D3DFMT_D15S1:
+    PUSH2(GLX_DEPTH_SIZE,   15);
+    break;
+    
+  case D3DFMT_D24X8:
+    PUSH2(GLX_DEPTH_SIZE,   24);
+    break;
+    
+  case D3DFMT_D24X4S4:
+    PUSH2(GLX_DEPTH_SIZE,   24);
+    PUSH2(GLX_STENCIL_SIZE, 4);
+    break;
+    
+  case D3DFMT_D24S8:
+    PUSH2(GLX_DEPTH_SIZE,   24);
+    PUSH2(GLX_STENCIL_SIZE, 8);
+    break;
+    
+  case D3DFMT_D32:
+    PUSH2(GLX_DEPTH_SIZE,   32);
+    break;
+
+  default:
+    break;
+  }
+
+  PUSH1(None);
+  
+  cfgs = glXChooseFBConfig(This->display, DefaultScreen(This->display), attribs, &nCfgs);
+  if (NULL != cfgs) {
+#if 0
+    int i;
+    for (i = 0; i < nCfgs; ++i) {
+      TRACE("for (%u,%s)/(%u,%s) found config[%d]@%p\n", BackBufferFormat, debug_d3dformat(BackBufferFormat), StencilBufferFormat, debug_d3dformat(StencilBufferFormat), i, cfgs[i]);
+    }
+#endif
+
+    if (NULL != This->renderTarget) {
+      GLenum prev_read;      
+      glFlush();
+      vcheckGLcall("glFlush");
+
+#if 0
+      /** very very usefull debug code */
+      glXSwapBuffers(This->display, This->drawable);   
+      printf("Hit Enter to get next frame ...\n");
+      getchar();
+#endif
+
+      glGetIntegerv(GL_READ_BUFFER, &prev_read);
+      vcheckGLcall("glIntegerv");
+      glReadBuffer(GL_BACK);
+      vcheckGLcall("glReadBuffer");
+      {
+	long j;
+	for (j = 0; j < This->renderTarget->myDesc.Height; ++j) {
+	  glReadPixels(0, 
+		       This->renderTarget->myDesc.Height - j - 1, 
+		       This->renderTarget->myDesc.Width, 
+		       1,
+		       D3DFmt2GLFmt(This->renderTarget->myDesc.Format), 
+		       D3DFmt2GLType(This->renderTarget->myDesc.Format), 
+		       This->renderTarget->allocatedMemory);
+	  vcheckGLcall("glReadPixels");
+	}
+      }      
+      glReadBuffer(prev_read);
+      vcheckGLcall("glReadBuffer");
+    }
+
+    if (BackBufferFormat != This->renderTarget->myDesc.Format && 
+	StencilBufferFormat != This->stencilBufferTarget->myDesc.Format) {
+      nAttribs = 0;
+      PUSH2(GLX_PBUFFER_WIDTH,  Width);
+      PUSH2(GLX_PBUFFER_HEIGHT, Height);
+      PUSH1(None);
+      This->drawable = glXCreatePbuffer(This->display, cfgs[0], attribs);
+            
+      This->render_ctx = glXCreateNewContext(This->display, cfgs[0], GLX_RGBA_TYPE, This->glCtx, TRUE);
+      if (NULL == This->render_ctx) {
+	ERR("cannot create glxContext\n"); 
+      }
+
+      glFlush();
+      glXSwapBuffers(This->display, This->drawable);
+      if (glXMakeContextCurrent(This->display, This->drawable, This->drawable, This->render_ctx) == False) {
+	TRACE("Error in setting current context: context %p drawable %ld (default %ld)!\n", This->glCtx, This->drawable, This->win);
+      }
+      checkGLcall("glXMakeContextCurrent");
+    }
+
+    tmp = This->renderTarget;
+    This->renderTarget = (IDirect3DSurface8Impl*) RenderSurface;
+    IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) This->renderTarget);
+    IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) tmp);
+
+    tmp = This->stencilBufferTarget;
+    This->stencilBufferTarget = (IDirect3DSurface8Impl*) StencilSurface;
+    IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) This->stencilBufferTarget);
+    IDirect3DSurface8Impl_Release((LPDIRECT3DSURFACE8) tmp);
+
+    return D3D_OK;
+
+  } else {
+    ERR("cannot get valides GLXFBConfig for (%u,%s)/(%u,%s)\n", BackBufferFormat, debug_d3dformat(BackBufferFormat), StencilBufferFormat, debug_d3dformat(StencilBufferFormat));
+  }
+
+#undef PUSH1
+#undef PUSH2
+
+#endif
+
+  return D3DERR_INVALIDCALL;
+}
Index: directx.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/directx.c,v
retrieving revision 1.34
diff -u -r1.34 directx.c
--- directx.c	17 May 2003 18:33:02 -0000	1.34
+++ directx.c	22 May 2003 22:24:16 -0000
@@ -85,18 +85,6 @@
   D3DFMT_X8R8G8B8
 };
 
-inline static int get_bpp_from_format(D3DFORMAT fmt) {
-  switch (fmt) {
-  case D3DFMT_P8:        return  8;
-  case D3DFMT_R3G3B2:    return  8;
-  case D3DFMT_R5G6B5:    return 16;
-  case D3DFMT_X1R5G5B5:  return 16;
-  case D3DFMT_X4R4G4B4:  return 16;
-  case D3DFMT_R8G8B8:    return 24;
-  case D3DFMT_X8R8G8B8:  return 32;
-  default:               return 16;
-  }
-}
 
 /* retrieve the X display to use on a given DC */
 inline static Display *get_display( HDC hdc )
@@ -415,33 +403,91 @@
 
     pCaps->CursorCaps = 0;
 
-    pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX | D3DDEVCAPS_HWTRANSFORMANDLIGHT | D3DDEVCAPS_PUREDEVICE;
-
-    pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW | D3DPMISCCAPS_CULLCW | D3DPMISCCAPS_COLORWRITEENABLE | D3DPMISCCAPS_CLIPTLVERTS  |
-                               D3DPMISCCAPS_CLIPPLANESCALEDPOINTS | D3DPMISCCAPS_MASKZ; /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
-    pCaps->RasterCaps = D3DPRASTERCAPS_DITHER | D3DPRASTERCAPS_PAT;
-    pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS | D3DPCMPCAPS_EQUAL | D3DPCMPCAPS_GREATER | D3DPCMPCAPS_GREATEREQUAL |
-                      D3DPCMPCAPS_LESS | D3DPCMPCAPS_LESSEQUAL | D3DPCMPCAPS_NEVER | D3DPCMPCAPS_NOTEQUAL;
+    pCaps->DevCaps = D3DDEVCAPS_DRAWPRIMTLVERTEX    | 
+                     D3DDEVCAPS_HWTRANSFORMANDLIGHT |
+                     D3DDEVCAPS_PUREDEVICE;
+
+    pCaps->PrimitiveMiscCaps = D3DPMISCCAPS_CULLCCW               | 
+                               D3DPMISCCAPS_CULLCW                | 
+                               D3DPMISCCAPS_COLORWRITEENABLE      |
+                               D3DPMISCCAPS_CLIPTLVERTS           |
+                               D3DPMISCCAPS_CLIPPLANESCALEDPOINTS | 
+                               D3DPMISCCAPS_MASKZ; 
+                               /*NOT: D3DPMISCCAPS_TSSARGTEMP*/
+
+    pCaps->RasterCaps = D3DPRASTERCAPS_DITHER   | 
+                        D3DPRASTERCAPS_PAT      | 
+                        D3DPRASTERCAPS_FOGRANGE;
+                        /* FIXME Add:
+			   D3DPRASTERCAPS_FOGVERTEX
+			   D3DPRASTERCAPS_FOGTABLE
+			   D3DPRASTERCAPS_MIPMAPLODBIAS
+			   D3DPRASTERCAPS_ZBIAS
+			   D3DPRASTERCAPS_ANISOTROPY
+			   D3DPRASTERCAPS_WFOG
+			   D3DPRASTERCAPS_ZFOG 
+			   D3DPRASTERCAPS_COLORPERSPECTIVE
+			   D3DPRASTERCAPS_STRETCHBLTMULTISAMPLE
+			   D3DPRASTERCAPS_ANTIALIASEDGES
+			   D3DPRASTERCAPS_ZBUFFERLESSHSR
+			   D3DPRASTERCAPS_WBUFFER */
+
+    pCaps->ZCmpCaps = D3DPCMPCAPS_ALWAYS       | 
+                      D3DPCMPCAPS_EQUAL        | 
+                      D3DPCMPCAPS_GREATER      | 
+                      D3DPCMPCAPS_GREATEREQUAL |
+                      D3DPCMPCAPS_LESS         | 
+                      D3DPCMPCAPS_LESSEQUAL    | 
+                      D3DPCMPCAPS_NEVER        |
+                      D3DPCMPCAPS_NOTEQUAL;
 
     pCaps->SrcBlendCaps  = 0xFFFFFFFF;   /*FIXME: Tidy up later */
     pCaps->DestBlendCaps = 0xFFFFFFFF;   /*FIXME: Tidy up later */
     pCaps->AlphaCmpCaps  = 0xFFFFFFFF;   /*FIXME: Tidy up later */
-    pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB | D3DPSHADECAPS_COLORGOURAUDRGB ;
-    pCaps->TextureCaps = D3DPTEXTURECAPS_ALPHA | D3DPTEXTURECAPS_ALPHAPALETTE | D3DPTEXTURECAPS_CUBEMAP | D3DPTEXTURECAPS_MIPCUBEMAP | D3DPTEXTURECAPS_CUBEMAP_POW2 | D3DPTEXTURECAPS_POW2 | D3DPTEXTURECAPS_VOLUMEMAP | D3DPTEXTURECAPS_MIPMAP;
-    pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR  | D3DPTFILTERCAPS_MAGFPOINT | D3DPTFILTERCAPS_MINFLINEAR | D3DPTFILTERCAPS_MINFPOINT |
-                               D3DPTFILTERCAPS_MIPFLINEAR  | D3DPTFILTERCAPS_MIPFPOINT ;
+
+    pCaps->ShadeCaps = D3DPSHADECAPS_SPECULARGOURAUDRGB | 
+                       D3DPSHADECAPS_COLORGOURAUDRGB;
+
+    pCaps->TextureCaps =  D3DPTEXTURECAPS_ALPHA        | 
+                          D3DPTEXTURECAPS_ALPHAPALETTE | 
+                          D3DPTEXTURECAPS_POW2         | 
+                          D3DPTEXTURECAPS_VOLUMEMAP    | 
+                          D3DPTEXTURECAPS_MIPMAP;
+#if defined(GL_VERSION_1_3) || defined(GL_ARB_texture_cube_map)
+    pCaps->TextureCaps |= D3DPTEXTURECAPS_CUBEMAP      | 
+                          D3DPTEXTURECAPS_MIPCUBEMAP   | 
+                          D3DPTEXTURECAPS_CUBEMAP_POW2;
+#endif
+
+    pCaps->TextureFilterCaps = D3DPTFILTERCAPS_MAGFLINEAR | 
+                               D3DPTFILTERCAPS_MAGFPOINT  | 
+                               D3DPTFILTERCAPS_MINFLINEAR | 
+                               D3DPTFILTERCAPS_MINFPOINT  |
+                               D3DPTFILTERCAPS_MIPFLINEAR | 
+                               D3DPTFILTERCAPS_MIPFPOINT;
+
     pCaps->CubeTextureFilterCaps = 0;
     pCaps->VolumeTextureFilterCaps = 0;
-    pCaps->TextureAddressCaps = D3DPTADDRESSCAPS_BORDER | D3DPTADDRESSCAPS_CLAMP | D3DPTADDRESSCAPS_WRAP;
+
+    pCaps->TextureAddressCaps =  D3DPTADDRESSCAPS_BORDER | 
+                                 D3DPTADDRESSCAPS_CLAMP  | 
+                                 D3DPTADDRESSCAPS_WRAP;
 #if defined(GL_VERSION_1_3)
     pCaps->TextureAddressCaps |= D3DPTADDRESSCAPS_MIRROR;
 #endif
+                                 /* FIXME: Add 
+				    D3DPTADDRESSCAPS_BORDER
+				    D3DPTADDRESSCAPS_MIRRORONCE */
+
     pCaps->VolumeTextureAddressCaps = 0;
 
-    pCaps->LineCaps = D3DLINECAPS_TEXTURE | D3DLINECAPS_ZTEST;
+    pCaps->LineCaps = D3DLINECAPS_TEXTURE | 
+                      D3DLINECAPS_ZTEST;
+                      /* FIXME: Add 
+			 D3DLINECAPS_BLEND
+			 D3DLINECAPS_ALPHACMP
+			 D3DLINECAPS_FOG */
 
-    /*pCaps->MaxTextureWidth = 16384;
-    pCaps->MaxTextureHeight = 16384;*/
     {
       GLint gl_tex_size;    
       glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_tex_size);
@@ -453,7 +499,6 @@
 
     pCaps->MaxTextureRepeat = 32768;
     pCaps->MaxTextureAspectRatio = 32768;
-    pCaps->MaxAnisotropy = 0;
     pCaps->MaxVertexW = 1.0;
 
     pCaps->GuardBandLeft = 0;
@@ -463,26 +508,52 @@
 
     pCaps->ExtentsAdjust = 0;
 
-    pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT | D3DSTENCILCAPS_INCRSAT | 
-                         D3DSTENCILCAPS_INVERT  | D3DSTENCILCAPS_KEEP    | 
-                         D3DSTENCILCAPS_REPLACE | D3DSTENCILCAPS_ZERO /* | D3DSTENCILCAPS_DECR | D3DSTENCILCAPS_INCR */;
+    pCaps->StencilCaps = D3DSTENCILCAPS_DECRSAT | 
+                         D3DSTENCILCAPS_INCRSAT | 
+                         D3DSTENCILCAPS_INVERT  | 
+                         D3DSTENCILCAPS_KEEP    | 
+                         D3DSTENCILCAPS_REPLACE | 
+                         D3DSTENCILCAPS_ZERO;
+                         /* FIXME: Add
+                             D3DSTENCILCAPS_DECR
+                             D3DSTENCILCAPS_INCR */
 
     pCaps->FVFCaps = D3DFVFCAPS_PSIZE | 0x80000;
 
-    pCaps->TextureOpCaps = D3DTEXOPCAPS_ADD | D3DTEXOPCAPS_ADDSIGNED | D3DTEXOPCAPS_ADDSIGNED2X |
-                           D3DTEXOPCAPS_MODULATE | D3DTEXOPCAPS_MODULATE2X | D3DTEXOPCAPS_MODULATE4X |
-                           D3DTEXOPCAPS_SELECTARG1 | D3DTEXOPCAPS_SELECTARG2 | D3DTEXOPCAPS_DISABLE;
+    pCaps->TextureOpCaps =  D3DTEXOPCAPS_ADD         | 
+                            D3DTEXOPCAPS_ADDSIGNED   | 
+                            D3DTEXOPCAPS_ADDSIGNED2X |
+                            D3DTEXOPCAPS_MODULATE    | 
+                            D3DTEXOPCAPS_MODULATE2X  | 
+                            D3DTEXOPCAPS_MODULATE4X  |
+                            D3DTEXOPCAPS_SELECTARG1  | 
+                            D3DTEXOPCAPS_SELECTARG2  | 
+                            D3DTEXOPCAPS_DISABLE;
 #if defined(GL_VERSION_1_3)
-    pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 | D3DTEXOPCAPS_SUBTRACT;
+    pCaps->TextureOpCaps |= D3DTEXOPCAPS_DOTPRODUCT3 | 
+                            D3DTEXOPCAPS_SUBTRACT;
 #endif
-              /* FIXME: Add D3DTEXOPCAPS_ADDSMOOTH D3DTEXOPCAPS_BLENDCURRENTALPHA D3DTEXOPCAPS_BLENDDIFFUSEALPHA D3DTEXOPCAPS_BLENDFACTORALPHA 
-                            D3DTEXOPCAPS_BLENDTEXTUREALPHA D3DTEXOPCAPS_BLENDTEXTUREALPHAPM D3DTEXOPCAPS_BUMPENVMAP D3DTEXOPCAPS_BUMPENVMAPLUMINANCE 
-                            D3DTEXOPCAPS_LERP D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA 
-                            D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA D3DTEXOPCAPS_MULTIPLYADD 
-                            D3DTEXOPCAPS_PREMODULATE */
+                            /* FIXME: Add 
+			      D3DTEXOPCAPS_ADDSMOOTH
+			      D3DTEXOPCAPS_BLENDCURRENTALPHA 
+			      D3DTEXOPCAPS_BLENDDIFFUSEALPHA 
+			      D3DTEXOPCAPS_BLENDFACTORALPHA 
+			      D3DTEXOPCAPS_BLENDTEXTUREALPHA 
+			      D3DTEXOPCAPS_BLENDTEXTUREALPHAPM 
+			      D3DTEXOPCAPS_BUMPENVMAP
+			      D3DTEXOPCAPS_BUMPENVMAPLUMINANCE 
+			      D3DTEXOPCAPS_LERP 
+			      D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR 
+			      D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA 
+			      D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR 
+			      D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
+			      D3DTEXOPCAPS_MULTIPLYADD 
+			      D3DTEXOPCAPS_PREMODULATE */
 
     {
         GLint gl_max;
+	GLfloat gl_float;
+
 #if defined(GL_VERSION_1_3)
         glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gl_max);
 #else
@@ -499,14 +570,34 @@
         glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
         pCaps->MaxActiveLights = min(MAX_ACTIVE_LIGHTS, gl_max);
         TRACE("GLCaps: GL_MAX_LIGHTS=%ld\n", pCaps->MaxActiveLights);
-    }
 
-    pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS | D3DVTXPCAPS_MATERIALSOURCE7 | D3DVTXPCAPS_POSITIONALLIGHTS | D3DVTXPCAPS_TEXGEN;
+#if defined(GL_ARB_vertex_blend)
+	glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
+	pCaps->MaxVertexBlendMatrices = gl_max;
+	pCaps->MaxVertexBlendMatrixIndex = 1;
+#else
+	pCaps->MaxVertexBlendMatrices = 0;
+	pCaps->MaxVertexBlendMatrixIndex = 1;
+#endif
+
+#if defined(GL_EXT_texture_filter_anisotropic)
+        glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
+        pCaps->MaxAnisotropy = gl_max;
+#else
+        pCaps->MaxAnisotropy = 0;
+#endif
 
-    pCaps->MaxVertexBlendMatrices = 1;
-    pCaps->MaxVertexBlendMatrixIndex = 1;
+	glGetFloatv(GL_POINT_SIZE_RANGE, &gl_float);
+	pCaps->MaxPointSize = gl_float;
+    }
 
-    pCaps->MaxPointSize = 128.0;
+    pCaps->VertexProcessingCaps = D3DVTXPCAPS_DIRECTIONALLIGHTS | 
+                                  D3DVTXPCAPS_MATERIALSOURCE7   | 
+                                  D3DVTXPCAPS_POSITIONALLIGHTS  | 
+                                  D3DVTXPCAPS_TEXGEN;
+                                  /* FIXME: Add 
+				     D3DVTXPCAPS_LOCALVIEWER 
+				     D3DVTXPCAPS_TWEENING */
 
     pCaps->MaxPrimitiveCount = 0xFFFFFFFF;
     pCaps->MaxVertexIndex = 0xFFFFFFFF;
@@ -718,24 +809,39 @@
                                             pPresentationParameters->BackBufferWidth,
                                             pPresentationParameters->BackBufferHeight,
                                             pPresentationParameters->BackBufferFormat,
-					    D3DMULTISAMPLE_NONE, TRUE,
+					    pPresentationParameters->MultiSampleType,
+					    TRUE,
                                             (LPDIRECT3DSURFACE8*) &object->frontBuffer);
 
     IDirect3DDevice8Impl_CreateRenderTarget((LPDIRECT3DDEVICE8) object,
                                             pPresentationParameters->BackBufferWidth,
                                             pPresentationParameters->BackBufferHeight,
                                             pPresentationParameters->BackBufferFormat,
-					    D3DMULTISAMPLE_NONE, TRUE,
+					    pPresentationParameters->MultiSampleType,
+					    TRUE,
                                             (LPDIRECT3DSURFACE8*) &object->backBuffer);
 
-    if (pPresentationParameters->EnableAutoDepthStencil)
-        IDirect3DDevice8Impl_CreateDepthStencilSurface((LPDIRECT3DDEVICE8) object,
-						       pPresentationParameters->BackBufferWidth,
-						       pPresentationParameters->BackBufferHeight,
-						       pPresentationParameters->AutoDepthStencilFormat,
-						       D3DMULTISAMPLE_NONE,
-						       (LPDIRECT3DSURFACE8*) &object->depthStencilBuffer);
-    
+    if (pPresentationParameters->EnableAutoDepthStencil) {
+       IDirect3DDevice8Impl_CreateDepthStencilSurface((LPDIRECT3DDEVICE8) object,
+	  					      pPresentationParameters->BackBufferWidth,
+						      pPresentationParameters->BackBufferHeight,
+						      pPresentationParameters->AutoDepthStencilFormat,
+						      D3DMULTISAMPLE_NONE,
+						      (LPDIRECT3DSURFACE8*) &object->depthStencilBuffer);
+    } else {
+      object->depthStencilBuffer = NULL;
+    }
+
+    /* init the default renderTarget management */
+    object->drawable = object->win;
+    object->render_ctx = object->glCtx;
+    object->renderTarget = object->frontBuffer;
+    IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->renderTarget);
+    object->stencilBufferTarget = object->depthStencilBuffer;
+    if (NULL != object->stencilBufferTarget)
+      IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) object->stencilBufferTarget);
+
+
     /* Now override the surface's Flip method (if in double buffering) ?COPIED from DDRAW!?
     ((x11_ds_private *) surface->private)->opengl_flip = TRUE;
     {
@@ -768,25 +874,29 @@
     checkGLcall("glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);");
 
     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
-    checkGLcall("glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
+    checkGLcall("glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);");
 
-    /* Initialize openGL extension related variables */
-    object->isMultiTexture = FALSE;
-    object->isDot3         = FALSE;
-    object->TextureUnits   = 1;
+    /* 
+     * Initialize openGL extension related variables
+     *  with Default values 
+     */
+    memset(&This->gl_info.supported, 0, sizeof(This->gl_info.supported));
+    This->gl_info.max_textures   = 1;
+    This->gl_info.vs_arb_version = VS_VERSION_NOT_SUPPORTED;
+    This->gl_info.vs_nv_version  = VS_VERSION_NOT_SUPPORTED;
 
     /* Retrieve opengl defaults */
     glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
-    object->clipPlanes   = min(MAX_CLIPPLANES, gl_max);
+    This->gl_info.max_clipplanes = min(MAX_CLIPPLANES, gl_max);
     TRACE("ClipPlanes support - num Planes=%d\n", gl_max);
 
     glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
-    object->maxLights = min(MAX_ACTIVE_LIGHTS, gl_max);
+    This->gl_info.max_lights = min(MAX_ACTIVE_LIGHTS, gl_max);
     TRACE("Lights support - max lights=%d\n", gl_max);
 
     /* Parse the gl supported features, in theory enabling parts of our code appropriately */
     GL_Extensions = glGetString(GL_EXTENSIONS);
-    TRACE("GL_Extensions reported:\n");  
+    FIXME("GL_Extensions reported:\n");  
     
     if (NULL == GL_Extensions) {
       ERR("   GL_Extensions returns NULL\n");      
@@ -800,17 +910,78 @@
 	  GL_Extensions++;
         }
         memcpy(ThisExtn, Start, (GL_Extensions - Start));
-        TRACE ("   %s\n", ThisExtn);
+        FIXME("- %s\n", ThisExtn);
+
+	/**
+	 * ARB 
+	 */
+        if (strcmp(ThisExtn, "GL_ARB_multisample") == 0) {
+	  FIXME(" FOUND: ARB Multisample support\n");
+	  This->gl_info.supported[ARB_MULTISAMPLE] = TRUE;
+	} else if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
+	  glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
+	  FIXME(" FOUND: ARB Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%u\n", gl_max);
+	  This->gl_info.supported[ARB_MULTITEXTURE] = TRUE;
+	  This->gl_info.max_textures = min(8, gl_max);
+        } else if (strcmp(ThisExtn, "GL_ARB_texture_cube_map") == 0) {
+	  FIXME(" FOUND: ARB Texture Cube Map support\n");
+	  This->gl_info.supported[ARB_TEXTURE_CUBE_MAP] = TRUE;
+        } else if (strcmp(ThisExtn, "GL_ARB_texture_compression") == 0) {
+	  FIXME(" FOUND: ARB Texture Compression support\n");
+	  This->gl_info.supported[ARB_TEXTURE_COMPRESSION] = TRUE;
+        } else if (strcmp(ThisExtn, "GL_ARB_texture_env_dot3") == 0) {
+	  FIXME(" FOUND: EXT Dot3 support\n");
+	  This->gl_info.supported[ARB_TEXTURE_ENV_DOT3] = TRUE;
+	} else if (strstr(ThisExtn, "GL_ARB_vertex_program")) {
+	  This->gl_info.vs_arb_version = VS_VERSION_11;
+	  FIXME(" FOUND: ARB Vertex Shader support - version=%02x\n", This->gl_info.vs_arb_version);
+	  This->gl_info.supported[ARB_VERTEX_PROGRAM] = TRUE;
+
+	/**
+	 * EXT
+	 */
+        } else if (strcmp(ThisExtn, "GL_EXT_fog_coord") == 0) {
+	  FIXME(" FOUND: EXT Fog coord support\n");
+	  This->gl_info.supported[EXT_FOG_COORD] = TRUE;
+        } else if (strcmp(ThisExtn, "GL_EXT_paletted_texture") == 0) {
+	  /* handle paletted texture extensions */
+	  FIXME(" FOUND: EXT Paletted texture support\n");
+	  This->gl_info.supported[EXT_PALETTED_TEXTURE] = TRUE;
+	} else if (strcmp(ThisExtn, "GL_EXT_secondary_color") == 0) {
+	  FIXME(" FOUND: EXT Secondary coord support\n");
+	  This->gl_info.supported[EXT_SECONDARY_COLOR] = TRUE;
+	} else if (strcmp(ThisExtn, "GL_EXT_texture_compression_s3tc") == 0) {
+	  FIXME(" FOUND: EXT Texture S3TC compression support\n");
+	  This->gl_info.supported[EXT_TEXTURE_COMPRESSION_S3TC] = TRUE;
+	} else if (strcmp(ThisExtn, "GL_EXT_texture_lod") == 0) {
+	  FIXME(" FOUND: EXT Texture LOD support\n");
+	  This->gl_info.supported[EXT_TEXTURE_LOD] = TRUE;
+	} else if (strcmp(ThisExtn, "GL_EXT_texture_lod_bias") == 0) {
+	  FIXME(" FOUND: EXT Texture LOD bias support\n");
+	  This->gl_info.supported[EXT_TEXTURE_LOD_BIAS] = TRUE;
+	} else if (strcmp(ThisExtn, "GL_EXT_vertex_weighting") == 0) {
+	  FIXME(" FOUND: EXT Vertex weighting support\n");
+	  This->gl_info.supported[EXT_VERTEX_WEIGHTING] = TRUE;
+
+	/**
+	 * NVIDIA 
+	 */
+	} else if (strstr(ThisExtn, "GL_NV_vertex_program")) {
+	  This->gl_info.vs_nv_version = max(This->gl_info.vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program1_1")) ? VS_VERSION_11 : VS_VERSION_10);
+	  This->gl_info.vs_nv_version = max(This->gl_info.vs_nv_version, (0 == strcmp(ThisExtn, "GL_NV_vertex_program2"))   ? VS_VERSION_20 : VS_VERSION_10);
+	  FIXME(" FOUND: NVIDIA (NV) Vertex Shader support - version=%02x\n", This->gl_info.vs_nv_version);
+	  This->gl_info.supported[NV_VERTEX_PROGRAM] = TRUE;
+
+	/**
+	 * ATI
+	 */
+	/** TODO */
+	} else if (strcmp(ThisExtn, "GL_EXT_vertex_shader") == 0) {
+	  This->gl_info.vs_ati_version = VS_VERSION_11;
+	  FIXME(" FOUND: ATI (EXT) Vertex Shader support - version=%02x\n", This->gl_info.vs_ati_version);
+	  This->gl_info.supported[EXT_VERTEX_SHADER] = TRUE;
+	}
 
-        if (strcmp(ThisExtn, "GL_ARB_multitexture") == 0) {
-            glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
-            object->isMultiTexture = TRUE;
-            object->TextureUnits   = min(8, gl_max);
-            TRACE("FOUND: Multitexture support - GL_MAX_TEXTURE_UNITS_ARB=%d\n", gl_max);
-        } else if (strcmp(ThisExtn, "GL_EXT_texture_env_dot3") == 0) {
-            object->isDot3 = TRUE;
-            TRACE("FOUND: Dot3 support\n");
-        }
 
         if (*GL_Extensions == ' ') GL_Extensions++;
       }
@@ -831,7 +1002,7 @@
 	  GLX_Extensions++;
         }
         memcpy(ThisExtn, Start, (GLX_Extensions - Start));
-        TRACE ("   %s\n", ThisExtn);
+        TRACE ("- %s\n", ThisExtn);
         if (*GLX_Extensions == ' ') GLX_Extensions++;
       }
     }
Index: resource.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/resource.c,v
retrieving revision 1.5
diff -u -r1.5 resource.c
--- resource.c	17 May 2003 18:33:02 -0000	1.5
+++ resource.c	22 May 2003 22:24:16 -0000
@@ -101,6 +101,30 @@
     return This->ResourceType;
 }
 
+D3DPOOL WINAPI IDirect3DResource8Impl_GetPool(LPDIRECT3DRESOURCE8 iface) {    
+    ICOM_THIS(IDirect3DResource8Impl,iface);
+
+    switch (This->ResourceType) { 
+    case D3DRTYPE_SURFACE:
+      return ((IDirect3DSurface8Impl*) This)->myDesc.Pool;
+    case D3DRTYPE_TEXTURE:
+      return ((IDirect3DTexture8Impl*) This)->surfaces[0]->myDesc.Pool;
+    case D3DRTYPE_VOLUME:
+      return ((IDirect3DVolume8Impl*) This)->myDesc.Pool;
+    case D3DRTYPE_VOLUMETEXTURE:
+      return ((IDirect3DVolumeTexture8Impl*) This)->volumes[0]->myDesc.Pool;
+    case D3DRTYPE_CUBETEXTURE:
+      return ((IDirect3DCubeTexture8Impl*) This)->surfaces[0][0]->myDesc.Pool;
+    case D3DRTYPE_VERTEXBUFFER:
+      return ((IDirect3DVertexBuffer8Impl*) This)->currentDesc.Pool;
+    case D3DRTYPE_INDEXBUFFER:
+      return ((IDirect3DIndexBuffer8Impl*) This)->currentDesc.Pool;
+    default:
+      FIXME("(%p) Unrecognized type(%d,%s)\n", This, This->ResourceType, debug_d3dressourcetype(This->ResourceType));
+      return D3DPOOL_DEFAULT;
+    }
+}
+
 ICOM_VTABLE(IDirect3DResource8) Direct3DResource8_Vtbl =
 {
     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
Index: shader.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/shader.c,v
retrieving revision 1.11
diff -u -r1.11 shader.c
--- shader.c	17 May 2003 18:33:02 -0000	1.11
+++ shader.c	22 May 2003 22:24:16 -0000
@@ -593,6 +593,7 @@
   TRACE_VECTOR(vshader->data->C[6]);
   TRACE_VECTOR(vshader->data->C[7]);
   TRACE_VECTOR(vshader->data->C[8]);
+  TRACE_VECTOR(vshader->data->C[64]);
   TRACE_VECTOR(input->V[D3DVSDE_POSITION]);
   TRACE_VECTOR(input->V[D3DVSDE_BLENDWEIGHT]);
   TRACE_VECTOR(input->V[D3DVSDE_BLENDINDICES]);
Index: stateblock.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/stateblock.c,v
retrieving revision 1.5
diff -u -r1.5 stateblock.c
--- stateblock.c	17 May 2003 18:33:02 -0000	1.5
+++ stateblock.c	22 May 2003 22:24:16 -0000
@@ -154,7 +154,7 @@
     IDirect3DDevice8Impl_SetRenderState(iface, D3DRS_NORMALORDER, D3DORDER_LINEAR);
 
     /* Texture Stage States - Put directly into state block, we will call function below */
-    for (i = 0; i < This->TextureUnits; i++) {
+    for (i = 0; i < GL_LIMITS(textures); i++) {
         memcpy(&This->StateBlock->transforms[D3DTS_TEXTURE0 + i], &idmatrix, sizeof(idmatrix));
         This->StateBlock->texture_state[i][D3DTSS_COLOROP               ] = (i==0)? D3DTOP_MODULATE :  D3DTOP_DISABLE;
         This->StateBlock->texture_state[i][D3DTSS_COLORARG1             ] = D3DTA_TEXTURE;
@@ -191,7 +191,7 @@
        texture stage, but disable all stages by default. Hence if a stage is enabled
        then the default texture will kick in until replaced by a SetTexture call     */
 
-    for (i = 0; i < This->TextureUnits; i++) {
+    for (i = 0; i < GL_LIMITS(textures); i++) {
         GLubyte white = 255;
 
         /* Note this avoids calling settexture, so pretend it has been called */
@@ -200,7 +200,7 @@
         This->StateBlock->textures[i] = NULL;
 
         /* Make appropriate texture active */
-        if (This->isMultiTexture) {
+        if (GL_SUPPORT(ARB_MULTITEXTURE)) {
 #if defined(GL_VERSION_1_3)
             glActiveTexture(GL_TEXTURE0 + i);
 #else
@@ -289,7 +289,7 @@
     for (i = 0; i < NUM_SAVEDPIXELSTATES_R; i++) {
       object->Changed.renderstate[SavedPixelStates_R[i]] = TRUE;
     }
-    for (j = 0; j < This->TextureUnits; i++) {
+    for (j = 0; j < GL_LIMITS(textures); i++) {
       for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
 	object->Changed.texture_state[j][SavedPixelStates_T[i]] = TRUE;
       }
@@ -304,12 +304,12 @@
     for (i = 0; i < NUM_SAVEDVERTEXSTATES_R; i++) {
       object->Changed.renderstate[SavedVertexStates_R[i]] = TRUE;
     }
-    for (j = 0; j < This->TextureUnits; i++) {
+    for (j = 0; j < GL_LIMITS(textures); i++) {
       for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
 	object->Changed.texture_state[j][SavedVertexStates_T[i]] = TRUE;
       }
     }
-    for (i = 0; i < This->maxLights; i++) {
+    for (i = 0; i < GL_LIMITS(lights); i++) {
       object->Changed.lightEnable[i] = TRUE;
       object->Changed.lights[i] = TRUE;
     }
@@ -385,7 +385,7 @@
 
     if (pSB->blockType == D3DSBT_RECORDED || pSB->blockType == D3DSBT_ALL || pSB->blockType == D3DSBT_VERTEXSTATE) {
 
-        for (i = 0; i < This->maxLights; i++) {
+        for (i = 0; i < GL_LIMITS(lights); i++) {
 
             if (pSB->Set.lightEnable[i] && pSB->Changed.lightEnable[i])
                 IDirect3DDevice8Impl_LightEnable(iface, i, pSB->lightEnable[i]);
@@ -428,7 +428,7 @@
                 IDirect3DDevice8Impl_SetStreamSource(iface, i, pSB->stream_source[i], pSB->stream_stride[i]);
         }
 
-        for (i = 0; i < This->clipPlanes; i++) {
+        for (i = 0; i < GL_LIMITS(clipplanes); i++) {
             if (pSB->Set.clipplane[i] && pSB->Changed.clipplane[i]) {
                 float clip[4];
 
@@ -447,7 +447,7 @@
         }
 
         /* Texture */
-        for (j = 0; j < This->TextureUnits; j++) {
+        for (j = 0; j < GL_LIMITS(textures); 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]);
@@ -467,7 +467,7 @@
 
         }
 
-        for (j = 0; j < This->TextureUnits; i++) {
+        for (j = 0; j < GL_LIMITS(textures); i++) {
             for (i = 0; i < NUM_SAVEDPIXELSTATES_T; i++) {
                 if (pSB->Set.texture_state[j][SavedPixelStates_T[i]] &&
                     pSB->Changed.texture_state[j][SavedPixelStates_T[i]])
@@ -482,7 +482,7 @@
                 IDirect3DDevice8Impl_SetRenderState(iface, SavedVertexStates_R[i], pSB->renderstate[SavedVertexStates_R[i]]);
         }
 
-        for (j = 0; j < This->TextureUnits; i++) {
+        for (j = 0; j < GL_LIMITS(textures); i++) {
             for (i = 0; i < NUM_SAVEDVERTEXSTATES_T; i++) {
                 if (pSB->Set.texture_state[j][SavedVertexStates_T[i]] &&
                     pSB->Changed.texture_state[j][SavedVertexStates_T[i]])
@@ -526,7 +526,7 @@
 
         /* TODO: Vertex Shader Constants */
 
-        for (i = 0; i < This->maxLights; i++) {
+        for (i = 0; i < GL_LIMITS(lights); i++) {
           if (updateBlock->Set.lightEnable[i] && This->StateBlock->lightEnable[i] != updateBlock->lightEnable[i]) {
               TRACE("Updating light enable for light %d to %d\n", i, This->StateBlock->lightEnable[i]);
               updateBlock->lightEnable[i] = This->StateBlock->lightEnable[i];
@@ -591,7 +591,7 @@
            }
        }
 
-       for (i = 0; i < This->clipPlanes; i++) {
+       for (i = 0; i < GL_LIMITS(clipplanes); i++) {
            if (updateBlock->Set.clipplane[i] && memcmp(&This->StateBlock->clipplane[i], 
                                                        &updateBlock->clipplane[i], 
                                                        sizeof(updateBlock->clipplane)) != 0) {
@@ -613,7 +613,7 @@
        }
 
        /* Texture */
-       for (j = 0; j < This->TextureUnits; j++) {
+       for (j = 0; j < GL_LIMITS(textures); j++) {
            for (i = 0; i < HIGHEST_TEXTURE_STATE; i++) {
 
                if (updateBlock->Set.texture_state[j][i] && (updateBlock->texture_state[j][i] != 
Index: surface.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/surface.c,v
retrieving revision 1.9
diff -u -r1.9 surface.c
--- surface.c	17 May 2003 18:33:02 -0000	1.9
+++ surface.c	22 May 2003 22:24:16 -0000
@@ -131,11 +131,13 @@
       return D3DERR_INVALIDCALL;
     }
 
-    if (This == This->Device->backBuffer || This == This->Device->frontBuffer || This->Device->depthStencilBuffer) {
+    if (This == This->Device->backBuffer || This == This->Device->renderTarget || This == This->Device->frontBuffer || This->Device->depthStencilBuffer) {
       if (This == This->Device->backBuffer) {
 	TRACE("(%p, backBuffer) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
       } else if (This == This->Device->frontBuffer) {
 	TRACE("(%p, frontBuffer) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
+      } else if (This == This->Device->renderTarget) {
+	TRACE("(%p, renderTarget) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
       } else if (This == This->Device->depthStencilBuffer) {
 	TRACE("(%p, stencilBuffer) : rect@%p flags(%08lx), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->allocatedMemory);
       }
@@ -167,7 +169,7 @@
 
     } else if (D3DUSAGE_RENDERTARGET & This->myDesc.Usage) { /* render surfaces */
       
-      if (This == This->Device->backBuffer || This == This->Device->frontBuffer) {
+      if (This == This->Device->backBuffer || This == This->Device->renderTarget || This == This->Device->frontBuffer) {
 	GLint  prev_store;
 	GLenum prev_read;
 	
@@ -188,84 +190,13 @@
 
 	if (This == This->Device->backBuffer) {
 	  glReadBuffer(GL_BACK);
-	} else if (This == This->Device->frontBuffer) {
+	} else if (This == This->Device->frontBuffer || This == This->Device->renderTarget) {
 	  glReadBuffer(GL_FRONT);
+	} else if (This == This->Device->depthStencilBuffer) {
+	  ERR("Stencil Buffer lock unsupported for now\n");
 	}
 	vcheckGLcall("glReadBuffer");
 
-	/** TODO: use an enhanced version of fmt2glintFmt here instad this switch */
-#if 0
-	switch (This->myDesc.Format) { 
-	case D3DFMT_R5G6B5:
-	  { 
-	    /*
-	      glReadPixels(This->lockedRect.left, This->lockedRect.top, 
-	                   This->lockedRect.right - This->lockedRect.left, This->lockedRect.bottom - This->lockedRect.top,
-	                   GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pLockedRect->pBits);
-	      vcheckGLcall("glReadPixels");
-	    */
-	    long j;
-	    for (j = This->lockedRect.top; j < This->lockedRect.bottom - This->lockedRect.top; ++j) {
-	      glReadPixels(This->lockedRect.left, 
-			   This->lockedRect.bottom - j - 1, 
-			   This->lockedRect.right - This->lockedRect.left, 
-			   1,
-			   GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pLockedRect->pBits);
-	      vcheckGLcall("glReadPixels");
-	    }
-	  }
-	  break;
-	case D3DFMT_R8G8B8:
-	  {
-	    /*
-	    glReadPixels(This->lockedRect.left, This->lockedRect.top, 
-			 This->lockedRect.right - This->lockedRect.left, This->lockedRect.bottom - This->lockedRect.top,
-			 GL_RGB, GL_UNSIGNED_BYTE, pLockedRect->pBits);
-	    vcheckGLcall("glReadPixels");
-	    */
-	    long j;
-	    for (j = This->lockedRect.top; j < This->lockedRect.bottom - This->lockedRect.top; ++j) {
-	      glReadPixels(This->lockedRect.left, 
-			   This->lockedRect.bottom - j - 1, 
-			   This->lockedRect.right - This->lockedRect.left, 
-			   1,
-			   GL_RGB, GL_UNSIGNED_BYTE, pLockedRect->pBits);
-	      vcheckGLcall("glReadPixels");
-	    }
-	  }
-	  break;
-	case D3DFMT_A8R8G8B8:
-	  {
-	    /*
-	    glPixelStorei(GL_PACK_SWAP_BYTES, TRUE);
-	    vcheckGLcall("glPixelStorei");
-	    glReadPixels(This->lockedRect.left, This->lockedRect.top, 
-			 This->lockedRect.right - This->lockedRect.left, This->lockedRect.bottom - This->lockedRect.top,
-			 GL_BGRA, GL_UNSIGNED_BYTE, pLockedRect->pBits);
-	    vcheckGLcall("glReadPixels");
-	    glPixelStorei(GL_PACK_SWAP_BYTES, prev_store);
-	    vcheckGLcall("glPixelStorei");
-	    */
-	    long j;
-	    glPixelStorei(GL_PACK_SWAP_BYTES, TRUE);
-	    vcheckGLcall("glPixelStorei");
-	    for (j = This->lockedRect.top; j < This->lockedRect.bottom - This->lockedRect.top; ++j) {
-	      glReadPixels(This->lockedRect.left, 
-			   This->lockedRect.bottom - j - 1, 
-			   This->lockedRect.right - This->lockedRect.left, 
-			   1,
-			   GL_BGRA, GL_UNSIGNED_BYTE, pLockedRect->pBits);
-	    vcheckGLcall("glReadPixels");
-	    }
-	    glPixelStorei(GL_PACK_SWAP_BYTES, prev_store);
-	    vcheckGLcall("glPixelStorei");
-	  }
-	  break;
-	default:
-	  FIXME("Unsupported Format %u in locking func\n", This->myDesc.Format);
-	}
-#endif
-
 	{
 	  long j;
 	  for (j = This->lockedRect.top; j < This->lockedRect.bottom - This->lockedRect.top; ++j) {
@@ -273,7 +204,9 @@
 			 This->lockedRect.bottom - j - 1, 
 			 This->lockedRect.right - This->lockedRect.left, 
 			 1,
-			 fmt2glFmt(This->myDesc.Format), fmt2glType(This->myDesc.Format), pLockedRect->pBits);
+			 D3DFmt2GLFmt(This->myDesc.Format), 
+                         D3DFmt2GLType(This->myDesc.Format), 
+                         pLockedRect->pBits);
 	    vcheckGLcall("glReadPixels");
 	  }
 	}
@@ -307,6 +240,8 @@
 	hr = IUnknown_QueryInterface(This->Container, &IID_IDirect3DBaseTexture8, (void**) &cont);
 	
 	if (SUCCEEDED(hr) && NULL != cont) {
+	  IDirect3DBaseTexture8Impl_SetDirty(cont, TRUE);
+#if 0
 	  /* Now setup the texture appropraitly */
 	  D3DRESOURCETYPE containerType = IDirect3DBaseTexture8Impl_GetType(cont);
 	  if (containerType == D3DRTYPE_TEXTURE) {
@@ -318,6 +253,7 @@
 	  } else {
             FIXME("Set dirty on container type %d\n", containerType);
 	  }
+#endif
 	  IDirect3DBaseTexture8_Release(cont);
 	  cont = NULL;
 	}
@@ -356,29 +292,10 @@
     }
 
     if (0 == This->myDesc.Usage) { /* classic surface */
-#if 0
-      if (This->Container) {
-	HRESULT hr;
-	IDirect3DBaseTexture8* cont = NULL;
-	hr = IUnknown_QueryInterface(This->Container, &IID_IDirect3DBaseTexture8, (void**) &cont);
-	
-	if (SUCCEEDED(hr) && NULL != cont) {
-	  /* Now setup the texture appropraitly */
-	  int containerType = IDirect3DBaseTexture8Impl_GetType(cont);
-	  if (containerType == D3DRTYPE_TEXTURE) {
-	    IDirect3DTexture8Impl *pTexture = (IDirect3DTexture8Impl *)cont;
-	    pTexture->Dirty = TRUE;
-	  } else if (containerType == D3DRTYPE_CUBETEXTURE) {
-	    IDirect3DCubeTexture8Impl *pTexture = (IDirect3DCubeTexture8Impl *)cont;
-	    pTexture->Dirty = TRUE;
-	  } else {
-	    FIXME("Set dirty on container type %d\n", containerType);
-	  }
-	  IDirect3DBaseTexture8_Release(cont);
-	  cont = NULL;
-	}
-      }
-#endif
+      /**
+       * nothing to do
+       * waiting to reload the surface via IDirect3DDevice8::UpdateTexture
+       */
     } else if (D3DUSAGE_RENDERTARGET & This->myDesc.Usage) { /* render surfaces */
 
       if (This == This->Device->backBuffer || This == This->Device->frontBuffer) {
@@ -441,6 +358,9 @@
 	glRasterPos3iv(&prev_rasterpos[0]);
 	vcheckGLcall("glRasterPos3iv");
 	LEAVE_GL();
+
+	This->Dirty = FALSE;
+
       } else {
 	FIXME("unsupported unlocking to Rendering surface surf@%p usage(%lu)\n", This, This->myDesc.Usage);
       }
@@ -462,7 +382,6 @@
     return D3D_OK;
 }
 
-
 ICOM_VTABLE(IDirect3DSurface8) Direct3DSurface8_Vtbl =
 {
     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
@@ -478,3 +397,80 @@
     IDirect3DSurface8Impl_LockRect,
     IDirect3DSurface8Impl_UnlockRect,
 };
+
+HRESULT WINAPI IDirect3DSurface8Impl_CreateGLTexture(LPDIRECT3DSURFACE8 iface, GLenum gl_target, GLenum gl_level) {
+  ICOM_THIS(IDirect3DSurface8Impl,iface);
+
+
+  if ((This->myDesc.Format == D3DFMT_P8 || This->myDesc.Format == D3DFMT_A8P8) && 
+      !GL_SUPPORT_DEV(EXT_PALETTED_TEXTURE, This->Device)) {
+    /**
+     * wanted a paletted texture and not really support it in HW 
+     * so software emulation code begin
+     */
+    UINT i;
+    PALETTEENTRY* pal = This->Device->palettes[This->Device->currentPalette];
+    VOID* surface = (VOID*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->myDesc.Width * This->myDesc.Height * sizeof(DWORD));
+    BYTE* dst = (BYTE*) surface;
+    BYTE* src = (BYTE*) This->allocatedMemory;
+          
+    for (i = 0; i < This->myDesc.Width * This->myDesc.Height; i++) {
+      BYTE color = *src++;
+      *dst++ = pal[color].peRed;
+      *dst++ = pal[color].peGreen;
+      *dst++ = pal[color].peBlue;
+      if (This->myDesc.Format == D3DFMT_A8P8)
+	*dst++ = pal[color].peFlags; 
+      else
+	*dst++ = 0xFF; 
+    }
+    
+    TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
+	  gl_target,
+	  gl_level, 
+	  GL_RGBA,
+	  This->myDesc.Width, 
+	  This->myDesc.Height, 
+	  0, 
+	  GL_RGBA,
+	  GL_UNSIGNED_BYTE,
+	  surface);
+    glTexImage2D(gl_target,
+		 gl_level, 
+		 GL_RGBA,
+		 This->myDesc.Width,
+		 This->myDesc.Height,
+		 0,
+		 GL_RGBA,
+		 GL_UNSIGNED_BYTE,
+		 surface);
+    checkGLcall("glTexImage2D");
+    HeapFree(GetProcessHeap(), 0, surface);
+
+    return D3D_OK;    
+  }
+
+  TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
+	gl_target, 
+	gl_level, 
+	D3DFmt2GLIntFmt(This->myDesc.Format), 
+	This->myDesc.Width, 
+	This->myDesc.Height, 
+	0, 
+	D3DFmt2GLFmt(This->myDesc.Format), 
+	D3DFmt2GLType(This->myDesc.Format),
+	This->allocatedMemory);
+  glTexImage2D(gl_target,
+	       gl_level,
+	       D3DFmt2GLIntFmt(This->myDesc.Format),
+	       This->myDesc.Width,
+	       This->myDesc.Height,
+	       0,
+	       D3DFmt2GLFmt(This->myDesc.Format),
+	       D3DFmt2GLType(This->myDesc.Format),
+	       This->allocatedMemory);
+  checkGLcall("glTexImage2D");
+  
+
+  return D3D_OK;
+}
Index: swapchain.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/swapchain.c,v
retrieving revision 1.4
diff -u -r1.4 swapchain.c
--- swapchain.c	11 May 2003 03:35:27 -0000	1.4
+++ swapchain.c	22 May 2003 22:24:16 -0000
@@ -74,7 +74,6 @@
     return D3D_OK;
 }
 
-
 ICOM_VTABLE(IDirect3DSwapChain8) Direct3DSwapChain8_Vtbl =
 {
     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
Index: texture.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/texture.c,v
retrieving revision 1.8
diff -u -r1.8 texture.c
--- texture.c	17 May 2003 18:33:02 -0000	1.8
+++ texture.c	22 May 2003 22:24:16 -0000
@@ -133,22 +133,30 @@
 	  checkGLcall("glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, This->levels)");
 	  
 	}
-	TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%lx, Mem=%p\n",
-	      GL_TEXTURE_2D, i, fmt2glintFmt(This->format), 
-	      This->surfaces[i]->myDesc.Width, This->surfaces[i]->myDesc.Height, 
-	      0, fmt2glFmt(This->format), fmt2glType(This->format),
+
+	IDirect3DSurface8Impl_CreateGLTexture((LPDIRECT3DSURFACE8) This->surfaces[i], GL_TEXTURE_2D, i); 
+#if 0
+	TRACE("Calling glTexImage2D %x i=%d, intfmt=%x, w=%d, h=%d,0=%d, glFmt=%x, glType=%x, Mem=%p\n",
+	      GL_TEXTURE_2D, 
+              i, 
+              D3DFmt2GLIntFmt(This->format),
+	      This->surfaces[i]->myDesc.Width, 
+              This->surfaces[i]->myDesc.Height, 
+	      0, 
+              D3DFmt2GLFmt(This->format), 
+              D3DFmt2GLType(This->format),
 	      This->surfaces[i]->allocatedMemory);
 	glTexImage2D(GL_TEXTURE_2D, 
 		     i,
-		     fmt2glintFmt(This->format),
+		     D3DFmt2GLIntFmt(This->format),
 		     This->surfaces[i]->myDesc.Width,
 		     This->surfaces[i]->myDesc.Height,
 		     0,
-		     fmt2glFmt(This->format),
-		     fmt2glType(This->format),
+		     D3DFmt2GLFmt(This->format),
+		     D3DFmt2GLType(This->format),
 		     This->surfaces[i]->allocatedMemory);
 	checkGLcall("glTexImage2D");
-	
+#endif
 	/* Removed glTexParameterf now TextureStageStates are initialized at startup */
 	This->Dirty = FALSE;
       }
@@ -202,20 +210,27 @@
     ICOM_THIS(IDirect3DTexture8Impl,iface);
     TRACE("(%p) Level (%d)\n", This, Level);
     if (Level < This->levels) {
-      /**
-       * Not dirtified while Surfaces don't notify dirtification
-       * This->Dirty = TRUE;
-       */
-      hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[Level], pLockedRect, pRect, Flags);
-      TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
+        /**
+	 * Not dirtified while Surfaces don't notify dirtification
+	 * This->Dirty = TRUE;
+	 */
+        hr = IDirect3DSurface8Impl_LockRect((LPDIRECT3DSURFACE8) This->surfaces[Level], pLockedRect, pRect, Flags);
+        TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
     } else {
         FIXME("Levels seems too high?!!\n");
     }
     return hr;
 }
 HRESULT  WINAPI        IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level) {
+    HRESULT hr;
     ICOM_THIS(IDirect3DTexture8Impl,iface);
-    TRACE("(%p) : stub\n", This);
+    TRACE("(%p) Level (%d)\n", This, Level);
+    if (Level < This->levels) {
+        hr = IDirect3DSurface8Impl_UnlockRect((LPDIRECT3DSURFACE8) This->surfaces[Level]);
+        TRACE("(%p) Level (%d) success(%lu)\n", This, Level, hr);
+    } else {
+        FIXME("Levels seems too high?!!\n");
+    }
     return D3D_OK;
 }
 HRESULT  WINAPI        IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect) {
Index: volumetexture.c
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/volumetexture.c,v
retrieving revision 1.8
diff -u -r1.8 volumetexture.c
--- volumetexture.c	13 May 2003 23:52:50 -0000	1.8
+++ volumetexture.c	22 May 2003 22:24:17 -0000
@@ -136,12 +136,17 @@
 	  glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, This->levels - 1); 
 	  checkGLcall("glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, This->levels - 1)");
 	}
-	
-	TRACE("Calling glTexImage3D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%lx, Mem=%p\n",
-	      GL_TEXTURE_3D, i, fmt2glintFmt(This->format), 
-	      This->volumes[i]->myDesc.Width, This->volumes[i]->myDesc.Height, 
+
+	TRACE("Calling glTexImage3D %x i=%d, intfmt=%x, w=%d, h=%d,d=%d, 0=%d, glFmt=%x, glType=%x, Mem=%p\n",
+	      GL_TEXTURE_3D, 
+	      i, 
+	      fmt2glintFmt(This->format), 
+	      This->volumes[i]->myDesc.Width, 
+	      This->volumes[i]->myDesc.Height, 
 	      This->volumes[i]->myDesc.Depth,
-	      0, fmt2glFmt(This->format), fmt2glType(This->format),
+	      0, 
+	      fmt2glFmt(This->format), 
+	      fmt2glType(This->format),
 	      This->volumes[i]->allocatedMemory);
 	glTexImage3D(GL_TEXTURE_3D, 
 		     i,
@@ -154,7 +159,7 @@
 		     fmt2glType(This->format),
 		     This->volumes[i]->allocatedMemory);
 	checkGLcall("glTexImage3D");
-	
+
 	/* Removed glTexParameterf now TextureStageStates are initialized at startup */
 	This->Dirty = FALSE;
       }
Index: d3d8_private.h
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/d3d8_private.h,v
retrieving revision 1.27
diff -u -r1.27 d3d8_private.h
--- d3d8_private.h	17 May 2003 18:33:02 -0000	1.27
+++ d3d8_private.h	22 May 2003 22:24:17 -0000
@@ -153,8 +153,61 @@
     } \
 }
 
-#define checkGLSupport(ExtName)  FALSE/*(TRUE == This->direct3d8->glInfo.supported[ExtName])*/
-#define GLExtCall(FuncName)      /*(This->direct3d8->glInfo.FuncName)*/
+typedef enum _GL_SupportedExt {
+  /* ARB */
+  ARB_MULTISAMPLE,
+  ARB_MULTITEXTURE,
+  ARB_POINT_PARAMETERS,
+  ARB_TEXTURE_COMPRESSION,
+  ARB_TEXTURE_CUBE_MAP,
+  ARB_TEXTURE_ENV_DOT3,
+  ARB_VERTEX_PROGRAM,
+  ARB_VERTEX_BLEND,
+  /* EXT */
+  EXT_FOG_COORD,
+  EXT_PALETTED_TEXTURE,
+  EXT_SECONDARY_COLOR,
+  EXT_TEXTURE_COMPRESSION_S3TC,
+  EXT_TEXTURE_LOD,
+  EXT_TEXTURE_LOD_BIAS,
+  EXT_VERTEX_WEIGHTING,
+  /* NVIDIA */
+  NV_VERTEX_PROGRAM,
+  /* ATI */
+  EXT_VERTEX_SHADER,
+
+  OPENGL_SUPPORTED_EXT_END
+} GL_SupportedExt;
+
+typedef enum _GL_VSVersion {
+  VS_VERSION_NOT_SUPPORTED = 0x0,
+  VS_VERSION_10 = 0x10,
+  VS_VERSION_11 = 0x11,
+  VS_VERSION_20 = 0x20,
+  VS_VERSION_30 = 0x30,
+  /*Force 32-bits*/
+  VS_VERSION_FORCE_DWORD = 0x7FFFFFFF
+} GL_VSVersion;
+
+typedef struct _GL_Info {
+  /** 
+   * CAPS Constants 
+   */
+  UINT   max_lights;
+  UINT   max_textures;
+  UINT   max_clipplanes;
+
+  GL_VSVersion vs_arb_version;
+  GL_VSVersion vs_nv_version;
+  GL_VSVersion vs_ati_version;
+  
+  BOOL supported[25];
+} GL_Info;
+
+#define GL_LIMITS(ExtName)     (This->direct3d8->gl_info.max_##ExtName)
+#define GL_SUPPORT(ExtName)    (TRUE == This->direct3d8->gl_info.supported[ExtName])
+#define GL_SUPPORT_DEV(ExtName, dev)    (TRUE == (dev)->direct3d8->gl_info.supported[ExtName])
+#define GLExtCall(FuncName)    /*(This->direct3d8->glInfo.FuncName)*/
 
 
 #define D3DCOLOR_R(dw) (((float) (((dw) >> 16) & 0xFF)) / 255.0f)
@@ -204,6 +257,7 @@
     DWORD                   ref;
 
     /* IDirect3D8 fields */
+    GL_Info                 gl_info;
 };
 
 /* IUnknown: */
@@ -252,9 +306,14 @@
 
     /* IDirect3DDevice8 fields */
     IDirect3D8Impl               *direct3d8;
+
     IDirect3DSurface8Impl        *frontBuffer;
     IDirect3DSurface8Impl        *backBuffer;
     IDirect3DSurface8Impl        *depthStencilBuffer;
+
+    IDirect3DSurface8Impl        *renderTarget;
+    IDirect3DSurface8Impl        *stencilBufferTarget;
+
     D3DPRESENT_PARAMETERS         PresentParms;
     D3DDEVICE_CREATION_PARAMETERS CreateParms;
 
@@ -288,19 +347,31 @@
     XVisualInfo                  *visInfo;
     Display                      *display;
     Window                        win;
+    GLXContext                    render_ctx;
+    Drawable                      drawable;
 
     /* OpenGL Extension related */
+#if 0
     BOOL                          isMultiTexture;
     BOOL                          isDot3;
     UINT                          TextureUnits;
     UINT                          clipPlanes;
     UINT                          maxLights;
+#endif
+
+    /* Cursor management */
+    BOOL                          bCursorVisible;
+    UINT                          xHotSpot;
+    UINT                          yHotSpot;
+    UINT                          xScreenSpace;
+    UINT                          yScreenSpace;
+    GLint                         cursor;
 
     UINT                          dummyTextureName[8];
 };
 
 /* IUnknown: */
-extern HRESULT WINAPI   IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface,REFIID refiid,LPVOID *obj);
+extern HRESULT WINAPI   IDirect3DDevice8Impl_QueryInterface(LPDIRECT3DDEVICE8 iface, REFIID refiid, LPVOID *obj);
 extern ULONG WINAPI     IDirect3DDevice8Impl_AddRef(LPDIRECT3DDEVICE8 iface);
 extern ULONG WINAPI     IDirect3DDevice8Impl_Release(LPDIRECT3DDEVICE8 iface);
 
@@ -313,47 +384,47 @@
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetDisplayMode(LPDIRECT3DDEVICE8 iface, D3DDISPLAYMODE* pMode);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetCreationParameters(LPDIRECT3DDEVICE8 iface, D3DDEVICE_CREATION_PARAMETERS* pParameters);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetCursorProperties(LPDIRECT3DDEVICE8 iface, UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8* pCursorBitmap);
-extern void     WINAPI  IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace,DWORD Flags);
+extern void     WINAPI  IDirect3DDevice8Impl_SetCursorPosition(LPDIRECT3DDEVICE8 iface, UINT XScreenSpace, UINT YScreenSpace, DWORD Flags);
 extern BOOL     WINAPI  IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL bShow);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer,D3DBACKBUFFER_TYPE Type,IDirect3DSurface8** ppBackBuffer);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_Present(LPDIRECT3DDEVICE8 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetBackBuffer(LPDIRECT3DDEVICE8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetRasterStatus(LPDIRECT3DDEVICE8 iface, D3DRASTER_STATUS* pRasterStatus);
-extern void     WINAPI  IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags,CONST D3DGAMMARAMP* pRamp);
+extern void     WINAPI  IDirect3DDevice8Impl_SetGammaRamp(LPDIRECT3DDEVICE8 iface, DWORD Flags, CONST D3DGAMMARAMP* pRamp);
 extern void     WINAPI  IDirect3DDevice8Impl_GetGammaRamp(LPDIRECT3DDEVICE8 iface, D3DGAMMARAMP* pRamp);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width,UINT Height,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DTexture8** ppTexture);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface, UINT Width,UINT Height,UINT Depth,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DVolumeTexture8** ppVolumeTexture);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture8** ppCubeTexture);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length,DWORD Usage,DWORD FVF,D3DPOOL Pool,IDirect3DVertexBuffer8** ppVertexBuffer);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DIndexBuffer8** ppIndexBuffer);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,BOOL Lockable,IDirect3DSurface8** ppSurface);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width,UINT Height,D3DFORMAT Format,D3DMULTISAMPLE_TYPE MultiSample,IDirect3DSurface8** ppSurface);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width,UINT Height,D3DFORMAT Format,IDirect3DSurface8** ppSurface);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pSourceSurface,CONST RECT* pSourceRectsArray,UINT cRects,IDirect3DSurface8* pDestinationSurface,CONST POINT* pDestPointsArray);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture,IDirect3DBaseTexture8* pDestinationTexture);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8** ppTexture);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateDepthStencilSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, IDirect3DSurface8** ppSurface);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateImageSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, IDirect3DSurface8** ppSurface);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_CopyRects(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pSourceSurface, CONST RECT* pSourceRectsArray, UINT cRects, IDirect3DSurface8* pDestinationSurface, CONST POINT* pDestPointsArray);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_UpdateTexture(LPDIRECT3DDEVICE8 iface, IDirect3DBaseTexture8* pSourceTexture, IDirect3DBaseTexture8* pDestinationTexture);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetFrontBuffer(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pDestSurface);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget,IDirect3DSurface8* pNewZStencil);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* pRenderTarget, IDirect3DSurface8* pNewZStencil);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetRenderTarget(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppRenderTarget);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetDepthStencilSurface(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8** ppZStencilSurface);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_BeginScene(LPDIRECT3DDEVICE8 iface);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_EndScene(LPDIRECT3DDEVICE8 iface);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count,CONST D3DRECT* pRects,DWORD Flags,D3DCOLOR Color,float Z,DWORD Stencil);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,CONST D3DMATRIX* pMatrix);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State,D3DMATRIX* pMatrix);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_Clear(LPDIRECT3DDEVICE8 iface, DWORD Count, CONST D3DRECT* pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, D3DMATRIX* pMatrix);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_MultiplyTransform(LPDIRECT3DDEVICE8 iface, D3DTRANSFORMSTATETYPE State, CONST D3DMATRIX* pMatrix);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetViewport(LPDIRECT3DDEVICE8 iface, CONST D3DVIEWPORT8* pViewport);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetViewport(LPDIRECT3DDEVICE8 iface, D3DVIEWPORT8* pViewport);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetMaterial(LPDIRECT3DDEVICE8 iface, CONST D3DMATERIAL8* pMaterial);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetMaterial(LPDIRECT3DDEVICE8 iface, D3DMATERIAL8* pMaterial);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST D3DLIGHT8* pLight);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index,D3DLIGHT8* pLight);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL Enable);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index,BOOL* pEnable);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,CONST float* pPlane);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index,float* pPlane);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD Value);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State,DWORD* pValue);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST D3DLIGHT8* pLight);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetLight(LPDIRECT3DDEVICE8 iface, DWORD Index, D3DLIGHT8* pLight);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_LightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index, BOOL Enable);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetLightEnable(LPDIRECT3DDEVICE8 iface, DWORD Index, BOOL* pEnable);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index, CONST float* pPlane);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetClipPlane(LPDIRECT3DDEVICE8 iface, DWORD Index, float* pPlane);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State, DWORD Value);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetRenderState(LPDIRECT3DDEVICE8 iface, D3DRENDERSTATETYPE State, DWORD* pValue);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_BeginStateBlock(LPDIRECT3DDEVICE8 iface);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_EndStateBlock(LPDIRECT3DDEVICE8 iface, DWORD* pToken);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_ApplyStateBlock(LPDIRECT3DDEVICE8 iface, DWORD Token);
@@ -362,20 +433,20 @@
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateStateBlock(LPDIRECT3DDEVICE8 iface, D3DSTATEBLOCKTYPE Type,DWORD* pToken);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetClipStatus(LPDIRECT3DDEVICE8 iface, CONST D3DCLIPSTATUS8* pClipStatus);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetClipStatus(LPDIRECT3DDEVICE8 iface, D3DCLIPSTATUS8* pClipStatus);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8* pTexture);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD* pValue);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage,D3DTEXTURESTAGESTATETYPE Type,DWORD Value);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8** ppTexture);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage, IDirect3DBaseTexture8* pTexture);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD* pValue);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetTextureStageState(LPDIRECT3DDEVICE8 iface, DWORD Stage, D3DTEXTURESTAGESTATETYPE Type, DWORD Value);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_ValidateDevice(LPDIRECT3DDEVICE8 iface, DWORD* pNumPasses);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID,void* pDevInfoStruct,DWORD DevInfoStructSize);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber,CONST PALETTEENTRY* pEntries);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber,PALETTEENTRY* pEntries);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetInfo(LPDIRECT3DDEVICE8 iface, DWORD DevInfoID, void* pDevInfoStruct, DWORD DevInfoStructSize);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetPaletteEntries(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber, PALETTEENTRY* pEntries);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT PaletteNumber);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_GetCurrentTexturePalette(LPDIRECT3DDEVICE8 iface, UINT *PaletteNumber);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT StartVertex,UINT PrimitiveCount);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT minIndex,UINT NumVertices,UINT startIndex,UINT primCount);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT PrimitiveCount,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
-extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType,UINT MinVertexIndex,UINT NumVertexIndices,UINT PrimitiveCount,CONST void* pIndexData,D3DFORMAT IndexDataFormat,CONST void* pVertexStreamZeroData,UINT VertexStreamZeroStride);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawIndexedPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT minIndex, UINT NumVertices, UINT startIndex, UINT primCount);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
+extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawIndexedPrimitiveUP(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT MinVertexIndex, UINT NumVertexIndices, UINT PrimitiveCount, CONST void* pIndexData, D3DFORMAT IndexDataFormat, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_ProcessVertices(LPDIRECT3DDEVICE8 iface, UINT SrcStartIndex,UINT DestIndex,UINT VertexCount,IDirect3DVertexBuffer8* pDestBuffer,DWORD Flags);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration,CONST DWORD* pFunction,DWORD* pHandle,DWORD Usage);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_SetVertexShader(LPDIRECT3DDEVICE8 iface, DWORD Handle);
@@ -400,6 +471,11 @@
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_DrawTriPatch(LPDIRECT3DDEVICE8 iface, UINT Handle,CONST float* pNumSegs,CONST D3DTRIPATCH_INFO* pTriPatchInfo);
 extern HRESULT  WINAPI  IDirect3DDevice8Impl_DeletePatch(LPDIRECT3DDEVICE8 iface, UINT Handle);
 
+/* internal Interfaces */
+extern HRESULT WINAPI   IDirect3DDevice8Impl_CleanRender(LPDIRECT3DDEVICE8 iface);
+extern HRESULT WINAPI   IDirect3DDevice8Impl_ActiveRender(LPDIRECT3DDEVICE8 iface, IDirect3DSurface8* RenderSurface, IDirect3DSurface8* StencilSurface);
+
+
 /* ---------------- */
 /* IDirect3DVolume8 */
 /* ---------------- */
@@ -444,6 +520,7 @@
 extern HRESULT WINAPI IDirect3DVolume8Impl_LockBox(LPDIRECT3DVOLUME8 iface, D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox, DWORD Flags);
 extern HRESULT WINAPI IDirect3DVolume8Impl_UnlockBox(LPDIRECT3DVOLUME8 iface);
 
+
 /* ------------------- */
 /* IDirect3DSwapChain8 */
 /* ------------------- */
@@ -477,6 +554,7 @@
 extern HRESULT WINAPI IDirect3DSwapChain8Impl_Present(LPDIRECT3DSWAPCHAIN8 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion);
 extern HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type,IDirect3DSurface8** ppBackBuffer);
 
+
 /* ----------------- */
 /* IDirect3DSurface8 */
 /* ----------------- */
@@ -500,15 +578,16 @@
     D3DRESOURCETYPE         ResourceType;
 
     IUnknown               *Container;
-
     D3DSURFACE_DESC         myDesc;
     BYTE                   *allocatedMemory;
     UINT                    textureName;
     UINT                    bytesPerPixel;
+
     BOOL                    lockable;
     BOOL                    locked;
     RECT                    lockedRect;
     BOOL                    Dirty;
+
 };
 
 /* IUnknown: */
@@ -526,6 +605,10 @@
 extern HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect,DWORD Flags);
 extern HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface);
 
+/* internal Interfaces */
+extern HRESULT WINAPI IDirect3DSurface8Impl_CreateGLTexture(LPDIRECT3DSURFACE8 iface, GLenum gl_target, GLenum gl_level);
+
+
 /* ------------------ */
 /* IDirect3DResource8 */
 /* ------------------ */
@@ -564,6 +647,10 @@
 extern void     WINAPI        IDirect3DResource8Impl_PreLoad(LPDIRECT3DRESOURCE8 iface);
 extern D3DRESOURCETYPE WINAPI IDirect3DResource8Impl_GetType(LPDIRECT3DRESOURCE8 iface);
 
+/* internal Interfaces */
+extern D3DPOOL WINAPI         IDirect3DResource8Impl_GetPool(LPDIRECT3DRESOURCE8 iface);
+
+
 /* ---------------------- */
 /* IDirect3DVertexBuffer8 */
 /* ---------------------- */
@@ -611,6 +698,7 @@
 extern HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_Unlock(LPDIRECT3DVERTEXBUFFER8 iface);
 extern HRESULT  WINAPI        IDirect3DVertexBuffer8Impl_GetDesc(LPDIRECT3DVERTEXBUFFER8 iface, D3DVERTEXBUFFER_DESC *pDesc);
 
+
 /* --------------------- */
 /* IDirect3DIndexBuffer8 */
 /* --------------------- */
@@ -658,6 +746,7 @@
 extern HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_Unlock(LPDIRECT3DINDEXBUFFER8 iface);
 extern HRESULT  WINAPI        IDirect3DIndexBuffer8Impl_GetDesc(LPDIRECT3DINDEXBUFFER8 iface, D3DINDEXBUFFER_DESC *pDesc);
 
+
 /* --------------------- */
 /* IDirect3DBaseTexture8 */
 /* --------------------- */
@@ -682,7 +771,8 @@
 
     /* IDirect3DBaseTexture8 fields */
     BOOL                    Dirty;
-
+    D3DFORMAT               format;
+    UINT                    levels;
     /*
      *BOOL                    isManaged;
      *DWORD                   lod;
@@ -709,6 +799,11 @@
 extern DWORD    WINAPI        IDirect3DBaseTexture8Impl_GetLOD(LPDIRECT3DBASETEXTURE8 iface);
 extern DWORD    WINAPI        IDirect3DBaseTexture8Impl_GetLevelCount(LPDIRECT3DBASETEXTURE8 iface);
 
+/* internal Interfaces */
+extern BOOL     WINAPI        IDirect3DBaseTexture8Impl_IsDirty(LPDIRECT3DBASETEXTURE8 iface);
+extern BOOL     WINAPI        IDirect3DBaseTexture8Impl_SetDirty(LPDIRECT3DBASETEXTURE8 iface, BOOL dirty);
+
+
 /* --------------------- */
 /* IDirect3DCubeTexture8 */
 /* --------------------- */
@@ -733,12 +828,12 @@
 
     /* IDirect3DBaseTexture8 fields */
     BOOL                    Dirty;
+    D3DFORMAT               format;
+    UINT                    levels;
 
     /* IDirect3DCubeTexture8 fields */
     UINT                    edgeLength;
     DWORD                   usage;
-    UINT                    levels;
-    D3DFORMAT               format;
 
     IDirect3DSurface8Impl  *surfaces[6][MAX_LEVELS];
 };
@@ -764,11 +859,12 @@
 extern DWORD    WINAPI        IDirect3DCubeTexture8Impl_GetLevelCount(LPDIRECT3DCUBETEXTURE8 iface);
 
 /* IDirect3DCubeTexture8 */
-extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface,UINT Level,D3DSURFACE_DESC *pDesc);
-extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface,D3DCUBEMAP_FACES FaceType,UINT Level,IDirect3DSurface8** ppCubeMapSurface);
-extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface,D3DCUBEMAP_FACES FaceType,UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
-extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface,D3DCUBEMAP_FACES FaceType,UINT Level);
-extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface,D3DCUBEMAP_FACES FaceType,CONST RECT* pDirtyRect);
+extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc);
+extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_GetCubeMapSurface(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, IDirect3DSurface8** ppCubeMapSurface);
+extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_LockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
+extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_UnlockRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, UINT Level);
+extern HRESULT  WINAPI        IDirect3DCubeTexture8Impl_AddDirtyRect(LPDIRECT3DCUBETEXTURE8 iface, D3DCUBEMAP_FACES FaceType, CONST RECT* pDirtyRect);
+
 
 /* ----------------- */
 /* IDirect3DTexture8 */
@@ -794,13 +890,13 @@
 
     /* IDirect3DBaseTexture8 fields */
     BOOL                    Dirty;
+    D3DFORMAT               format;
+    UINT                    levels;
 
     /* IDirect3DTexture8 fields */
     UINT                    width;
     UINT                    height;
-    UINT                    levels;
     DWORD                   usage;
-    D3DFORMAT               format;
 
     IDirect3DSurface8Impl  *surfaces[MAX_LEVELS];
 };
@@ -826,12 +922,13 @@
 extern DWORD    WINAPI        IDirect3DTexture8Impl_GetLevelCount(LPDIRECT3DTEXTURE8 iface);
 
 /* IDirect3DTexture8: */
-extern HRESULT  WINAPI        IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DSURFACE_DESC* pDesc);
-extern HRESULT  WINAPI        IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level,IDirect3DSurface8** ppSurfaceLevel);
-extern HRESULT  WINAPI        IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level,D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags);
+extern HRESULT  WINAPI        IDirect3DTexture8Impl_GetLevelDesc(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DSURFACE_DESC* pDesc);
+extern HRESULT  WINAPI        IDirect3DTexture8Impl_GetSurfaceLevel(LPDIRECT3DTEXTURE8 iface, UINT Level, IDirect3DSurface8** ppSurfaceLevel);
+extern HRESULT  WINAPI        IDirect3DTexture8Impl_LockRect(LPDIRECT3DTEXTURE8 iface, UINT Level, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
 extern HRESULT  WINAPI        IDirect3DTexture8Impl_UnlockRect(LPDIRECT3DTEXTURE8 iface, UINT Level);
 extern HRESULT  WINAPI        IDirect3DTexture8Impl_AddDirtyRect(LPDIRECT3DTEXTURE8 iface, CONST RECT* pDirtyRect);
 
+
 /* ----------------------- */
 /* IDirect3DVolumeTexture8 */
 /* ----------------------- */
@@ -856,14 +953,14 @@
 
     /* IDirect3DBaseTexture8 fields */
     BOOL                    Dirty;
+    D3DFORMAT               format;
+    UINT                    levels;
 
     /* IDirect3DVolumeTexture8 fields */
     UINT                    width;
     UINT                    height;
     UINT                    depth;
-    UINT                    levels;
     DWORD                   usage;
-    D3DFORMAT               format;
 
     IDirect3DVolume8Impl   *volumes[MAX_LEVELS];
 };
@@ -889,12 +986,13 @@
 extern DWORD    WINAPI        IDirect3DVolumeTexture8Impl_GetLevelCount(LPDIRECT3DVOLUMETEXTURE8 iface);
 
 /* IDirect3DVolumeTexture8: */
-extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level,D3DVOLUME_DESC *pDesc);
-extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level,IDirect3DVolume8** ppVolumeLevel);
-extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_LockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level,D3DLOCKED_BOX* pLockedVolume,CONST D3DBOX* pBox,DWORD Flags);
+extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetLevelDesc(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, D3DVOLUME_DESC *pDesc);
+extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_GetVolumeLevel(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, IDirect3DVolume8** ppVolumeLevel);
+extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_LockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level, D3DLOCKED_BOX* pLockedVolume, CONST D3DBOX* pBox, DWORD Flags);
 extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_UnlockBox(LPDIRECT3DVOLUMETEXTURE8 iface, UINT Level);
 extern HRESULT  WINAPI        IDirect3DVolumeTexture8Impl_AddDirtyBox(LPDIRECT3DVOLUMETEXTURE8 iface, CONST D3DBOX* pDirtyBox);
 
+
 /* ==============================================================================
     Private interfactes: beginning of cleaning/splitting for HAL and d3d9 support
    ============================================================================== */
@@ -1127,11 +1225,29 @@
  *
  * to see how not defined it here
  */ 
-void setupTextureStates(LPDIRECT3DDEVICE8 iface, DWORD Stage);
-SHORT bytesPerPixel(D3DFORMAT fmt);
-GLint fmt2glintFmt(D3DFORMAT fmt);
+void   setupTextureStates(LPDIRECT3DDEVICE8 iface, DWORD Stage);
+SHORT  bytesPerPixel(D3DFORMAT fmt);
+GLint  fmt2glintFmt(D3DFORMAT fmt);
 GLenum fmt2glFmt(D3DFORMAT fmt);
-DWORD fmt2glType(D3DFORMAT fmt);
+GLenum fmt2glType(D3DFORMAT fmt);
+
+SHORT  D3DFmtGetBpp(D3DFORMAT fmt);
+GLint  D3DFmt2GLIntFmt(D3DFORMAT fmt);
+GLenum D3DFmt2GLFmt(D3DFORMAT fmt);
+GLenum D3DFmt2GLType(D3DFORMAT fmt);
+
+GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt);
+GLenum D3DFmt2GLDepthType(D3DFORMAT fmt);
+
+int D3DPrimitiveListGetVertexSize(D3DPRIMITIVETYPE PrimitiveType, int iNumPrim);
+int D3DPrimitive2GLenum(D3DPRIMITIVETYPE PrimitiveType);
+int D3DFVFGetSize(D3DFORMAT fvf);
+
+int SOURCEx_RGB_EXT(DWORD arg);
+int OPERANDx_RGB_EXT(DWORD arg);
+int SOURCEx_ALPHA_EXT(DWORD arg);
+int OPERANDx_ALPHA_EXT(DWORD arg);
+GLenum StencilOp(DWORD op);
 
 /**
  * Internals debug functions
@@ -1140,5 +1256,6 @@
 const char* debug_d3dusage(DWORD usage);
 const char* debug_d3dformat(D3DFORMAT fmt);
 const char* debug_d3dressourcetype(D3DRESOURCETYPE res);
+const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType);
 
 #endif /* __WINE_D3DX8_PRIVATE_H */
Index: Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/d3d8/Makefile.in,v
retrieving revision 1.7
diff -u -r1.7 Makefile.in
--- Makefile.in	3 Apr 2003 23:55:55 -0000	1.7
+++ Makefile.in	22 May 2003 22:24:17 -0000
@@ -26,7 +26,8 @@
 	vertexbuffer.c \
 	volume.c \
 	volumetexture.c \
-	vshaderdeclaration.c
+	vshaderdeclaration.c \
+	utils.c
 
 RC_SRCS = version.rc
 
--- /dev/null	1970-01-01 01:00:00.000000000 +0100
+++ utils.c	2003-05-23 00:21:43.000000000 +0200
@@ -0,0 +1,420 @@
+/*
+ * D3D8 utils
+ *
+ * Copyright 2002-2003 Jason Edmeades
+ *                     Raphael Junqueira
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "config.h"
+
+#include <math.h>
+
+#define NONAMELESSUNION
+#define NONAMELESSSTRUCT
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "wingdi.h"
+#include "wine/debug.h"
+
+#include "d3d8_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(d3d);
+
+
+#if 0
+# define VTRACE(A) TRACE A
+#else 
+# define VTRACE(A) 
+#endif
+
+const char* debug_d3ddevicetype(D3DDEVTYPE devtype) {
+  switch (devtype) {
+#define DEVTYPE_TO_STR(dev) case dev: return #dev
+    DEVTYPE_TO_STR(D3DDEVTYPE_HAL);
+    DEVTYPE_TO_STR(D3DDEVTYPE_REF);
+    DEVTYPE_TO_STR(D3DDEVTYPE_SW);    
+#undef DEVTYPE_TO_STR
+  default:
+    FIXME("Unrecognized %u D3DDEVTYPE!\n", devtype);
+    return "unrecognized";
+  }
+}
+
+const char* debug_d3dusage(DWORD usage) {
+  switch (usage) {
+#define D3DUSAGE_TO_STR(u) case u: return #u
+    D3DUSAGE_TO_STR(D3DUSAGE_RENDERTARGET);
+    D3DUSAGE_TO_STR(D3DUSAGE_DEPTHSTENCIL);
+    D3DUSAGE_TO_STR(D3DUSAGE_WRITEONLY);
+    D3DUSAGE_TO_STR(D3DUSAGE_SOFTWAREPROCESSING);
+    D3DUSAGE_TO_STR(D3DUSAGE_DONOTCLIP);
+    D3DUSAGE_TO_STR(D3DUSAGE_POINTS);
+    D3DUSAGE_TO_STR(D3DUSAGE_RTPATCHES);
+    D3DUSAGE_TO_STR(D3DUSAGE_NPATCHES);
+    D3DUSAGE_TO_STR(D3DUSAGE_DYNAMIC);
+#undef D3DUSAGE_TO_STR
+  case 0: return "none";
+  default:
+    FIXME("Unrecognized %lu Usage!\n", usage);
+    return "unrecognized";
+  }
+}
+
+const char* debug_d3dformat(D3DFORMAT fmt) {
+  switch (fmt) {
+#define FMT_TO_STR(fmt) case fmt: return #fmt
+    FMT_TO_STR(D3DFMT_UNKNOWN);
+    FMT_TO_STR(D3DFMT_R8G8B8);
+    FMT_TO_STR(D3DFMT_A8R8G8B8);
+    FMT_TO_STR(D3DFMT_X8R8G8B8);
+    FMT_TO_STR(D3DFMT_R5G6B5);
+    FMT_TO_STR(D3DFMT_X1R5G5B5);
+    FMT_TO_STR(D3DFMT_A1R5G5B5);
+    FMT_TO_STR(D3DFMT_A4R4G4B4);
+    FMT_TO_STR(D3DFMT_R3G3B2);
+    FMT_TO_STR(D3DFMT_A8);
+    FMT_TO_STR(D3DFMT_A8R3G3B2);
+    FMT_TO_STR(D3DFMT_X4R4G4B4);
+    FMT_TO_STR(D3DFMT_A8P8);
+    FMT_TO_STR(D3DFMT_P8);
+    FMT_TO_STR(D3DFMT_L8);
+    FMT_TO_STR(D3DFMT_A8L8);
+    FMT_TO_STR(D3DFMT_A4L4);
+    FMT_TO_STR(D3DFMT_V8U8);
+    FMT_TO_STR(D3DFMT_L6V5U5);
+    FMT_TO_STR(D3DFMT_X8L8V8U8);
+    FMT_TO_STR(D3DFMT_Q8W8V8U8);
+    FMT_TO_STR(D3DFMT_V16U16);
+    FMT_TO_STR(D3DFMT_W11V11U10);
+    FMT_TO_STR(D3DFMT_UYVY);
+    FMT_TO_STR(D3DFMT_YUY2);
+    FMT_TO_STR(D3DFMT_DXT1);
+    FMT_TO_STR(D3DFMT_DXT2);
+    FMT_TO_STR(D3DFMT_DXT3);
+    FMT_TO_STR(D3DFMT_DXT4);
+    FMT_TO_STR(D3DFMT_DXT5);
+    FMT_TO_STR(D3DFMT_D16_LOCKABLE);
+    FMT_TO_STR(D3DFMT_D32);
+    FMT_TO_STR(D3DFMT_D15S1);
+    FMT_TO_STR(D3DFMT_D24S8);
+    FMT_TO_STR(D3DFMT_D16);
+    FMT_TO_STR(D3DFMT_D24X8);
+    FMT_TO_STR(D3DFMT_D24X4S4);
+    FMT_TO_STR(D3DFMT_VERTEXDATA);
+    FMT_TO_STR(D3DFMT_INDEX16);
+    FMT_TO_STR(D3DFMT_INDEX32);
+#undef FMT_TO_STR
+  default:
+    FIXME("Unrecognized %u D3DFORMAT!\n", fmt);
+    return "unrecognized";
+  }
+}
+
+const char* debug_d3dressourcetype(D3DRESOURCETYPE res) {
+  switch (res) {
+#define RES_TO_STR(res) case res: return #res;
+    RES_TO_STR(D3DRTYPE_SURFACE);
+    RES_TO_STR(D3DRTYPE_VOLUME);
+    RES_TO_STR(D3DRTYPE_TEXTURE);
+    RES_TO_STR(D3DRTYPE_VOLUMETEXTURE);
+    RES_TO_STR(D3DRTYPE_CUBETEXTURE);
+    RES_TO_STR(D3DRTYPE_VERTEXBUFFER);
+    RES_TO_STR(D3DRTYPE_INDEXBUFFER);
+#undef  RES_TO_STR
+  default:
+    FIXME("Unrecognized %u D3DRESOURCETYPE!\n", res);
+    return "unrecognized";
+  }
+}
+
+const char* debug_d3dprimitivetype(D3DPRIMITIVETYPE PrimitiveType) {
+  switch (PrimitiveType) {
+#define PRIM_TO_STR(prim) case prim: return #prim;
+    PRIM_TO_STR(D3DPT_POINTLIST);
+    PRIM_TO_STR(D3DPT_LINELIST);
+    PRIM_TO_STR(D3DPT_LINESTRIP);
+    PRIM_TO_STR(D3DPT_TRIANGLELIST);
+    PRIM_TO_STR(D3DPT_TRIANGLESTRIP);
+    PRIM_TO_STR(D3DPT_TRIANGLEFAN);
+#undef  PRIM_TO_STR
+  default:
+    FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
+    return "unrecognized";
+  }
+}
+
+/*
+ * Simple utility routines used for dx -> gl mapping of byte formats
+ */
+SHORT bytesPerPixel(D3DFORMAT fmt) {
+    SHORT retVal;
+
+    switch (fmt) {
+    /* color buffer */
+    case D3DFMT_P8:               retVal = 1; break;
+    case D3DFMT_R3G3B2:           retVal = 1; break;
+    case D3DFMT_R5G6B5:           retVal = 2; break;
+    case D3DFMT_X1R5G5B5:         retVal = 2; break;
+    case D3DFMT_A4R4G4B4:         retVal = 2; break;
+    case D3DFMT_X4R4G4B4:         retVal = 2; break;
+    case D3DFMT_A1R5G5B5:         retVal = 2; break;
+    case D3DFMT_R8G8B8:           retVal = 3; break;
+    case D3DFMT_X8R8G8B8:         retVal = 4; break;
+    case D3DFMT_A8R8G8B8:         retVal = 4; break;
+    /* depth/stencil buffer */
+    case D3DFMT_D16_LOCKABLE:     retVal = 2; break;
+    case D3DFMT_D16:              retVal = 2; break;
+    case D3DFMT_D15S1:            retVal = 2; break;
+    case D3DFMT_D24X4S4:          retVal = 4; break;
+    case D3DFMT_D24S8:            retVal = 4; break;
+    case D3DFMT_D24X8:            retVal = 4; break;
+    case D3DFMT_D32:              retVal = 4; break;
+    /* unknown */				  
+    case D3DFMT_UNKNOWN:
+      /* Guess at the highest value of the above */
+      TRACE("D3DFMT_UNKNOWN - Guessing at 4 bytes/pixel %u\n", fmt);
+      retVal = 4;
+      break;
+
+    default:
+      FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
+      retVal = 4;
+    }
+    TRACE("bytes/Pxl for fmt(%u,%s) = %d\n", fmt, debug_d3dformat(fmt), retVal);
+    return retVal;
+}
+
+GLint fmt2glintFmt(D3DFORMAT fmt) {
+    GLint retVal;
+
+    switch (fmt) {
+    case D3DFMT_A4R4G4B4:         retVal = GL_RGBA4; break;
+    case D3DFMT_A8R8G8B8:         retVal = GL_RGBA8; break;
+    case D3DFMT_X8R8G8B8:         retVal = GL_RGB8; break;
+    case D3DFMT_R8G8B8:           retVal = GL_RGB8; break;
+    case D3DFMT_R5G6B5:           retVal = GL_RGB5; break; /* fixme: internal format 6 for g? */
+    case D3DFMT_A1R5G5B5:         retVal = GL_RGB5_A1; break;
+    default:
+        FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
+        retVal = GL_RGB8;
+    }
+    TRACE("fmt2glintFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
+    return retVal;
+}
+
+GLenum fmt2glFmt(D3DFORMAT fmt) {
+    GLenum retVal;
+
+    switch (fmt) {
+    case D3DFMT_A4R4G4B4:         retVal = GL_BGRA; break;
+    case D3DFMT_A8R8G8B8:         retVal = GL_BGRA; break;
+    case D3DFMT_X8R8G8B8:         retVal = GL_BGRA; break;
+    case D3DFMT_R8G8B8:           retVal = GL_BGR; break;
+    case D3DFMT_R5G6B5:           retVal = GL_RGB; break;
+    case D3DFMT_A1R5G5B5:         retVal = GL_BGRA; break;
+    default:
+        FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
+        retVal = GL_BGR;
+    }
+    TRACE("fmt2glFmt for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
+    return retVal;
+}
+
+GLenum fmt2glType(D3DFORMAT fmt) {
+    GLenum retVal;
+
+    switch (fmt) {
+    case D3DFMT_A4R4G4B4:         retVal = GL_UNSIGNED_SHORT_4_4_4_4_REV; break;
+    case D3DFMT_A8R8G8B8:         retVal = GL_UNSIGNED_BYTE; break;
+    case D3DFMT_X8R8G8B8:         retVal = GL_UNSIGNED_BYTE; break;
+    case D3DFMT_R5G6B5:           retVal = GL_UNSIGNED_SHORT_5_6_5; break;
+    case D3DFMT_R8G8B8:           retVal = GL_UNSIGNED_BYTE; break;
+    case D3DFMT_A1R5G5B5:         retVal = GL_UNSIGNED_SHORT_1_5_5_5_REV; break;
+    default:
+        FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
+        retVal = GL_UNSIGNED_BYTE;
+    }
+    TRACE("fmt2glType for fmt(%u,%s) = %x\n", fmt, debug_d3dformat(fmt), retVal);
+    return retVal;
+}
+
+int D3DPrimitiveListGetVertexSize(D3DPRIMITIVETYPE PrimitiveType, int iNumPrim) {
+  switch (PrimitiveType) {
+  case D3DPT_POINTLIST:     return iNumPrim;
+  case D3DPT_LINELIST:      return iNumPrim * 2;
+  case D3DPT_LINESTRIP:     return iNumPrim + 1;
+  case D3DPT_TRIANGLELIST:  return iNumPrim * 3;
+  case D3DPT_TRIANGLESTRIP: return iNumPrim + 2;
+  case D3DPT_TRIANGLEFAN:   return iNumPrim + 2;
+  default:
+    FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
+    return 0;
+  }
+}
+
+int D3DPrimitive2GLenum(D3DPRIMITIVETYPE PrimitiveType) {
+  switch (PrimitiveType) {
+  case D3DPT_POINTLIST:     return GL_POINTS;
+  case D3DPT_LINELIST:      return GL_LINES;
+  case D3DPT_LINESTRIP:     return GL_LINE_STRIP;
+  case D3DPT_TRIANGLELIST:  return GL_TRIANGLES;
+  case D3DPT_TRIANGLESTRIP: return GL_TRIANGLE_STRIP;
+  case D3DPT_TRIANGLEFAN:   return GL_TRIANGLE_FAN;
+  default:
+    FIXME("Unrecognized %u D3DPRIMITIVETYPE!\n", PrimitiveType);
+    return GL_POLYGON;
+  }
+}
+
+int D3DFVFGetSize(D3DFORMAT fvf) {
+  int ret = 0;
+  if      (fvf & D3DFVF_XYZ)    ret += 3 * sizeof(float);
+  else if (fvf & D3DFVF_XYZRHW) ret += 4 * sizeof(float);
+  if (fvf & D3DFVF_NORMAL)      ret += 3 * sizeof(float);
+  if (fvf & D3DFVF_PSIZE)       ret += sizeof(float);
+  if (fvf & D3DFVF_DIFFUSE)     ret += sizeof(DWORD);
+  if (fvf & D3DFVF_SPECULAR)    ret += sizeof(DWORD);
+  /*if (fvf & D3DFVF_TEX1)        ret += 1;*/
+  return ret;
+}
+
+GLenum D3DFmt2GLDepthFmt(D3DFORMAT fmt) {
+  switch (fmt) {
+  /* depth/stencil buffer */
+  case D3DFMT_D16_LOCKABLE:
+  case D3DFMT_D16:
+  case D3DFMT_D15S1:
+  case D3DFMT_D24X4S4:
+  case D3DFMT_D24S8:
+  case D3DFMT_D24X8:
+  case D3DFMT_D32:
+    return GL_DEPTH_COMPONENT;
+  default:
+    FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
+  }
+  return 0;
+}
+
+GLenum D3DFmt2GLDepthType(D3DFORMAT fmt) {
+  switch (fmt) {
+  /* depth/stencil buffer */
+  case D3DFMT_D15S1:
+  case D3DFMT_D16_LOCKABLE:     
+  case D3DFMT_D16:              
+    return GL_UNSIGNED_SHORT;
+  case D3DFMT_D24X4S4:          
+  case D3DFMT_D24S8:            
+  case D3DFMT_D24X8:            
+  case D3DFMT_D32:              
+    return GL_UNSIGNED_INT;
+  default:
+    FIXME("Unhandled fmt(%u,%s)\n", fmt, debug_d3dformat(fmt));
+  }
+  return 0;
+}
+
+SHORT D3DFmtGetBpp(D3DFORMAT fmt) {
+  return bytesPerPixel(fmt);
+}
+
+GLint D3DFmt2GLIntFmt(D3DFORMAT fmt) {
+  return fmt2glintFmt(fmt);
+}
+
+GLenum D3DFmt2GLFmt(D3DFORMAT fmt) {
+  return fmt2glFmt(fmt);
+}
+
+GLenum D3DFmt2GLType(D3DFORMAT fmt) {
+  return fmt2glType(fmt);
+}
+
+int SOURCEx_RGB_EXT(DWORD arg) {
+    switch(arg) {
+    case D3DTSS_COLORARG0: return GL_SOURCE2_RGB_EXT;
+    case D3DTSS_COLORARG1: return GL_SOURCE0_RGB_EXT;
+    case D3DTSS_COLORARG2: return GL_SOURCE1_RGB_EXT;
+    case D3DTSS_ALPHAARG0:
+    case D3DTSS_ALPHAARG1:
+    case D3DTSS_ALPHAARG2:
+    default:
+        FIXME("Invalid arg %ld\n", arg);
+        return GL_SOURCE0_RGB_EXT;
+    }
+}
+
+int OPERANDx_RGB_EXT(DWORD arg) {
+    switch(arg) {
+    case D3DTSS_COLORARG0: return GL_OPERAND2_RGB_EXT;
+    case D3DTSS_COLORARG1: return GL_OPERAND0_RGB_EXT;
+    case D3DTSS_COLORARG2: return GL_OPERAND1_RGB_EXT;
+    case D3DTSS_ALPHAARG0:
+    case D3DTSS_ALPHAARG1:
+    case D3DTSS_ALPHAARG2:
+    default:
+        FIXME("Invalid arg %ld\n", arg);
+        return GL_OPERAND0_RGB_EXT;
+    }
+}
+
+int SOURCEx_ALPHA_EXT(DWORD arg) {
+    switch(arg) {
+    case D3DTSS_ALPHAARG0:  return GL_SOURCE2_ALPHA_EXT;
+    case D3DTSS_ALPHAARG1:  return GL_SOURCE0_ALPHA_EXT;
+    case D3DTSS_ALPHAARG2:  return GL_SOURCE1_ALPHA_EXT;
+    case D3DTSS_COLORARG0:
+    case D3DTSS_COLORARG1:
+    case D3DTSS_COLORARG2:
+    default:
+        FIXME("Invalid arg %ld\n", arg);
+        return GL_SOURCE0_ALPHA_EXT;
+    }
+}
+
+int OPERANDx_ALPHA_EXT(DWORD arg) {
+    switch(arg) {
+    case D3DTSS_ALPHAARG0:  return GL_OPERAND2_ALPHA_EXT;
+    case D3DTSS_ALPHAARG1:  return GL_OPERAND0_ALPHA_EXT;
+    case D3DTSS_ALPHAARG2:  return GL_OPERAND1_ALPHA_EXT;
+    case D3DTSS_COLORARG0:
+    case D3DTSS_COLORARG1:
+    case D3DTSS_COLORARG2:
+    default:
+        FIXME("Invalid arg %ld\n", arg);
+        return GL_OPERAND0_ALPHA_EXT;
+    }
+}
+
+GLenum StencilOp(DWORD op) {
+    switch(op) {                
+    case D3DSTENCILOP_KEEP    : return GL_KEEP;
+    case D3DSTENCILOP_ZERO    : return GL_ZERO;
+    case D3DSTENCILOP_REPLACE : return GL_REPLACE;
+    case D3DSTENCILOP_INCRSAT : return GL_INCR;
+    case D3DSTENCILOP_DECRSAT : return GL_DECR;
+    case D3DSTENCILOP_INVERT  : return GL_INVERT;
+    case D3DSTENCILOP_INCR    : FIXME("Unsupported stencil op D3DSTENCILOP_INCR\n");
+                                return GL_INCR; /* Fixme - needs to support wrap */
+    case D3DSTENCILOP_DECR    : FIXME("Unsupported stencil op D3DSTENCILOP_DECR\n");
+                                return GL_DECR; /* Fixme - needs to support wrap */
+    default:
+        FIXME("Invalid stencil op %ld\n", op);
+        return GL_ALWAYS;
+    }
+}
+

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

  Powered by Linux