| Index: ddraw/glDirect3D.cpp |
| — | — | @@ -16,6 +16,7 @@ |
| 17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | 18 |
|
| 19 | 19 | #include "common.h"
|
| | 20 | +#include "glRenderer.h"
|
| 20 | 21 | #include "glDirect3D.h"
|
| 21 | 22 | #include "glDirect3DDevice.h"
|
| 22 | 23 | #include "glDirectDraw.h"
|
| Index: ddraw/glDirect3DDevice.cpp |
| — | — | @@ -17,11 +17,11 @@ |
| 18 | 18 |
|
| 19 | 19 | #include "common.h"
|
| 20 | 20 | #include "glDirect3D.h"
|
| | 21 | +#include "glRenderer.h"
|
| 21 | 22 | #include "glDirectDraw.h"
|
| 22 | 23 | #include "glDirectDrawSurface.h"
|
| 23 | 24 | #include "glDirect3DDevice.h"
|
| 24 | 25 | #include "glDirect3DLight.h"
|
| 25 | | -#include "glRenderer.h"
|
| 26 | 26 | #include "shadergen.h"
|
| 27 | 27 | #include "glutil.h"
|
| 28 | 28 | #include "matrix.h"
|
| — | — | @@ -120,7 +120,28 @@ |
| 121 | 121 | FALSE, //clipplaneenable
|
| 122 | 122 | };
|
| 123 | 123 |
|
| | 124 | +int setdrawmode(D3DPRIMITIVETYPE d3dptPrimitiveType)
|
| | 125 | +{
|
| | 126 | + switch(d3dptPrimitiveType)
|
| | 127 | + {
|
| | 128 | + case D3DPT_POINTLIST:
|
| | 129 | + return GL_POINTS;
|
| | 130 | + case D3DPT_LINELIST:
|
| | 131 | + return GL_LINES;
|
| | 132 | + case D3DPT_LINESTRIP:
|
| | 133 | + return GL_LINE_STRIP;
|
| | 134 | + case D3DPT_TRIANGLELIST:
|
| | 135 | + return GL_TRIANGLES;
|
| | 136 | + case D3DPT_TRIANGLESTRIP:
|
| | 137 | + return GL_TRIANGLE_STRIP;
|
| | 138 | + case D3DPT_TRIANGLEFAN:
|
| | 139 | + return GL_TRIANGLE_FAN;
|
| | 140 | + default:
|
| | 141 | + return -1;
|
| | 142 | + }
|
| | 143 | +}
|
| 124 | 144 |
|
| | 145 | +
|
| 125 | 146 | glDirect3DDevice7::glDirect3DDevice7(glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7)
|
| 126 | 147 | {
|
| 127 | 148 | int zbuffer = 0;
|
| — | — | @@ -249,7 +270,7 @@ |
| 250 | 271 | else if(size > maxarray) normals = (GLfloat*)realloc(normals,size*4*sizeof(GLfloat));
|
| 251 | 272 | }
|
| 252 | 273 |
|
| 253 | | -__int64 glDirect3DDevice7::SelectShader(DWORD VertexType)
|
| | 274 | +__int64 glDirect3DDevice7::SelectShader(GLVERTEX *VertexType)
|
| 254 | 275 | {
|
| 255 | 276 | int i;
|
| 256 | 277 | __int64 shader = 0;
|
| — | — | @@ -284,12 +305,14 @@ |
| 285 | 306 | shader |= ((renderstate[D3DRENDERSTATE_SPECULARMATERIALSOURCE] & 3) << 25);
|
| 286 | 307 | shader |= ((renderstate[D3DRENDERSTATE_AMBIENTMATERIALSOURCE] & 3) << 27);
|
| 287 | 308 | shader |= ((renderstate[D3DRENDERSTATE_EMISSIVEMATERIALSOURCE] & 3) << 29);
|
| 288 | | - int numtextures = (VertexType & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
|
| | 309 | + int numtextures = 0;
|
| | 310 | + for(int i = 0; i < 8; i++)
|
| | 311 | + if(VertexType[i+10].data) numtextures++;
|
| 289 | 312 | shader |= (__int64)numtextures << 31;
|
| 290 | | - if(VertexType & D3DFVF_XYZRHW) shader |= (1i64 << 34);
|
| 291 | | - if(VertexType & D3DFVF_DIFFUSE) shader |= (1i64<<35);
|
| 292 | | - if(VertexType & D3DFVF_SPECULAR) shader |= (1i64<<36);
|
| 293 | | - if(VertexType & D3DFVF_NORMAL) shader |= (1i64 << 37);
|
| | 313 | + if(VertexType[1].data) shader |= (1i64 << 34);
|
| | 314 | + if(VertexType[8].data) shader |= (1i64<<35);
|
| | 315 | + if(VertexType[9].data) shader |= (1i64<<36);
|
| | 316 | + if(VertexType[7].data) shader |= (1i64 << 37);
|
| 294 | 317 | int lightindex = 0;
|
| 295 | 318 | for(i = 0; i < 8; i++)
|
| 296 | 319 | {
|
| — | — | @@ -300,17 +323,98 @@ |
| 301 | 324 | lightindex++;
|
| 302 | 325 | }
|
| 303 | 326 | }
|
| 304 | | - if(((VertexType >> 1) & 7) >= 3) shader |= (__int64)(((VertexType >> 1) & 7) - 2) << 46;
|
| 305 | | -
|
| | 327 | + int blendweights = 0;
|
| | 328 | + for(i = 0; i < 5; i++)
|
| | 329 | + if(VertexType[i+2].data) blendweights++;
|
| | 330 | + shader |= (__int64)blendweights << 46;
|
| | 331 | + //TODO: Implement texture stages.
|
| 306 | 332 | return shader;
|
| 307 | 333 | }
|
| 308 | 334 |
|
| | 335 | +HRESULT glDirect3DDevice7::fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr)
|
| | 336 | +{
|
| | 337 | + int i;
|
| | 338 | + int ptr = 0;
|
| | 339 | + if((dwVertexTypeDesc & D3DFVF_XYZ) && (dwVertexTypeDesc & D3DFVF_XYZRHW))
|
| | 340 | + return DDERR_INVALIDPARAMS;
|
| | 341 | + if(dwVertexTypeDesc & D3DFVF_XYZ)
|
| | 342 | + {
|
| | 343 | + vertdata[0].data = vertptr;
|
| | 344 | + vertdata[1].data = NULL;
|
| | 345 | + ptr += 3;
|
| | 346 | + }
|
| | 347 | + else if(dwVertexTypeDesc & D3DFVF_XYZRHW)
|
| | 348 | + {
|
| | 349 | + vertdata[0].data = vertptr;
|
| | 350 | + vertdata[1].data = &vertptr[3];
|
| | 351 | + ptr += 4;
|
| | 352 | + }
|
| | 353 | + else return DDERR_INVALIDPARAMS;
|
| | 354 | + for(i = 0; i < 5; i++)
|
| | 355 | + vertdata[i+2].data = NULL;
|
| | 356 | + if(((dwVertexTypeDesc >> 1) & 7) >= 3)
|
| | 357 | + {
|
| | 358 | + for(i = 0; i < (signed)(((dwVertexTypeDesc >> 1) & 7) - 2); i++)
|
| | 359 | + {
|
| | 360 | + vertdata[((dwVertexTypeDesc >> 1) & 7)].data = &vertptr[ptr];
|
| | 361 | + ptr++;
|
| | 362 | + }
|
| | 363 | + }
|
| | 364 | + if(dwVertexTypeDesc & D3DFVF_NORMAL)
|
| | 365 | + {
|
| | 366 | + vertdata[7].data = &vertptr[ptr];
|
| | 367 | + ptr += 3;
|
| | 368 | + }
|
| | 369 | + else vertdata[7].data = NULL;
|
| | 370 | + if(dwVertexTypeDesc & D3DFVF_DIFFUSE)
|
| | 371 | + {
|
| | 372 | + vertdata[8].data = &vertptr[ptr];
|
| | 373 | + ptr++;
|
| | 374 | + }
|
| | 375 | + else vertdata[8].data = NULL;
|
| | 376 | + if(dwVertexTypeDesc & D3DFVF_SPECULAR)
|
| | 377 | + {
|
| | 378 | + vertdata[9].data = &vertptr[ptr];
|
| | 379 | + ptr++;
|
| | 380 | + }
|
| | 381 | + else vertdata[9].data = NULL;
|
| | 382 | + for(i = 0; i < 8; i++)
|
| | 383 | + vertdata[i+10].data = NULL;
|
| | 384 | + int numtex = (dwVertexTypeDesc&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT;
|
| | 385 | + for(i = 0; i < numtex; i++)
|
| | 386 | + {
|
| | 387 | + vertdata[i+10].data = &vertptr[ptr];
|
| | 388 | + texformats[i] = (dwVertexTypeDesc>>(16+(2*i))&3);
|
| | 389 | + switch(texformats[i])
|
| | 390 | + {
|
| | 391 | + case 0: // st
|
| | 392 | + ptr += 2;
|
| | 393 | + break;
|
| | 394 | + case 1: // str
|
| | 395 | + ptr += 3;
|
| | 396 | + break;
|
| | 397 | + case 2: // strq
|
| | 398 | + ptr += 4;
|
| | 399 | + break;
|
| | 400 | + case 3: // s
|
| | 401 | + ptr++;
|
| | 402 | + break;
|
| | 403 | + }
|
| | 404 | + }
|
| | 405 | + int stride = NextMultipleOf8(ptr*4);
|
| | 406 | + for(i = 0; i < 17; i++)
|
| | 407 | + vertdata[i].stride = stride;
|
| | 408 | + return D3D_OK;
|
| | 409 | +}
|
| | 410 | +
|
| 309 | 411 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 310 | 412 | LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| 311 | 413 | {
|
| 312 | 414 | if(!this) return DDERR_INVALIDPARAMS;
|
| 313 | 415 | if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
| 314 | | - return glD3D7->glDD7->renderer->DrawIndexedPrimitive(this,d3dptPrimitiveType,dwVertexTypeDesc,lpvVertices,
|
| | 416 | + HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
|
| | 417 | + if(err != D3D_OK) return err;
|
| | 418 | + return glD3D7->glDD7->renderer->DrawPrimitives(this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
|
| 315 | 419 | dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
|
| 316 | 420 | }
|
| 317 | 421 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| — | — | @@ -330,9 +434,7 @@ |
| 331 | 435 | HRESULT WINAPI glDirect3DDevice7::DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc, LPVOID lpVertices,
|
| 332 | 436 | DWORD dwVertexCount, DWORD dwFlags)
|
| 333 | 437 | {
|
| 334 | | - if(!this) return DDERR_INVALIDPARAMS;
|
| 335 | | - FIXME("glDirect3DDevice7::DrawPrimitive: stub");
|
| 336 | | - ERR(DDERR_GENERIC);
|
| | 438 | + return DrawIndexedPrimitive(dptPrimitiveType,dwVertexTypeDesc,lpVertices,dwVertexCount,NULL,0,dwFlags);
|
| 337 | 439 | }
|
| 338 | 440 | HRESULT WINAPI glDirect3DDevice7::DrawPrimitiveStrided(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 339 | 441 | LPD3DDRAWPRIMITIVESTRIDEDDATA lpVertexArray, DWORD dwVertexCount, DWORD dwFlags)
|
| Index: ddraw/glDirect3DDevice.h |
| — | — | @@ -86,7 +86,7 @@ |
| 87 | 87 | HRESULT WINAPI SetViewport(LPD3DVIEWPORT7 lpViewport);
|
| 88 | 88 | HRESULT WINAPI ValidateDevice(LPDWORD lpdwPasses);
|
| 89 | 89 | void SetArraySize(DWORD size, DWORD vertex, DWORD texcoord);
|
| 90 | | - __int64 SelectShader(DWORD VertexType);
|
| | 90 | + __int64 SelectShader(GLVERTEX *VertexType);
|
| 91 | 91 | void UpdateNormalMatrix();
|
| 92 | 92 | GLfloat matWorld[16];
|
| 93 | 93 | GLfloat matView[16];
|
| — | — | @@ -101,6 +101,7 @@ |
| 102 | 102 | DWORD renderstate[153];
|
| 103 | 103 |
|
| 104 | 104 | private:
|
| | 105 | + HRESULT fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr);
|
| 105 | 106 | glDirect3D7 *glD3D7;
|
| 106 | 107 | ULONG refcount;
|
| 107 | 108 | GLuint gltextures[8];
|
| — | — | @@ -115,6 +116,8 @@ |
| 116 | 117 | GLubyte *specular;
|
| 117 | 118 | GLubyte *ambient;
|
| 118 | 119 | GLfloat *texcoords[8];
|
| | 120 | + GLVERTEX vertdata[17];
|
| | 121 | + int texformats[8];
|
| 119 | 122 | };
|
| 120 | 123 |
|
| 121 | 124 | #endif //__GLDIRECT3DDEVICE_H |
| \ No newline at end of file |
| Index: ddraw/glRenderer.cpp |
| — | — | @@ -19,9 +19,9 @@ |
| 20 | 20 | #include "glDirectDraw.h"
|
| 21 | 21 | #include "glDirectDrawSurface.h"
|
| 22 | 22 | #include "glDirectDrawPalette.h"
|
| | 23 | +#include "glRenderer.h"
|
| 23 | 24 | #include "glDirect3DDevice.h"
|
| 24 | 25 | #include "glDirect3DLight.h"
|
| 25 | | -#include "glRenderer.h"
|
| 26 | 26 | #include "glutil.h"
|
| 27 | 27 | #include "ddraw.h"
|
| 28 | 28 | #include "scalers.h"
|
| — | — | @@ -46,28 +46,6 @@ |
| 47 | 47 | return (number<<2)+(number>>4);
|
| 48 | 48 | }
|
| 49 | 49 |
|
| 50 | | -int setdrawmode(D3DPRIMITIVETYPE d3dptPrimitiveType)
|
| 51 | | -{
|
| 52 | | - switch(d3dptPrimitiveType)
|
| 53 | | - {
|
| 54 | | - case D3DPT_POINTLIST:
|
| 55 | | - return GL_POINTS;
|
| 56 | | - case D3DPT_LINELIST:
|
| 57 | | - return GL_LINES;
|
| 58 | | - case D3DPT_LINESTRIP:
|
| 59 | | - return GL_LINE_STRIP;
|
| 60 | | - case D3DPT_TRIANGLELIST:
|
| 61 | | - return GL_TRIANGLES;
|
| 62 | | - case D3DPT_TRIANGLESTRIP:
|
| 63 | | - return GL_TRIANGLE_STRIP;
|
| 64 | | - case D3DPT_TRIANGLEFAN:
|
| 65 | | - return GL_TRIANGLE_FAN;
|
| 66 | | - default:
|
| 67 | | - return -1;
|
| 68 | | - }
|
| 69 | | -}
|
| 70 | | -
|
| 71 | | -
|
| 72 | 50 | int oldswap = 0;
|
| 73 | 51 | int swapinterval = 0;
|
| 74 | 52 | inline void SetSwap(int swap)
|
| — | — | @@ -412,21 +390,21 @@ |
| 413 | 391 | LeaveCriticalSection(&cs);
|
| 414 | 392 | }
|
| 415 | 393 |
|
| 416 | | -HRESULT glRenderer::DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 417 | | - LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| | 394 | +HRESULT glRenderer::DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| | 395 | + DWORD indexcount, DWORD flags)
|
| 418 | 396 | {
|
| 419 | 397 | MSG Msg;
|
| 420 | 398 | EnterCriticalSection(&cs);
|
| 421 | 399 | wndbusy = true;
|
| 422 | 400 | inputs[0] = device;
|
| 423 | | - inputs[1] = (void*)d3dptPrimitiveType;
|
| 424 | | - inputs[2] = (void*)dwVertexTypeDesc;
|
| 425 | | - inputs[3] = lpvVertices;
|
| 426 | | - inputs[4] = (void*)dwVertexCount;
|
| 427 | | - inputs[5] = lpwIndices;
|
| 428 | | - inputs[6] = (void*)dwIndexCount;
|
| 429 | | - inputs[7] = (void*)dwFlags;
|
| 430 | | - SendMessage(hRenderWnd,GLEVENT_DRAWINDEXEDPRIMITIVE,0,0);
|
| | 401 | + inputs[1] = (void*)mode;
|
| | 402 | + inputs[2] = vertices;
|
| | 403 | + inputs[3] = texformats;
|
| | 404 | + inputs[4] = (void*)count;
|
| | 405 | + inputs[5] = indices;
|
| | 406 | + inputs[6] = (void*)indexcount;
|
| | 407 | + inputs[7] = (void*)flags;
|
| | 408 | + SendMessage(hRenderWnd,GLEVENT_DRAWPRIMITIVES,0,0);
|
| 431 | 409 | while(wndbusy)
|
| 432 | 410 | {
|
| 433 | 411 | while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| — | — | @@ -436,7 +414,6 @@ |
| 437 | 415 | }
|
| 438 | 416 | Sleep(0);
|
| 439 | 417 | }
|
| 440 | | - LeaveCriticalSection(&cs);
|
| 441 | 418 | return (HRESULT)outputs[0];
|
| 442 | 419 | }
|
| 443 | 420 |
|
| — | — | @@ -1031,15 +1008,11 @@ |
| 1032 | 1009 | glFlush();
|
| 1033 | 1010 | }
|
| 1034 | 1011 |
|
| 1035 | | -void glRenderer::_DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 1036 | | - LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| | 1012 | +void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| | 1013 | + DWORD indexcount, DWORD flags)
|
| 1037 | 1014 | {
|
| 1038 | 1015 | GLfloat tmpmat[16];
|
| 1039 | 1016 | bool transformed;
|
| 1040 | | - int normalptr = 0;
|
| 1041 | | - int colorptr[2] = {0,0};
|
| 1042 | | - int blendptr[5] = {0,0,0,0,0};
|
| 1043 | | - int texptr[8] = {0,0,0,0,0,0,0,0};
|
| 1044 | 1017 | char blendvar[] = "blendX";
|
| 1045 | 1018 | char rgbavar[] = "rgbaX";
|
| 1046 | 1019 | char svar[] = "sX";
|
| — | — | @@ -1047,122 +1020,52 @@ |
| 1048 | 1021 | char strvar[] = "strX";
|
| 1049 | 1022 | char strqvar[] = "strqX";
|
| 1050 | 1023 | int i;
|
| 1051 | | - GLfloat* vertices = (GLfloat*)lpvVertices;
|
| 1052 | | - int drawmode = setdrawmode(d3dptPrimitiveType);
|
| 1053 | | - if(drawmode == -1)
|
| | 1024 | + if(vertices[1].data) transformed = false;
|
| | 1025 | + else transformed = true;
|
| | 1026 | + if(!vertices[0].data)
|
| 1054 | 1027 | {
|
| 1055 | 1028 | outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| 1056 | 1029 | wndbusy = false;
|
| 1057 | 1030 | return;
|
| 1058 | 1031 | }
|
| 1059 | | - if((dwVertexTypeDesc & D3DFVF_XYZ) && (dwVertexTypeDesc & D3DFVF_XYZRHW))
|
| 1060 | | - {
|
| 1061 | | - outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| 1062 | | - wndbusy = false;
|
| 1063 | | - return;
|
| 1064 | | - }
|
| 1065 | | - int ptr = 0;
|
| 1066 | | - if(dwVertexTypeDesc & D3DFVF_XYZ)
|
| 1067 | | - {
|
| 1068 | | - transformed = false;
|
| 1069 | | - ptr+= 3;
|
| 1070 | | - }
|
| 1071 | | - if(dwVertexTypeDesc & D3DFVF_XYZRHW)
|
| 1072 | | - {
|
| 1073 | | - transformed = true;
|
| 1074 | | - ptr+= 4;
|
| 1075 | | - }
|
| 1076 | | - if(!ptr)
|
| 1077 | | - {
|
| 1078 | | - outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| 1079 | | - wndbusy = false;
|
| 1080 | | - return;
|
| 1081 | | - }
|
| 1082 | | - if(((dwVertexTypeDesc >> 1) & 7) >= 3)
|
| 1083 | | - {
|
| 1084 | | - for(i = 0; i < (signed)(((dwVertexTypeDesc >> 1) & 7) - 2); i++)
|
| 1085 | | - {
|
| 1086 | | - blendptr[(((dwVertexTypeDesc >> 1) & 7) - 2)] = ptr;
|
| 1087 | | - ptr++;
|
| 1088 | | - }
|
| 1089 | | - }
|
| 1090 | | - if(dwVertexTypeDesc & D3DFVF_NORMAL)
|
| 1091 | | - {
|
| 1092 | | - normalptr = ptr;
|
| 1093 | | - ptr+= 3;
|
| 1094 | | - }
|
| 1095 | | - if(dwVertexTypeDesc & D3DFVF_DIFFUSE)
|
| 1096 | | - {
|
| 1097 | | - colorptr[0] = ptr;
|
| 1098 | | - ptr++;
|
| 1099 | | - }
|
| 1100 | | - if(dwVertexTypeDesc & D3DFVF_SPECULAR)
|
| 1101 | | - {
|
| 1102 | | - colorptr[1] = ptr;
|
| 1103 | | - ptr++;
|
| 1104 | | - }
|
| 1105 | | - int numtex = (dwVertexTypeDesc&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT;
|
| 1106 | | - for(i = 0; i < numtex; i++)
|
| 1107 | | - {
|
| 1108 | | - texptr[0] = ptr;
|
| 1109 | | - switch(dwVertexTypeDesc>>(16+(2*i))&3)
|
| 1110 | | - {
|
| 1111 | | - case 0: // st
|
| 1112 | | - ptr += 2;
|
| 1113 | | - break;
|
| 1114 | | - case 1: // str
|
| 1115 | | - ptr += 3;
|
| 1116 | | - break;
|
| 1117 | | - case 2: // strq
|
| 1118 | | - ptr += 4;
|
| 1119 | | - break;
|
| 1120 | | - case 3: // s
|
| 1121 | | - ptr++;
|
| 1122 | | - break;
|
| 1123 | | - }
|
| 1124 | | - }
|
| 1125 | | - int stride = NextMultipleOf8(ptr*4);
|
| 1126 | 1032 | TexState texstage;
|
| 1127 | 1033 | ZeroMemory(&texstage,sizeof(TexState));
|
| 1128 | | - __int64 shader = device->SelectShader(dwVertexTypeDesc);
|
| | 1034 | + __int64 shader = device->SelectShader(vertices);
|
| 1129 | 1035 | SetShader(shader,&texstage,0);
|
| 1130 | 1036 | GLuint prog = GetProgram();
|
| | 1037 | + GLint xyzloc = glGetAttribLocation(prog,"xyz");
|
| | 1038 | + glEnableVertexAttribArray(xyzloc);
|
| | 1039 | + glVertexAttribPointer(xyzloc,3,GL_FLOAT,false,vertices[0].stride,vertices[0].data);
|
| 1131 | 1040 | if(transformed)
|
| 1132 | 1041 | {
|
| 1133 | | - GLint xyzwloc = glGetAttribLocation(prog,"xyzw");
|
| | 1042 | + GLint xyzwloc = glGetAttribLocation(prog,"rhw");
|
| 1134 | 1043 | glEnableVertexAttribArray(xyzwloc);
|
| 1135 | | - glVertexAttribPointer(xyzwloc,4,GL_FLOAT,false,stride,vertices);
|
| | 1044 | + glVertexAttribPointer(xyzwloc,4,GL_FLOAT,false,vertices[1].stride,vertices[1].data);
|
| 1136 | 1045 | }
|
| 1137 | | - else
|
| 1138 | | - {
|
| 1139 | | - GLint xyzloc = glGetAttribLocation(prog,"xyz");
|
| 1140 | | - glEnableVertexAttribArray(xyzloc);
|
| 1141 | | - glVertexAttribPointer(xyzloc,3,GL_FLOAT,false,stride,vertices);
|
| 1142 | | - }
|
| 1143 | 1046 | for(i = 0; i < 5; i++)
|
| 1144 | 1047 | {
|
| 1145 | 1048 | GLint blendloc;
|
| 1146 | | - if(blendptr[i])
|
| | 1049 | + if(vertices[i+2].data)
|
| 1147 | 1050 | {
|
| 1148 | 1051 | blendvar[5] = i+'0';
|
| 1149 | 1052 | blendloc = glGetAttribLocation(prog,blendvar);
|
| 1150 | | - glVertexAttribPointer(blendloc,1,GL_FLOAT,false,stride,vertices+blendptr[i]);
|
| | 1053 | + glVertexAttribPointer(blendloc,1,GL_FLOAT,false,vertices[i+2].stride,vertices[i+2].data);
|
| 1151 | 1054 | }
|
| 1152 | 1055 | }
|
| 1153 | | - if(normalptr)
|
| | 1056 | + if(vertices[7].data)
|
| 1154 | 1057 | {
|
| 1155 | 1058 | GLint normalloc = glGetAttribLocation(prog,"nxyz");
|
| 1156 | 1059 | glEnableVertexAttribArray(normalloc);
|
| 1157 | | - glVertexAttribPointer(normalloc,3,GL_FLOAT,false,stride,vertices+normalptr);
|
| | 1060 | + glVertexAttribPointer(normalloc,3,GL_FLOAT,false,vertices[7].stride,vertices[7].data);
|
| 1158 | 1061 | }
|
| 1159 | 1062 | for(i = 0; i < 2; i++)
|
| 1160 | 1063 | {
|
| 1161 | 1064 | GLint colorloc;
|
| 1162 | | - if(colorptr[i])
|
| | 1065 | + if(vertices[i+8].data)
|
| 1163 | 1066 | {
|
| 1164 | 1067 | rgbavar[4] = i + '0';
|
| 1165 | 1068 | colorloc = glGetAttribLocation(prog,rgbavar);
|
| 1166 | | - glVertexAttribPointer(colorloc,4,GL_UNSIGNED_BYTE,true,stride,vertices+colorptr[i]);
|
| | 1069 | + glVertexAttribPointer(colorloc,4,GL_UNSIGNED_BYTE,true,vertices[i+8].stride,vertices[i+8].data);
|
| 1167 | 1070 | }
|
| 1168 | 1071 | }
|
| 1169 | 1072 | if(device->normal_dirty) device->UpdateNormalMatrix();
|
| — | — | @@ -1241,8 +1144,9 @@ |
| 1242 | 1145 | }
|
| 1243 | 1146 | SetFBO(device->glDDS7->texture,device->glDDS7->zbuffer->texture,device->glDDS7->zbuffer->hasstencil);
|
| 1244 | 1147 | glViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
|
| 1245 | | - glDrawRangeElements(drawmode,0,dwIndexCount,dwVertexCount,GL_UNSIGNED_SHORT,lpwIndices);
|
| 1246 | | - if(dwFlags & D3DDP_WAIT) glFlush();
|
| | 1148 | + if(indices) glDrawRangeElements(mode,0,indexcount,count,GL_UNSIGNED_SHORT,indices);
|
| | 1149 | + else glDrawArrays(mode,0,count);
|
| | 1150 | + if(flags & D3DDP_WAIT) glFlush();
|
| 1247 | 1151 | outputs[0] = (void*)D3D_OK;
|
| 1248 | 1152 | wndbusy = false;
|
| 1249 | 1153 | return;
|
| — | — | @@ -1253,7 +1157,6 @@ |
| 1254 | 1158 | int oldx,oldy;
|
| 1255 | 1159 | float mulx, muly;
|
| 1256 | 1160 | float tmpfloats[16];
|
| 1257 | | - D3DPRIMITIVETYPE d3dpt;
|
| 1258 | 1161 | int translatex, translatey;
|
| 1259 | 1162 | LPARAM newpos;
|
| 1260 | 1163 | HWND hParent;
|
| — | — | @@ -1378,10 +1281,9 @@ |
| 1379 | 1282 | case GLEVENT_FLUSH:
|
| 1380 | 1283 | _Flush();
|
| 1381 | 1284 | return 0;
|
| 1382 | | - case GLEVENT_DRAWINDEXEDPRIMITIVE:
|
| 1383 | | - memcpy(&d3dpt,&inputs[1],4);
|
| 1384 | | - _DrawIndexedPrimitive((glDirect3DDevice7*)inputs[0],d3dpt,(DWORD)inputs[2],(LPVOID)inputs[3],
|
| 1385 | | - (DWORD)inputs[4],(LPWORD)inputs[5],(DWORD)inputs[6],(DWORD)inputs[7]);
|
| | 1285 | + case GLEVENT_DRAWPRIMITIVES:
|
| | 1286 | + _DrawPrimitives((glDirect3DDevice7*)inputs[0],(GLenum)inputs[1],(GLVERTEX*)inputs[2],(int*)inputs[3],(DWORD)inputs[4],
|
| | 1287 | + (LPWORD)inputs[5],(DWORD)inputs[6],(DWORD)inputs[7]);
|
| 1386 | 1288 | return 0;
|
| 1387 | 1289 | default:
|
| 1388 | 1290 | return DefWindowProc(hwnd,msg,wParam,lParam);
|
| Index: ddraw/glRenderer.h |
| — | — | @@ -41,6 +41,12 @@ |
| 42 | 42 | BYTE *pixels;
|
| 43 | 43 | } DIB;
|
| 44 | 44 |
|
| | 45 | +struct GLVERTEX
|
| | 46 | +{
|
| | 47 | + void *data;
|
| | 48 | + int stride;
|
| | 49 | +};
|
| | 50 | +
|
| 45 | 51 | struct BltVertex
|
| 46 | 52 | {
|
| 47 | 53 | GLfloat x,y;
|
| — | — | @@ -62,18 +68,15 @@ |
| 63 | 69 | #define GLEVENT_INITD3D WM_USER+8
|
| 64 | 70 | #define GLEVENT_CLEAR WM_USER+9
|
| 65 | 71 | #define GLEVENT_FLUSH WM_USER+10
|
| 66 | | -#define GLEVENT_DRAWPRIMITIVE WM_USER+11
|
| 67 | | -#define GLEVENT_DRAWPRIMITIVESTRIDED WM_USER+12
|
| 68 | | -#define GLEVENT_DRAWPRIMITIVEVB WM_USER+13
|
| 69 | | -#define GLEVENT_DRAWINDEXEDPRIMITIVE WM_USER+14
|
| 70 | | -#define GLEVENT_DRAWINDEXEDPRIMITIVESTRIDED WM_USER+15
|
| 71 | | -#define GLEVENT_DRAWINDEXEDPRIMITIVEVB WM_USER+16
|
| | 72 | +#define GLEVENT_DRAWPRIMITIVES WM_USER+11
|
| 72 | 73 |
|
| 73 | 74 |
|
| 74 | 75 | extern int swapinterval;
|
| 75 | 76 | extern inline void SetSwap(int swap);
|
| 76 | 77 |
|
| | 78 | +class glDirectDraw7;
|
| 77 | 79 | class glDirect3DDevice7;
|
| | 80 | +class glDirectDrawSurface7;
|
| 78 | 81 |
|
| 79 | 82 | class glRenderer
|
| 80 | 83 | {
|
| — | — | @@ -91,8 +94,8 @@ |
| 92 | 95 | void InitD3D(int zbuffer);
|
| 93 | 96 | void Flush();
|
| 94 | 97 | HRESULT Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
|
| 95 | | - HRESULT DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 96 | | - LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags);
|
| | 98 | + HRESULT DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| | 99 | + DWORD indexcount, DWORD flags);
|
| 97 | 100 | HGLRC hRC;
|
| 98 | 101 | LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
| 99 | 102 | private:
|
| — | — | @@ -109,8 +112,8 @@ |
| 110 | 113 | void _DrawBackbuffer(GLuint *texture, int x, int y);
|
| 111 | 114 | void _InitD3D(int zbuffer);
|
| 112 | 115 | void _Clear(glDirectDrawSurface7 *target, DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil);
|
| 113 | | - void _DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 114 | | - LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags);
|
| | 116 | + void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
|
| | 117 | + DWORD indexcount, DWORD flags);
|
| 115 | 118 | glDirectDraw7 *ddInterface;
|
| 116 | 119 | void _Flush();
|
| 117 | 120 | void* inputs[32];
|
| Index: ddraw/shadergen.cpp |
| — | — | @@ -174,7 +174,7 @@ |
| 175 | 175 | static const char mainend[] = "} ";
|
| 176 | 176 | // Attributes
|
| 177 | 177 | static const char attr_xyz[] = "attribute vec3 xyz;\n";
|
| 178 | | -static const char attr_xyzw[] = "attribute vec4 xyzw;\n";
|
| | 178 | +static const char attr_rhw[] = "attribute float rhw;\n";
|
| 179 | 179 | static const char attr_nxyz[] = "attribute vec3 nxyz;\n";
|
| 180 | 180 | static const char attr_blend[] = "attribute float blendX;\n";
|
| 181 | 181 | static const char attr_rgba[] = "attribute vec4 rgbaX;\n";
|
| — | — | @@ -278,8 +278,8 @@ |
| 279 | 279 | vsrc->append(idheader);
|
| 280 | 280 | vsrc->append(idstring);
|
| 281 | 281 | // Attributes
|
| 282 | | - if((id>>34)&1) vsrc->append(attr_xyzw);
|
| 283 | | - else vsrc->append(attr_xyz);
|
| | 282 | + vsrc->append(attr_xyz);
|
| | 283 | + if((id>>34)&1) vsrc->append(attr_rhw);
|
| 284 | 284 | tmp = attr_rgba;
|
| 285 | 285 | if((id>>35)&1)
|
| 286 | 286 | {
|