Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -22,6 +22,7 @@ |
23 | 23 | #include "glDirect3DDevice.h"
|
24 | 24 | #include "glDirect3DLight.h"
|
25 | 25 | #include "glRenderer.h"
|
| 26 | +#include "shadergen.h"
|
26 | 27 | #include "glutil.h"
|
27 | 28 |
|
28 | 29 | const DWORD renderstate_default[153] = {0, // 0
|
— | — | @@ -240,26 +241,6 @@ |
241 | 242 | FIXME("glDirect3DDevice7::DeleteStateBlock: stub");
|
242 | 243 | ERR(DDERR_GENERIC);
|
243 | 244 | }
|
244 | | -int setdrawmode(D3DPRIMITIVETYPE d3dptPrimitiveType)
|
245 | | -{
|
246 | | - switch(d3dptPrimitiveType)
|
247 | | - {
|
248 | | - case D3DPT_POINTLIST:
|
249 | | - return GL_POINTS;
|
250 | | - case D3DPT_LINELIST:
|
251 | | - return GL_LINES;
|
252 | | - case D3DPT_LINESTRIP:
|
253 | | - return GL_LINE_STRIP;
|
254 | | - case D3DPT_TRIANGLELIST:
|
255 | | - return GL_TRIANGLES;
|
256 | | - case D3DPT_TRIANGLESTRIP:
|
257 | | - return GL_TRIANGLE_STRIP;
|
258 | | - case D3DPT_TRIANGLEFAN:
|
259 | | - return GL_TRIANGLE_FAN;
|
260 | | - default:
|
261 | | - return -1;
|
262 | | - }
|
263 | | -}
|
264 | 245 |
|
265 | 246 | void glDirect3DDevice7::SetArraySize(DWORD size, DWORD vertex, DWORD texcoord)
|
266 | 247 | {
|
— | — | @@ -307,10 +288,9 @@ |
308 | 289 | int numtextures = (VertexType & D3DFVF_TEXCOUNT_MASK) >> D3DFVF_TEXCOUNT_SHIFT;
|
309 | 290 | shader |= (__int64)numtextures << 31;
|
310 | 291 | if(VertexType & D3DFVF_XYZRHW) shader |= (1i64 << 34);
|
311 | | - if((VertexType & D3DFVF_DIFFUSE) && (VertexType & D3DFVF_SPECULAR)) shader |= (1i64<<35);
|
312 | | - for(i = 0; i < numtextures; i++)
|
313 | | - shader |= (__int64)((VertexType >> (16+(2*i))) & 3) << (36 + (2*i));
|
314 | | - if(VertexType & D3DFVF_NORMAL) shader |= (1i64 << 52);
|
| 292 | + if(VertexType & D3DFVF_DIFFUSE) shader |= (1i64<<35);
|
| 293 | + if(VertexType & D3DFVF_SPECULAR) shader |= (1i64<<36);
|
| 294 | + if(VertexType & D3DFVF_NORMAL) shader |= (1i64 << 37);
|
315 | 295 | int lightindex = 0;
|
316 | 296 | for(i = 0; i < 8; i++)
|
317 | 297 | {
|
— | — | @@ -317,11 +297,12 @@ |
318 | 298 | if(gllights[i] != -1)
|
319 | 299 | {
|
320 | 300 | if(lights[gllights[i]]->light.dltType != D3DLIGHT_DIRECTIONAL)
|
321 | | - shader |= (1i64 << (53+lightindex));
|
| 301 | + shader |= (1i64 << (38+lightindex));
|
322 | 302 | lightindex++;
|
323 | 303 | }
|
324 | 304 | }
|
325 | | - if(((VertexType >> 1) & 7) >= 3) shader |= (__int64)(((VertexType >> 1) & 7) - 2) << 61;
|
| 305 | + if(((VertexType >> 1) & 7) >= 3) shader |= (__int64)(((VertexType >> 1) & 7) - 2) << 46;
|
| 306 | +
|
326 | 307 | return shader;
|
327 | 308 | }
|
328 | 309 |
|
— | — | @@ -330,13 +311,8 @@ |
331 | 312 | {
|
332 | 313 | if(!this) return DDERR_INVALIDPARAMS;
|
333 | 314 | if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
|
334 | | - int drawmode = setdrawmode(d3dptPrimitiveType);
|
335 | | - if(drawmode == -1) return DDERR_INVALIDPARAMS;
|
336 | | - if(dwVertexTypeDesc & D3DFVF_XYZB1) ERR(DDERR_GENERIC);
|
337 | | -
|
338 | | - //for(int i = 0; i <
|
339 | | - FIXME("glDirect3DDevice7::DrawIndexedPrimitive: stub");
|
340 | | - ERR(DDERR_GENERIC);
|
| 315 | + return glD3D7->glDD7->renderer->DrawIndexedPrimitive(this,d3dptPrimitiveType,dwVertexTypeDesc,lpvVertices,
|
| 316 | + dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
|
341 | 317 | }
|
342 | 318 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
343 | 319 | LPD3DDRAWPRIMITIVESTRIDEDDATA lpvVerticexArray, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
Index: ddraw/glDirect3DDevice.h |
— | — | @@ -86,9 +86,9 @@ |
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 | 91 |
|
91 | 92 | private:
|
92 | | - __int64 SelectShader(DWORD VertexType);
|
93 | 93 | D3DMATRIX matWorld,matView,matProjection;
|
94 | 94 | glDirect3D7 *glD3D7;
|
95 | 95 | glDirectDrawSurface7 *glDDS7;
|
Index: ddraw/glDirectDraw.cpp |
— | — | @@ -649,14 +649,9 @@ |
650 | 650 | }
|
651 | 651 | if(riid == IID_IDirect3D7)
|
652 | 652 | {
|
653 | | - #ifdef _DEBUG
|
654 | 653 | this->AddRef();
|
655 | 654 | *ppvObj = new glDirect3D7(this);
|
656 | 655 | return DD_OK;
|
657 | | - #else
|
658 | | - FIXME("Add IDirect3D Interfaces\n");
|
659 | | - ERR(DDERR_GENERIC);
|
660 | | - #endif
|
661 | 656 | }
|
662 | 657 | if(riid == IID_IDirectDrawGammaControl)
|
663 | 658 | {
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | #include "glDirectDraw.h"
|
21 | 21 | #include "glDirectDrawSurface.h"
|
22 | 22 | #include "glDirectDrawPalette.h"
|
| 23 | +#include "glDirect3DDevice.h"
|
23 | 24 | #include "glRenderer.h"
|
24 | 25 | #include "glutil.h"
|
25 | 26 | #include "ddraw.h"
|
— | — | @@ -43,6 +44,28 @@ |
44 | 45 | return (number<<2)+(number>>4);
|
45 | 46 | }
|
46 | 47 |
|
| 48 | +int setdrawmode(D3DPRIMITIVETYPE d3dptPrimitiveType)
|
| 49 | +{
|
| 50 | + switch(d3dptPrimitiveType)
|
| 51 | + {
|
| 52 | + case D3DPT_POINTLIST:
|
| 53 | + return GL_POINTS;
|
| 54 | + case D3DPT_LINELIST:
|
| 55 | + return GL_LINES;
|
| 56 | + case D3DPT_LINESTRIP:
|
| 57 | + return GL_LINE_STRIP;
|
| 58 | + case D3DPT_TRIANGLELIST:
|
| 59 | + return GL_TRIANGLES;
|
| 60 | + case D3DPT_TRIANGLESTRIP:
|
| 61 | + return GL_TRIANGLE_STRIP;
|
| 62 | + case D3DPT_TRIANGLEFAN:
|
| 63 | + return GL_TRIANGLE_FAN;
|
| 64 | + default:
|
| 65 | + return -1;
|
| 66 | + }
|
| 67 | +}
|
| 68 | +
|
| 69 | +
|
47 | 70 | int oldswap = 0;
|
48 | 71 | int swapinterval = 0;
|
49 | 72 | inline void SetSwap(int swap)
|
— | — | @@ -387,6 +410,35 @@ |
388 | 411 | LeaveCriticalSection(&cs);
|
389 | 412 | }
|
390 | 413 |
|
| 414 | +HRESULT glRenderer::DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 415 | + LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| 416 | +{
|
| 417 | + MSG Msg;
|
| 418 | + EnterCriticalSection(&cs);
|
| 419 | + wndbusy = true;
|
| 420 | + inputs[0] = device;
|
| 421 | + inputs[1] = (void*)d3dptPrimitiveType;
|
| 422 | + inputs[2] = (void*)dwVertexTypeDesc;
|
| 423 | + inputs[3] = lpvVertices;
|
| 424 | + inputs[4] = (void*)dwVertexCount;
|
| 425 | + inputs[5] = lpwIndices;
|
| 426 | + inputs[6] = (void*)dwIndexCount;
|
| 427 | + inputs[7] = (void*)dwFlags;
|
| 428 | + SendMessage(hRenderWnd,GLEVENT_DRAWINDEXEDPRIMITIVE,0,0);
|
| 429 | + while(wndbusy)
|
| 430 | + {
|
| 431 | + while(PeekMessage(&Msg,hRenderWnd,0,0,PM_REMOVE))
|
| 432 | + {
|
| 433 | + TranslateMessage(&Msg);
|
| 434 | + DispatchMessage(&Msg);
|
| 435 | + }
|
| 436 | + Sleep(0);
|
| 437 | + }
|
| 438 | + LeaveCriticalSection(&cs);
|
| 439 | + return (HRESULT)outputs[0];
|
| 440 | +}
|
| 441 | +
|
| 442 | +
|
391 | 443 | DWORD glRenderer::_Entry()
|
392 | 444 | {
|
393 | 445 | MSG Msg;
|
— | — | @@ -969,11 +1021,37 @@ |
970 | 1022 | glFlush();
|
971 | 1023 | }
|
972 | 1024 |
|
| 1025 | +void glRenderer::_DrawIndexedPrimitive(glDirect3DDevice7 *device, D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
| 1026 | + LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
| 1027 | +{
|
| 1028 | + int drawmode = setdrawmode(d3dptPrimitiveType);
|
| 1029 | + if(drawmode == -1)
|
| 1030 | + {
|
| 1031 | + outputs[0] = (void*)DDERR_INVALIDPARAMS;
|
| 1032 | + wndbusy = false;
|
| 1033 | + return;
|
| 1034 | + }
|
| 1035 | + if(dwVertexTypeDesc & D3DFVF_XYZB1)
|
| 1036 | + {
|
| 1037 | + outputs[0] = (void*)DDERR_GENERIC;
|
| 1038 | + wndbusy = false;
|
| 1039 | + FIXME("glDirect3DDevice::DrawIndexedPrimitive: D3DFVF_XYZB1 stub");
|
| 1040 | + return;
|
| 1041 | + }
|
| 1042 | + SetShader(device->SelectShader(dwVertexTypeDesc),NULL,0);
|
| 1043 | +
|
| 1044 | + FIXME("glDirect3DDevice::DrawIndexedPrimitive: stub");
|
| 1045 | + outputs[0] = (void*)DDERR_GENERIC;
|
| 1046 | + wndbusy = false;
|
| 1047 | + return;
|
| 1048 | +}
|
| 1049 | +
|
973 | 1050 | LRESULT glRenderer::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
974 | 1051 | {
|
975 | 1052 | int oldx,oldy;
|
976 | 1053 | float mulx, muly;
|
977 | 1054 | float tmpfloats[16];
|
| 1055 | + D3DPRIMITIVETYPE d3dpt;
|
978 | 1056 | int translatex, translatey;
|
979 | 1057 | LPARAM newpos;
|
980 | 1058 | HWND hParent;
|
— | — | @@ -1099,6 +1177,11 @@ |
1100 | 1178 | case GLEVENT_FLUSH:
|
1101 | 1179 | _Flush();
|
1102 | 1180 | return 0;
|
| 1181 | + case GLEVENT_DRAWINDEXEDPRIMITIVE:
|
| 1182 | + memcpy(&d3dpt,&inputs[1],4);
|
| 1183 | + _DrawIndexedPrimitive((glDirect3DDevice7*)inputs[0],d3dpt,(DWORD)inputs[2],(LPVOID)inputs[3],
|
| 1184 | + (DWORD)inputs[4],(LPWORD)inputs[5],(DWORD)inputs[6],(DWORD)inputs[7]);
|
| 1185 | + return 0;
|
1103 | 1186 | }
|
1104 | 1187 | return DefWindowProc(hwnd,msg,wParam,lParam);
|
1105 | 1188 | }
|
Index: ddraw/glRenderer.h |
— | — | @@ -62,10 +62,19 @@ |
63 | 63 | #define GLEVENT_INITD3D WM_USER+8
|
64 | 64 | #define GLEVENT_CLEAR WM_USER+9
|
65 | 65 | #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
|
66 | 72 |
|
| 73 | +
|
67 | 74 | extern int swapinterval;
|
68 | 75 | extern inline void SetSwap(int swap);
|
69 | 76 |
|
| 77 | +class glDirect3DDevice7;
|
| 78 | +
|
70 | 79 | class glRenderer
|
71 | 80 | {
|
72 | 81 | public:
|
— | — | @@ -82,6 +91,8 @@ |
83 | 92 | void InitD3D(int zbuffer);
|
84 | 93 | void Flush();
|
85 | 94 | 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);
|
86 | 97 | HGLRC hRC;
|
87 | 98 | LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
88 | 99 | private:
|
— | — | @@ -98,6 +109,8 @@ |
99 | 110 | void _DrawBackbuffer(GLuint *texture, int x, int y);
|
100 | 111 | void _InitD3D(int zbuffer);
|
101 | 112 | 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);
|
102 | 115 | glDirectDraw7 *ddInterface;
|
103 | 116 | void _Flush();
|
104 | 117 | void* inputs[32];
|
Index: ddraw/shadergen.cpp |
— | — | @@ -34,9 +34,11 @@ |
35 | 35 | {
|
36 | 36 | _GENSHADER shader;
|
37 | 37 | __int64 id;
|
| 38 | + __int64 texids[8];
|
38 | 39 | };
|
39 | 40 | GenShader genshaders[256];
|
40 | 41 | static __int64 current_shader = 0;
|
| 42 | +static __int64 current_texid[8];
|
41 | 43 | static int shadercount = 0;
|
42 | 44 | static int genindex = 0;
|
43 | 45 | static bool initialized = false;
|
— | — | @@ -65,16 +67,31 @@ |
66 | 68 | Bits 29-30 - Emissive material source
|
67 | 69 | Bits 31-33 - Number of textures
|
68 | 70 | Bit 34 - Use transformed vertices
|
69 | | -Bit 35 - Use secondary color
|
70 | | -Bits 36-51 - Texture coordinate format:
|
71 | | -00=2dim 01=3dim 10=4dim 11=1dim
|
72 | | -Bit 52 - Enable normals
|
73 | | -Bits 53-60 - Light types
|
74 | | -Bits 61-63 - Number of blending weights
|
| 71 | +Bit 35 - Use diffuse color
|
| 72 | +Bit 36 - Use specular color
|
| 73 | +Bit 37 - Enable normals
|
| 74 | +Bits 38-45 - Light types
|
| 75 | +Bits 46-48 - Number of blending weights
|
75 | 76 | */
|
76 | 77 |
|
77 | 78 | /* Bits in Texture Stage ID:
|
78 | | -
|
| 79 | +Bits 0-4: Texture color operation
|
| 80 | +Bits 5-10: Texture color argument 1
|
| 81 | +Bits 11-16: Texture color argument 2
|
| 82 | +Bits 17-20: Texture alpha operation
|
| 83 | +Bits 21-26: Texture alpha argument 1
|
| 84 | +Bits 27-32: Texture alpha argument 2
|
| 85 | +Bits 33-35: Texture coordinate index
|
| 86 | +Bits 36-37: Texture coordinate flags
|
| 87 | +Bits 38-39: U Texture address
|
| 88 | +Bits 40-41: V Texture address
|
| 89 | +Bits 42-44: Texture magnification filter
|
| 90 | +Bits 45-46: Texture minification filter
|
| 91 | +Bit 47: Enable texture coordinate transform
|
| 92 | +Bits 48-49: Number of texcoord dimensions
|
| 93 | +Bit 50: Projected texcoord
|
| 94 | +Bits 51-52: Texutre coordinate format:
|
| 95 | +00=2dim 01=3dim 10=4dim 11=1dim
|
79 | 96 | */
|
80 | 97 | void ZeroShaderArray()
|
81 | 98 | {
|
— | — | @@ -95,7 +112,10 @@ |
96 | 113 | }
|
97 | 114 | else
|
98 | 115 | {
|
99 | | - if(!isbuiltin && (id == current_shader)) return;
|
| 116 | + if(!isbuiltin && (id == current_shader))
|
| 117 | + {
|
| 118 | + if(!memcmp(current_texid,texstate,8*sizeof(__int64))) return;
|
| 119 | + }
|
100 | 120 | current_shader = id;
|
101 | 121 | isbuiltin=false;
|
102 | 122 | for(int i = 0; i < shadercount; i++)
|
— | — | @@ -102,8 +122,11 @@ |
103 | 123 | {
|
104 | 124 | if(genshaders[i].id == id)
|
105 | 125 | {
|
106 | | - shaderindex = i;
|
107 | | - break;
|
| 126 | + if(!memcmp(genshaders[i].texids,texstate,8*sizeof(__int64)))
|
| 127 | + {
|
| 128 | + shaderindex = i;
|
| 129 | + break;
|
| 130 | + }
|
108 | 131 | }
|
109 | 132 | }
|
110 | 133 | if(shaderindex == -1)
|
— | — | @@ -120,7 +143,7 @@ |
121 | 144 | delete genshaders[shaderindex].shader.fsrc;
|
122 | 145 | ZeroMemory(&genshaders[shaderindex],sizeof(GenShader));
|
123 | 146 | }
|
124 | | - CreateShader(genindex,id);
|
| 147 | + CreateShader(genindex,id,texstate);
|
125 | 148 | shaderindex = genindex;
|
126 | 149 | genindex++;
|
127 | 150 | if(genindex == 256) genindex = 0;
|
— | — | @@ -198,7 +221,7 @@ |
199 | 222 | // Operations
|
200 | 223 | static const char normalize[] = "vec3 N = normalize(vec3(modelview*vec4(nxyz,0.0)));\n";
|
201 | 224 |
|
202 | | -void CreateShader(int index, __int64 id)
|
| 225 | +void CreateShader(int index, __int64 id, TexState *texstate)
|
203 | 226 | {
|
204 | 227 | string tmp;
|
205 | 228 | int i;
|
— | — | @@ -227,7 +250,7 @@ |
228 | 251 | vsrc->append(tmp);
|
229 | 252 | }
|
230 | 253 | }
|
231 | | -
|
| 254 | +
|
232 | 255 | //Main
|
233 | 256 | vsrc->append(mainstart);
|
234 | 257 |
|
Index: ddraw/shadergen.h |
— | — | @@ -33,6 +33,6 @@ |
34 | 34 | void SetShader(__int64 id, TexState *texstate, bool builtin);
|
35 | 35 | GLuint GetProgram();
|
36 | 36 | void ZeroShaderArray();
|
37 | | -void CreateShader(int index, __int64 id);
|
| 37 | +void CreateShader(int index, __int64 id, TexState *texstate);
|
38 | 38 |
|
39 | 39 | #endif |
\ No newline at end of file |
Index: dxgltest/dxgltest.cpp |
— | — | @@ -713,21 +713,15 @@ |
714 | 714 | tab.pszText = _T("2D Graphics");
|
715 | 715 | hTab = GetDlgItem(hWnd,IDC_TABS);
|
716 | 716 | SendDlgItemMessage(hWnd,IDC_TABS,TCM_INSERTITEM,1,(LPARAM)&tab);
|
717 | | - #ifdef _DEBUG
|
718 | 717 | tab.pszText = _T("3D Graphics");
|
719 | 718 | SendDlgItemMessage(hWnd,IDC_TABS,TCM_INSERTITEM,2,(LPARAM)&tab);
|
720 | | - #endif
|
721 | 719 | tabwnd[0] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_SYSINFO),hTab,SysTabCallback);
|
722 | 720 | tabwnd[1] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_TESTGFX),hTab,Test2DCallback);
|
723 | | - #ifdef _DEBUG
|
724 | 721 | tabwnd[2] = CreateDialog(hinstance,MAKEINTRESOURCE(IDD_TESTGFX),hTab,Test3DCallback);
|
725 | | - #endif
|
726 | 722 | SendDlgItemMessage(hWnd,IDC_TABS,TCM_GETITEMRECT,0,(LPARAM)&tabrect);
|
727 | 723 | SetWindowPos(tabwnd[0],NULL,tabrect.left,tabrect.bottom+3,0,0,SWP_SHOWWINDOW|SWP_NOSIZE);
|
728 | 724 | ShowWindow(tabwnd[1],SW_HIDE);
|
729 | | - #ifdef _DEBUG
|
730 | 725 | ShowWindow(tabwnd[2],SW_HIDE);
|
731 | | - #endif
|
732 | 726 | tabopen = 0;
|
733 | 727 | ShowWindow(hWnd,SW_SHOWNORMAL);
|
734 | 728 | return TRUE;
|