Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 1 | /* Direct3D ExecuteBuffer |
| 2 | (c) 1998 Lionel ULMER |
| 3 | |
| 4 | This files contains the implementation of Direct3DExecuteBuffer. */ |
| 5 | |
| 6 | |
David Luyer | ee517e8 | 1999-02-28 12:27:56 +0000 | [diff] [blame] | 7 | #include <string.h> |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 8 | #include "config.h" |
Jim Aston | 2e1cafa | 1999-03-14 16:35:05 +0000 | [diff] [blame] | 9 | #include "windef.h" |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 10 | #include "winerror.h" |
Francois Gouget | a94d649 | 1999-02-02 16:14:23 +0000 | [diff] [blame] | 11 | #include "wine/obj_base.h" |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 12 | #include "heap.h" |
| 13 | #include "ddraw.h" |
| 14 | #include "d3d.h" |
| 15 | #include "debug.h" |
| 16 | |
| 17 | #include "d3d_private.h" |
| 18 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 19 | DEFAULT_DEBUG_CHANNEL(ddraw) |
| 20 | |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 21 | #ifdef HAVE_MESAGL |
| 22 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 23 | /* Structure to store the 'semi transformed' vertices */ |
| 24 | typedef struct { |
| 25 | D3DVALUE x; |
| 26 | D3DVALUE y; |
| 27 | D3DVALUE z; |
| 28 | D3DVALUE w; |
| 29 | |
| 30 | D3DVALUE nx; |
| 31 | D3DVALUE ny; |
| 32 | D3DVALUE nz; |
| 33 | |
| 34 | D3DVALUE u; |
| 35 | D3DVALUE v; |
| 36 | } OGL_Vertex; |
| 37 | |
| 38 | typedef struct { |
| 39 | D3DVALUE x; |
| 40 | D3DVALUE y; |
| 41 | D3DVALUE z; |
| 42 | D3DVALUE w; |
| 43 | |
| 44 | D3DCOLOR c; |
| 45 | D3DCOLOR sc; |
| 46 | |
| 47 | D3DVALUE u; |
| 48 | D3DVALUE v; |
| 49 | } OGL_LVertex; |
| 50 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 51 | static ICOM_VTABLE(IDirect3DExecuteBuffer) executebuffer_vtable; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 52 | |
| 53 | /******************************************************************************* |
| 54 | * ExecuteBuffer static functions |
| 55 | */ |
| 56 | void _dump_d3dstatus(LPD3DSTATUS lpStatus) { |
| 57 | |
| 58 | } |
| 59 | |
| 60 | void _dump_executedata(LPD3DEXECUTEDATA lpData) { |
| 61 | DUMP("dwSize : %ld\n", lpData->dwSize); |
| 62 | DUMP("Vertex Offset : %ld Count : %ld\n", lpData->dwVertexOffset, lpData->dwVertexCount); |
| 63 | DUMP("Instruction Offset : %ld Length : %ld\n", lpData->dwInstructionOffset, lpData->dwInstructionLength); |
| 64 | DUMP("HVertex Offset : %ld\n", lpData->dwHVertexOffset); |
| 65 | _dump_d3dstatus(&(lpData->dsStatus)); |
| 66 | } |
| 67 | |
| 68 | #define DO_VERTEX(index) \ |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 69 | { \ |
| 70 | glTexCoord2f(vx[index].u, \ |
| 71 | vx[index].v); \ |
| 72 | glNormal3f(vx[index].nx, \ |
| 73 | vx[index].ny, \ |
| 74 | vx[index].nz); \ |
| 75 | glVertex4f(vx[index].x, \ |
| 76 | vx[index].y, \ |
| 77 | vx[index].z, \ |
| 78 | vx[index].w); \ |
| 79 | \ |
| 80 | TRACE(ddraw, " V: %f %f %f %f (%f %f %f) (%f %f)\n", \ |
| 81 | vx[index].x, vx[index].y, vx[index].z, vx[index].w, \ |
| 82 | vx[index].nx, vx[index].ny, vx[index].nz, \ |
| 83 | vx[index].u, vx[index].v); \ |
| 84 | } |
| 85 | |
| 86 | #define DO_LVERTEX(index) \ |
| 87 | { \ |
| 88 | DWORD col = l_vx[index].c; \ |
| 89 | \ |
| 90 | glColor3f(((col >> 16) & 0xFF) / 255.0, \ |
| 91 | ((col >> 8) & 0xFF) / 255.0, \ |
| 92 | ((col >> 0) & 0xFF) / 255.0); \ |
| 93 | glTexCoord2f(l_vx[index].u, \ |
| 94 | l_vx[index].v); \ |
| 95 | glVertex4f(l_vx[index].x, \ |
| 96 | l_vx[index].y, \ |
| 97 | l_vx[index].z, \ |
| 98 | l_vx[index].w); \ |
| 99 | \ |
| 100 | TRACE(ddraw, " LV: %f %f %f %f (%02lx %02lx %02lx) (%f %f)\n", \ |
| 101 | l_vx[index].x, l_vx[index].y, l_vx[index].z, l_vx[index].w, \ |
| 102 | ((col >> 16) & 0xFF), ((col >> 8) & 0xFF), ((col >> 0) & 0xFF), \ |
| 103 | l_vx[index].u, l_vx[index].v); \ |
| 104 | } |
| 105 | |
| 106 | #define DO_TLVERTEX(index) \ |
| 107 | { \ |
| 108 | D3DTLVERTEX *vx = &(tl_vx[index]); \ |
| 109 | DWORD col = vx->c.color; \ |
| 110 | \ |
| 111 | glColor3f(((col >> 16) & 0xFF) / 255.0, \ |
| 112 | ((col >> 8) & 0xFF) / 255.0, \ |
| 113 | ((col >> 0) & 0xFF) / 255.0); \ |
| 114 | glTexCoord2f(vx->u.tu, vx->v.tv); \ |
| 115 | if (vx->r.rhw < 0.01) \ |
| 116 | glVertex3f(vx->x.sx, \ |
| 117 | vx->y.sy, \ |
| 118 | vx->z.sz); \ |
| 119 | else \ |
| 120 | glVertex4f(vx->x.sx / vx->r.rhw, \ |
| 121 | vx->y.sy / vx->r.rhw, \ |
| 122 | vx->z.sz / vx->r.rhw, \ |
| 123 | 1.0 / vx->r.rhw); \ |
| 124 | TRACE(ddraw, " TLV: %f %f %f (%02lx %02lx %02lx) (%f %f) (%f)\n", \ |
| 125 | vx->x.sx, vx->y.sy, vx->z.sz, \ |
| 126 | ((col >> 16) & 0xFF), ((col >> 8) & 0xFF), ((col >> 0) & 0xFF), \ |
| 127 | vx->u.tu, vx->v.tv, vx->r.rhw); \ |
| 128 | } |
| 129 | |
| 130 | #define TRIANGLE_LOOP(macro) \ |
| 131 | { \ |
| 132 | glBegin(GL_TRIANGLES); { \ |
| 133 | for (i = 0; i < count; i++) { \ |
| 134 | LPD3DTRIANGLE ci = (LPD3DTRIANGLE) instr; \ |
| 135 | \ |
| 136 | TRACE(ddraw, " v1: %d v2: %d v3: %d\n", \ |
| 137 | ci->v1.v1, ci->v2.v2, ci->v3.v3); \ |
| 138 | TRACE(ddraw, " Flags : "); \ |
| 139 | if (TRACE_ON(ddraw)) { \ |
| 140 | /* Wireframe */ \ |
| 141 | if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1) \ |
| 142 | DUMP("EDGEENABLE1 "); \ |
| 143 | if (ci->wFlags & D3DTRIFLAG_EDGEENABLE2) \ |
| 144 | DUMP("EDGEENABLE2 "); \ |
| 145 | if (ci->wFlags & D3DTRIFLAG_EDGEENABLE1) \ |
| 146 | DUMP("EDGEENABLE3 "); \ |
| 147 | \ |
| 148 | /* Strips / Fans */ \ |
| 149 | if (ci->wFlags == D3DTRIFLAG_EVEN) \ |
| 150 | DUMP("EVEN "); \ |
| 151 | if (ci->wFlags == D3DTRIFLAG_ODD) \ |
| 152 | DUMP("ODD "); \ |
| 153 | if (ci->wFlags == D3DTRIFLAG_START) \ |
| 154 | DUMP("START "); \ |
| 155 | if ((ci->wFlags > 0) && (ci->wFlags < 30)) \ |
| 156 | DUMP("STARTFLAT(%d) ", ci->wFlags); \ |
| 157 | DUMP("\n"); \ |
| 158 | } \ |
| 159 | \ |
| 160 | /* Draw the triangle */ \ |
| 161 | macro(ci->v1.v1); \ |
| 162 | macro(ci->v2.v2); \ |
| 163 | macro(ci->v3.v3); \ |
| 164 | \ |
| 165 | instr += size; \ |
| 166 | } \ |
| 167 | } glEnd(); \ |
| 168 | } |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 169 | |
| 170 | |
| 171 | static void execute(LPDIRECT3DEXECUTEBUFFER lpBuff, |
| 172 | LPDIRECT3DDEVICE dev, |
| 173 | LPDIRECT3DVIEWPORT vp) { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 174 | IDirect3DExecuteBufferImpl* ilpBuff=(IDirect3DExecuteBufferImpl*)lpBuff; |
| 175 | IDirect3DViewport2Impl* ivp=(IDirect3DViewport2Impl*)vp; |
| 176 | /* DWORD bs = ilpBuff->desc.dwBufferSize; */ |
| 177 | DWORD vs = ilpBuff->data.dwVertexOffset; |
| 178 | /* DWORD vc = ilpBuff->data.dwVertexCount; */ |
| 179 | DWORD is = ilpBuff->data.dwInstructionOffset; |
| 180 | /* DWORD il = ilpBuff->data.dwInstructionLength; */ |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 181 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 182 | void *instr = ilpBuff->desc.lpData + is; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 183 | OpenGL_IDirect3DDevice *odev = (OpenGL_IDirect3DDevice *) dev; |
| 184 | |
| 185 | TRACE(ddraw, "ExecuteData : \n"); |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 186 | if (TRACE_ON(ddraw)) |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 187 | _dump_executedata(&(ilpBuff->data)); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 188 | |
Lionel Ulmer | ad72585 | 1999-05-13 18:53:05 +0000 | [diff] [blame] | 189 | ENTER_GL(); |
| 190 | |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 191 | while (1) { |
| 192 | LPD3DINSTRUCTION current = (LPD3DINSTRUCTION) instr; |
| 193 | BYTE size; |
| 194 | WORD count; |
| 195 | |
| 196 | count = current->wCount; |
| 197 | size = current->bSize; |
| 198 | instr += sizeof(D3DINSTRUCTION); |
| 199 | |
| 200 | switch (current->bOpcode) { |
| 201 | case D3DOP_POINT: { |
| 202 | TRACE(ddraw, "POINT-s (%d)\n", count); |
| 203 | |
| 204 | instr += count * size; |
| 205 | } break; |
| 206 | |
| 207 | case D3DOP_LINE: { |
| 208 | TRACE(ddraw, "LINE-s (%d)\n", count); |
| 209 | |
| 210 | instr += count * size; |
| 211 | } break; |
| 212 | |
| 213 | case D3DOP_TRIANGLE: { |
| 214 | int i; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 215 | float z_inv_matrix[16] = { |
| 216 | 1.0, 0.0, 0.0, 0.0, |
| 217 | 0.0, 1.0, 0.0, 0.0, |
| 218 | 0.0, 0.0, -1.0, 0.0, |
| 219 | 0.0, 0.0, 1.0, 1.0 |
| 220 | }; |
| 221 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 222 | OGL_Vertex *vx = (OGL_Vertex *) ilpBuff->vertex_data; |
| 223 | OGL_LVertex *l_vx = (OGL_LVertex *) ilpBuff->vertex_data; |
| 224 | D3DTLVERTEX *tl_vx = (D3DTLVERTEX *) ilpBuff->vertex_data; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 225 | |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 226 | TRACE(ddraw, "TRIANGLE (%d)\n", count); |
| 227 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 228 | switch (ilpBuff->vertex_type) { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 229 | case D3DVT_VERTEX: |
| 230 | /* This time, there is lighting */ |
| 231 | glEnable(GL_LIGHTING); |
| 232 | |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 233 | /* Use given matrixes */ |
| 234 | glMatrixMode(GL_MODELVIEW); |
| 235 | glLoadIdentity(); /* The model transformation was done during the |
| 236 | transformation phase */ |
| 237 | glMatrixMode(GL_PROJECTION); |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 238 | TRACE(ddraw, " Projection Matrix : (%p)\n", odev->proj_mat); |
| 239 | dump_mat(odev->proj_mat); |
| 240 | TRACE(ddraw, " View Matrix : (%p)\n", odev->view_mat); |
| 241 | dump_mat(odev->view_mat); |
| 242 | |
| 243 | glLoadMatrixf((float *) z_inv_matrix); |
| 244 | glMultMatrixf((float *) odev->proj_mat); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 245 | glMultMatrixf((float *) odev->view_mat); |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 246 | break; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 247 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 248 | case D3DVT_LVERTEX: |
| 249 | /* No lighting */ |
| 250 | glDisable(GL_LIGHTING); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 251 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 252 | /* Use given matrixes */ |
| 253 | glMatrixMode(GL_MODELVIEW); |
| 254 | glLoadIdentity(); /* The model transformation was done during the |
| 255 | transformation phase */ |
| 256 | glMatrixMode(GL_PROJECTION); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 257 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 258 | TRACE(ddraw, " Projection Matrix : (%p)\n", odev->proj_mat); |
| 259 | dump_mat(odev->proj_mat); |
| 260 | TRACE(ddraw, " View Matrix : (%p)\n", odev->view_mat); |
| 261 | dump_mat(odev->view_mat); |
| 262 | |
| 263 | glLoadMatrixf((float *) z_inv_matrix); |
| 264 | glMultMatrixf((float *) odev->proj_mat); |
| 265 | glMultMatrixf((float *) odev->view_mat); |
| 266 | break; |
| 267 | |
| 268 | case D3DVT_TLVERTEX: { |
| 269 | GLdouble height, width, minZ, maxZ; |
| 270 | |
| 271 | /* First, disable lighting */ |
| 272 | glDisable(GL_LIGHTING); |
| 273 | |
| 274 | /* Then do not put any transformation matrixes */ |
| 275 | glMatrixMode(GL_MODELVIEW); |
| 276 | glLoadIdentity(); |
| 277 | glMatrixMode(GL_PROJECTION); |
| 278 | glLoadIdentity(); |
| 279 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 280 | if (ivp == NULL) { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 281 | ERR(ddraw, "No current viewport !\n"); |
| 282 | /* Using standard values */ |
| 283 | height = 640.0; |
| 284 | width = 480.0; |
| 285 | minZ = -10.0; |
| 286 | maxZ = 10.0; |
| 287 | } else { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 288 | height = (GLdouble) ivp->viewport.vp1.dwHeight; |
| 289 | width = (GLdouble) ivp->viewport.vp1.dwWidth; |
| 290 | minZ = (GLdouble) ivp->viewport.vp1.dvMinZ; |
| 291 | maxZ = (GLdouble) ivp->viewport.vp1.dvMaxZ; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 292 | |
| 293 | if (minZ == maxZ) { |
| 294 | /* I do not know why, but many Dx 3.0 games have minZ = maxZ = 0.0 */ |
| 295 | minZ = 0.0; |
| 296 | maxZ = 1.0; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 297 | } |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 298 | } |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 299 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 300 | glOrtho(0.0, width, height, 0.0, -minZ, -maxZ); |
| 301 | } break; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 302 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 303 | default: |
| 304 | ERR(ddraw, "Unhandled vertex type !\n"); |
| 305 | break; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 306 | } |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 307 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 308 | switch (ilpBuff->vertex_type) { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 309 | case D3DVT_VERTEX: |
| 310 | TRIANGLE_LOOP(DO_VERTEX); |
| 311 | break; |
| 312 | |
| 313 | case D3DVT_LVERTEX: |
| 314 | TRIANGLE_LOOP(DO_LVERTEX); |
| 315 | break; |
| 316 | |
| 317 | case D3DVT_TLVERTEX: |
| 318 | TRIANGLE_LOOP(DO_TLVERTEX); |
| 319 | break; |
| 320 | |
| 321 | default: |
| 322 | ERR(ddraw, "Unhandled vertex type !\n"); |
| 323 | } |
| 324 | |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 325 | } break; |
| 326 | |
| 327 | case D3DOP_MATRIXLOAD: { |
| 328 | TRACE(ddraw, "MATRIXLOAD-s (%d)\n", count); |
| 329 | |
| 330 | instr += count * size; |
| 331 | } break; |
| 332 | |
| 333 | case D3DOP_MATRIXMULTIPLY: { |
| 334 | int i; |
| 335 | TRACE(ddraw, "MATRIXMULTIPLY (%d)\n", count); |
| 336 | |
| 337 | for (i = 0; i < count; i++) { |
| 338 | LPD3DMATRIXMULTIPLY ci = (LPD3DMATRIXMULTIPLY) instr; |
| 339 | LPD3DMATRIX a = (LPD3DMATRIX) ci->hDestMatrix; |
| 340 | LPD3DMATRIX b = (LPD3DMATRIX) ci->hSrcMatrix1; |
| 341 | LPD3DMATRIX c = (LPD3DMATRIX) ci->hSrcMatrix2; |
| 342 | |
| 343 | TRACE(ddraw, " Dest : %08lx Src1 : %08lx Src2 : %08lx\n", |
| 344 | ci->hDestMatrix, ci->hSrcMatrix1, ci->hSrcMatrix2); |
| 345 | |
| 346 | /* Do the multiplication.. |
| 347 | As I am VERY lazy, I let OpenGL do the multiplication for me */ |
| 348 | glMatrixMode(GL_PROJECTION); |
| 349 | /* Save the current matrix */ |
| 350 | glPushMatrix(); |
| 351 | /* Load Matrix one and do the multiplication */ |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 352 | glLoadMatrixf((float *) c); |
| 353 | glMultMatrixf((float *) b); |
| 354 | glGetFloatv(GL_PROJECTION_MATRIX, (float *) a); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 355 | /* Restore the current matrix */ |
| 356 | glPopMatrix(); |
| 357 | |
| 358 | instr += size; |
| 359 | } |
| 360 | } break; |
| 361 | |
| 362 | case D3DOP_STATETRANSFORM: { |
| 363 | int i; |
| 364 | TRACE(ddraw, "STATETRANSFORM (%d)\n", count); |
| 365 | |
| 366 | for (i = 0; i < count; i++) { |
| 367 | LPD3DSTATE ci = (LPD3DSTATE) instr; |
| 368 | |
| 369 | /* Handle the state transform */ |
| 370 | switch (ci->t.dtstTransformStateType) { |
| 371 | case D3DTRANSFORMSTATE_WORLD: { |
| 372 | TRACE(ddraw, " WORLD (%p)\n", (D3DMATRIX*) ci->v.dwArg[0]); |
| 373 | odev->world_mat = (D3DMATRIX*) ci->v.dwArg[0]; |
| 374 | } break; |
| 375 | |
| 376 | case D3DTRANSFORMSTATE_VIEW: { |
| 377 | TRACE(ddraw, " VIEW (%p)\n", (D3DMATRIX*) ci->v.dwArg[0]); |
| 378 | odev->view_mat = (D3DMATRIX*) ci->v.dwArg[0]; |
| 379 | } break; |
| 380 | |
| 381 | case D3DTRANSFORMSTATE_PROJECTION: { |
| 382 | TRACE(ddraw, " PROJECTION (%p)\n", (D3DMATRIX*) ci->v.dwArg[0]); |
| 383 | odev->proj_mat = (D3DMATRIX*) ci->v.dwArg[0]; |
| 384 | } break; |
| 385 | |
| 386 | default: |
| 387 | ERR(ddraw, " Unhandled state transformation !! (%d)\n", (int) ci->t.dtstTransformStateType); |
| 388 | break; |
| 389 | |
| 390 | } |
| 391 | |
| 392 | instr += size; |
| 393 | } |
| 394 | } break; |
| 395 | |
| 396 | case D3DOP_STATELIGHT: { |
| 397 | int i; |
| 398 | TRACE(ddraw, "STATELIGHT (%d)\n", count); |
| 399 | |
| 400 | for (i = 0; i < count; i++) { |
| 401 | LPD3DSTATE ci = (LPD3DSTATE) instr; |
| 402 | |
| 403 | /* Handle the state transform */ |
| 404 | switch (ci->t.dlstLightStateType) { |
| 405 | case D3DLIGHTSTATE_MATERIAL: { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 406 | IDirect3DMaterial2Impl* mat = (IDirect3DMaterial2Impl*) ci->v.dwArg[0]; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 407 | TRACE(ddraw, " MATERIAL\n"); |
| 408 | |
| 409 | if (mat != NULL) { |
| 410 | mat->activate(mat); |
| 411 | } else { |
| 412 | TRACE(ddraw, " bad Material Handle\n"); |
| 413 | } |
| 414 | } break ; |
| 415 | |
| 416 | case D3DLIGHTSTATE_AMBIENT: { |
| 417 | float light[4]; |
| 418 | DWORD dwLightState = ci->v.dwArg[0]; |
| 419 | TRACE(ddraw, " AMBIENT\n"); |
| 420 | |
| 421 | light[0] = ((dwLightState >> 16) & 0xFF) / 255.0; |
| 422 | light[1] = ((dwLightState >> 8) & 0xFF) / 255.0; |
| 423 | light[2] = ((dwLightState >> 0) & 0xFF) / 255.0; |
| 424 | light[3] = 1.0; |
| 425 | glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (float *) light); |
| 426 | |
| 427 | TRACE(ddraw, " R:%02lx G:%02lx B:%02lx A:%02lx\n", |
| 428 | ((dwLightState >> 16) & 0xFF), |
| 429 | ((dwLightState >> 8) & 0xFF), |
| 430 | ((dwLightState >> 0) & 0xFF), |
| 431 | ((dwLightState >> 24) & 0xFF)); |
| 432 | } break ; |
| 433 | |
| 434 | case D3DLIGHTSTATE_COLORMODEL: { |
| 435 | TRACE(ddraw, " COLORMODEL\n"); |
| 436 | } break ; |
| 437 | |
| 438 | case D3DLIGHTSTATE_FOGMODE: { |
| 439 | TRACE(ddraw, " FOGMODE\n"); |
| 440 | } break ; |
| 441 | |
| 442 | case D3DLIGHTSTATE_FOGSTART: { |
| 443 | TRACE(ddraw, " FOGSTART\n"); |
| 444 | } break ; |
| 445 | |
| 446 | case D3DLIGHTSTATE_FOGEND: { |
| 447 | TRACE(ddraw, " FOGEND\n"); |
| 448 | } break ; |
| 449 | |
| 450 | case D3DLIGHTSTATE_FOGDENSITY: { |
| 451 | TRACE(ddraw, " FOGDENSITY\n"); |
| 452 | } break ; |
| 453 | |
| 454 | default: |
| 455 | ERR(ddraw, " Unhandled light state !! (%d)\n", (int) ci->t.dlstLightStateType); |
| 456 | break; |
| 457 | } |
| 458 | instr += size; |
| 459 | } |
| 460 | } break; |
| 461 | |
| 462 | case D3DOP_STATERENDER: { |
| 463 | int i; |
| 464 | TRACE(ddraw, "STATERENDER (%d)\n", count); |
| 465 | |
| 466 | for (i = 0; i < count; i++) { |
| 467 | LPD3DSTATE ci = (LPD3DSTATE) instr; |
| 468 | |
| 469 | /* Handle the state transform */ |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 470 | set_render_state(ci->t.drstRenderStateType, ci->v.dwArg[0], &(odev->rs)); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 471 | |
| 472 | instr += size; |
| 473 | } |
| 474 | } break; |
| 475 | |
| 476 | case D3DOP_PROCESSVERTICES: { |
| 477 | int i; |
| 478 | TRACE(ddraw, "PROCESSVERTICES (%d)\n", count); |
| 479 | |
| 480 | for (i = 0; i < count; i++) { |
| 481 | LPD3DPROCESSVERTICES ci = (LPD3DPROCESSVERTICES) instr; |
| 482 | |
| 483 | TRACE(ddraw, " Start : %d Dest : %d Count : %ld\n", |
| 484 | ci->wStart, ci->wDest, ci->dwCount); |
| 485 | TRACE(ddraw, " Flags : "); |
| 486 | if (TRACE_ON(ddraw)) { |
| 487 | if (ci->dwFlags & D3DPROCESSVERTICES_COPY) |
| 488 | DUMP("COPY "); |
| 489 | if (ci->dwFlags & D3DPROCESSVERTICES_NOCOLOR) |
| 490 | DUMP("NOCOLOR "); |
| 491 | if (ci->dwFlags == D3DPROCESSVERTICES_OPMASK) |
| 492 | DUMP("OPMASK "); |
| 493 | if (ci->dwFlags & D3DPROCESSVERTICES_TRANSFORM) |
| 494 | DUMP("TRANSFORM "); |
| 495 | if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) |
| 496 | DUMP("TRANSFORMLIGHT "); |
| 497 | if (ci->dwFlags & D3DPROCESSVERTICES_UPDATEEXTENTS) |
| 498 | DUMP("UPDATEEXTENTS "); |
| 499 | DUMP("\n"); |
| 500 | } |
| 501 | |
| 502 | /* This is where doing Direct3D on top on OpenGL is quite difficult. |
| 503 | This method transforms a set of vertices using the CURRENT state |
| 504 | (lighting, projection, ...) but does not rasterize them. |
| 505 | They will oinly be put on screen later (with the POINT / LINE and |
| 506 | TRIANGLE op-codes). The problem is that you can have a triangle |
| 507 | with each point having been transformed using another state... |
| 508 | |
| 509 | In this implementation, I will emulate only ONE thing : each |
| 510 | vertex can have its own "WORLD" transformation (this is used in the |
| 511 | TWIST.EXE demo of the 5.2 SDK). I suppose that all vertices of the |
| 512 | execute buffer use the same state. |
| 513 | |
| 514 | If I find applications that change other states, I will try to do a |
| 515 | more 'fine-tuned' state emulation (but I may become quite tricky if |
| 516 | it changes a light position in the middle of a triangle). |
| 517 | |
| 518 | In this case, a 'direct' approach (i.e. without using OpenGL, but |
| 519 | writing our own 3D rasterizer) would be easier. */ |
| 520 | |
| 521 | /* The current method (with the hypothesis that only the WORLD matrix |
| 522 | will change between two points) is like this : |
| 523 | - I transform 'manually' all the vertices with the current WORLD |
| 524 | matrix and store them in the vertex buffer |
| 525 | - during the rasterization phase, the WORLD matrix will be set to |
| 526 | the Identity matrix */ |
| 527 | |
| 528 | /* Enough for the moment */ |
| 529 | if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORMLIGHT) { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 530 | int nb; |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 531 | D3DVERTEX *src = ((LPD3DVERTEX) (ilpBuff->desc.lpData + vs)) + ci->wStart; |
| 532 | OGL_Vertex *dst = ((OGL_Vertex *) (ilpBuff->vertex_data)) + ci->wDest; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 533 | D3DMATRIX *mat = odev->world_mat; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 534 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 535 | TRACE(ddraw, " World Matrix : (%p)\n", mat); |
| 536 | dump_mat(mat); |
| 537 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 538 | ilpBuff->vertex_type = D3DVT_VERTEX; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 539 | |
| 540 | for (nb = 0; nb < ci->dwCount; nb++) { |
| 541 | /* For the moment, no normal transformation... */ |
| 542 | dst->nx = src->nx.nx; |
| 543 | dst->ny = src->ny.ny; |
| 544 | dst->nz = src->nz.nz; |
| 545 | |
| 546 | dst->u = src->u.tu; |
| 547 | dst->v = src->v.tv; |
| 548 | |
| 549 | /* Now, the matrix multiplication */ |
| 550 | dst->x = (src->x.x * mat->_11) + (src->y.y * mat->_21) + (src->z.z * mat->_31) + (1.0 * mat->_41); |
| 551 | dst->y = (src->x.x * mat->_12) + (src->y.y * mat->_22) + (src->z.z * mat->_32) + (1.0 * mat->_42); |
| 552 | dst->z = (src->x.x * mat->_13) + (src->y.y * mat->_23) + (src->z.z * mat->_33) + (1.0 * mat->_43); |
| 553 | dst->w = (src->x.x * mat->_14) + (src->y.y * mat->_24) + (src->z.z * mat->_34) + (1.0 * mat->_44); |
| 554 | |
| 555 | src++; |
| 556 | dst++; |
| 557 | } |
| 558 | } else if (ci->dwFlags == D3DPROCESSVERTICES_TRANSFORM) { |
| 559 | int nb; |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 560 | D3DLVERTEX *src = ((LPD3DLVERTEX) (ilpBuff->desc.lpData + vs)) + ci->wStart; |
| 561 | OGL_LVertex *dst = ((OGL_LVertex *) (ilpBuff->vertex_data)) + ci->wDest; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 562 | D3DMATRIX *mat = odev->world_mat; |
| 563 | |
| 564 | TRACE(ddraw, " World Matrix : (%p)\n", mat); |
| 565 | dump_mat(mat); |
| 566 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 567 | ilpBuff->vertex_type = D3DVT_LVERTEX; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 568 | |
| 569 | for (nb = 0; nb < ci->dwCount; nb++) { |
| 570 | dst->c = src->c.color; |
| 571 | dst->sc = src->s.specular; |
| 572 | dst->u = src->u.tu; |
| 573 | dst->v = src->v.tv; |
| 574 | |
| 575 | /* Now, the matrix multiplication */ |
| 576 | dst->x = (src->x.x * mat->_11) + (src->y.y * mat->_21) + (src->z.z * mat->_31) + (1.0 * mat->_41); |
| 577 | dst->y = (src->x.x * mat->_12) + (src->y.y * mat->_22) + (src->z.z * mat->_32) + (1.0 * mat->_42); |
| 578 | dst->z = (src->x.x * mat->_13) + (src->y.y * mat->_23) + (src->z.z * mat->_33) + (1.0 * mat->_43); |
| 579 | dst->w = (src->x.x * mat->_14) + (src->y.y * mat->_24) + (src->z.z * mat->_34) + (1.0 * mat->_44); |
| 580 | |
| 581 | src++; |
| 582 | dst++; |
| 583 | } |
| 584 | } else if (ci->dwFlags == D3DPROCESSVERTICES_COPY) { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 585 | D3DTLVERTEX *src = ((LPD3DTLVERTEX) (ilpBuff->desc.lpData + vs)) + ci->wStart; |
| 586 | D3DTLVERTEX *dst = ((LPD3DTLVERTEX) (ilpBuff->vertex_data)) + ci->wDest; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 587 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 588 | ilpBuff->vertex_type = D3DVT_TLVERTEX; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 589 | |
| 590 | memcpy(dst, src, ci->dwCount * sizeof(D3DTLVERTEX)); |
| 591 | } else { |
| 592 | ERR(ddraw, "Unhandled vertex processing !\n"); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | instr += size; |
| 596 | } |
| 597 | } break; |
| 598 | |
| 599 | case D3DOP_TEXTURELOAD: { |
| 600 | TRACE(ddraw, "TEXTURELOAD-s (%d)\n", count); |
| 601 | |
| 602 | instr += count * size; |
| 603 | } break; |
| 604 | |
| 605 | case D3DOP_EXIT: { |
| 606 | TRACE(ddraw, "EXIT (%d)\n", count); |
| 607 | /* We did this instruction */ |
| 608 | instr += size; |
| 609 | /* Exit this loop */ |
| 610 | goto end_of_buffer; |
| 611 | } break; |
| 612 | |
| 613 | case D3DOP_BRANCHFORWARD: { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 614 | int i; |
| 615 | TRACE(ddraw, "BRANCHFORWARD (%d)\n", count); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 616 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 617 | for (i = 0; i < count; i++) { |
| 618 | LPD3DBRANCH ci = (LPD3DBRANCH) instr; |
| 619 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 620 | if ((ilpBuff->data.dsStatus.dwStatus & ci->dwMask) == ci->dwValue) { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 621 | if (!ci->bNegate) { |
| 622 | TRACE(ddraw," Should branch to %ld\n", ci->dwOffset); |
| 623 | } |
| 624 | } else { |
| 625 | if (ci->bNegate) { |
| 626 | TRACE(ddraw," Should branch to %ld\n", ci->dwOffset); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | instr += size; |
| 631 | } |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 632 | } break; |
| 633 | |
| 634 | case D3DOP_SPAN: { |
| 635 | TRACE(ddraw, "SPAN-s (%d)\n", count); |
| 636 | |
| 637 | instr += count * size; |
| 638 | } break; |
| 639 | |
| 640 | case D3DOP_SETSTATUS: { |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 641 | int i; |
| 642 | TRACE(ddraw, "SETSTATUS (%d)\n", count); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 643 | |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 644 | for (i = 0; i < count; i++) { |
| 645 | LPD3DSTATUS ci = (LPD3DSTATUS) instr; |
| 646 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 647 | ilpBuff->data.dsStatus = *ci; |
Lionel Ulmer | 0155445 | 1999-01-23 12:29:44 +0000 | [diff] [blame] | 648 | |
| 649 | instr += size; |
| 650 | } |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 651 | } break; |
| 652 | |
| 653 | default: |
| 654 | ERR(ddraw, "Unhandled OpCode !!!\n"); |
| 655 | /* Try to save ... */ |
| 656 | instr += count * size; |
| 657 | break; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | end_of_buffer: |
Lionel Ulmer | ad72585 | 1999-05-13 18:53:05 +0000 | [diff] [blame] | 662 | LEAVE_GL(); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | /******************************************************************************* |
| 666 | * ExecuteBuffer Creation functions |
| 667 | */ |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 668 | LPDIRECT3DEXECUTEBUFFER d3dexecutebuffer_create(IDirect3DDeviceImpl* d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc) |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 669 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 670 | IDirect3DExecuteBufferImpl* eb; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 671 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 672 | eb = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DExecuteBufferImpl)); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 673 | eb->ref = 1; |
| 674 | eb->lpvtbl = &executebuffer_vtable; |
| 675 | eb->d3ddev = d3ddev; |
| 676 | |
| 677 | /* Initializes memory */ |
| 678 | eb->desc = *lpDesc; |
| 679 | |
| 680 | /* No buffer given */ |
| 681 | if (!(eb->desc.dwFlags & D3DDEB_LPDATA)) |
| 682 | eb->desc.lpData = NULL; |
| 683 | |
| 684 | /* No buffer size given */ |
| 685 | if (!(lpDesc->dwFlags & D3DDEB_BUFSIZE)) |
| 686 | eb->desc.dwBufferSize = 0; |
| 687 | |
| 688 | /* Create buffer if asked */ |
| 689 | if ((eb->desc.lpData == NULL) && (eb->desc.dwBufferSize > 0)) { |
| 690 | eb->need_free = TRUE; |
| 691 | eb->desc.lpData = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,eb->desc.dwBufferSize); |
| 692 | } else { |
| 693 | eb->need_free = FALSE; |
| 694 | } |
| 695 | |
| 696 | /* No vertices for the moment */ |
| 697 | eb->vertex_data = NULL; |
| 698 | |
| 699 | eb->desc.dwFlags |= D3DDEB_LPDATA; |
| 700 | |
| 701 | eb->execute = execute; |
| 702 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 703 | return (LPDIRECT3DEXECUTEBUFFER)eb; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | /******************************************************************************* |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 707 | * IDirect3ExecuteBuffer methods |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 708 | */ |
| 709 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 710 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_QueryInterface(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 711 | REFIID riid, |
| 712 | LPVOID* ppvObj) |
| 713 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 714 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 715 | char xrefiid[50]; |
| 716 | |
| 717 | WINE_StringFromCLSID((LPCLSID)riid,xrefiid); |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 718 | FIXME(ddraw, "(%p)->(%s,%p): stub\n", This, xrefiid,ppvObj); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 719 | |
| 720 | return S_OK; |
| 721 | } |
| 722 | |
| 723 | |
| 724 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 725 | static ULONG WINAPI IDirect3DExecuteBufferImpl_AddRef(LPDIRECT3DEXECUTEBUFFER iface) |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 726 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 727 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 728 | TRACE(ddraw, "(%p)->()incrementing from %lu.\n", This, This->ref ); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 729 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 730 | return ++(This->ref); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | |
| 734 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 735 | static ULONG WINAPI IDirect3DExecuteBufferImpl_Release(LPDIRECT3DEXECUTEBUFFER iface) |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 736 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 737 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 738 | FIXME( ddraw, "(%p)->() decrementing from %lu.\n", This, This->ref ); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 739 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 740 | if (!--(This->ref)) { |
| 741 | if ((This->desc.lpData != NULL) && This->need_free) |
| 742 | HeapFree(GetProcessHeap(),0,This->desc.lpData); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 743 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 744 | if (This->vertex_data != NULL) |
| 745 | HeapFree(GetProcessHeap(),0,This->vertex_data); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 746 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 747 | HeapFree(GetProcessHeap(),0,This); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 748 | return 0; |
| 749 | } |
| 750 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 751 | return This->ref; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 754 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_Initialize(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 755 | LPDIRECT3DDEVICE lpDirect3DDevice, |
| 756 | LPD3DEXECUTEBUFFERDESC lpDesc) |
| 757 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 758 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 759 | FIXME(ddraw, "(%p)->(%p,%p): stub\n", This, lpDirect3DDevice, lpDesc); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 760 | |
| 761 | return DD_OK; |
| 762 | } |
| 763 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 764 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_Lock(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 765 | LPD3DEXECUTEBUFFERDESC lpDesc) |
| 766 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 767 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 768 | TRACE(ddraw, "(%p)->(%p)\n", This, lpDesc); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 769 | |
| 770 | /* Copies the buffer description */ |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 771 | *lpDesc = This->desc; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 772 | |
| 773 | return DD_OK; |
| 774 | } |
| 775 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 776 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_Unlock(LPDIRECT3DEXECUTEBUFFER iface) |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 777 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 778 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 779 | TRACE(ddraw, "(%p)->()\n", This); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 780 | |
| 781 | return DD_OK; |
| 782 | } |
| 783 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 784 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_SetExecuteData(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 785 | LPD3DEXECUTEDATA lpData) |
| 786 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 787 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 788 | DWORD nbvert; |
| 789 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 790 | TRACE(ddraw, "(%p)->(%p)\n", This, lpData); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 791 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 792 | This->data = *lpData; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 793 | |
| 794 | /* Get the number of vertices in the execute buffer */ |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 795 | nbvert = This->data.dwVertexCount; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 796 | |
| 797 | /* Prepares the transformed vertex buffer */ |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 798 | if (This->vertex_data != NULL) |
| 799 | HeapFree(GetProcessHeap(), 0, This->vertex_data); |
| 800 | This->vertex_data = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,nbvert * sizeof(OGL_Vertex)); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 801 | |
| 802 | |
| 803 | if (TRACE_ON(ddraw)) { |
| 804 | _dump_executedata(lpData); |
| 805 | } |
| 806 | |
| 807 | return DD_OK; |
| 808 | } |
| 809 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 810 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_GetExecuteData(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 811 | LPD3DEXECUTEDATA lpData) |
| 812 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 813 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 814 | TRACE(ddraw, "(%p)->(%p): stub\n", This, lpData); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 815 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 816 | *lpData = This->data; |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 817 | |
| 818 | return DD_OK; |
| 819 | } |
| 820 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 821 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_Validate(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 822 | LPDWORD lpdwOffset, |
| 823 | LPD3DVALIDATECALLBACK lpFunc, |
| 824 | LPVOID lpUserArg, |
| 825 | DWORD dwReserved) |
| 826 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 827 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 828 | TRACE(ddraw, "(%p)->(%p,%p,%p,%lu)\n", This, lpdwOffset, lpFunc, lpUserArg, dwReserved); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 829 | |
| 830 | return DD_OK; |
| 831 | } |
| 832 | |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 833 | static HRESULT WINAPI IDirect3DExecuteBufferImpl_Optimize(LPDIRECT3DEXECUTEBUFFER iface, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 834 | DWORD dwReserved) |
| 835 | { |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 836 | ICOM_THIS(IDirect3DExecuteBufferImpl,iface); |
| 837 | TRACE(ddraw, "(%p)->(%lu)\n", This, dwReserved); |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 838 | |
| 839 | return DD_OK; |
| 840 | } |
| 841 | |
| 842 | |
| 843 | /******************************************************************************* |
| 844 | * IDirect3DLight VTable |
| 845 | */ |
Paul Quinn | 2305f3c | 1999-05-22 11:41:38 +0000 | [diff] [blame] | 846 | static ICOM_VTABLE(IDirect3DExecuteBuffer) executebuffer_vtable = |
| 847 | { |
| 848 | ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 849 | /*** IUnknown methods ***/ |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 850 | IDirect3DExecuteBufferImpl_QueryInterface, |
| 851 | IDirect3DExecuteBufferImpl_AddRef, |
| 852 | IDirect3DExecuteBufferImpl_Release, |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 853 | /*** IDirect3DExecuteBuffer methods ***/ |
Francois Gouget | 022d372 | 1999-03-27 16:56:13 +0000 | [diff] [blame] | 854 | IDirect3DExecuteBufferImpl_Initialize, |
| 855 | IDirect3DExecuteBufferImpl_Lock, |
| 856 | IDirect3DExecuteBufferImpl_Unlock, |
| 857 | IDirect3DExecuteBufferImpl_SetExecuteData, |
| 858 | IDirect3DExecuteBufferImpl_GetExecuteData, |
| 859 | IDirect3DExecuteBufferImpl_Validate, |
| 860 | IDirect3DExecuteBufferImpl_Optimize |
Lionel Ulmer | 5ff0077 | 1999-01-03 17:00:19 +0000 | [diff] [blame] | 861 | }; |
| 862 | |
| 863 | #endif /* HAVE_MESAGL */ |