Index: ddraw/glDirect3DDevice.cpp |
— | — | @@ -920,6 +920,7 @@ |
921 | 921 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
922 | 922 | LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
|
923 | 923 | {
|
| 924 | + RenderTarget target;
|
924 | 925 | TRACE_ENTER(8,9,d3dptPrimitiveType,9,dwVertexTypeDesc,14,lpvVertices,8,dwVertexCount,14,lpwIndices,8,dwIndexCount,9,dwFlags);
|
925 | 926 | if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
|
926 | 927 | if(!inscene) TRACE_RET(HRESULT,23,D3DERR_SCENE_NOT_IN_SCENE);
|
— | — | @@ -927,7 +928,21 @@ |
928 | 929 | if(lpwIndices) AddStats(d3dptPrimitiveType,dwIndexCount,&stats);
|
929 | 930 | else AddStats(d3dptPrimitiveType,dwVertexCount,&stats);
|
930 | 931 | if(err != D3D_OK) TRACE_RET(HRESULT,23,err);
|
931 | | - TRACE_RET(HRESULT,23,glRenderer_DrawPrimitives(renderer,this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
|
| 932 | + target.target = glDDS7->texture;
|
| 933 | + target.level = glDDS7->miplevel;
|
| 934 | + target.mulx = glDDS7->mulx;
|
| 935 | + target.muly = glDDS7->muly;
|
| 936 | + if (glDDS7->zbuffer)
|
| 937 | + {
|
| 938 | + target.zbuffer = glDDS7->zbuffer->texture;
|
| 939 | + target.zlevel = glDDS7->zbuffer->miplevel;
|
| 940 | + }
|
| 941 | + else
|
| 942 | + {
|
| 943 | + target.zbuffer = NULL;
|
| 944 | + target.zlevel = 0;
|
| 945 | + }
|
| 946 | + TRACE_RET(HRESULT,23,glRenderer_DrawPrimitives(renderer,&target,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
|
932 | 947 | dwVertexCount,lpwIndices,dwIndexCount,dwFlags));
|
933 | 948 | }
|
934 | 949 | HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -21,10 +21,8 @@ |
22 | 22 | #include "glUtil.h"
|
23 | 23 | #include "timer.h"
|
24 | 24 | #include "glDirectDraw.h"
|
25 | | -#include "glDirectDrawSurface.h"
|
26 | 25 | #include "glRenderWindow.h"
|
27 | 26 | #include "glRenderer.h"
|
28 | | -#include "glDirect3DDevice.h"
|
29 | 27 | #include "ddraw.h"
|
30 | 28 | #include "ShaderGen3D.h"
|
31 | 29 | #include "matrix.h"
|
— | — | @@ -254,10 +252,11 @@ |
255 | 253 | // Generate vertices
|
256 | 254 | // Write vertices to VBO
|
257 | 255 | // Write Palette Draw command to buffer
|
258 | | - error = DDERR_UNSUPPORTED;
|
| 256 | + error = DDERR_CURRENTLYNOTAVAIL;
|
259 | 257 | break;
|
260 | 258 | case OP_INITD3D: // Initialize renderer for Direct3D rendering.
|
261 | 259 | // Set initial viewport
|
| 260 | + // Initialize texture stages 0 through 7
|
262 | 261 | // Post InitD3D command
|
263 | 262 | error = DDERR_CURRENTLYNOTAVAIL;
|
264 | 263 | break;
|
— | — | @@ -265,7 +264,8 @@ |
266 | 265 | // Size should hold number of rects plus each rect, or 0 for screen.
|
267 | 266 | error = DDERR_CURRENTLYNOTAVAIL;
|
268 | 267 | break;
|
269 | | - case OP_FLUSH: // Probably should consider retiring this one. Flip buffers if called.
|
| 268 | + case OP_FLUSH: // Probably should consider retiring this one. Flip buffers if called
|
| 269 | + // to ensure the renderer gets flushed.
|
270 | 270 | error = DDERR_CURRENTLYNOTAVAIL;
|
271 | 271 | break;
|
272 | 272 | case OP_DRAWPRIMITIVES: // Add primitives to the render buffer, check and adjust buffer
|
— | — | @@ -308,7 +308,10 @@ |
309 | 309 | case OP_DXGLBREAK: // Breakpoint command, flip buffers and wait or just add to command stream?
|
310 | 310 | error = DDERR_CURRENTLYNOTAVAIL;
|
311 | 311 | break;
|
312 | | - case OP_SETMODE2D: // Set up renderer for 2D DirectDraw commands.
|
| 312 | + case OP_ENDCOMMAND: // Not for this section.
|
| 313 | + error = DDERR_INVALIDPARAMS;
|
| 314 | + break;
|
| 315 | + case OP_INITTEXTURESTAGE: // Initializes a texture stage.
|
313 | 316 | error = DDERR_CURRENTLYNOTAVAIL;
|
314 | 317 | break;
|
315 | 318 | default:
|
— | — | @@ -837,8 +840,8 @@ |
838 | 841 | * Draws one or more primitives to the currently selected render target.
|
839 | 842 | * @param This
|
840 | 843 | * Pointer to glRenderer object
|
841 | | - * @param device
|
842 | | - * glDirect3DDevice7 interface to use for drawing
|
| 844 | + * @param target
|
| 845 | + * Textures and mip levels of the current render target
|
843 | 846 | * @param mode
|
844 | 847 | * OpenGL primitive drawing mode to use
|
845 | 848 | * @param vertices
|
— | — | @@ -861,11 +864,10 @@ |
862 | 865 | * D3D_OK if the call succeeds, or D3DERR_INVALIDVERTEXTYPE if the vertex format
|
863 | 866 | * has no position coordinates.
|
864 | 867 | */
|
865 | | -HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| 868 | +HRESULT glRenderer_DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
866 | 869 | DWORD indexcount, DWORD flags)
|
867 | 870 | {
|
868 | 871 | EnterCriticalSection(&This->cs);
|
869 | | - This->inputs[0] = device;
|
870 | 872 | This->inputs[1] = (void*)mode;
|
871 | 873 | This->inputs[2] = vertices;
|
872 | 874 | This->inputs[3] = texformats;
|
— | — | @@ -873,6 +875,7 @@ |
874 | 876 | This->inputs[5] = indices;
|
875 | 877 | This->inputs[6] = (void*)indexcount;
|
876 | 878 | This->inputs[7] = (void*)flags;
|
| 879 | + memcpy(&This->inputs[8], target, sizeof(RenderTarget));
|
877 | 880 | This->opcode = OP_DRAWPRIMITIVES;
|
878 | 881 | SetEvent(This->start);
|
879 | 882 | WaitForSingleObject(This->busy,INFINITE);
|
— | — | @@ -1276,7 +1279,7 @@ |
1277 | 1280 | glRenderer__Flush(This);
|
1278 | 1281 | break;
|
1279 | 1282 | case OP_DRAWPRIMITIVES:
|
1280 | | - glRenderer__DrawPrimitives(This,(glDirect3DDevice7*)This->inputs[0],(GLenum)This->inputs[1],
|
| 1283 | + glRenderer__DrawPrimitives(This,(RenderTarget*)&This->inputs[8],(GLenum)This->inputs[1],
|
1281 | 1284 | (GLVERTEX*)This->inputs[2],(int*)This->inputs[3],(DWORD)This->inputs[4],(LPWORD)This->inputs[5],
|
1282 | 1285 | (DWORD)This->inputs[6],(DWORD)This->inputs[7]);
|
1283 | 1286 | break;
|
— | — | @@ -2505,7 +2508,7 @@ |
2506 | 2509 | glUtil_BlendFunc(This->util, glsrc, gldest);
|
2507 | 2510 | }
|
2508 | 2511 |
|
2509 | | -void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| 2512 | +void glRenderer__DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
2510 | 2513 | DWORD indexcount, DWORD flags)
|
2511 | 2514 | {
|
2512 | 2515 | bool transformed;
|
— | — | @@ -2516,10 +2519,10 @@ |
2517 | 2520 | int i;
|
2518 | 2521 | glTexture *ztexture = NULL;
|
2519 | 2522 | GLint zlevel = 0;
|
2520 | | - if (device->glDDS7->zbuffer)
|
| 2523 | + if (target->zbuffer)
|
2521 | 2524 | {
|
2522 | | - ztexture = device->glDDS7->zbuffer->texture;
|
2523 | | - zlevel = device->glDDS7->zbuffer->miplevel;
|
| 2525 | + ztexture = target->zbuffer;
|
| 2526 | + zlevel = target->zlevel;
|
2524 | 2527 | }
|
2525 | 2528 | if(vertices[1].data) transformed = true;
|
2526 | 2529 | else transformed = false;
|
— | — | @@ -2720,21 +2723,21 @@ |
2721 | 2724 | if(prog->uniforms[139]!= -1) This->ext->glUniform1f(prog->uniforms[139],This->viewport.dwX);
|
2722 | 2725 | if(prog->uniforms[140]!= -1) This->ext->glUniform1f(prog->uniforms[140],This->viewport.dwY);
|
2723 | 2726 | if(prog->uniforms[141]!= -1) This->ext->glUniform1i(prog->uniforms[141],This->renderstate[D3DRENDERSTATE_ALPHAREF]);
|
2724 | | - if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
|
| 2727 | + if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)target->target->colorbits);
|
2725 | 2728 | do
|
2726 | 2729 | {
|
2727 | | - if (glUtil_SetFBOSurface(This->util, device->glDDS7->texture, ztexture,
|
2728 | | - device->glDDS7->miplevel, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
|
2729 | | - if (!device->glDDS7->texture->internalformats[1]) break;
|
2730 | | - glTexture__Repair(device->glDDS7->texture, TRUE);
|
| 2730 | + if (glUtil_SetFBOSurface(This->util, target->target, ztexture,
|
| 2731 | + target->level, zlevel, FALSE) == GL_FRAMEBUFFER_COMPLETE) break;
|
| 2732 | + if (!target->target->internalformats[1]) break;
|
| 2733 | + glTexture__Repair(target->target, TRUE);
|
2731 | 2734 | glUtil_SetFBO(This->util, NULL);
|
2732 | | - device->glDDS7->texture->levels[device->glDDS7->miplevel].fbo.fbcolor = NULL;
|
2733 | | - device->glDDS7->texture->levels[device->glDDS7->miplevel].fbo.fbz = NULL;
|
| 2735 | + target->target->levels[target->level].fbo.fbcolor = NULL;
|
| 2736 | + target->target->levels[target->level].fbo.fbz = NULL;
|
2734 | 2737 | } while (1);
|
2735 | | - glUtil_SetViewport(This->util, (int)((float)This->viewport.dwX*device->glDDS7->mulx),
|
2736 | | - (int)((float)This->viewport.dwY*device->glDDS7->muly),
|
2737 | | - (int)((float)This->viewport.dwWidth*device->glDDS7->mulx),
|
2738 | | - (int)((float)This->viewport.dwHeight*device->glDDS7->muly));
|
| 2738 | + glUtil_SetViewport(This->util, (int)((float)This->viewport.dwX*target->mulx),
|
| 2739 | + (int)((float)This->viewport.dwY*target->muly),
|
| 2740 | + (int)((float)This->viewport.dwWidth*target->mulx),
|
| 2741 | + (int)((float)This->viewport.dwHeight*target->muly));
|
2739 | 2742 | glUtil_SetDepthRange(This->util, This->viewport.dvMinZ, This->viewport.dvMaxZ);
|
2740 | 2743 | if (This->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) glUtil_BlendEnable(This->util, TRUE);
|
2741 | 2744 | else glUtil_BlendEnable(This->util, FALSE);
|
— | — | @@ -2748,8 +2751,8 @@ |
2749 | 2752 | glUtil_SetShadeMode(This->util, (D3DSHADEMODE)This->renderstate[D3DRENDERSTATE_SHADEMODE]);
|
2750 | 2753 | if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
|
2751 | 2754 | else glDrawArrays(mode,0,count);
|
2752 | | - if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->texture->levels[device->glDDS7->miplevel].dirty |= 2;
|
2753 | | - device->glDDS7->texture->levels[device->glDDS7->miplevel].dirty |= 2;
|
| 2755 | + if(target->zbuffer) target->zbuffer->levels[target->zlevel].dirty |= 2;
|
| 2756 | + target->target->levels[target->level].dirty |= 2;
|
2754 | 2757 | if(flags & D3DDP_WAIT) glFlush();
|
2755 | 2758 | This->outputs[0] = (void*)D3D_OK;
|
2756 | 2759 | SetEvent(This->busy);
|
Index: ddraw/glRenderer.h |
— | — | @@ -109,7 +109,7 @@ |
110 | 110 | #define OP_SETTEXTURECOLORKEY 23
|
111 | 111 | #define OP_MAKETEXTUREPRIMARY 24
|
112 | 112 | #define OP_ENDCOMMAND 25
|
113 | | -#define OP_SETMODE2D 26
|
| 113 | +#define OP_INITTEXTURESTAGE 26
|
114 | 114 |
|
115 | 115 | extern const DWORD renderstate_default[153];
|
116 | 116 | extern const TEXTURESTAGE texstagedefault0;
|
— | — | @@ -158,6 +158,7 @@ |
159 | 159 | D3DMATRIX transform[24];
|
160 | 160 | D3DVIEWPORT7 viewport;
|
161 | 161 | CommandBuffer cmd1, cmd2;
|
| 162 | + float mulx, muly;
|
162 | 163 | RenderState state;
|
163 | 164 | size_t scenesize, scenesizevertex, scenesizeindex;
|
164 | 165 | } glRenderer;
|
— | — | @@ -177,7 +178,7 @@ |
178 | 179 | void glRenderer_Flush(glRenderer *This);
|
179 | 180 | void glRenderer_SetWnd(glRenderer *This, int width, int height, int bpp, int fullscreen, unsigned int frequency, HWND newwnd, BOOL devwnd);
|
180 | 181 | HRESULT glRenderer_Clear(glRenderer *This, ClearCommand *cmd);
|
181 | | -HRESULT glRenderer_DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
| 182 | +HRESULT glRenderer_DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
|
182 | 183 | DWORD indexcount, DWORD flags);
|
183 | 184 | //void glRenderer_UpdateClipper(glRenderer *This, glTexture *stencil, GLushort *indices, BltVertex *vertices,
|
184 | 185 | void glRenderer_UpdateClipper(glRenderer *This, glTexture *stencil, GLushort *indices, BltVertex *vertices,
|
— | — | @@ -210,7 +211,7 @@ |
211 | 212 | void glRenderer__DrawBackbufferRect(glRenderer *This, glTexture *texture, RECT srcrect, int progtype);
|
212 | 213 | void glRenderer__InitD3D(glRenderer *This, int zbuffer, int x, int y);
|
213 | 214 | void glRenderer__Clear(glRenderer *This, ClearCommand *cmd);
|
214 | | -void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
|
| 215 | +void glRenderer__DrawPrimitives(glRenderer *This, RenderTarget *target, GLenum mode, GLVERTEX *vertices, int *texcormats, DWORD count, LPWORD indices,
|
215 | 216 | DWORD indexcount, DWORD flags);
|
216 | 217 | void glRenderer__Flush(glRenderer *This);
|
217 | 218 | void glRenderer__SetWnd(glRenderer *This, int width, int height, int fullscreen, int bpp, unsigned int frequency, HWND newwnd, BOOL devwnd);
|
Index: ddraw/struct.h |
— | — | @@ -455,4 +455,14 @@ |
456 | 456 | BltCommand last_blt;
|
457 | 457 | } RenderState;
|
458 | 458 |
|
| 459 | +typedef struct RenderTarget
|
| 460 | +{
|
| 461 | + glTexture *target;
|
| 462 | + glTexture *zbuffer;
|
| 463 | + GLint level;
|
| 464 | + GLint zlevel;
|
| 465 | + float mulx;
|
| 466 | + float muly;
|
| 467 | +} RenderTarget;
|
| 468 | +
|
459 | 469 | #endif //__STRUCT_H |
\ No newline at end of file |
Index: ddraw/struct_command.h |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | glTexture *paltex;
|
64 | 64 | GLint vsync;
|
65 | 65 | glTexture *previous;
|
66 | | -};
|
| 66 | +} DrawScreenCmd;
|
67 | 67 | typedef struct InitD3DCmd
|
68 | 68 | {
|
69 | 69 | DWORD opcode;
|
— | — | @@ -70,11 +70,22 @@ |
71 | 71 | int zbuffer;
|
72 | 72 | int x;
|
73 | 73 | int y;
|
74 | | -};
|
| 74 | +} InitD3DCmd;
|
75 | 75 | typedef struct ClearCmd
|
76 | 76 | {
|
77 | 77 | DWORD opcode;
|
78 | 78 | DWORD size;
|
79 | 79 | ClearCommand cmd;
|
80 | | -};
|
| 80 | +} ClearCmd;
|
| 81 | +typedef struct FlushCmd
|
| 82 | +{
|
| 83 | + DWORD opcode;
|
| 84 | + DWORD size;
|
| 85 | +} FlushCmd;
|
| 86 | +typedef struct DrawPrimitivesCmd
|
| 87 | +{
|
| 88 | + DWORD opcode;
|
| 89 | + DWORD size;
|
| 90 | + // Add params
|
| 91 | +} DrawPrimitivesCmd;
|
81 | 92 | #endif //__STRUCT_COMMAND_H |
\ No newline at end of file |