Index: ddraw/glRenderer.cpp |
— | — | @@ -237,6 +237,7 @@ |
238 | 238 | {
|
239 | 239 | BOOL usedest = FALSE;
|
240 | 240 | BOOL usepattern = FALSE;
|
| 241 | + BOOL usetexture = FALSE;
|
241 | 242 | if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
|
242 | 243 | {
|
243 | 244 | if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
|
— | — | @@ -280,24 +281,33 @@ |
281 | 282 | tmp_cmd.Blt.cmd.destlevel = 0;
|
282 | 283 | glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
|
283 | 284 | }
|
284 | | - i = 0;
|
| 285 | + // Set Src texture (Unit 8)
|
| 286 | + i = -1;
|
285 | 287 | tmp_cmd.SetTexture.opcode = OP_SETTEXTURE;
|
286 | | - tmp_cmd.SetTexture.size = sizeof(SetTextureCmd);
|
287 | | - // Set Src texture (Unit 8)
|
| 288 | + tmp_cmd.SetTexture.size = sizeof(SetTextureCmd) - (sizeof(DWORD) + sizeof(glTexture*));
|
288 | 289 | if (cmd->Blt.cmd.src)
|
289 | 290 | {
|
| 291 | + tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
|
| 292 | + i++;
|
| 293 | + usetexture = TRUE;
|
290 | 294 | tmp_cmd.SetTexture.texstage[i].stage = 8;
|
291 | 295 | tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.src;
|
| 296 | + }
|
| 297 | + // Set Dest texture (Unit 9) - reads from temporary buffer
|
| 298 | + if (usedest)
|
| 299 | + {
|
292 | 300 | tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
|
293 | 301 | i++;
|
| 302 | + usetexture = TRUE;
|
| 303 | + tmp_cmd.SetTexture.texstage[i].stage = 9;
|
| 304 | + tmp_cmd.SetTexture.texstage[i].texture = This->backbuffer;
|
294 | 305 | }
|
295 | | - // Set Dest texture (Unit 9)
|
296 | | - tmp_cmd.SetTexture.texstage[i].stage = 9;
|
297 | | - tmp_cmd.SetTexture.texstage[i].texture = tmp_cmd.Blt.cmd.dest;
|
298 | 306 | // Set Pattern texture (Unit 10)
|
299 | 307 | if (usepattern)
|
300 | 308 | {
|
301 | 309 | tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
|
| 310 | + i++;
|
| 311 | + usetexture = TRUE;
|
302 | 312 | tmp_cmd.SetTexture.texstage[i].stage = 10;
|
303 | 313 | tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.pattern;
|
304 | 314 | }
|
— | — | @@ -305,10 +315,12 @@ |
306 | 316 | if (cmd->Blt.cmd.dest->stencil)
|
307 | 317 | {
|
308 | 318 | tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
|
| 319 | + i++;
|
| 320 | + usetexture = TRUE;
|
309 | 321 | tmp_cmd.SetTexture.texstage[i].stage = 11;
|
310 | 322 | tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.dest->stencil;
|
311 | 323 | }
|
312 | | - glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
|
| 324 | + if(usetexture) glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
|
313 | 325 | // Set shader mode and params
|
314 | 326 | tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
|
315 | 327 | tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd);
|
— | — | @@ -318,8 +330,58 @@ |
319 | 331 | else tmp_cmd.SetShader2D.id = cmd->Blt.cmd.flags & 0xF2FAADFF;
|
320 | 332 | glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
|
321 | 333 | // Set render target
|
| 334 | + if ((This->state.target.target != cmd->Blt.cmd.dest)
|
| 335 | + || (This->state.target.level != cmd->Blt.cmd.destlevel))
|
| 336 | + {
|
| 337 | + tmp_cmd.SetRenderTarget.opcode = OP_SETRENDERTARGET;
|
| 338 | + tmp_cmd.SetRenderTarget.size = sizeof(SetRenderTargetCmd);
|
| 339 | + tmp_cmd.SetRenderTarget.target.target = cmd->Blt.cmd.dest;
|
| 340 | + tmp_cmd.SetRenderTarget.target.level = cmd->Blt.cmd.destlevel;
|
| 341 | + tmp_cmd.SetRenderTarget.target.zbuffer = NULL;
|
| 342 | + tmp_cmd.SetRenderTarget.target.zlevel = 0;
|
| 343 | + if (cmd->Blt.cmd.destlevel == 0 && (cmd->Blt.cmd.dest->levels[0].ddsd.dwWidth != cmd->Blt.cmd.dest->bigwidth) ||
|
| 344 | + (cmd->Blt.cmd.dest->levels[0].ddsd.dwHeight != cmd->Blt.cmd.dest->bigheight))
|
| 345 | + {
|
| 346 | + tmp_cmd.SetRenderTarget.target.mulx = (GLfloat)cmd->Blt.cmd.dest->bigwidth / (GLfloat)cmd->Blt.cmd.dest->levels[0].ddsd.dwWidth;
|
| 347 | + tmp_cmd.SetRenderTarget.target.muly = (GLfloat)cmd->Blt.cmd.dest->bigheight / (GLfloat)cmd->Blt.cmd.dest->levels[0].ddsd.dwHeight;
|
| 348 | + }
|
| 349 | + else tmp_cmd.SetRenderTarget.target.mulx = tmp_cmd.SetRenderTarget.target.muly = 1.0f;
|
| 350 | + glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
|
| 351 | + }
|
322 | 352 | // Set viewport
|
| 353 | + if (!cmd->Blt.cmd.destlevel)
|
| 354 | + {
|
| 355 | + r2.right = cmd->Blt.cmd.dest->bigwidth;
|
| 356 | + r2.bottom = cmd->Blt.cmd.dest->bigheight;
|
| 357 | + }
|
| 358 | + else
|
| 359 | + {
|
| 360 | + r2.right = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
|
| 361 | + r2.bottom = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
|
| 362 | + }
|
| 363 | + if (This->state.viewport.x || This->state.viewport.y ||
|
| 364 | + (This->state.viewport.width != r2.right) || (This->state.viewport.hieght != r2.bottom))
|
| 365 | + {
|
| 366 | + tmp_cmd.SetViewport.opcode = OP_SETVIEWPORT;
|
| 367 | + tmp_cmd.SetViewport.size = sizeof(SetViewportCmd);
|
| 368 | + tmp_cmd.SetViewport.viewport.x = tmp_cmd.SetViewport.viewport.y = 0;
|
| 369 | + tmp_cmd.SetViewport.viewport.width = r2.right;
|
| 370 | + tmp_cmd.SetViewport.viewport.hieght = r2.bottom;
|
| 371 | + glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
|
| 372 | + }
|
323 | 373 | // Generate vertices
|
| 374 | + /*tmp_cmd.BltVertex_STORAGE.vertex*/
|
| 375 | + if (usedest)
|
| 376 | + {
|
| 377 | + tmp_cmd.BltVertex_STORAGE.vertex[1].dests =
|
| 378 | + tmp_cmd.BltVertex_STORAGE.vertex[3].dests = 0.;
|
| 379 | + tmp_cmd.BltVertex_STORAGE.vertex[0].dests =
|
| 380 | + tmp_cmd.BltVertex_STORAGE.vertex[2].dests = (GLfloat)(r1.right - r1.left) / (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
|
| 381 | + tmp_cmd.BltVertex_STORAGE.vertex[0].destt =
|
| 382 | + tmp_cmd.BltVertex_STORAGE.vertex[1].destt = 1.;
|
| 383 | + tmp_cmd.BltVertex_STORAGE.vertex[2].destt =
|
| 384 | + tmp_cmd.BltVertex_STORAGE.vertex[3].destt = 1.0 - ((GLfloat)(r1.bottom - r1.top) / (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight);
|
| 385 | + }
|
324 | 386 | // Rotate vertices if necessary
|
325 | 387 | // Write vertices to VBO
|
326 | 388 | // Write command to buffer
|
— | — | @@ -423,6 +485,12 @@ |
424 | 486 | case OP_SETSHADER:
|
425 | 487 | error = DDERR_CURRENTLYNOTAVAIL;
|
426 | 488 | break;
|
| 489 | + case OP_SETRENDERTARGET:
|
| 490 | + error = DDERR_CURRENTLYNOTAVAIL;
|
| 491 | + break;
|
| 492 | + case OP_SETVIEWPORT:
|
| 493 | + error = DDERR_CURRENTLYNOTAVAIL;
|
| 494 | + break;
|
427 | 495 | default:
|
428 | 496 | error = DDERR_INVALIDPARAMS;
|
429 | 497 | break;
|
— | — | @@ -1347,8 +1415,6 @@ |
1348 | 1416 | {
|
1349 | 1417 | glTexture_Release(This->backbuffer, TRUE);
|
1350 | 1418 | This->backbuffer = NULL;
|
1351 | | - This->backx = 0;
|
1352 | | - This->backy = 0;
|
1353 | 1419 | }
|
1354 | 1420 | glRenderer__DeleteCommandBuffer(&This->cmd1);
|
1355 | 1421 | glRenderer__DeleteCommandBuffer(&This->cmd2);
|
— | — | @@ -1870,9 +1936,9 @@ |
1871 | 1937 | ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, 0);
|
1872 | 1938 | glRenderer__DrawBackbufferRect(This, cmd->dest, destrect, PROG_TEXTURE);
|
1873 | 1939 | This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
|
1874 | | - This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
|
| 1940 | + This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
|
1875 | 1941 | This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
|
1876 | | - This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
|
| 1942 | + This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight);
|
1877 | 1943 | }
|
1878 | 1944 | ShaderManager_SetShader(This->shaders, shaderid, NULL, 1);
|
1879 | 1945 | GenShader2D *shader = (GenShader2D*)This->shaders->gen3d->current_genshader;
|
— | — | @@ -2034,10 +2100,8 @@ |
2035 | 2101 | ddsd.lPitch = x * 4;
|
2036 | 2102 | ddsd.dwHeight = y;
|
2037 | 2103 | glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
|
2038 | | - This->backx = x;
|
2039 | | - This->backy = y;
|
2040 | 2104 | }
|
2041 | | - if((This->backx != x) || (This->backy != y))
|
| 2105 | + if((This->backbuffer->levels[0].ddsd.dwWidth != x) || (This->backbuffer->levels[0].ddsd.dwHeight != y))
|
2042 | 2106 | {
|
2043 | 2107 | ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
|
2044 | 2108 | ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
— | — | @@ -2045,8 +2109,6 @@ |
2046 | 2110 | ddsd.dwHeight = y;
|
2047 | 2111 | ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
|
2048 | 2112 | glTexture__SetSurfaceDesc(This->backbuffer, &ddsd);
|
2049 | | - This->backx = x;
|
2050 | | - This->backy = y;
|
2051 | 2113 | }
|
2052 | 2114 | glUtil_SetFBOTextures(This->util,&This->fbo,This->backbuffer,NULL,0,0,FALSE);
|
2053 | 2115 | view[0] = view[2] = 0;
|
— | — | @@ -2089,10 +2151,10 @@ |
2090 | 2152 | ddsd.dwHeight = y;
|
2091 | 2153 | glTexture_Create(&ddsd, &This->backbuffer, This, x, y, FALSE, TRUE);
|
2092 | 2154 | }
|
2093 | | - if ((This->backx < x) || (This->backy < y))
|
| 2155 | + if ((This->backbuffer->levels[0].ddsd.dwWidth < x) || (This->backbuffer->levels[0].ddsd.dwHeight < y))
|
2094 | 2156 | {
|
2095 | | - if (This->backx > x) x = This->backx;
|
2096 | | - if (This->backx > y) y = This->backx;
|
| 2157 | + if (This->backbuffer->levels[0].ddsd.dwWidth > x) x = This->backbuffer->levels[0].ddsd.dwWidth;
|
| 2158 | + if (This->backbuffer->levels[0].ddsd.dwHeight > y) y = This->backbuffer->levels[0].ddsd.dwHeight;
|
2097 | 2159 | ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2));
|
2098 | 2160 | ddsd.dwSize = sizeof(DDSURFACEDESC2);
|
2099 | 2161 | ddsd.dwWidth = x;
|
— | — | @@ -2099,15 +2161,13 @@ |
2100 | 2162 | ddsd.dwHeight = y;
|
2101 | 2163 | ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT;
|
2102 | 2164 | glTexture__SetSurfaceDesc(This->backbuffer, &ddsd);
|
2103 | | - This->backx = x;
|
2104 | | - This->backy = y;
|
2105 | 2165 | }
|
2106 | 2166 | glUtil_SetFBOTextures(This->util, &This->fbo, This->backbuffer, NULL, 0, 0, FALSE);
|
2107 | 2167 | view[0] = view[2] = 0;
|
2108 | | - view[1] = (GLfloat)This->backx;
|
2109 | | - view[3] = (GLfloat)This->backy;
|
2110 | | - glUtil_SetViewport(This->util, 0, 0, This->backx, This->backy);
|
2111 | | - glUtil_SetScissor(This->util, TRUE, 0, 0, This->backx, This->backy);
|
| 2168 | + view[1] = (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
|
| 2169 | + view[3] = (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight;
|
| 2170 | + glUtil_SetViewport(This->util, 0, 0, This->backbuffer->levels[0].ddsd.dwWidth, This->backbuffer->levels[0].ddsd.dwHeight);
|
| 2171 | + glUtil_SetScissor(This->util, TRUE, 0, 0, This->backbuffer->levels[0].ddsd.dwWidth, This->backbuffer->levels[0].ddsd.dwHeight);
|
2112 | 2172 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2113 | 2173 | glUtil_SetScissor(This->util, FALSE, 0, 0, 0, 0);
|
2114 | 2174 | glUtil_SetTexture(This->util, 0, texture);
|
Index: ddraw/glRenderer.h |
— | — | @@ -95,6 +95,8 @@ |
96 | 96 | #define OP_SETTEXTURESURFACEDESC 28
|
97 | 97 | #define OP_SETSHADER2D 29
|
98 | 98 | #define OP_SETSHADER 30
|
| 99 | +#define OP_SETRENDERTARGET 31
|
| 100 | +#define OP_SETVIEWPORT 32
|
99 | 101 |
|
100 | 102 | extern const DWORD renderstate_default[153];
|
101 | 103 | extern const TEXTURESTAGE texstagedefault0;
|
— | — | @@ -125,8 +127,6 @@ |
126 | 128 | unsigned int frequency;
|
127 | 129 | DXGLTimer timer;
|
128 | 130 | glTexture *backbuffer;
|
129 | | - int backx;
|
130 | | - int backy;
|
131 | 131 | DWORD fogcolor;
|
132 | 132 | GLfloat fogstart;
|
133 | 133 | GLfloat fogend;
|
Index: ddraw/struct.h |
— | — | @@ -453,8 +453,8 @@ |
454 | 454 | glTexture *zbuffer;
|
455 | 455 | GLint level;
|
456 | 456 | GLint zlevel;
|
457 | | - float mulx;
|
458 | | - float muly;
|
| 457 | + GLfloat mulx;
|
| 458 | + GLfloat muly;
|
459 | 459 | } RenderTarget;
|
460 | 460 |
|
461 | 461 | typedef struct GLCAPS
|
— | — | @@ -476,4 +476,12 @@ |
477 | 477 | __int64 texstageid[8];
|
478 | 478 | } SHADERSTATE;
|
479 | 479 |
|
| 480 | +typedef struct VIEWPORT
|
| 481 | +{
|
| 482 | + GLint x;
|
| 483 | + GLint y;
|
| 484 | + GLsizei width;
|
| 485 | + GLsizei hieght;
|
| 486 | +} VIEWPORT;
|
| 487 | +
|
480 | 488 | #endif //__STRUCT_H |
\ No newline at end of file |
Index: ddraw/struct_command.h |
— | — | @@ -236,7 +236,7 @@ |
237 | 237 | DWORD size;
|
238 | 238 | int type; // 0 for builtin, 1 for 2D, 2 for 3D (INVALID, use full command)
|
239 | 239 | __int64 id;
|
240 | | -};
|
| 240 | +} SetShader2DCmd;
|
241 | 241 | typedef struct SetShaderCmd
|
242 | 242 | {
|
243 | 243 | DWORD opcode;
|
— | — | @@ -244,8 +244,25 @@ |
245 | 245 | int type; // 0 for builtin, 1 for 2D, 2 for 3D
|
246 | 246 | __int64 id;
|
247 | 247 | __int64 texstate[8];
|
248 | | -};
|
| 248 | +} SetShaderCmd;
|
| 249 | +typedef struct SetRenderTargetCmd
|
| 250 | +{
|
| 251 | + DWORD opcode;
|
| 252 | + DWORD size;
|
| 253 | + RenderTarget target;
|
| 254 | +} SetRenderTargetCmd;
|
| 255 | +typedef struct SetViewportCmd
|
| 256 | +{
|
| 257 | + DWORD opcode;
|
| 258 | + DWORD size;
|
| 259 | + VIEWPORT viewport;
|
| 260 | +} SetViewportCmd;
|
249 | 261 |
|
| 262 | +typedef struct BltVertex_STORAGE_Cmd // Store vertices in stack for Blt()
|
| 263 | +{
|
| 264 | + BltVertex vertex[4];
|
| 265 | + WORD index[64];
|
| 266 | +} BltVertex_STORAGE_Cmd;
|
250 | 267 | typedef struct MIN_STORAGE_Cmd
|
251 | 268 | {
|
252 | 269 | BYTE data[256];
|
— | — | @@ -281,6 +298,9 @@ |
282 | 299 | SetTextureSurfaceDescCmd SetTextureSurfaceDesc;
|
283 | 300 | SetShader2DCmd SetShader2D;
|
284 | 301 | SetShaderCmd SetShader;
|
| 302 | + SetRenderTargetCmd SetRenderTarget;
|
| 303 | + SetViewportCmd SetViewport;
|
| 304 | + BltVertex_STORAGE_Cmd BltVertex_STORAGE;
|
285 | 305 | MIN_STORAGE_CMD MIN_STORAGE;
|
286 | 306 | } QueueCmd;
|
287 | 307 |
|
— | — | @@ -289,6 +309,8 @@ |
290 | 310 | CommandBuffer *cmd;
|
291 | 311 | QueueCmd last_cmd;
|
292 | 312 | BYTE *last_cmd_start;
|
| 313 | + RenderTarget target;
|
| 314 | + VIEWPORT viewport;
|
293 | 315 | } RenderState;
|
294 | 316 |
|
295 | 317 | #endif //__STRUCT_COMMAND_H |
\ No newline at end of file |