Advertisement
Guest User

vertex blend patch for wine 1.3.18

a guest
Apr 19th, 2011
755
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.43 KB | None | 0 0
  1. diff -Naur a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
  2. --- a/dlls/wined3d/directx.c    2011-02-03 14:37:38.000000000 +0300
  3. +++ b/dlls/wined3d/directx.c    2011-02-05 15:18:48.000000000 +0300
  4. @@ -4586,8 +4586,13 @@
  5.      caps->MaxUserClipPlanes = gl_info->limits.clipplanes;
  6.      caps->MaxActiveLights = gl_info->limits.lights;
  7.  
  8. -    caps->MaxVertexBlendMatrices = gl_info->limits.blends;
  9. -    caps->MaxVertexBlendMatrixIndex   = 0;
  10. +    if (gl_info->supported[ARB_VERTEX_BLEND]) {
  11. +        caps->MaxVertexBlendMatrices    = gl_info->limits.blends;
  12. +        caps->MaxVertexBlendMatrixIndex = 0;
  13. +    } else {
  14. +        caps->MaxVertexBlendMatrices    = 4;
  15. +        caps->MaxVertexBlendMatrixIndex = 255;
  16. +    }
  17.  
  18.      caps->MaxAnisotropy = gl_info->limits.anisotropy;
  19.      caps->MaxPointSize = gl_info->limits.pointsize_max;
  20. diff -Naur a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
  21. --- a/dlls/wined3d/drawprim.c   2011-01-29 03:46:55.000000000 +0300
  22. +++ b/dlls/wined3d/drawprim.c   2011-02-05 17:59:33.000000000 +0300
  23. @@ -50,6 +50,75 @@
  24.  }
  25.  
  26.  /*
  27. + * Emit a vertex using swoftware vertex blending
  28. + */
  29. +static void emitBlendedVertex(struct wined3d_stateblock *stateBlock,
  30. +                              const float *weights, int nweights, const BYTE *indices,
  31. +                              const float *pos, const float *norm)
  32. +{
  33. +    const float *m;
  34. +    float        vec[4];
  35. +    float        mat[4*4];
  36. +    float        last = 1.f;
  37. +    int          i, j;
  38. +
  39. +    /* compute the weighted sum of the matrices */
  40. +    m = &stateBlock->state.transforms[WINED3DTS_WORLDMATRIX((indices ? indices[0] : 0))].u.m[0][0];
  41. +    for (j = 0; j < 16; j++)
  42. +        mat[j] = m[j] * weights[0];
  43. +    last -= weights[0];
  44. +
  45. +    for (i = 1; i < nweights; i++) {
  46. +        if (weights[i]) {
  47. +            m = &stateBlock->state.transforms[WINED3DTS_WORLDMATRIX((indices ? indices[i] : i))].u.m[0][0];
  48. +            for (j = 0; j < 16; j++)
  49. +                mat[j] += m[j] * weights[i];
  50. +            last -= weights[i];
  51. +        }
  52. +    }
  53. +
  54. +    /* do the last */
  55. +    if (last) {
  56. +        m = &stateBlock->state.transforms[WINED3DTS_WORLDMATRIX((indices ? indices[i] : i))].u.m[0][0];
  57. +        for (j = 0; j < 16; j++)
  58. +            mat[j] += m[j] * last;
  59. +    }
  60. +
  61. +    if (norm) {
  62. +        /* compute the resulting normal */
  63. +        vec[0] = norm[0] * mat[0] + norm[1] * mat[4] + norm[2] * mat[8];
  64. +        vec[1] = norm[0] * mat[1] + norm[1] * mat[5] + norm[2] * mat[9];
  65. +        vec[2] = norm[0] * mat[2] + norm[1] * mat[6] + norm[2] * mat[10];
  66. +        /* normalize */
  67. +        vec[3] = vec[0]*vec[0] + vec[1]*vec[1] + vec[2]*vec[2];
  68. +        if (vec[3]) {
  69. +            vec[3] = 1.f / sqrtf(vec[3]);
  70. +            vec[0] *= vec[3];
  71. +            vec[1] *= vec[3];
  72. +            vec[2] *= vec[3];
  73. +        }
  74. +
  75. +        glNormal3fv(vec);
  76. +    }
  77. +
  78. +    if (pos) {
  79. +        /* compute the resulting position */
  80. +        vec[0] = pos[0] * mat[0] + pos[1] * mat[4] + pos[2] * mat[8] + mat[12];
  81. +        vec[1] = pos[0] * mat[1] + pos[1] * mat[5] + pos[2] * mat[9] + mat[13];
  82. +        vec[2] = pos[0] * mat[2] + pos[1] * mat[6] + pos[2] * mat[10] + mat[14];
  83. +        vec[3] = pos[0] * mat[3] + pos[1] * mat[7] + pos[2] * mat[11] + mat[15];
  84. +        /* normalize */
  85. +        if (vec[3]) {
  86. +            vec[0] /= vec[3];
  87. +            vec[1] /= vec[3];
  88. +            vec[2] /= vec[3];
  89. +        }
  90. +
  91. +        glVertex3fv(vec);
  92. +    }
  93. +}
  94. +
  95. +/*
  96.   * Actually draw using the supplied information.
  97.   * Slower GL version which extracts info about each vertex in turn
  98.   */
  99. @@ -69,7 +138,8 @@
  100.      BOOL pixelShader = use_ps(state);
  101.      BOOL specular_fog = FALSE;
  102.      const BYTE *texCoords[WINED3DDP_MAXTEXCOORD];
  103. -    const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
  104. +    const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL, *weights = NULL, *indices = NULL;
  105. +    int nweights = 0;
  106.      const struct wined3d_gl_info *gl_info = context->gl_info;
  107.      UINT texture_stages = gl_info->limits.texture_stages;
  108.      const struct wined3d_stream_info_element *element;
  109. @@ -161,6 +231,31 @@
  110.      {
  111.          GL_EXTCALL(glSecondaryColor3fEXT)(0, 0, 0);
  112.      }
  113. +    
  114. +    if (device->vertexBlendSW) {
  115. +        if (!si->elements[WINED3D_FFP_BLENDWEIGHT].data) {
  116. +            WARN("vertex blending enabled but blendWeights.data=NULL\n");
  117. +        } else if (si->elements[WINED3D_FFP_BLENDWEIGHT].format->gl_vtx_type != GL_FLOAT) {
  118. +            FIXME("unsupported blend weights datatype (%d)\n", si->elements[WINED3D_FFP_BLENDWEIGHT].format->id);
  119. +        } else if (position && si->elements[WINED3D_FFP_POSITION].format->emit_idx != WINED3D_FFP_EMIT_FLOAT3) {
  120. +            FIXME("unsupported postion datatype (%d)\n", si->elements[WINED3D_FFP_POSITION].format->id);
  121. +        } else if (normal && si->elements[WINED3D_FFP_NORMAL].format->emit_idx != WINED3D_FFP_EMIT_FLOAT3) {
  122. +            FIXME("unsupported normal datatype (%d)\n", si->elements[WINED3D_FFP_NORMAL].format->id);
  123. +        } else {
  124. +            element = &si->elements[WINED3D_FFP_BLENDWEIGHT];
  125. +            weights = element->data + streams[element->stream_idx].offset;
  126. +            nweights = element->format->gl_vtx_format;
  127. +        }
  128. +        
  129. +        if (si->elements[WINED3D_FFP_BLENDINDICES].data) {
  130. +            if (si->elements[WINED3D_FFP_BLENDINDICES].format->emit_idx != WINED3D_FFP_EMIT_UBYTE4) {
  131. +                FIXME("unsupported blend indices datatype (%d)\n", si->elements[WINED3D_FFP_BLENDINDICES].format->id);
  132. +            } else {
  133. +                element = &si->elements[WINED3D_FFP_BLENDINDICES];
  134. +                indices = element->data + streams[element->stream_idx].offset;
  135. +            }
  136. +        }
  137. +    }
  138.  
  139.      for (textureNo = 0; textureNo < texture_stages; ++textureNo)
  140.      {
  141. @@ -278,17 +373,24 @@
  142.              }
  143.          }
  144.  
  145. -        /* Normal -------------------------------- */
  146. -        if (normal)
  147. -        {
  148. -            const void *ptrToCoords = normal + SkipnStrides * si->elements[WINED3D_FFP_NORMAL].stride;
  149. -            normal_funcs[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptrToCoords);
  150. -        }
  151. -
  152. -        /* Position -------------------------------- */
  153. -        if (position) {
  154. -            const void *ptrToCoords = position + SkipnStrides * si->elements[WINED3D_FFP_POSITION].stride;
  155. -            position_funcs[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptrToCoords);
  156. +        if (weights) {
  157. +            emitBlendedVertex(device->stateBlock,
  158. +                              (const float*)(weights + SkipnStrides * si->elements[WINED3D_FFP_BLENDWEIGHT].stride), nweights,
  159. +                              indices ? (indices + SkipnStrides * si->elements[WINED3D_FFP_BLENDINDICES].stride) : NULL,
  160. +                              (const float*)(position ? (position + SkipnStrides * si->elements[WINED3D_FFP_POSITION].stride) : NULL),
  161. +                              (const float*)(normal ? (normal + SkipnStrides * si->elements[WINED3D_FFP_NORMAL].stride) : NULL));
  162. +        } else {
  163. +            /* Normal -------------------------------- */
  164. +            if (normal) {
  165. +                const void *ptrToCoords = normal + SkipnStrides * si->elements[WINED3D_FFP_NORMAL].stride;
  166. +                normal_funcs[si->elements[WINED3D_FFP_NORMAL].format->emit_idx](ptrToCoords);
  167. +            }
  168. +
  169. +            /* Position -------------------------------- */
  170. +            if (position) {
  171. +                const void *ptrToCoords = position + SkipnStrides * si->elements[WINED3D_FFP_POSITION].stride;
  172. +                position_funcs[si->elements[WINED3D_FFP_POSITION].format->emit_idx](ptrToCoords);
  173. +            }
  174.          }
  175.  
  176.          /* For non indexed mode, step onto next parts */
  177. @@ -678,6 +780,17 @@
  178.                  }
  179.                  emulation = TRUE;
  180.              }
  181. +            else if (device->vertexBlendSW)
  182. +            {
  183. +                static BOOL warned;
  184. +                if (!warned) {
  185. +                    FIXME("Using software emulation because vertex blending is enabled\n");
  186. +                    warned = TRUE;
  187. +                } else {
  188. +                    TRACE("Using software emulation because vertex blending is enabled\n");
  189. +                }
  190. +                emulation = TRUE;
  191. +            }
  192.  
  193.              if(emulation) {
  194.                  stream_info = &stridedlcl;
  195. diff -Naur a/dlls/wined3d/state.c b/dlls/wined3d/state.c
  196. --- a/dlls/wined3d/state.c  2011-02-01 16:17:23.000000000 +0300
  197. +++ b/dlls/wined3d/state.c  2011-02-05 17:33:09.000000000 +0300
  198. @@ -3768,7 +3768,7 @@
  199.      if(context->last_was_rhw) {
  200.          glLoadIdentity();
  201.          checkGLcall("glLoadIdentity()");
  202. -    } else {
  203. +    } else if (!stateblock->device->vertexBlendSW) {
  204.          /* In the general case, the view matrix is the identity matrix */
  205.          if (stateblock->device->view_ident)
  206.          {
  207. @@ -3782,6 +3782,9 @@
  208.              glMultMatrixf(&stateblock->state.transforms[WINED3DTS_WORLDMATRIX(0)].u.m[0][0]);
  209.              checkGLcall("glMultMatrixf");
  210.          }
  211. +    } else {
  212. +        glLoadMatrixf(&stateblock->state.transforms[WINED3DTS_VIEW].u.m[0][0]);
  213. +        checkGLcall("glLoadMatrixf");
  214.      }
  215.  }
  216.  
  217. diff -Naur a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c
  218. --- a/dlls/wined3d/vertexdeclaration.c  2011-02-05 15:14:05.000000000 +0300
  219. +++ b/dlls/wined3d/vertexdeclaration.c  2011-02-05 15:18:48.000000000 +0300
  220. @@ -106,6 +106,15 @@
  221.                  default:
  222.                      return FALSE;
  223.              }
  224. +            
  225. +        case WINED3DDECLUSAGE_BLENDINDICES:
  226. +            switch(element->format)
  227. +            {
  228. +                case WINED3DFMT_R8G8B8A8_UINT:
  229. +                    return TRUE;
  230. +                default:
  231. +                    return FALSE;
  232. +            }
  233.  
  234.          case WINED3DDECLUSAGE_NORMAL:
  235.              switch(element->format)
  236. diff -Naur a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
  237. --- a/dlls/wined3d/wined3d_private.h    2011-02-05 15:14:05.000000000 +0300
  238. +++ b/dlls/wined3d/wined3d_private.h    2011-02-05 15:18:48.000000000 +0300
  239. @@ -1680,6 +1680,7 @@
  240.      WORD view_ident : 1;                /* true iff view matrix is identity */
  241.      WORD untransformed : 1;
  242.      WORD vertexBlendUsed : 1;           /* To avoid needless setting of the blend matrices */
  243. +    WORD vertexBlendSW : 1;             /* vertexBlend software fallback used */
  244.      WORD isRecordingState : 1;
  245.      WORD isInDraw : 1;
  246.      WORD bCursorVisible : 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement