WINED3D: Move fields common to vertex shaders and pixel shaders to IWineD3DBaseShader

H. Verbeet hverbeet at gmail.com
Thu Mar 30 11:14:31 CST 2006


Changelog:
  - Move fields common to vertex shaders and pixel shaders to IWineD3DBaseShader
-------------- next part --------------
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index d322e82..f2c7c7f 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1620,7 +1620,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_Create
     IWineD3DVertexShaderImpl *object;  /* NOTE: impl usage is ok, this is a create */
     HRESULT hr = D3D_OK;
     D3DCREATEOBJECTINSTANCE(object, VertexShader)
-    object->shader_ins = IWineD3DVertexShaderImpl_shader_ins;
+    object->baseShader.shader_ins = IWineD3DVertexShaderImpl_shader_ins;
 
     TRACE("(%p) : Created Vertex shader %p\n", This, *ppVertexShader);
 
@@ -1665,7 +1665,7 @@ HRESULT WINAPI IWineD3DDeviceImpl_Create
     HRESULT hr = D3D_OK;
 
     D3DCREATEOBJECTINSTANCE(object, PixelShader)
-    object->shader_ins = IWineD3DPixelShaderImpl_shader_ins;
+    object->baseShader.shader_ins = IWineD3DPixelShaderImpl_shader_ins;
     hr = IWineD3DPixelShader_SetFunction(*ppPixelShader, pFunction);
     if (D3D_OK == hr) {
         TRACE("(%p) : Created Pixel shader %p\n", This, *ppPixelShader);
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 34241bd..be8c038 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -1797,13 +1797,13 @@ UINT numberOfvertices, UINT numberOfIndi
                 TRACE("Using vertex shader\n");
 
                 /* Bind the vertex program */
-                GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->prgId));
+                GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.prgId));
                 checkGLcall("glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertexShader->prgId);");
 
                 /* Enable OpenGL vertex programs */
                 glEnable(GL_VERTEX_PROGRAM_ARB);
                 checkGLcall("glEnable(GL_VERTEX_PROGRAM_ARB);");
-                TRACE_(d3d_shader)("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n", This, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->prgId);
+                TRACE_(d3d_shader)("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n", This, ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.prgId);
 
                 /* Vertex Shader 8 constants */
                 vertexDeclaration = (IWineD3DVertexDeclarationImpl *)((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->vertexDeclaration;
@@ -1834,13 +1834,13 @@ UINT numberOfvertices, UINT numberOfIndi
                 TRACE("Using pixel shader\n");
 
                 /* Bind the fragment program */
-                GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->prgId));
+                GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.prgId));
                 checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, pixelShader->prgId);");
 
                 /* Enable OpenGL fragment programs */
                 glEnable(GL_FRAGMENT_PROGRAM_ARB);
                 checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
-                TRACE_(d3d_shader)("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->prgId);
+                TRACE_(d3d_shader)("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.prgId);
 
                 /* Update the constants */
                 for (i = 0; i < WINED3D_PSHADER_MAX_CONSTANTS; ++i) {
@@ -2062,7 +2062,7 @@ void drawPrimitive(IWineD3DDevice *iface
     int                           useHW = FALSE;
 
     if (This->stateBlock->vertexShader != NULL && wined3d_settings.vs_mode != VS_NONE 
-            &&((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->function != NULL 
+            &&((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.function != NULL
             && GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
         useVertexShaderFunction = TRUE;
     } else {
@@ -2071,7 +2071,7 @@ void drawPrimitive(IWineD3DDevice *iface
 
     if (wined3d_settings.ps_mode != PS_NONE && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)
             && This->stateBlock->pixelShader
-            && ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->function) {
+            && ((IWineD3DPixelShaderImpl *)This->stateBlock->pixelShader)->baseShader.function) {
         usePixelShaderFunction = TRUE;
     }
 
diff --git a/dlls/wined3d/pixelshader.c b/dlls/wined3d/pixelshader.c
index 05ca70e..2952982 100644
--- a/dlls/wined3d/pixelshader.c
+++ b/dlls/wined3d/pixelshader.c
@@ -111,22 +111,22 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_G
   FIXME("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
 
   if (NULL == pData) {
-    *pSizeOfData = This->functionLength;
+    *pSizeOfData = This->baseShader.functionLength;
     return D3D_OK;
   }
-  if (*pSizeOfData < This->functionLength) {
-    *pSizeOfData = This->functionLength;
+  if (*pSizeOfData < This->baseShader.functionLength) {
+    *pSizeOfData = This->baseShader.functionLength;
     return D3DERR_MOREDATA;
   }
-  if (NULL == This->function) { /* no function defined */
+  if (NULL == This->baseShader.function) { /* no function defined */
     TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
     (*(DWORD **) pData) = NULL;
   } else {
-    if (This->functionLength == 0) {
+    if (This->baseShader.functionLength == 0) {
 
     }
     TRACE("(%p) : GetFunction copying to %p\n", This, pData);
-    memcpy(pData, This->function, This->functionLength);
+    memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
   }
   return D3D_OK;
 }
@@ -745,9 +745,9 @@ CONST SHADER_OPCODE IWineD3DPixelShaderI
 
 inline static const SHADER_OPCODE* pshader_program_get_opcode(IWineD3DPixelShaderImpl *This, const DWORD code) {
     DWORD i = 0;
-    DWORD version = This->version;
+    DWORD version = This->baseShader.version;
     DWORD hex_version = D3DPS_VERSION(version/10, version%10);
-    const SHADER_OPCODE *shader_ins = This->shader_ins;
+    const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
 
     /** TODO: use dichotomic search */
     while (NULL != shader_ins[i].name) {
@@ -1496,12 +1496,12 @@ inline static VOID IWineD3DPixelShaderIm
         }
 
         /* TODO: change to resource.glObjectHandel or something like that */
-        GL_EXTCALL(glGenProgramsARB(1, &This->prgId));
+        GL_EXTCALL(glGenProgramsARB(1, &This->baseShader.prgId));
 
-        TRACE("Creating a hw pixel shader, prg=%d\n", This->prgId);
-        GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, This->prgId));
+        TRACE("Creating a hw pixel shader, prg=%d\n", This->baseShader.prgId);
+        GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, This->baseShader.prgId));
 
-        TRACE("Created hw pixel shader, prg=%d\n", This->prgId);
+        TRACE("Created hw pixel shader, prg=%d\n", This->baseShader.prgId);
         /* Create the program and check for errors */
         GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pgmStr), pgmStr));
         if (glGetError() == GL_INVALID_OPERATION) {
@@ -1509,7 +1509,7 @@ inline static VOID IWineD3DPixelShaderIm
             glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
             FIXME("HW PixelShader Error at position %d: %s\n",
                   errPos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
-            This->prgId = -1;
+            This->baseShader.prgId = -1;
         }
     }
 #if 1 /* if were using the data buffer of device then we don't need to free it */
@@ -1719,7 +1719,7 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_S
     if (NULL != pToken) {
         while (D3DPS_END() != *pToken) {
             if (pshader_is_version_token(*pToken)) { /** version */
-                This->version = (((*pToken >> 8) & 0x0F) * 10) + (*pToken & 0x0F);
+                This->baseShader.version = (((*pToken >> 8) & 0x0F) * 10) + (*pToken & 0x0F);
                 TRACE("ps_%lu_%lu\n", (*pToken >> 8) & 0x0F, (*pToken & 0x0F));
                 ++pToken;
                 ++len;
@@ -1733,7 +1733,7 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_S
                 len += comment_len + 1;
                 continue;
             }
-            if (!This->version) {
+            if (!This->baseShader.version) {
                 WARN("(%p) : pixel shader doesn't have a valid version identifier\n", This);
             }
             curOpcode = pshader_program_get_opcode(This, *pToken);
@@ -1793,9 +1793,9 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_S
                 TRACE("\n");
             }
         }
-        This->functionLength = (len + 1) * sizeof(DWORD);
+        This->baseShader.functionLength = (len + 1) * sizeof(DWORD);
     } else {
-        This->functionLength = 1; /* no Function defined use fixed function vertex processing */
+        This->baseShader.functionLength = 1; /* no Function defined use fixed function vertex processing */
     }
 
     /* Generate HW shader in needed */
@@ -1809,10 +1809,10 @@ HRESULT WINAPI IWineD3DPixelShaderImpl_S
     TRACE("(%p) : Copying the function\n", This);
     /* copy the function ... because it will certainly be released by application */
     if (NULL != pFunction) {
-        This->function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->functionLength);
-        memcpy((void *)This->function, pFunction, This->functionLength);
+        This->baseShader.function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->baseShader.functionLength);
+        memcpy((void *)This->baseShader.function, pFunction, This->baseShader.functionLength);
     } else {
-        This->function = NULL;
+        This->baseShader.function = NULL;
     }
 
     /* TODO: Some proper return values for failures */
diff --git a/dlls/wined3d/vertexshader.c b/dlls/wined3d/vertexshader.c
index 24059d0..26701f6 100644
--- a/dlls/wined3d/vertexshader.c
+++ b/dlls/wined3d/vertexshader.c
@@ -693,7 +693,7 @@ CONST SHADER_OPCODE IWineD3DVertexShader
 
 inline static const SHADER_OPCODE* vshader_program_get_opcode(IWineD3DVertexShaderImpl *This, const DWORD code) {
     DWORD i = 0;
-    const SHADER_OPCODE *shader_ins = This->shader_ins;
+    const SHADER_OPCODE *shader_ins = This->baseShader.shader_ins;
 
     /** TODO: use dichotomic search or hash table */
     while (NULL != shader_ins[i].name) {
@@ -1694,9 +1694,9 @@ inline static VOID IWineD3DVertexShaderI
   if (GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
       /*  Create the hw shader */
       /* TODO: change to resource.glObjectHandel or something like that */
-      GL_EXTCALL(glGenProgramsARB(1, &This->prgId));
-      TRACE("Creating a hw vertex shader, prg=%d\n", This->prgId);
-      GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, This->prgId));
+      GL_EXTCALL(glGenProgramsARB(1, &This->baseShader.prgId));
+      TRACE("Creating a hw vertex shader, prg=%d\n", This->baseShader.prgId);
+      GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, This->baseShader.prgId));
 
       /* Create the program and check for errors */
       GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pgmStr)/*pgmLength*/, pgmStr));
@@ -1705,7 +1705,7 @@ inline static VOID IWineD3DVertexShaderI
           glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
           FIXME("HW VertexShader Error at position %d: %s\n",
                 errPos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
-          This->prgId = -1;
+          This->baseShader.prgId = -1;
       }
   }
 #if 1 /* if were using the data buffer of device then we don't need to free it */
@@ -1733,7 +1733,7 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_
     WINED3DSHADERVECTOR d;
     WINED3DSHADERVECTOR s[3];
     /** parser datas */
-    const DWORD* pToken = This->function;
+    const DWORD* pToken = This->baseShader.function;
     const SHADER_OPCODE* curOpcode = NULL;
     /** functions parameters */
     WINED3DSHADERVECTOR* p[4];
@@ -1791,9 +1791,9 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_
             /* TODO: Think of a name for 0x80000000 and replace its use with a constant */
             while (*pToken & 0x80000000) {
                 if (i == 0) {
-                    FIXME("unrecognized opcode: pos=%d token=%08lX\n", (pToken - 1) - This->function, *(pToken - 1));
+                    FIXME("unrecognized opcode: pos=%d token=%08lX\n", (pToken - 1) - This->baseShader.function, *(pToken - 1));
                 }
-                FIXME("unrecognized opcode param: pos=%d token=%08lX what=", pToken - This->function, *pToken);
+                FIXME("unrecognized opcode param: pos=%d token=%08lX what=", pToken - This->baseShader.function, *pToken);
                 vshader_program_dump_param(*pToken, i);
                 TRACE("\n");
                 ++i;
@@ -2088,22 +2088,22 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_
     FIXME("(%p) : pData(%p), pSizeOfData(%p)\n", This, pData, pSizeOfData);
 
     if (NULL == pData) {
-        *pSizeOfData = This->functionLength;
+        *pSizeOfData = This->baseShader.functionLength;
         return D3D_OK;
     }
-    if (*pSizeOfData < This->functionLength) {
-        *pSizeOfData = This->functionLength;
+    if (*pSizeOfData < This->baseShader.functionLength) {
+        *pSizeOfData = This->baseShader.functionLength;
         return D3DERR_MOREDATA;
     }
-    if (NULL == This->function) { /* no function defined */
+    if (NULL == This->baseShader.function) { /* no function defined */
         TRACE("(%p) : GetFunction no User Function defined using NULL to %p\n", This, pData);
         (*(DWORD **) pData) = NULL;
     } else {
-        if(This->functionLength == 0){
+        if(This->baseShader.functionLength == 0){
 
         }
         TRACE("(%p) : GetFunction copying to %p\n", This, pData);
-        memcpy(pData, This->function, This->functionLength);
+        memcpy(pData, This->baseShader.function, This->baseShader.functionLength);
     }
     return D3D_OK;
 }
@@ -2187,9 +2187,9 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_
                 TRACE("\n");
             }
         }
-        This->functionLength = (len + 1) * sizeof(DWORD);
+        This->baseShader.functionLength = (len + 1) * sizeof(DWORD);
     } else {
-        This->functionLength = 1; /* no Function defined use fixed function vertex processing */
+        This->baseShader.functionLength = 1; /* no Function defined use fixed function vertex processing */
     }
 
     /* Generate HW shader in needed */
@@ -2201,10 +2201,10 @@ HRESULT WINAPI IWineD3DVertexShaderImpl_
 
     /* copy the function ... because it will certainly be released by application */
     if (NULL != pFunction) {
-        This->function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->functionLength);
-        memcpy((void *)This->function, pFunction, This->functionLength);
+        This->baseShader.function = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->baseShader.functionLength);
+        memcpy((void *)This->baseShader.function, pFunction, This->baseShader.functionLength);
     } else {
-        This->function = NULL;
+        This->baseShader.function = NULL;
     }
     return D3D_OK;
 }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index dad25f6..f852536 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1170,6 +1170,27 @@ typedef struct SHADER_OPCODE {
 } SHADER_OPCODE;
 
 /*****************************************************************************
+ * IDirect3DBaseShader implementation structure
+ */
+typedef struct IWineD3DBaseShaderClass
+{
+    DWORD                           version;
+    CONST SHADER_OPCODE             *shader_ins;
+    CONST DWORD                     *function;
+    UINT                            functionLength;
+    GLuint                          prgId;
+} IWineD3DBaseShaderClass;
+
+typedef struct IWineD3DBaseShaderImpl {
+    /* IUnknown */
+    const IWineD3DBaseShaderVtbl    *lpVtbl;
+    LONG                            ref;
+
+    /* IWineD3DBaseShader */
+    IWineD3DBaseShaderClass         baseShader;
+} IWineD3DBaseShaderImpl;
+
+/*****************************************************************************
  * IDirect3DVertexShader implementation structure
  */
 typedef struct IWineD3DVertexShaderImpl {
@@ -1177,16 +1198,14 @@ typedef struct IWineD3DVertexShaderImpl 
     const IWineD3DVertexShaderVtbl *lpVtbl;
     LONG                        ref;     /* Note: Ref counting not required */
 
-    IUnknown                    *parent;
-    IWineD3DDeviceImpl          *wineD3DDevice;
+    /* IWineD3DBaseShader */
+    IWineD3DBaseShaderClass     baseShader;
 
     /* IWineD3DVertexShaderImpl */
-    CONST SHADER_OPCODE         *shader_ins;
-    CONST DWORD                 *function;
-    UINT                         functionLength;
+    IUnknown                    *parent;
+    IWineD3DDeviceImpl          *wineD3DDevice;
 
     DWORD usage;
-    DWORD version;
 
     /* vertex declaration array mapping */
     BOOL                        namedArrays;    /* don't map use named functions */
@@ -1197,7 +1216,6 @@ typedef struct IWineD3DVertexShaderImpl 
     /* FIXME: This needs to be populated with some flags of VS_CONSTANT_NOT_USED, VS_CONSTANT_CONSTANT, VS_CONSTANT_INTEGER, VS_CONSTANT_BOOLEAN, VS_CONSTANT_FLOAT, a half byte bitmap will be the best option, but I'll keep it as chards for siplicity */
     /* run time datas...  */
     VSHADERDATA                *data;
-    GLuint                      prgId;
     IWineD3DVertexDeclaration  *vertexDeclaration;
 #if 0 /* needs reworking */
     /* run time datas */
@@ -1216,19 +1234,17 @@ typedef struct IWineD3DPixelShaderImpl {
     const IWineD3DPixelShaderVtbl *lpVtbl;
     LONG                        ref;     /* Note: Ref counting not required */
 
+    /* IWineD3DBaseShader */
+    IWineD3DBaseShaderClass     baseShader;
+
+    /* IWineD3DPixelShaderImpl */
     IUnknown                   *parent;
     IWineD3DDeviceImpl         *wineD3DDevice;
 
-    /* IWineD3DPixelShaderImpl */
-    const SHADER_OPCODE         *shader_ins;
-    CONST DWORD                *function;
-    UINT                        functionLength;
-    DWORD                       version;
     CHAR                        constants[WINED3D_PSHADER_MAX_CONSTANTS];
 
     /* run time data */
     PSHADERDATA                *data;
-    GLuint                      prgId;
 
 #if 0 /* needs reworking */
     PSHADERINPUTDATA input;



More information about the wine-patches mailing list