DXGL r691 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r690‎ | r691 | r692 >
Date:02:16, 24 December 2016
Author:admin
Status:new
Tags:
Comment:
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/struct.h (modified) (history)
  • /ddraw/struct_command.h (modified) (history)
  • /ddraw/util.c (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -27,6 +27,7 @@
2828 #include "ShaderGen3D.h"
2929 #include "matrix.h"
3030 #include "util.h"
 31+#include <stdarg.h>
3132
3233 extern "C" {
3334
@@ -132,6 +133,445 @@
133134 }
134135
135136 /**
 137+ * Check buffer for SetUniformCmd command and post it if it would overflow
 138+ * @param This
 139+ * Pointer to glRenderer object
 140+ * @param cmd
 141+ * Command to check, will be reinitialized if posted
 142+ * @param ptr
 143+ * Address of SetUniformCmdData pointer, will be updated if command is posted
 144+ * @param buffer_size
 145+ * Size of buffer holding command
 146+ * @param request_size
 147+ * Size of buffer to be requested
 148+ * @param inner
 149+ * Inner parameter for glRenderer_AddCommand if command is posted
 150+ * @return
 151+ * TRUE if command gets posted and reinitialized
 152+ */
 153+BOOL check_uniform_cmd_buffer(glRenderer *This, SetUniformCmd *cmd, SetUniformCmdData **ptr, DWORD buffer_size, DWORD request_size, BOOL inner)
 154+{
 155+ if (request_size > buffer_size)
 156+ {
 157+ glRenderer_AddCommand(This, (QueueCmd*)cmd, inner, FALSE);
 158+ cmd->size = sizeof(SetUniformCmdBase) - 8;
 159+ cmd->tmp_ptr = (BYTE*)&cmd->data;
 160+ cmd->count = 0;
 161+ *ptr = (SetUniformCmdData*)cmd->tmp_ptr;
 162+ return TRUE;
 163+ }
 164+ else return FALSE;
 165+}
 166+
 167+/**
 168+* Check buffer for SetAttribCmd command and post it if it would overflow
 169+* @param This
 170+* Pointer to glRenderer object
 171+* @param cmd
 172+* Command to check, will be reinitialized if posted
 173+* @param ptr
 174+* Address of SetUniformCmdData pointer, will be updated if command is posted
 175+* @param buffer_size
 176+* Size of buffer holding command
 177+* @param request_size
 178+* Size of buffer to be requested
 179+* @param inner
 180+* Inner parameter for glRenderer_AddCommand if command is posted
 181+* @return
 182+* TRUE if command gets posted and reinitialized
 183+*/
 184+BOOL check_attrib_cmd_buffer(glRenderer *This, SetAttribCmd *cmd, DWORD buffer_size, DWORD request_size, BOOL inner)
 185+{
 186+ if (request_size > buffer_size)
 187+ {
 188+ glRenderer_AddCommand(This, (QueueCmd*)cmd, inner, FALSE);
 189+ cmd->size = sizeof(SetAttribCmdBase) - 8;
 190+ cmd->count = 0;
 191+ return TRUE;
 192+ }
 193+ else return FALSE;
 194+}
 195+
 196+
 197+/**
 198+ * Appends data to a SetUniformCmd command.
 199+ * The size, count, and tmp_ptr fields must be initialized before the first
 200+ * call to this function.
 201+ * @param This
 202+ * Pointer to glRenderer object
 203+ * @param cmd
 204+ * Pointer to SetUniformCmd command
 205+ * @param uniform
 206+ * GLSL uniform to modify
 207+ * For builtin shaders, this is the actual GLSL uniform.
 208+ * For generated shaders, this is the array offset of the generated structure for the uniform.
 209+ * @param type
 210+ * Encoded type for uniform, see struct_command.h for more info
 211+ * @param count
 212+ * Count for certain types of uniforms, color order for colorkey
 213+ * @param transpose
 214+ * Transpose parameter for matrix uniforms
 215+ * @param inner
 216+ * Inner parameter for glRenderer_AddCommand if buffer overflows
 217+ * @param buffer_size
 218+ * Size of the buffer containing the SetUniformCmd command
 219+ * @param data
 220+ * First value to pass to glUniform function
 221+ * @param ...
 222+ * Additional commands for certain glUniform functions
 223+ */
 224+void append_uniform_cmd(glRenderer *This, SetUniformCmd *cmd, GLint uniform, DWORD type, GLsizei count, BOOL transpose, BOOL inner, size_t buffer_size, DWORD_PTR data, ...)
 225+{
 226+ DWORD r, g, b, a;
 227+ DWORD *colorsizes;
 228+ DWORD *colorbits;
 229+ size_t size;
 230+ size_t multiplier;
 231+ SetUniformCmdData *uniform_ptr = (SetUniformCmdData*)cmd->tmp_ptr;
 232+ va_list va;
 233+ va_start(va, data);
 234+ switch (type)
 235+ {
 236+ case 0: // glUniform1i()
 237+ default:
 238+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 239+ cmd->size + 8 + sizeof(SetUniformCmdData), inner);
 240+ uniform_ptr->size = sizeof(SetUniformCmdData);
 241+ uniform_ptr->type = type;
 242+ uniform_ptr->data[0] = (GLint)data;
 243+ break;
 244+ case 1: // glUniform2i()
 245+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 246+ cmd->size + 8 + sizeof(SetUniformCmdData) + sizeof(GLint), inner);
 247+ uniform_ptr->size = sizeof(SetUniformCmdData) + sizeof(GLint);
 248+ uniform_ptr->type = type;
 249+ uniform_ptr->data[0] = (GLint)data;
 250+ uniform_ptr->data[1] = va_arg(va, GLint);
 251+ break;
 252+ case 2: // glUniform3i()
 253+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 254+ cmd->size + 8 + sizeof(SetUniformCmdData) + (2 * sizeof(GLint)), inner);
 255+ uniform_ptr->size = sizeof(SetUniformCmdData) + (2 * sizeof(GLint));
 256+ uniform_ptr->type = type;
 257+ uniform_ptr->data[0] = (GLint)data;
 258+ uniform_ptr->data[1] = va_arg(va, GLint);
 259+ uniform_ptr->data[2] = va_arg(va, GLint);
 260+ break;
 261+ case 3: // glUniform4i()
 262+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 263+ cmd->size + 8 + sizeof(SetUniformCmdData) + (3 * sizeof(GLint)), inner);
 264+ uniform_ptr->size = sizeof(SetUniformCmdData) + (3 * sizeof(GLint));
 265+ uniform_ptr->type = type;
 266+ uniform_ptr->data[0] = (GLint)data;
 267+ uniform_ptr->data[1] = va_arg(va, GLint);
 268+ uniform_ptr->data[2] = va_arg(va, GLint);
 269+ uniform_ptr->data[3] = va_arg(va, GLint);
 270+ break;
 271+ case 4: // glUniform1f()
 272+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 273+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + sizeof(GLfloat), inner);
 274+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + sizeof(GLfloat);
 275+ uniform_ptr->type = type;
 276+ *((GLfloat*)&uniform_ptr->data[0]) = (GLfloat)data;
 277+ break;
 278+ case 5: // glUniform2f()
 279+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 280+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + (2 * sizeof(GLfloat)), inner);
 281+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + (2 * sizeof(GLfloat));
 282+ uniform_ptr->type = type;
 283+ *((GLfloat*)&uniform_ptr->data[0]) = (GLfloat)data;
 284+ *((GLfloat*)&uniform_ptr->data[1]) = va_arg(va, GLfloat);
 285+ break;
 286+ case 6: // glUniform3f()
 287+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 288+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + (3 * sizeof(GLfloat)), inner);
 289+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + (3 * sizeof(GLfloat));
 290+ uniform_ptr->type = type;
 291+ *((GLfloat*)&uniform_ptr->data[0]) = (GLfloat)data;
 292+ *((GLfloat*)&uniform_ptr->data[1]) = va_arg(va, GLfloat);
 293+ *((GLfloat*)&uniform_ptr->data[2]) = va_arg(va, GLfloat);
 294+ break;
 295+ case 7: // glUniform4f()
 296+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 297+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + (4 * sizeof(GLfloat)), inner);
 298+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + (4 * sizeof(GLfloat));
 299+ uniform_ptr->type = type;
 300+ *((GLfloat*)&uniform_ptr->data[0]) = (GLfloat)data;
 301+ *((GLfloat*)&uniform_ptr->data[1]) = va_arg(va, GLfloat);
 302+ *((GLfloat*)&uniform_ptr->data[2]) = va_arg(va, GLfloat);
 303+ *((GLfloat*)&uniform_ptr->data[3]) = va_arg(va, GLfloat);
 304+ break;
 305+ case 8: // glUniform1ui()
 306+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 307+ uniform_ptr->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + sizeof(GLuint), inner);
 308+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + sizeof(GLuint);
 309+ uniform_ptr->type = type;
 310+ *((GLuint*)&uniform_ptr->data[0]) = (GLuint)data;
 311+ break;
 312+ case 9: // glUniform2ui()
 313+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 314+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + (2 * sizeof(GLuint)), inner);
 315+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + (2 * sizeof(GLuint));
 316+ uniform_ptr->type = type;
 317+ *((GLuint*)&uniform_ptr->data[0]) = (GLuint)data;
 318+ *((GLuint*)&uniform_ptr->data[1]) = va_arg(va, GLuint);
 319+ break;
 320+ case 10: // glUniform3ui()
 321+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 322+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + (3 * sizeof(GLuint)), inner);
 323+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + (3 * sizeof(GLuint));
 324+ uniform_ptr->type = type;
 325+ *((GLuint*)&uniform_ptr->data[0]) = (GLuint)data;
 326+ *((GLuint*)&uniform_ptr->data[1]) = va_arg(va, GLuint);
 327+ *((GLuint*)&uniform_ptr->data[2]) = va_arg(va, GLuint);
 328+ break;
 329+ case 11: // glUniform4ui()
 330+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 331+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) + (4 * sizeof(GLuint)), inner);
 332+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) + (4 * sizeof(GLuint));
 333+ uniform_ptr->type = type;
 334+ *((GLuint*)&uniform_ptr->data[0]) = (GLuint)data;
 335+ *((GLuint*)&uniform_ptr->data[1]) = va_arg(va, GLuint);
 336+ *((GLuint*)&uniform_ptr->data[2]) = va_arg(va, GLuint);
 337+ *((GLuint*)&uniform_ptr->data[3]) = va_arg(va, GLuint);
 338+ break;
 339+ case 16: // glUniform1iv()
 340+ case 17: // glUniform12v()
 341+ case 18: // glUniform13v()
 342+ case 19: // glUniform14v()
 343+ multiplier = (type & 3) - 1;
 344+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 345+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) +
 346+ (multiplier * count * sizeof(GLint)), inner);
 347+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) +
 348+ (multiplier * count * sizeof(GLint));
 349+ uniform_ptr->type = type;
 350+ uniform_ptr->count = count;
 351+ memcpy(uniform_ptr->data, (GLint*)data, (multiplier * count * sizeof(GLint)));
 352+ break;
 353+ case 20: // glUniform1fv()
 354+ case 21: // glUniform2fv()
 355+ case 22: // glUniform3fv()
 356+ case 23: // glUniform4fv()
 357+ multiplier = (type & 3) - 1;
 358+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 359+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) +
 360+ (multiplier * count * sizeof(GLfloat)), inner);
 361+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) +
 362+ (multiplier * count * sizeof(GLfloat));
 363+ uniform_ptr->type = type;
 364+ uniform_ptr->count = count;
 365+ memcpy(uniform_ptr->data, (GLfloat*)data, (multiplier * count * sizeof(GLfloat)));
 366+ break;
 367+ case 24: // glUniform1uiv()
 368+ case 25: // glUniform2uiv()
 369+ case 26: // glUniform3uiv()
 370+ case 27: // glUniform4uiv()
 371+ multiplier = (type & 3) - 1;
 372+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 373+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) +
 374+ (multiplier * count * sizeof(GLint)), inner);
 375+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) +
 376+ (multiplier * count * sizeof(GLint));
 377+ uniform_ptr->type = type;
 378+ uniform_ptr->count = count;
 379+ memcpy(uniform_ptr->data, (GLint*)data, (multiplier * count * sizeof(GLint)));
 380+ break;
 381+ case 33: // glUniformMatrix2fv()
 382+ case 34: // glUniformMatrix3fv()
 383+ case 35: // glUniformMatrix4fv()
 384+ if (type == 33) multiplier = 4;
 385+ else if (type == 34) multiplier = 9;
 386+ else if (type == 35) multiplier = 16;
 387+ check_uniform_cmd_buffer(This, cmd, &uniform_ptr, buffer_size,
 388+ cmd->size + 8 + sizeof(SetUniformCmdData) - sizeof(GLint) +
 389+ (multiplier * count * sizeof(GLfloat)), inner);
 390+ uniform_ptr->size = sizeof(SetUniformCmdData) - sizeof(GLint) +
 391+ (multiplier * count * sizeof(GLfloat));
 392+ uniform_ptr->type = type;
 393+ uniform_ptr->count = count;
 394+ uniform_ptr->transpose = transpose;
 395+ memcpy(uniform_ptr->data, (GLfloat*)data, (multiplier * count * sizeof(GLfloat)));
 396+ break;
 397+ case 256: // Color key, uses glUniform3i() or glUniform4i()
 398+ colorsizes = va_arg(va, DWORD*);
 399+ colorbits = va_arg(va, DWORD*);
 400+ switch (count)
 401+ {
 402+ case 0:
 403+ r = data & colorsizes[0];
 404+ data >>= colorbits[0];
 405+ g = data & colorsizes[1];
 406+ data >>= colorbits[1];
 407+ b = data & colorsizes[2];
 408+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, g, b);
 409+ break;
 410+ case 1:
 411+ b = data & colorsizes[2];
 412+ data >>= colorbits[2];
 413+ g = data & colorsizes[1];
 414+ data >>= colorbits[1];
 415+ r = data & colorsizes[0];
 416+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, g, b);
 417+ break;
 418+ case 2:
 419+ a = data & colorsizes[3];
 420+ data >>= colorbits[3];
 421+ r = data & colorsizes[0];
 422+ data >>= colorbits[0];
 423+ g = data & colorsizes[1];
 424+ data >>= colorbits[1];
 425+ b = data & colorsizes[2];
 426+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, g, b);
 427+ break;
 428+ case 3:
 429+ a = data & colorsizes[3];
 430+ data >>= colorbits[3];
 431+ b = data & colorsizes[2];
 432+ data >>= colorbits[2];
 433+ g = data & colorsizes[1];
 434+ data >>= colorbits[1];
 435+ r = data & colorsizes[0];
 436+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, g, b);
 437+ break;
 438+ case 4:
 439+ r = data & colorsizes[0];
 440+ if (This->ext->glver_major >= 3)
 441+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, 0, 0);
 442+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, r, r);
 443+ break;
 444+ case 5:
 445+ r = data & colorsizes[0];
 446+ append_uniform_cmd(This, cmd, uniform, 2, 0, FALSE, inner, buffer_size, r, r, r);
 447+ break;
 448+ case 6:
 449+ a = data & colorsizes[3];
 450+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, 0, 0, 0, a);
 451+ break;
 452+ case 7:
 453+ r = data & colorsizes[0];
 454+ data >>= colorbits[0];
 455+ a = data & colorsizes[3];
 456+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, r, r, a);
 457+ break;
 458+ }
 459+ va_end(va);
 460+ return;
 461+ case 257:
 462+ colorsizes = va_arg(va, DWORD*);
 463+ colorbits = va_arg(va, DWORD*);
 464+ switch (count)
 465+ {
 466+ case 0:
 467+ r = data & colorsizes[0];
 468+ data >>= colorbits[0];
 469+ g = data & colorsizes[1];
 470+ data >>= colorbits[1];
 471+ b = data & colorsizes[2];
 472+ data >>= colorbits[2];
 473+ a = data & colorsizes[3];
 474+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, g, b, a);
 475+ break;
 476+ case 1:
 477+ b = data & colorsizes[2];
 478+ data >>= colorbits[2];
 479+ g = data & colorsizes[1];
 480+ data >>= colorbits[1];
 481+ r = data & colorsizes[0];
 482+ data >>= colorbits[0];
 483+ a = data & colorsizes[3];
 484+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, g, b, a);
 485+ break;
 486+ case 2:
 487+ a = data & colorsizes[3];
 488+ data >>= colorbits[3];
 489+ r = data & colorsizes[0];
 490+ data >>= colorbits[0];
 491+ g = data & colorsizes[1];
 492+ data >>= colorbits[1];
 493+ b = data & colorsizes[2];
 494+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, g, b, a);
 495+ break;
 496+ case 3:
 497+ a = data & colorsizes[3];
 498+ data >>= colorbits[3];
 499+ b = data & colorsizes[2];
 500+ data >>= colorbits[2];
 501+ g = data & colorsizes[1];
 502+ data >>= colorbits[1];
 503+ r = data & colorsizes[0];
 504+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, g, b, a);
 505+ break;
 506+ case 4:
 507+ r = data & colorsizes[0];
 508+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, r, r, r);
 509+ break;
 510+ case 5:
 511+ r = data & colorsizes[0];
 512+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, r, r, r);
 513+ break;
 514+ case 6:
 515+ a = data & colorsizes[3];
 516+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, a, a, a, a);
 517+ break;
 518+ case 7:
 519+ r = data & colorsizes[0];
 520+ data >>= colorbits[0];
 521+ a = data & colorsizes[3];
 522+ append_uniform_cmd(This, cmd, uniform, 3, 0, FALSE, inner, buffer_size, r, r, r, a);
 523+ break;
 524+ }
 525+ va_end(va);
 526+ return;
 527+ }
 528+ cmd->size += uniform_ptr->size;
 529+ cmd->tmp_ptr += uniform_ptr->size;
 530+ cmd->count++;
 531+ va_end(va);
 532+}
 533+
 534+
 535+/**
 536+ * Appends data to a SetAttribCmd command.
 537+ * The size, count, and tmp_ptr fields must be initialized before the first
 538+ * call to this function.
 539+ * @param This
 540+ * Pointer to glRenderer object
 541+ * @param cmd
 542+ * Pointer to SetAttribCmd command
 543+ * @param attrib
 544+ * GLSL attribute to set up
 545+ * For builtin shaders, this is the actual GLSL attribute.
 546+ * For generated shaders, this is the array offset of the generated structure for the attribute.
 547+ * @param size
 548+ * Number of components per attribute, or GL_BGRA
 549+ * @param type
 550+ * Type of components in the attribute
 551+ * @param normalized
 552+ * Whether or not integer types are normalized to -1 to 1 for signed, 0 to 1 for unsinged.
 553+ * @param stride
 554+ * Number of bytes between the beginning of one attribute element and the beginning of the next.
 555+ * @param inner
 556+ * Inner parameter for glRenderer_AddCommand if buffer overflows
 557+ * @param buffer_size
 558+ * Size of the buffer containing the SetAttribCmd command
 559+ */
 560+void append_attrib_cmd(glRenderer *This, SetAttribCmd *cmd, GLuint attrib, GLint size,
 561+ GLint type, GLboolean normalized, GLsizei stride, const GLvoid *pointer, BOOL inner, size_t buffer_size)
 562+{
 563+ check_attrib_cmd_buffer(This, cmd, buffer_size, cmd->size + sizeof(SetAttribCmdBase), inner);
 564+ cmd->attrib[cmd->count].index = attrib;
 565+ cmd->attrib[cmd->count].size = size;
 566+ cmd->attrib[cmd->count].type = type;
 567+ cmd->attrib[cmd->count].normalized = normalized;
 568+ cmd->attrib[cmd->count].stride = stride;
 569+ cmd->attrib[cmd->count].ptr = pointer;
 570+ cmd->size += sizeof(SetAttribCmdBase);
 571+ cmd->count++;
 572+}
 573+
 574+const WORD indexbase[6] = { 0,1,2,2,3,0 };
 575+/**
136576 * Adds a command to the active command buffer.
137577 * @param This
138578 * Pointer to glRenderer object
@@ -159,6 +599,7 @@
160600 int screenx, screeny;
161601 LONG_PTR winstyle, winstyleex;
162602 BOOL restart_cmd = FALSE;
 603+ __int64 shaderid;
163604 if (!inner) EnterCriticalSection(&This->cs);
164605 switch (cmd->Generic.opcode)
165606 {
@@ -224,12 +665,87 @@
225666 {
226667 if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 2) restart_cmd = TRUE;
227668 }
 669+ // Check if buffer can accomodate command
 670+ if(!restart_cmd) restart_cmd = CheckCmdBuffer(This, 0, 0, 4 * sizeof(BltVertex), 6 * sizeof(WORD));
228671 if(!restart_cmd)
229672 {
 673+ Vertex2DCmd *lastcmd = (Vertex2DCmd*)((BYTE*)(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd));
 674+ int rotates = 0;
 675+ // cmdout.flags & 1 = usedest
230676 // Generate vertices
 677+ if (!memcmp(&cmd->Blt.cmd.srcrect, &nullrect, sizeof(RECT)))
 678+ {
 679+ r1.left = r1.top = 0;
 680+ if (cmd->Blt.cmd.src)
 681+ {
 682+ r1.right = cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwWidth;
 683+ r1.bottom = cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwHeight;
 684+ }
 685+ else r1.right = r1.bottom = 0;
 686+ }
 687+ else r1 = cmd->Blt.cmd.srcrect;
 688+ if (!memcmp(&cmd->Blt.cmd.destrect, &nullrect, sizeof(RECT)))
 689+ {
 690+ r2.left = r2.top = 0;
 691+ r2.right = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 692+ r2.bottom = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 693+ }
 694+ else r2 = cmd->Blt.cmd.destrect;
 695+ tmp_cmd.BltVertex_STORAGE.vertex[1].x = tmp_cmd.BltVertex_STORAGE.vertex[3].x = (GLfloat)r2.left;
 696+ tmp_cmd.BltVertex_STORAGE.vertex[0].x = tmp_cmd.BltVertex_STORAGE.vertex[2].x = (GLfloat)r2.right;
 697+ tmp_cmd.BltVertex_STORAGE.vertex[0].y = tmp_cmd.BltVertex_STORAGE.vertex[1].y = (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight - (GLfloat)r2.top;
 698+ tmp_cmd.BltVertex_STORAGE.vertex[2].y = tmp_cmd.BltVertex_STORAGE.vertex[3].y = (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight - (GLfloat)r2.bottom;
 699+ tmp_cmd.BltVertex_STORAGE.vertex[1].s = tmp_cmd.BltVertex_STORAGE.vertex[3].s = (GLfloat)r1.left / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwWidth;
 700+ tmp_cmd.BltVertex_STORAGE.vertex[0].s = tmp_cmd.BltVertex_STORAGE.vertex[2].s = (GLfloat)r1.right / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwWidth;
 701+ tmp_cmd.BltVertex_STORAGE.vertex[0].t = tmp_cmd.BltVertex_STORAGE.vertex[1].t = (GLfloat)r1.top / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwHeight;
 702+ tmp_cmd.BltVertex_STORAGE.vertex[2].t = tmp_cmd.BltVertex_STORAGE.vertex[3].t = (GLfloat)r1.bottom / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwHeight;
 703+ if (lastcmd->flags & 1)
 704+ {
 705+ tmp_cmd.BltVertex_STORAGE.vertex[1].dests =
 706+ tmp_cmd.BltVertex_STORAGE.vertex[3].dests = 0.;
 707+ tmp_cmd.BltVertex_STORAGE.vertex[0].dests =
 708+ tmp_cmd.BltVertex_STORAGE.vertex[2].dests = (GLfloat)(r1.right - r1.left) / (GLfloat)This->backbuffer->levels[0].ddsd.dwWidth;
 709+ tmp_cmd.BltVertex_STORAGE.vertex[0].destt =
 710+ tmp_cmd.BltVertex_STORAGE.vertex[1].destt = 1.;
 711+ tmp_cmd.BltVertex_STORAGE.vertex[2].destt =
 712+ tmp_cmd.BltVertex_STORAGE.vertex[3].destt = 1.0 - ((GLfloat)(r1.bottom - r1.top) / (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight);
 713+ }
 714+ if (cmd->Blt.cmd.flags & 0x10000000)
 715+ {
 716+ tmp_cmd.BltVertex_STORAGE.vertex[1].stencils = tmp_cmd.BltVertex_STORAGE.vertex[3].stencils = tmp_cmd.BltVertex_STORAGE.vertex[1].x / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 717+ tmp_cmd.BltVertex_STORAGE.vertex[0].stencils = tmp_cmd.BltVertex_STORAGE.vertex[2].stencils = tmp_cmd.BltVertex_STORAGE.vertex[0].x / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 718+ tmp_cmd.BltVertex_STORAGE.vertex[0].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[1].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[0].y / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 719+ tmp_cmd.BltVertex_STORAGE.vertex[2].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[3].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[2].y / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 720+ }
231721 // Rotate vertices if necessary
 722+ if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_DDFX))
 723+ {
 724+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
 725+ BltFlipLR(tmp_cmd.BltVertex_STORAGE.vertex);
 726+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_MIRRORUPDOWN)
 727+ BltFlipUD(tmp_cmd.BltVertex_STORAGE.vertex);
 728+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_ROTATE90) rotates++;
 729+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_ROTATE180) rotates += 2;
 730+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_ROTATE270) rotates += 3;
 731+ rotates &= 3;
 732+ if (rotates)
 733+ {
 734+ RotateBlt90(tmp_cmd.BltVertex_STORAGE.vertex, rotates);
 735+ }
 736+ }
232737 // Write vertices to VBO
 738+ memcpy(tmp_cmd.BltVertex_STORAGE.index, indexbase, 6 * sizeof(WORD));
 739+ for (i = 0; i < 6; i++)
 740+ tmp_cmd.BltVertex_STORAGE.index[i] += lastcmd->count;
 741+ memcpy(This->state.cmd->vertices->pointer + This->state.cmd->write_ptr_vertex,
 742+ tmp_cmd.BltVertex_STORAGE.vertex, 4 * sizeof(BltVertex));
 743+ memcpy(This->state.cmd->indices->pointer + This->state.cmd->write_ptr_index,
 744+ tmp_cmd.BltVertex_STORAGE.index, 6 * sizeof(WORD));
 745+ This->state.cmd->write_ptr_vertex += 4 * sizeof(BltVertex);
 746+ This->state.cmd->write_ptr_index += 6 * sizeof(WORD);
233747 // Update command in buffer
 748+ lastcmd->count += 4;
 749+ lastcmd->indexcount += 6;
234750 }
235751
236752 }
@@ -238,6 +754,7 @@
239755 BOOL usedest = FALSE;
240756 BOOL usepattern = FALSE;
241757 BOOL usetexture = FALSE;
 758+ int rotates = 0;
242759 if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
243760 {
244761 if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
@@ -265,19 +782,19 @@
266783 if (newdesc.dwWidth < r1.right) newdesc.dwWidth = r1.right;
267784 if (newdesc.dwHeight < r1.bottom) newdesc.dwHeight = r1.bottom;
268785 tmp_cmd.SetTextureSurfaceDesc.opcode = OP_SETTEXTURESURFACEDESC;
269 - tmp_cmd.SetTextureSurfaceDesc.size = sizeof(SetTextureSurfaceDescCmd);
 786+ tmp_cmd.SetTextureSurfaceDesc.size = sizeof(SetTextureSurfaceDescCmd) - 8;
270787 tmp_cmd.SetTextureSurfaceDesc.level = 0;
271788 tmp_cmd.SetTextureSurfaceDesc.desc = newdesc;
272789 glRenderer_AddCommand(This, &tmp_cmd, TRUE, TRUE);
273790 }
274791 tmp_cmd.Blt.opcode = OP_BLT;
275 - tmp_cmd.Blt.size = sizeof(BltCmd);
 792+ tmp_cmd.Blt.size = sizeof(BltCmd) - 8;
276793 tmp_cmd.Blt.cmd.flags = 0;
277794 tmp_cmd.Blt.cmd.destrect = r1;
278795 tmp_cmd.Blt.cmd.srcrect = cmd->Blt.cmd.destrect;
279796 tmp_cmd.Blt.cmd.src = cmd->Blt.cmd.dest;
280797 tmp_cmd.Blt.cmd.dest = This->backbuffer;
281 - tmp_cmd.Blt.cmd.srclevel = cmd->Blt.cmd.srclevel;
 798+ tmp_cmd.Blt.cmd.srclevel = cmd->Blt.cmd.destlevel;
282799 tmp_cmd.Blt.cmd.destlevel = 0;
283800 glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
284801 }
@@ -284,7 +801,7 @@
285802 // Set Src texture (Unit 8)
286803 i = -1;
287804 tmp_cmd.SetTexture.opcode = OP_SETTEXTURE;
288 - tmp_cmd.SetTexture.size = sizeof(SetTextureCmd) - (sizeof(DWORD) + sizeof(glTexture*));
 805+ tmp_cmd.SetTexture.size = sizeof(SetTextureCmd) - (sizeof(DWORD) + sizeof(glTexture*)) - 8;
289806 if (cmd->Blt.cmd.src)
290807 {
291808 tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
@@ -320,21 +837,95 @@
321838 tmp_cmd.SetTexture.texstage[i].stage = 11;
322839 tmp_cmd.SetTexture.texstage[i].texture = cmd->Blt.cmd.dest->stencil;
323840 }
 841+ tmp_cmd.SetTexture.count = i + 1;
324842 if(usetexture) glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
325 - // Set shader mode and params
 843+ // Set shader
326844 tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
327 - tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd);
 845+ tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd) - 8;
328846 tmp_cmd.SetShader2D.type = 1;
329847 if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
330848 tmp_cmd.SetShader2D.id = PackROPBits(cmd->Blt.cmd.bltfx.dwROP, cmd->Blt.cmd.flags);
331849 else tmp_cmd.SetShader2D.id = cmd->Blt.cmd.flags & 0xF2FAADFF;
332850 glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 851+ // Set shader uniforms
 852+ tmp_cmd.SetUniform.opcode = OP_SETUNIFORM;
 853+ tmp_cmd.SetUniform.size = 0;
 854+ SetUniformCmdData *uniform_ptr = &tmp_cmd.SetUniform.data;
 855+ tmp_cmd.SetUniform.size = sizeof(SetUniformCmdBase) - 8;
 856+ tmp_cmd.SetUniform.tmp_ptr = (BYTE*)&tmp_cmd.SetUniform.data;
 857+ tmp_cmd.SetUniform.count = 0;
 858+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 0, 7, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD),
 859+ 0.0f, (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth,
 860+ 0.0f, (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight);
 861+ if (!(cmd->Blt.cmd.flags & DDBLT_COLORFILL))
 862+ {
 863+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 1, 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 8);
 864+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 10, 19, 1, FALSE, TRUE, sizeof(MIN_STORAGE_CMD),
 865+ (DWORD_PTR)&cmd->Blt.cmd.src->colorsizes[0]);
 866+ }
 867+ if (usedest)
 868+ {
 869+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 2, 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 9);
 870+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 11, 19, 1, FALSE, TRUE, sizeof(MIN_STORAGE_CMD),
 871+ (DWORD_PTR)&cmd->Blt.cmd.dest->colorsizes[0]);
 872+ }
 873+ if (usepattern)
 874+ {
 875+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 3, 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 10);
 876+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 9, 1, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD),
 877+ cmd->Blt.cmd.pattern->levels[cmd->Blt.cmd.patternlevel].ddsd.dwWidth,
 878+ cmd->Blt.cmd.pattern->levels[cmd->Blt.cmd.patternlevel].ddsd.dwHeight);
 879+ }
 880+ if (cmd->Blt.cmd.dest->stencil)
 881+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 4, 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 11);
 882+ if ((cmd->Blt.cmd.flags & DDBLT_KEYSRC) && (cmd->Blt.cmd.src &&
 883+ (cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwFlags & DDSD_CKSRCBLT))
 884+ && !(cmd->Blt.cmd.flags & DDBLT_COLORFILL))
 885+ {
 886+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 5, 256, cmd->Blt.cmd.src->colororder, FALSE, TRUE,
 887+ sizeof(MIN_STORAGE_CMD), cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue,
 888+ cmd->Blt.cmd.src->colorsizes, cmd->Blt.cmd.src->colorbits);
 889+ if(cmd->Blt.cmd.flags & 0x20000000)
 890+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 7, 256, cmd->Blt.cmd.src->colororder, FALSE, TRUE,
 891+ sizeof(MIN_STORAGE_CMD), cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue,
 892+ cmd->Blt.cmd.src->colorsizes, cmd->Blt.cmd.src->colorbits);
 893+ }
 894+ if ((cmd->Blt.cmd.flags & DDBLT_KEYDEST) && (This && (cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwFlags & DDSD_CKDESTBLT)))
 895+ {
 896+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 6, 256, cmd->Blt.cmd.dest->colororder, FALSE, TRUE,
 897+ sizeof(MIN_STORAGE_CMD), cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.ddckCKSrcBlt.dwColorSpaceLowValue,
 898+ cmd->Blt.cmd.dest->colorsizes, cmd->Blt.cmd.dest->colorbits);
 899+ if (cmd->Blt.cmd.flags & 0x40000000)
 900+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 8, 256, cmd->Blt.cmd.dest->colororder, FALSE, TRUE,
 901+ sizeof(MIN_STORAGE_CMD), cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.ddckCKSrcBlt.dwColorSpaceHighValue,
 902+ cmd->Blt.cmd.dest->colorsizes, cmd->Blt.cmd.dest->colorbits);
 903+ }
 904+ if (cmd->Blt.cmd.flags & DDBLT_COLORFILL)
 905+ append_uniform_cmd(This, &tmp_cmd.SetUniform, 12, 257, cmd->Blt.cmd.src->colororder, FALSE, TRUE,
 906+ sizeof(MIN_STORAGE_CMD), cmd->Blt.cmd.bltfx.dwFillColor,
 907+ cmd->Blt.cmd.src->colorsizes, cmd->Blt.cmd.src->colorbits);
 908+ // Set shader attributes
 909+ tmp_cmd.SetAttrib.opcode = OP_SETATTRIB;
 910+ tmp_cmd.SetAttrib.size = sizeof(SetAttribCmdBase) - 8;
 911+ tmp_cmd.SetAttrib.count = 0;
 912+ BltVertex *vertex = (BltVertex*)This->state.cmd->write_ptr_vertex;
 913+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, 0, 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &vertex->x,
 914+ TRUE, sizeof(MIN_STORAGE_CMD));
 915+ if (!(cmd->Blt.cmd.flags & DDBLT_COLORFILL))
 916+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, 3, 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &vertex->s,
 917+ TRUE, sizeof(MIN_STORAGE_CMD));
 918+ if(usedest)
 919+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, 4, 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &vertex->dests,
 920+ TRUE, sizeof(MIN_STORAGE_CMD));
 921+ if (cmd->Blt.cmd.flags & 0x10000000) // Use clipper
 922+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, 5, 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &vertex->stencils,
 923+ TRUE, sizeof(MIN_STORAGE_CMD));
333924 // Set render target
334925 if ((This->state.target.target != cmd->Blt.cmd.dest)
335926 || (This->state.target.level != cmd->Blt.cmd.destlevel))
336927 {
337928 tmp_cmd.SetRenderTarget.opcode = OP_SETRENDERTARGET;
338 - tmp_cmd.SetRenderTarget.size = sizeof(SetRenderTargetCmd);
 929+ tmp_cmd.SetRenderTarget.size = sizeof(SetRenderTargetCmd) - 8;
339930 tmp_cmd.SetRenderTarget.target.target = cmd->Blt.cmd.dest;
340931 tmp_cmd.SetRenderTarget.target.level = cmd->Blt.cmd.destlevel;
341932 tmp_cmd.SetRenderTarget.target.zbuffer = NULL;
@@ -363,14 +954,47 @@
364955 (This->state.viewport.width != r2.right) || (This->state.viewport.hieght != r2.bottom))
365956 {
366957 tmp_cmd.SetViewport.opcode = OP_SETVIEWPORT;
367 - tmp_cmd.SetViewport.size = sizeof(SetViewportCmd);
 958+ tmp_cmd.SetViewport.size = sizeof(SetViewportCmd) - 8;
368959 tmp_cmd.SetViewport.viewport.x = tmp_cmd.SetViewport.viewport.y = 0;
369960 tmp_cmd.SetViewport.viewport.width = r2.right;
370961 tmp_cmd.SetViewport.viewport.hieght = r2.bottom;
371962 glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
372963 }
 964+ // Disable depth test
 965+ if (This->state.depthtest)
 966+ {
 967+ tmp_cmd.SetDepthTest.opcode = OP_SETDEPTHTEST;
 968+ tmp_cmd.SetDepthTest.size = sizeof(SetDepthTestCmd);
 969+ tmp_cmd.SetDepthTest.enabled = FALSE;
 970+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 971+ }
373972 // Generate vertices
374 - /*tmp_cmd.BltVertex_STORAGE.vertex*/
 973+ if (!memcmp(&cmd->Blt.cmd.srcrect, &nullrect, sizeof(RECT)))
 974+ {
 975+ r1.left = r1.top = 0;
 976+ if (cmd->Blt.cmd.src)
 977+ {
 978+ r1.right = cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwWidth;
 979+ r1.bottom = cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwHeight;
 980+ }
 981+ else r1.right = r1.bottom = 0;
 982+ }
 983+ else r1 = cmd->Blt.cmd.srcrect;
 984+ if (!memcmp(&cmd->Blt.cmd.destrect, &nullrect, sizeof(RECT)))
 985+ {
 986+ r2.left = r2.top = 0;
 987+ r2.right = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 988+ r2.bottom = cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 989+ }
 990+ else r2 = cmd->Blt.cmd.destrect;
 991+ tmp_cmd.BltVertex_STORAGE.vertex[1].x = tmp_cmd.BltVertex_STORAGE.vertex[3].x = (GLfloat)r2.left;
 992+ tmp_cmd.BltVertex_STORAGE.vertex[0].x = tmp_cmd.BltVertex_STORAGE.vertex[2].x = (GLfloat)r2.right;
 993+ tmp_cmd.BltVertex_STORAGE.vertex[0].y = tmp_cmd.BltVertex_STORAGE.vertex[1].y = (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight - (GLfloat)r2.top;
 994+ tmp_cmd.BltVertex_STORAGE.vertex[2].y = tmp_cmd.BltVertex_STORAGE.vertex[3].y = (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight - (GLfloat)r2.bottom;
 995+ tmp_cmd.BltVertex_STORAGE.vertex[1].s = tmp_cmd.BltVertex_STORAGE.vertex[3].s = (GLfloat)r1.left / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwWidth;
 996+ tmp_cmd.BltVertex_STORAGE.vertex[0].s = tmp_cmd.BltVertex_STORAGE.vertex[2].s = (GLfloat)r1.right / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwWidth;
 997+ tmp_cmd.BltVertex_STORAGE.vertex[0].t = tmp_cmd.BltVertex_STORAGE.vertex[1].t = (GLfloat)r1.top / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwHeight;
 998+ tmp_cmd.BltVertex_STORAGE.vertex[2].t = tmp_cmd.BltVertex_STORAGE.vertex[3].t = (GLfloat)r1.bottom / (GLfloat)cmd->Blt.cmd.src->levels[cmd->Blt.cmd.srclevel].ddsd.dwHeight;
375999 if (usedest)
3761000 {
3771001 tmp_cmd.BltVertex_STORAGE.vertex[1].dests =
@@ -382,38 +1006,351 @@
3831007 tmp_cmd.BltVertex_STORAGE.vertex[2].destt =
3841008 tmp_cmd.BltVertex_STORAGE.vertex[3].destt = 1.0 - ((GLfloat)(r1.bottom - r1.top) / (GLfloat)This->backbuffer->levels[0].ddsd.dwHeight);
3851009 }
 1010+ if (cmd->Blt.cmd.flags & 0x10000000)
 1011+ {
 1012+ tmp_cmd.BltVertex_STORAGE.vertex[1].stencils = tmp_cmd.BltVertex_STORAGE.vertex[3].stencils = tmp_cmd.BltVertex_STORAGE.vertex[1].x / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 1013+ tmp_cmd.BltVertex_STORAGE.vertex[0].stencils = tmp_cmd.BltVertex_STORAGE.vertex[2].stencils = tmp_cmd.BltVertex_STORAGE.vertex[0].x / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwWidth;
 1014+ tmp_cmd.BltVertex_STORAGE.vertex[0].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[1].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[0].y / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 1015+ tmp_cmd.BltVertex_STORAGE.vertex[2].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[3].stencilt = tmp_cmd.BltVertex_STORAGE.vertex[2].y / (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight;
 1016+ }
3861017 // Rotate vertices if necessary
 1018+ if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_DDFX))
 1019+ {
 1020+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_MIRRORLEFTRIGHT)
 1021+ BltFlipLR(tmp_cmd.BltVertex_STORAGE.vertex);
 1022+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_MIRRORUPDOWN)
 1023+ BltFlipUD(tmp_cmd.BltVertex_STORAGE.vertex);
 1024+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_ROTATE90) rotates++;
 1025+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_ROTATE180) rotates += 2;
 1026+ if (cmd->Blt.cmd.bltfx.dwDDFX & DDBLTFX_ROTATE270) rotates += 3;
 1027+ rotates &= 3;
 1028+ if (rotates)
 1029+ {
 1030+ RotateBlt90(tmp_cmd.BltVertex_STORAGE.vertex, rotates);
 1031+ }
 1032+ }
 1033+ // Create command and check buffers
 1034+ Vertex2DCmd cmdout;
 1035+ cmdout.opcode = OP_VERTEX2D;
 1036+ cmdout.size = sizeof(Vertex2DCmd) - 8;
 1037+ cmdout.count = 4;
 1038+ cmdout.indexcount = 6;
 1039+ if (usedest) cmdout.flags = 1;
 1040+ else cmdout.flags = 0;
 1041+ CheckCmdBuffer(This, cmdout.size + 8, 0, 4*sizeof(BltVertex), 6*sizeof(WORD));
3871042 // Write vertices to VBO
 1043+ cmdout.offset = This->state.cmd->write_ptr_vertex;
 1044+ cmdout.indexoffset = This->state.cmd->write_ptr_index;
 1045+ memcpy(This->state.cmd->vertices->pointer + This->state.cmd->write_ptr_vertex,
 1046+ tmp_cmd.BltVertex_STORAGE.vertex, 4 * sizeof(BltVertex));
 1047+ memcpy(This->state.cmd->indices->pointer + This->state.cmd->write_ptr_index,
 1048+ indexbase, 6 * sizeof(WORD));
 1049+ This->state.cmd->write_ptr_vertex += 4 * sizeof(BltVertex);
 1050+ This->state.cmd->write_ptr_index += 6 * sizeof(WORD);
3881051 // Write command to buffer
 1052+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, &cmdout, cmdout.size + 8);
 1053+ This->state.cmd->write_ptr_cmd_modify = This->state.cmd->write_ptr_cmd;
 1054+ This->state.cmd->write_ptr_cmd += (cmdout.size + 8);
3891055 }
390 - error = DDERR_CURRENTLYNOTAVAIL;
 1056+ error = DD_OK;
3911057 break;
3921058 case OP_DRAWSCREEN: // Draws the screen. Flip command buffer after executing.
 1059+ // First get window dimensions and adjust renderer window if necessary
 1060+ if (cmd->DrawScreen.texture->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
 1061+ {
 1062+ GetClientRect(This->hWnd, &r1);
 1063+ GetClientRect(This->RenderWnd->GetHWnd(), &r2);
 1064+ if (memcmp(&r2, &r1, sizeof(RECT)))
 1065+ SetWindowPos(This->RenderWnd->GetHWnd(), NULL, 0, 0, r1.right, r1.bottom, SWP_SHOWWINDOW);
 1066+ }
 1067+ LONG sizes[6];
 1068+ GLfloat view[4];
 1069+ GLint viewport[4];
 1070+ This->ddInterface->GetSizes(sizes);
 1071+ if (cmd->DrawScreen.texture->levels[0].ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
 1072+ {
 1073+ if (This->ddInterface->GetFullscreen())
 1074+ {
 1075+ viewport[0] = viewport[1] = 0;
 1076+ viewport[2] = sizes[4];
 1077+ viewport[3] = sizes[5];
 1078+ view[0] = (GLfloat)-(sizes[4] - sizes[0]) / 2;
 1079+ view[1] = (GLfloat)(sizes[4] - sizes[0]) / 2 + sizes[0];
 1080+ view[2] = (GLfloat)(sizes[5] - sizes[1]) / 2 + sizes[1];
 1081+ view[3] = (GLfloat)-(sizes[5] - sizes[1]) / 2;
 1082+ }
 1083+ else
 1084+ {
 1085+ viewport[0] = viewport[1] = 0;
 1086+ viewport[2] = r2.right;
 1087+ viewport[3] = r2.bottom;
 1088+ ClientToScreen(This->RenderWnd->GetHWnd(), (LPPOINT)&r2.left);
 1089+ ClientToScreen(This->RenderWnd->GetHWnd(), (LPPOINT)&r2.right);
 1090+ view[0] = (GLfloat)r2.left;
 1091+ view[1] = (GLfloat)r2.right;
 1092+ view[2] = (GLfloat)cmd->DrawScreen.texture->bigheight - (GLfloat)r2.top;
 1093+ view[3] = (GLfloat)cmd->DrawScreen.texture->bigheight - (GLfloat)r2.bottom;
 1094+ }
 1095+ }
 1096+ else
 1097+ {
 1098+ view[0] = 0;
 1099+ view[1] = (GLfloat)cmd->DrawScreen.texture->bigwidth;
 1100+ view[2] = 0;
 1101+ view[3] = (GLfloat)cmd->DrawScreen.texture->bigheight;
 1102+ }
 1103+ // Mark primary as front buffer and clear frontbuffer bit on previous
 1104+ tmp_cmd.SetFrontBufferBits.opcode = OP_SETFRONTBUFFERBITS;
 1105+ tmp_cmd.SetFrontBufferBits.size = sizeof(SetFrontBufferBitsCmd) - 8;
 1106+ tmp_cmd.SetFrontBufferBits.front = cmd->DrawScreen.texture;
 1107+ tmp_cmd.SetFrontBufferBits.back = cmd->DrawScreen.previous;
 1108+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1109+ // Set Src texture (Unit 8) to primary
 1110+ i = 0;
 1111+ tmp_cmd.SetTexture.opcode = OP_SETTEXTURE;
 1112+ tmp_cmd.SetTexture.size = sizeof(SetTextureCmd);
 1113+ tmp_cmd.SetTexture.texstage[0].stage = 8;
 1114+ tmp_cmd.SetTexture.texstage[0].texture = cmd->DrawScreen.texture;
 1115+ // Set Palette texture (Unit 9) to palette if 8-bit
 1116+ if (This->ddInterface->GetBPP() == 8)
 1117+ {
 1118+ i++;
 1119+ tmp_cmd.SetTexture.size += (sizeof(DWORD) + sizeof(glTexture*));
 1120+ tmp_cmd.SetTexture.texstage[1].stage = 9;
 1121+ tmp_cmd.SetTexture.texstage[1].texture = cmd->DrawScreen.paltex;
 1122+ }
 1123+ tmp_cmd.SetTexture.count = i + 1;
 1124+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1125+ // Disable depth test
 1126+ tmp_cmd.SetDepthTest.opcode = OP_SETDEPTHTEST;
 1127+ tmp_cmd.SetDepthTest.size = sizeof(SetDepthTestCmd) - 8;
 1128+ tmp_cmd.SetDepthTest.enabled = FALSE;
 1129+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
3931130 // If 8 bit scaled linear:
394 - // Set Src texture (Unit 8) to primary
395 - // Set Palette texture (Unit 9) to palette
396 - // Set shader mode and params
397 - // Set render target to backbuffer
398 - // Set viewport to backbuffer
399 - // Generate vertices
400 - // Write vertices to FBO
401 - // Write Palette draw command to buffer
402 - // Set Src texture (Unit 8) to backbuffer
403 - // Set shader mode and params
 1131+ if ((This->ddInterface->GetBPP() == 8) && (dxglcfg.scalingfilter) &&
 1132+ ((cmd->DrawScreen.texture->bigwidth != (view[1]-view[0])) ||
 1133+ (cmd->DrawScreen.texture->bigheight != (view[3]-view[2]))))
 1134+ {
 1135+ // Check backbuffer size and resize
 1136+ if ((This->backbuffer->levels[0].ddsd.dwWidth < cmd->DrawScreen.texture->bigwidth) ||
 1137+ (This->backbuffer->levels[0].ddsd.dwHeight < cmd->DrawScreen.texture->bigheight))
 1138+ {
 1139+ DDSURFACEDESC2 newdesc = This->backbuffer->levels[0].ddsd;
 1140+ if (newdesc.dwWidth < cmd->DrawScreen.texture->bigwidth)
 1141+ newdesc.dwWidth = cmd->DrawScreen.texture->bigwidth;
 1142+ if (newdesc.dwHeight < cmd->DrawScreen.texture->bigheight)
 1143+ newdesc.dwHeight = cmd->DrawScreen.texture->bigheight;
 1144+ tmp_cmd.SetTextureSurfaceDesc.opcode = OP_SETTEXTURESURFACEDESC;
 1145+ tmp_cmd.SetTextureSurfaceDesc.size = sizeof(SetTextureSurfaceDescCmd) - 8;
 1146+ tmp_cmd.SetTextureSurfaceDesc.level = 0;
 1147+ tmp_cmd.SetTextureSurfaceDesc.desc = newdesc;
 1148+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, TRUE);
 1149+ }
 1150+ // Set shader to 256-color palette
 1151+ tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
 1152+ tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd) - 8;
 1153+ tmp_cmd.SetShader2D.type = 0;
 1154+ tmp_cmd.SetShader2D.id = PROG_PAL256;
 1155+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1156+ // Set shader uniforms
 1157+ tmp_cmd.SetUniform.opcode = OP_SETUNIFORM;
 1158+ tmp_cmd.SetUniform.size = sizeof(SetUniformCmdBase) - 8;
 1159+ tmp_cmd.SetUniform.tmp_ptr = (BYTE*)&tmp_cmd.SetUniform.data;
 1160+ tmp_cmd.SetUniform.count = 0;
 1161+ append_uniform_cmd(This, &tmp_cmd.SetUniform, This->shaders->shaders[PROG_PAL256].tex0,
 1162+ 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 8);
 1163+ append_uniform_cmd(This, &tmp_cmd.SetUniform, This->shaders->shaders[PROG_PAL256].pal,
 1164+ 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 9);
 1165+ append_uniform_cmd(This, &tmp_cmd.SetUniform, This->shaders->shaders[PROG_PAL256].view,
 1166+ 7, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), view[0], view[1], view[2], view[3]);
 1167+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1168+ // Set shader attributes
 1169+ tmp_cmd.SetAttrib.opcode = OP_SETATTRIB;
 1170+ tmp_cmd.SetAttrib.size = sizeof(SetAttribCmdBase) - 8;
 1171+ tmp_cmd.SetAttrib.count = 0;
 1172+ BltVertex *vertex = (BltVertex*)This->state.cmd->write_ptr_vertex;
 1173+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, This->shaders->shaders[PROG_PAL256].pos, 2, GL_FLOAT, GL_FALSE,
 1174+ sizeof(BltVertex), &vertex->x, TRUE, sizeof(MIN_STORAGE_CMD));
 1175+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, This->shaders->shaders[PROG_PAL256].texcoord, 2, GL_FLOAT, GL_FALSE,
 1176+ sizeof(BltVertex), &vertex->s, TRUE, sizeof(MIN_STORAGE_CMD));
 1177+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1178+ // Set render target to backbuffer
 1179+ if ((This->state.target.target != This->backbuffer) || (This->state.target.target != 0))
 1180+ {
 1181+ tmp_cmd.SetRenderTarget.opcode = OP_SETRENDERTARGET;
 1182+ tmp_cmd.SetRenderTarget.size = sizeof(SetRenderTargetCmd) - 8;
 1183+ tmp_cmd.SetRenderTarget.target.target = This->backbuffer;
 1184+ tmp_cmd.SetRenderTarget.target.level = 0;
 1185+ tmp_cmd.SetRenderTarget.target.zbuffer = NULL;
 1186+ tmp_cmd.SetRenderTarget.target.zlevel = 0;
 1187+ tmp_cmd.SetRenderTarget.target.mulx = tmp_cmd.SetRenderTarget.target.muly = 1.0f;
 1188+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1189+ }
 1190+ // Set viewport to backbuffer
 1191+ r2.right = This->backbuffer->levels[0].ddsd.dwWidth;
 1192+ r2.bottom = This->backbuffer->levels[0].ddsd.dwHeight;
 1193+ if (This->state.viewport.x || This->state.viewport.y ||
 1194+ (This->state.viewport.width != r2.right) || (This->state.viewport.hieght != r2.bottom))
 1195+ {
 1196+ tmp_cmd.SetViewport.opcode = OP_SETVIEWPORT;
 1197+ tmp_cmd.SetViewport.size = sizeof(SetViewportCmd) - 8;
 1198+ tmp_cmd.SetViewport.viewport.x = tmp_cmd.SetViewport.viewport.y = 0;
 1199+ tmp_cmd.SetViewport.viewport.width = r2.right;
 1200+ tmp_cmd.SetViewport.viewport.hieght = r2.bottom;
 1201+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1202+ }
 1203+ // Generate vertices
 1204+ r2.left = r2.top = 0;
 1205+ r2.right = cmd->DrawScreen.texture->bigwidth;
 1206+ r2.bottom = cmd->DrawScreen.texture->bigheight;
 1207+ tmp_cmd.BltVertex_STORAGE.vertex[1].x = tmp_cmd.BltVertex_STORAGE.vertex[3].x = (GLfloat)r2.left;
 1208+ tmp_cmd.BltVertex_STORAGE.vertex[0].x = tmp_cmd.BltVertex_STORAGE.vertex[2].x = (GLfloat)r2.right;
 1209+ tmp_cmd.BltVertex_STORAGE.vertex[0].y = tmp_cmd.BltVertex_STORAGE.vertex[1].y = (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight - (GLfloat)r2.top;
 1210+ tmp_cmd.BltVertex_STORAGE.vertex[2].y = tmp_cmd.BltVertex_STORAGE.vertex[3].y = (GLfloat)cmd->Blt.cmd.dest->levels[cmd->Blt.cmd.destlevel].ddsd.dwHeight - (GLfloat)r2.bottom;
 1211+ tmp_cmd.BltVertex_STORAGE.vertex[1].s = tmp_cmd.BltVertex_STORAGE.vertex[3].s =
 1212+ tmp_cmd.BltVertex_STORAGE.vertex[0].t = tmp_cmd.BltVertex_STORAGE.vertex[1].t = 0.0f;
 1213+ tmp_cmd.BltVertex_STORAGE.vertex[0].s = tmp_cmd.BltVertex_STORAGE.vertex[2].s =
 1214+ tmp_cmd.BltVertex_STORAGE.vertex[2].t = tmp_cmd.BltVertex_STORAGE.vertex[3].t = 1.0f;
 1215+ // Create Palette draw command and check buffers
 1216+ Vertex2DCmd cmdout;
 1217+ cmdout.opcode = sizeof(Vertex2DCmd) - 8;
 1218+ cmdout.count = 4;
 1219+ cmdout.indexcount = 6;
 1220+ cmdout.flags = 0;
 1221+ CheckCmdBuffer(This, cmdout.size + 8, 0, 4 * sizeof(BltVertex), 6 * sizeof(WORD));
 1222+ // Write vertices to VBO
 1223+ cmdout.offset = This->state.cmd->write_ptr_vertex;
 1224+ cmdout.indexoffset = This->state.cmd->write_ptr_index;
 1225+ memcpy(This->state.cmd->vertices->pointer + This->state.cmd->write_ptr_vertex,
 1226+ tmp_cmd.BltVertex_STORAGE.vertex, 4 * sizeof(BltVertex));
 1227+ memcpy(This->state.cmd->indices->pointer + This->state.cmd->write_ptr_index,
 1228+ indexbase, 6 * sizeof(WORD));
 1229+ This->state.cmd->write_ptr_vertex += 4 * sizeof(BltVertex);
 1230+ This->state.cmd->write_ptr_index += 6 * sizeof(WORD);
 1231+ // Write command to buffer
 1232+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, &cmdout, cmdout.size + 8);
 1233+ This->state.cmd->write_ptr_cmd_modify = This->state.cmd->write_ptr_cmd;
 1234+ This->state.cmd->write_ptr_cmd += (cmdout.size + 8);
 1235+ // Set Src texture (Unit 8) to backbuffer
 1236+ tmp_cmd.SetTexture.opcode = OP_SETTEXTURE;
 1237+ tmp_cmd.SetTexture.size = sizeof(SetTextureCmd) + sizeof(DWORD) + sizeof(glTexture*);
 1238+ tmp_cmd.SetTexture.texstage[0].stage = 8;
 1239+ tmp_cmd.SetTexture.texstage[0].texture = This->backbuffer;
 1240+ tmp_cmd.SetTexture.count = 1;
 1241+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1242+ }
 1243+ // Set shader and texture filter
 1244+ if ((This->ddInterface->GetBPP() == 8) && (!dxglcfg.scalingfilter ||
 1245+ ((cmd->DrawScreen.texture->bigwidth == (view[1] - view[0])) &&
 1246+ (cmd->DrawScreen.texture->bigheight == (view[3] - view[2])))))
 1247+ {
 1248+ // 256 color, unscaled or scaled nearest
 1249+ tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
 1250+ tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd) - 8;
 1251+ tmp_cmd.SetShader2D.type = 0;
 1252+ tmp_cmd.SetShader2D.id = PROG_PAL256;
 1253+ shaderid = PROG_PAL256;
 1254+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1255+ tmp_cmd.SetTextureStageState.opcode = OP_SETTEXTURESTAGESTATE;
 1256+ tmp_cmd.SetTextureStageState.size = sizeof(SetTextureStageStateCmd) - 8 + sizeof(DWORD)
 1257+ + sizeof(D3DTEXTURESTAGESTATETYPE);
 1258+ tmp_cmd.SetTextureStageState.dwStage = 8;
 1259+ tmp_cmd.SetTextureStageState.count = 2;
 1260+ tmp_cmd.SetTextureStageState.state[0].dwState = D3DTSS_MAGFILTER;
 1261+ tmp_cmd.SetTextureStageState.state[0].dwValue = D3DTFG_POINT;
 1262+ tmp_cmd.SetTextureStageState.state[1].dwState = D3DTSS_MINFILTER;
 1263+ tmp_cmd.SetTextureStageState.state[1].dwValue = D3DTFN_POINT;
 1264+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1265+ }
 1266+ else
 1267+ {
 1268+ // Full-color mode or 256-color scaled linear
 1269+ tmp_cmd.SetShader2D.opcode = OP_SETSHADER2D;
 1270+ tmp_cmd.SetShader2D.size = sizeof(SetShader2DCmd) - 8;
 1271+ tmp_cmd.SetShader2D.type = 0;
 1272+ tmp_cmd.SetShader2D.id = PROG_TEXTURE;
 1273+ shaderid = PROG_TEXTURE;
 1274+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1275+ tmp_cmd.SetTextureStageState.opcode = OP_SETTEXTURESTAGESTATE;
 1276+ tmp_cmd.SetTextureStageState.size = sizeof(SetTextureStageStateCmd) - 8 + sizeof(DWORD)
 1277+ + sizeof(D3DTEXTURESTAGESTATETYPE);
 1278+ tmp_cmd.SetTextureStageState.dwStage = 8;
 1279+ tmp_cmd.SetTextureStageState.count = 2;
 1280+ tmp_cmd.SetTextureStageState.state[0].dwState = D3DTSS_MAGFILTER;
 1281+ if(dxglcfg.scalingfilter)
 1282+ tmp_cmd.SetTextureStageState.state[0].dwValue = D3DTFG_LINEAR;
 1283+ else tmp_cmd.SetTextureStageState.state[0].dwValue = D3DTFG_POINT;
 1284+ tmp_cmd.SetTextureStageState.state[1].dwState = D3DTSS_MINFILTER;
 1285+ if (dxglcfg.scalingfilter)
 1286+ tmp_cmd.SetTextureStageState.state[1].dwValue = D3DTFG_LINEAR;
 1287+ else tmp_cmd.SetTextureStageState.state[1].dwValue = D3DTFN_POINT;
 1288+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1289+ }
 1290+ // Set shader uniforms
 1291+ tmp_cmd.SetUniform.opcode = OP_SETUNIFORM;
 1292+ tmp_cmd.SetUniform.size = sizeof(SetUniformCmdBase) - 8;
 1293+ tmp_cmd.SetUniform.tmp_ptr = (BYTE*)&tmp_cmd.SetUniform.data;
 1294+ tmp_cmd.SetUniform.count = 0;
 1295+ append_uniform_cmd(This, &tmp_cmd.SetUniform, This->shaders->shaders[shaderid].tex0,
 1296+ 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 8);
 1297+ if (shaderid == PROG_PAL256)
 1298+ append_uniform_cmd(This, &tmp_cmd.SetUniform, This->shaders->shaders[shaderid].pal,
 1299+ 0, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), 9);
 1300+ append_uniform_cmd(This, &tmp_cmd.SetUniform, This->shaders->shaders[shaderid].view,
 1301+ 7, 0, FALSE, TRUE, sizeof(MIN_STORAGE_CMD), view[0], view[1], view[2], view[3]);
 1302+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1303+ // Set shader attributes
 1304+ tmp_cmd.SetAttrib.opcode = OP_SETATTRIB;
 1305+ tmp_cmd.SetAttrib.size = sizeof(SetAttribCmdBase) - 8;
 1306+ tmp_cmd.SetAttrib.count = 0;
 1307+ BltVertex *vertex = (BltVertex*)This->state.cmd->write_ptr_vertex;
 1308+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, This->shaders->shaders[shaderid].pos, 2, GL_FLOAT, GL_FALSE,
 1309+ sizeof(BltVertex), &vertex->x, TRUE, sizeof(MIN_STORAGE_CMD));
 1310+ append_attrib_cmd(This, &tmp_cmd.SetAttrib, This->shaders->shaders[shaderid].pos, 2, GL_FLOAT, GL_FALSE,
 1311+ sizeof(BltVertex), &vertex->s, TRUE, sizeof(MIN_STORAGE_CMD));
 1312+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
4041313 // Set render target to null
 1314+ if (This->state.target.target)
 1315+ {
 1316+ tmp_cmd.SetRenderTarget.opcode = OP_SETRENDERTARGET;
 1317+ tmp_cmd.SetRenderTarget.size = sizeof(SetRenderTargetCmd) - 8;
 1318+ tmp_cmd.SetRenderTarget.target.target = NULL;
 1319+ tmp_cmd.SetRenderTarget.target.level = 0;
 1320+ tmp_cmd.SetRenderTarget.target.zbuffer = NULL;
 1321+ tmp_cmd.SetRenderTarget.target.zlevel = 0;
 1322+ tmp_cmd.SetRenderTarget.target.mulx = tmp_cmd.SetRenderTarget.target.muly = 1.0f;
 1323+ glRenderer_AddCommand(This, &tmp_cmd, TRUE, FALSE);
 1324+ }
4051325 // Set viewport to window buffer
 1326+ #error do viewport
4061327 // Generate vertices
 1328+ if (This->ddInterface->GetFullscreen())
 1329+ {
 1330+ This->bltvertices[0].x = This->bltvertices[2].x = (float)sizes[0];
 1331+ This->bltvertices[0].y = This->bltvertices[1].y = This->bltvertices[1].x = This->bltvertices[3].x = 0.;
 1332+ This->bltvertices[2].y = This->bltvertices[3].y = (float)sizes[1];
 1333+ }
 1334+ else
 1335+ {
 1336+ This->bltvertices[0].x = This->bltvertices[2].x = (float)texture->bigwidth;
 1337+ This->bltvertices[0].y = This->bltvertices[1].y = This->bltvertices[1].x = This->bltvertices[3].x = 0.;
 1338+ This->bltvertices[2].y = This->bltvertices[3].y = (float)texture->bigheight;
 1339+ }
 1340+ if ((This->ddInterface->GetBPP() == 8) && (dxglcfg.scalingfilter) &&
 1341+ ((cmd->DrawScreen.texture->bigwidth != (view[1] - view[0])) ||
 1342+ (cmd->DrawScreen.texture->bigheight != (view[3] - view[2]))))
 1343+ {
 1344+ #error do texcoord for backbuffer
 1345+ }
 1346+ else
 1347+ {
 1348+ This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
 1349+ This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
 1350+ }
 1351+ // Write 2D Vertex command and check buffers
4071352 // Write vertices to VBO
408 - // Write Draw command to buffer
409 - // If 8-bit unscaled or scaled nearest:
410 - // Set Src texture (Unit 8) to primary
411 - // Set Palette texture (Unit 9) to palette
412 - // Set shader mode and params
413 - // Set render target to null
414 - // Set viewport to window buffer
415 - // Generate vertices
416 - // Write vertices to VBO
417 - // Write Palette Draw command to buffer
 1353+ // Set swap interval
 1354+ // Swap buffers
4181355 error = DDERR_CURRENTLYNOTAVAIL;
4191356 break;
4201357 case OP_INITD3D: // Initialize renderer for Direct3D rendering.
@@ -491,6 +1428,27 @@
4921429 case OP_SETVIEWPORT:
4931430 error = DDERR_CURRENTLYNOTAVAIL;
4941431 break;
 1432+ case OP_VERTEX2D:
 1433+ error = DDERR_CURRENTLYNOTAVAIL;
 1434+ break;
 1435+ case OP_SETDEPTHTEST:
 1436+ error = DDERR_CURRENTLYNOTAVAIL;
 1437+ break;
 1438+ case OP_SETFRONTBUFFERBITS:
 1439+ error = DDERR_CURRENTLYNOTAVAIL;
 1440+ break;
 1441+ case OP_SETSWAP:
 1442+ error = DDERR_CURRENTLYNOTAVAIL;
 1443+ break;
 1444+ case OP_SWAPBUFFERS:
 1445+ error = DDERR_CURRENTLYNOTAVAIL;
 1446+ break;
 1447+ case OP_SETUNIFORM:
 1448+ error = DDERR_CURRENTLYNOTAVAIL;
 1449+ break;
 1450+ case OP_SETATTRIB:
 1451+ error = DDERR_CURRENTLYNOTAVAIL;
 1452+ break;
4951453 default:
4961454 error = DDERR_INVALIDPARAMS;
4971455 break;
Index: ddraw/glRenderer.h
@@ -97,6 +97,13 @@
9898 #define OP_SETSHADER 30
9999 #define OP_SETRENDERTARGET 31
100100 #define OP_SETVIEWPORT 32
 101+#define OP_VERTEX2D 33
 102+#define OP_SETDEPTHTEST 34
 103+#define OP_SETFRONTBUFFERBITS 35
 104+#define OP_SETSWAP 36
 105+#define OP_SWAPBUFFERS 37
 106+#define OP_SETUNIFORM 38
 107+#define OP_SETATTRIB 39
101108
102109 extern const DWORD renderstate_default[153];
103110 extern const TEXTURESTAGE texstagedefault0;
@@ -148,7 +155,7 @@
149156 size_t scenesize, scenesizevertex, scenesizeindex;
150157 } glRenderer;
151158
152 -HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *command, BOOL inner, BOOL wait);
 159+HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *cmd, BOOL inner, BOOL wait);
153160 void glRenderer_Init(glRenderer *This, int width, int height, int bpp, BOOL fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
154161 void glRenderer_Delete(glRenderer *This);
155162 DWORD glRenderer_GetBPP(glRenderer *This);
@@ -226,6 +233,10 @@
227234 void glRenderer__DXGLBreak(glRenderer *This);
228235 void glRenderer__EndCommand(glRenderer *This, BOOL wait);
229236
 237+void BltFlipLR(BltVertex *vertices);
 238+void BltFlipUD(BltVertex *vertices);
 239+void RotateBlt90(BltVertex *vertices, int times);
 240+
230241 #ifdef __cplusplus
231242 }
232243 #endif
Index: ddraw/struct.h
@@ -181,7 +181,7 @@
182182 ULONG busy;
183183 GLuint buffer;
184184 GLsizei size;
185 - void *pointer;
 185+ GLbyte *pointer;
186186 BOOL mapped;
187187 BOOL bound;
188188 BOOL target;
@@ -438,6 +438,7 @@
439439 BufferObject *vertices;
440440 BufferObject *indices;
441441 size_t write_ptr_cmd;
 442+ size_t write_ptr_cmd_modify;
442443 size_t read_ptr_cmd;
443444 size_t write_ptr_upload;
444445 size_t read_ptr_upload;
Index: ddraw/struct_command.h
@@ -257,11 +257,108 @@
258258 DWORD size;
259259 VIEWPORT viewport;
260260 } SetViewportCmd;
 261+typedef struct Vertex2DCmd
 262+{
 263+ DWORD opcode;
 264+ DWORD size;
 265+ DWORD count;
 266+ DWORD indexcount;
 267+ DWORD flags;
 268+ size_t offset;
 269+ size_t indexoffset;
 270+} Vertex2DCmd;
 271+typedef struct SetDepthTestCmd
 272+{
 273+ DWORD opcode;
 274+ DWORD size;
 275+ BOOL enabled;
 276+} SetDepthTestCmd;
 277+typedef struct SetFrontBufferBitsCmd
 278+{
 279+ DWORD opcode;
 280+ DWORD size;
 281+ glTexture *front;
 282+ glTexture *back;
 283+} SetFrontBufferBitsCmd;
 284+typedef struct SetSwapCmd
 285+{
 286+ DWORD opcode;
 287+ DWORD size;
 288+ GLint interval;
 289+} SetSwapCmd;
 290+typedef struct SwapBuffersCmd
 291+{
 292+ DWORD opcode;
 293+ DWORD size;
 294+} SwapBuffersCmd;
 295+typedef struct SetUniformCmdData
 296+{
 297+ size_t size;
 298+ GLint uniform;
 299+ DWORD type;
 300+ // Types:
 301+ // bits 0-1 number of fields - 1 (0-3 for 1-4 fields)
 302+ // bit 2 floating point if 1, int if 0
 303+ // bit 3 unsigned if 1/double if float
 304+ // bit 4 pointer
 305+ // bit 5 square matrix
 306+ // Special types, processed client side, converted to above types
 307+ // 256 - Color key, count is the color order, first data is key,
 308+ // second data is pointer to color sizes,
 309+ // third data is pointer to color bits
 310+ // 257 - Color fill, count is the color order, first data is fill color,
 311+ // second data is pointer to color sizes,
 312+ // third data is pointer to color bits
 313+ GLsizei count; // ignored if not pointer or matrix
 314+ BOOL transpose; // for matrices only
 315+ GLint data[1];
 316+} SetUniformCmdData;
 317+typedef struct SetUniformCmd
 318+{
 319+ DWORD opcode;
 320+ DWORD size;
 321+ DWORD count;
 322+ BYTE *tmp_ptr; // For the append command, ignored in the command buffer
 323+ SetUniformCmdData data;
 324+} SetUniformCmd;
 325+typedef struct SetUniformCmdBase // For getting size of SetUniformCmd before adding data
 326+{
 327+ DWORD opcode;
 328+ DWORD size;
 329+ DWORD count;
 330+ BYTE *tmp_ptr; // For the append command, ignored in the command buffer
 331+} SetUniformCmdBase;
 332+typedef struct SetAttribCmdData
 333+{
 334+ GLuint index;
 335+ GLint size;
 336+ GLint type;
 337+ BOOL normalized;
 338+ GLsizei stride;
 339+ const GLvoid *ptr;
 340+} SetAttribCmdData;
 341+typedef struct SetAttribCmd
 342+{
 343+ DWORD opcode;
 344+ DWORD size;
 345+ DWORD count;
 346+ SetAttribCmdData attrib[1];
 347+} SetAttribCmd;
 348+typedef struct SetAttribCmdBase
 349+{
 350+ DWORD opcode;
 351+ DWORD size;
 352+ DWORD count;
 353+} SetAttribCmdBase;
261354
262355 typedef struct BltVertex_STORAGE_Cmd // Store vertices in stack for Blt()
 356+// Also for variables for DrawScreen
263357 {
264358 BltVertex vertex[4];
265 - WORD index[64];
 359+ WORD index[6];
 360+ LONG sizes[6];
 361+ GLfloat view[4];
 362+ GLint viewport[4];
266363 } BltVertex_STORAGE_Cmd;
267364 typedef struct MIN_STORAGE_Cmd
268365 {
@@ -300,6 +397,13 @@
301398 SetShaderCmd SetShader;
302399 SetRenderTargetCmd SetRenderTarget;
303400 SetViewportCmd SetViewport;
 401+ Vertex2DCmd Vertex2D;
 402+ SetDepthTestCmd SetDepthTest;
 403+ SetFrontBufferBitsCmd SetFrontBufferBits;
 404+ SetSwapCmd SetSwap;
 405+ SwapBuffersCmd SwapBuffers;
 406+ SetUniformCmd SetUniform;
 407+ SetAttribCmd SetAttrib;
304408 BltVertex_STORAGE_Cmd BltVertex_STORAGE;
305409 MIN_STORAGE_CMD MIN_STORAGE;
306410 } QueueCmd;
@@ -311,6 +415,7 @@
312416 BYTE *last_cmd_start;
313417 RenderTarget target;
314418 VIEWPORT viewport;
 419+ BOOL depthtest;
315420 } RenderState;
316421
317422 #endif //__STRUCT_COMMAND_H
\ No newline at end of file
Index: ddraw/util.c
@@ -123,16 +123,16 @@
124124 0x00000000, // dwZBufferHigh
125125 0x00000000, // dwZBufferBaseDest
126126 0xFFFFFFFF, // dwZDestConstBitDepth
127 - (LPDIRECTDRAWSURFACE)0x00000000, // dwZDestConst and lpDDSZBufferDest
 127+ 0x00000000, // dwZDestConst and lpDDSZBufferDest
128128 0xFFFFFFFF, // dwZSrcConstBitDepth
129 - (LPDIRECTDRAWSURFACE)0x00000000, // dwZSrcConst and lpDDSZBufferSrc
 129+ 0x00000000, // dwZSrcConst and lpDDSZBufferSrc
130130 0xFFFFFFFF, // dwAlphaEdgeBlendBitDepth
131131 0x00000000, // dwAlphaEdgeBlend
132132 0x00000000, // dwReserved
133133 0xFFFFFFFF, // dwAlphaDestConstBitDepth
134 - (LPDIRECTDRAWSURFACE)0x00000000, // dwAlphaDestConst and lpDDSAlphaDest
 134+ 0x00000000, // dwAlphaDestConst and lpDDSAlphaDest
135135 0xFFFFFFFF, // dwAlphaSrcConstBitDepth
136 - (LPDIRECTDRAWSURFACE)0x00000000, // dwAlphaSrcConst and lpDDSAlphaSrc
 136+ 0x00000000, // dwAlphaSrcConst and lpDDSAlphaSrc
137137 0x00000000, // dwFillColor, dwFillDepth, dwFillPixel, and lpDDSPattern
138138 {0,0}, // ddckDestColorkey
139139 {0,0} // ddckSrcColorkey
@@ -148,12 +148,12 @@
149149 if(flags & DDBLT_ROP)
150150 {
151151 if (rop_texture_usage[(a->dwROP >> 16) & 0xFF] & 4)
152 - comp_mask.lpDDSPattern = _PTR_MASK;
 152+ comp_mask.lpDDSPattern = (LPDIRECTDRAWSURFACE)_PTR_MASK;
153153 }
154 - if (flags & DDBLT_ZBUFFERDESTOVERRIDE) comp_mask.lpDDSZBufferDest = _PTR_MASK;
155 - if (flags & DDBLT_ZBUFFERSRCOVERRIDE) comp_mask.lpDDSZBufferSrc = _PTR_MASK;
156 - if (flags & DDBLT_ALPHADESTSURFACEOVERRIDE) comp_mask.lpDDSAlphaDest = _PTR_MASK;
157 - if (flags & DDBLT_ALPHASRCSURFACEOVERRIDE) comp_mask.lpDDSAlphaSrc = _PTR_MASK;
 154+ if (flags & DDBLT_ZBUFFERDESTOVERRIDE) comp_mask.lpDDSZBufferDest = (LPDIRECTDRAWSURFACE)_PTR_MASK;
 155+ if (flags & DDBLT_ZBUFFERSRCOVERRIDE) comp_mask.lpDDSZBufferSrc = (LPDIRECTDRAWSURFACE)_PTR_MASK;
 156+ if (flags & DDBLT_ALPHADESTSURFACEOVERRIDE) comp_mask.lpDDSAlphaDest = (LPDIRECTDRAWSURFACE)_PTR_MASK;
 157+ if (flags & DDBLT_ALPHASRCSURFACEOVERRIDE) comp_mask.lpDDSAlphaSrc = (LPDIRECTDRAWSURFACE)_PTR_MASK;
158158 AndMem(&comp_a, a, &comp_mask, sizeof(DDBLTFX));
159159 AndMem(&comp_b, b, &comp_mask, sizeof(DDBLTFX));
160160 if (!memcmp(&comp_a, &comp_b, sizeof(DDBLTFX))) return FALSE;