DXGL r688 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r687‎ | r688 | r689 >
Date:00:45, 9 November 2016
Author:admin
Status:new
Tags:
Comment:
Small amount of work towards new renderer.
No functional changes this commit.
Modified paths:
  • /ddraw/ShaderGen2D.cpp (modified) (history)
  • /ddraw/const.c (modified) (history)
  • /ddraw/const.h (modified) (history)
  • /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)
  • /ddraw/util.h (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.cpp
@@ -57,86 +57,6 @@
5858 AND the dwFlags by 0xF2FAADFF before packing ROP index bits
5959 */
6060
61 -const DWORD valid_rop_codes[256] = {
62 - 0x00000042,0x00010289,0x00020C89,0x000300AA,0x00040C88,0x000500A9,0x00060865,0x000702C5,
63 - 0x00080F08,0x00090245,0x000A0329,0x000B0B2A,0x000C0324,0x000D0B25,0x000E08A5,0x000F0001,
64 - 0x00100C85,0x001100A6,0x00120868,0x001302C8,0x00140869,0x001502C9,0x00165CCA,0x00171D54,
65 - 0x00180D59,0x00191CC8,0x001A06C5,0x001B0768,0x001C06CA,0x001D0766,0x001E01A5,0x001F0385,
66 - 0x00200F09,0x00210248,0x00220326,0x00230B24,0x00240D55,0x00251CC5,0x002606C8,0x00271868,
67 - 0x00280369,0x002916CA,0x002A0CC9,0x002B1D58,0x002C0784,0x002D060A,0x002E064A,0x002F0E2A,
68 - 0x0030032A,0x00310B28,0x00320688,0x00330008,0x003406C4,0x00351864,0x003601A8,0x00370388,
69 - 0x0038078A,0x00390604,0x003A0644,0x003B0E24,0x003C004A,0x003D18A4,0x003E1B24,0x003F00EA,
70 - 0x00400F0A,0x00410249,0x00420D5D,0x00431CC4,0x00440328,0x00450B29,0x004606C6,0x0047076A,
71 - 0x00480368,0x004916C5,0x004A0789,0x004B0605,0x004C0CC8,0x004D1954,0x004E0645,0x004F0E25,
72 - 0x00500325,0x00510B26,0x005206C9,0x00530764,0x005408A9,0x00550009,0x005601A9,0x00570389,
73 - 0x00580785,0x00590609,0x005A0049,0x005B18A9,0x005C0649,0x005D0E29,0x005E1B29,0x005F00E9,
74 - 0x00600365,0x006116C6,0x00620786,0x00630608,0x00640788,0x00650606,0x00660046,0x006718A8,
75 - 0x006858A6,0x00690145,0x006A01E9,0x006B178A,0x006C01E8,0x006D1785,0x006E1E28,0x006F0C65,
76 - 0x00700CC5,0x00711D5C,0x00720648,0x00730E28,0x00740646,0x00750E26,0x00761B28,0x007700E6,
77 - 0x007801E5,0x00791786,0x007A1E29,0x007B0C68,0x007C1E24,0x007D0C69,0x007E0955,0x007F03C9,
78 - 0x008003E9,0x00810975,0x00820C49,0x00831E04,0x00840C48,0x00851E05,0x008617A6,0x008701C5,
79 - 0x008800C6,0x00891B08,0x008A0E06,0x008B0666,0x008C0E08,0x008D0668,0x008E1D7C,0x008F0CE5,
80 - 0x00900C45,0x00911E08,0x009217A9,0x009301C4,0x009417AA,0x009501C9,0x00960169,0x0097588A,
81 - 0x00981888,0x00990066,0x009A0709,0x009B07A8,0x009C0704,0x009D07A6,0x009E16E6,0x009F0345,
82 - 0x00A000C9,0x00A11B05,0x00A20E09,0x00A30669,0x00A41885,0x00A50065,0x00A60706,0x00A707A5,
83 - 0x00A803A9,0x00A90189,0x00AA0029,0x00AB0889,0x00AC0744,0x00AD06E9,0x00AE0B06,0x00AF0229,
84 - 0x00B00E05,0x00B10665,0x00B21974,0x00B30CE8,0x00B4070A,0x00B507A9,0x00B616E9,0x00B70348,
85 - 0x00B8074A,0x00B906E6,0x00BA0B09,0x00BB0226,0x00BC1CE4,0x00BD0D7D,0x00BE0269,0x00BF08C9,
86 - 0x00C000CA,0x00C11B04,0x00C21884,0x00C3006A,0x00C40E04,0x00C50664,0x00C60708,0x00C707AA,
87 - 0x00C803A8,0x00C90184,0x00CA0749,0x00CB06E4,0x00CC0020,0x00CD0888,0x00CE0B08,0x00CF0224,
88 - 0x00D00E0A,0x00D1066A,0x00D20705,0x00D307A4,0x00D41D78,0x00D50CE9,0x00D616EA,0x00D70349,
89 - 0x00D80745,0x00D906E8,0x00DA1CE9,0x00DB0D75,0x00DC0B04,0x00DD0228,0x00DE0268,0x00DF08C8,
90 - 0x00E003A5,0x00E10185,0x00E20746,0x00E306EA,0x00E40748,0x00E506E5,0x00E61CE8,0x00E70D79,
91 - 0x00E81D74,0x00E95CE6,0x00EA02E9,0x00EB0849,0x00EC02E8,0x00ED0848,0x00EE0086,0x00EF0A08,
92 - 0x00F00021,0x00F10885,0x00F20B05,0x00F3022A,0x00F40B0A,0x00F50225,0x00F60265,0x00F708C5,
93 - 0x00F802E5,0x00F90845,0x00FA0089,0x00FB0A09,0x00FC008A,0x00FD0A0A,0x00FE02A9,0x00FF0062
94 -};
95 -
96 -/*
97 -1 - Source
98 -2 - Dest
99 -4 - Pattern */
100 -const DWORD rop_texture_usage[256] = {
101 - 0,7,7,5,7,6,7,7,7,7,6,7,5,7,7,4,
102 - 7,3,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
103 - 7,7,3,7,7,7,7,7,7,7,7,7,7,7,7,7,
104 - 5,7,7,1,7,7,7,7,7,7,7,7,5,7,7,5,
105 - 7,7,7,7,3,7,7,7,7,7,7,7,7,7,7,7,
106 - 6,7,7,7,7,2,7,7,7,7,6,7,7,7,7,6,
107 - 7,7,7,7,7,7,3,7,7,7,7,7,7,7,7,7,
108 - 7,7,7,7,7,7,7,3,7,7,7,7,7,7,7,7,
109 - 7,7,7,7,7,7,7,7,3,7,7,7,7,7,7,7,
110 - 7,7,7,7,7,7,7,7,7,3,7,7,7,7,7,7,
111 - 6,7,7,7,7,6,7,7,7,7,2,7,7,7,7,6,
112 - 7,7,7,7,7,7,7,7,7,7,7,3,7,7,7,7,
113 - 5,7,7,5,7,7,7,7,7,7,7,7,1,7,7,5,
114 - 7,7,7,7,7,7,7,7,7,7,7,7,7,3,7,7,
115 - 7,7,7,7,7,7,7,7,7,7,7,7,7,7,3,7,
116 - 4,7,7,5,7,6,7,7,7,7,6,7,5,7,7,0
117 -};
118 -
119 -const DWORD supported_rops[8] = {
120 - 0xFFFFFFFF,
121 - 0xFFFFFFFF,
122 - 0xFFFFFFFF,
123 - 0xFFFFFFFF,
124 - 0xFFFFFFFF,
125 - 0xFFFFFFFF,
126 - 0xFFFFFFFF,
127 - 0xFFFFFFFF
128 -};
129 -
130 -const DWORD supported_rops_gl2[8] = {
131 - 0x00008001,
132 - 0x00080000,
133 - 0x00200000,
134 - 0x00000000,
135 - 0x00000000,
136 - 0x00000400,
137 - 0x00001000,
138 - 0x80010000
139 -};
140 -
14161 static const char revheader[] =
14262 "//REV" STR(SHADER2DVERSION) "\n";
14363 static const char version_110[] = "#version 110\n";
Index: ddraw/const.c
@@ -17,4 +17,83 @@
1818
1919 #include "common.h"
2020
21 -const RECT nullrect = { -1,-1,-1,-1 };
\ No newline at end of file
 21+const RECT nullrect = { -1,-1,-1,-1 };
 22+const DWORD valid_rop_codes[256] = {
 23+ 0x00000042,0x00010289,0x00020C89,0x000300AA,0x00040C88,0x000500A9,0x00060865,0x000702C5,
 24+ 0x00080F08,0x00090245,0x000A0329,0x000B0B2A,0x000C0324,0x000D0B25,0x000E08A5,0x000F0001,
 25+ 0x00100C85,0x001100A6,0x00120868,0x001302C8,0x00140869,0x001502C9,0x00165CCA,0x00171D54,
 26+ 0x00180D59,0x00191CC8,0x001A06C5,0x001B0768,0x001C06CA,0x001D0766,0x001E01A5,0x001F0385,
 27+ 0x00200F09,0x00210248,0x00220326,0x00230B24,0x00240D55,0x00251CC5,0x002606C8,0x00271868,
 28+ 0x00280369,0x002916CA,0x002A0CC9,0x002B1D58,0x002C0784,0x002D060A,0x002E064A,0x002F0E2A,
 29+ 0x0030032A,0x00310B28,0x00320688,0x00330008,0x003406C4,0x00351864,0x003601A8,0x00370388,
 30+ 0x0038078A,0x00390604,0x003A0644,0x003B0E24,0x003C004A,0x003D18A4,0x003E1B24,0x003F00EA,
 31+ 0x00400F0A,0x00410249,0x00420D5D,0x00431CC4,0x00440328,0x00450B29,0x004606C6,0x0047076A,
 32+ 0x00480368,0x004916C5,0x004A0789,0x004B0605,0x004C0CC8,0x004D1954,0x004E0645,0x004F0E25,
 33+ 0x00500325,0x00510B26,0x005206C9,0x00530764,0x005408A9,0x00550009,0x005601A9,0x00570389,
 34+ 0x00580785,0x00590609,0x005A0049,0x005B18A9,0x005C0649,0x005D0E29,0x005E1B29,0x005F00E9,
 35+ 0x00600365,0x006116C6,0x00620786,0x00630608,0x00640788,0x00650606,0x00660046,0x006718A8,
 36+ 0x006858A6,0x00690145,0x006A01E9,0x006B178A,0x006C01E8,0x006D1785,0x006E1E28,0x006F0C65,
 37+ 0x00700CC5,0x00711D5C,0x00720648,0x00730E28,0x00740646,0x00750E26,0x00761B28,0x007700E6,
 38+ 0x007801E5,0x00791786,0x007A1E29,0x007B0C68,0x007C1E24,0x007D0C69,0x007E0955,0x007F03C9,
 39+ 0x008003E9,0x00810975,0x00820C49,0x00831E04,0x00840C48,0x00851E05,0x008617A6,0x008701C5,
 40+ 0x008800C6,0x00891B08,0x008A0E06,0x008B0666,0x008C0E08,0x008D0668,0x008E1D7C,0x008F0CE5,
 41+ 0x00900C45,0x00911E08,0x009217A9,0x009301C4,0x009417AA,0x009501C9,0x00960169,0x0097588A,
 42+ 0x00981888,0x00990066,0x009A0709,0x009B07A8,0x009C0704,0x009D07A6,0x009E16E6,0x009F0345,
 43+ 0x00A000C9,0x00A11B05,0x00A20E09,0x00A30669,0x00A41885,0x00A50065,0x00A60706,0x00A707A5,
 44+ 0x00A803A9,0x00A90189,0x00AA0029,0x00AB0889,0x00AC0744,0x00AD06E9,0x00AE0B06,0x00AF0229,
 45+ 0x00B00E05,0x00B10665,0x00B21974,0x00B30CE8,0x00B4070A,0x00B507A9,0x00B616E9,0x00B70348,
 46+ 0x00B8074A,0x00B906E6,0x00BA0B09,0x00BB0226,0x00BC1CE4,0x00BD0D7D,0x00BE0269,0x00BF08C9,
 47+ 0x00C000CA,0x00C11B04,0x00C21884,0x00C3006A,0x00C40E04,0x00C50664,0x00C60708,0x00C707AA,
 48+ 0x00C803A8,0x00C90184,0x00CA0749,0x00CB06E4,0x00CC0020,0x00CD0888,0x00CE0B08,0x00CF0224,
 49+ 0x00D00E0A,0x00D1066A,0x00D20705,0x00D307A4,0x00D41D78,0x00D50CE9,0x00D616EA,0x00D70349,
 50+ 0x00D80745,0x00D906E8,0x00DA1CE9,0x00DB0D75,0x00DC0B04,0x00DD0228,0x00DE0268,0x00DF08C8,
 51+ 0x00E003A5,0x00E10185,0x00E20746,0x00E306EA,0x00E40748,0x00E506E5,0x00E61CE8,0x00E70D79,
 52+ 0x00E81D74,0x00E95CE6,0x00EA02E9,0x00EB0849,0x00EC02E8,0x00ED0848,0x00EE0086,0x00EF0A08,
 53+ 0x00F00021,0x00F10885,0x00F20B05,0x00F3022A,0x00F40B0A,0x00F50225,0x00F60265,0x00F708C5,
 54+ 0x00F802E5,0x00F90845,0x00FA0089,0x00FB0A09,0x00FC008A,0x00FD0A0A,0x00FE02A9,0x00FF0062
 55+};
 56+
 57+/*
 58+1 - Source
 59+2 - Dest
 60+4 - Pattern */
 61+const DWORD rop_texture_usage[256] = {
 62+ 0,7,7,5,7,6,7,7,7,7,6,7,5,7,7,4,
 63+ 7,3,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 64+ 7,7,3,7,7,7,7,7,7,7,7,7,7,7,7,7,
 65+ 5,7,7,1,7,7,7,7,7,7,7,7,5,7,7,5,
 66+ 7,7,7,7,3,7,7,7,7,7,7,7,7,7,7,7,
 67+ 6,7,7,7,7,2,7,7,7,7,6,7,7,7,7,6,
 68+ 7,7,7,7,7,7,3,7,7,7,7,7,7,7,7,7,
 69+ 7,7,7,7,7,7,7,3,7,7,7,7,7,7,7,7,
 70+ 7,7,7,7,7,7,7,7,3,7,7,7,7,7,7,7,
 71+ 7,7,7,7,7,7,7,7,7,3,7,7,7,7,7,7,
 72+ 6,7,7,7,7,6,7,7,7,7,2,7,7,7,7,6,
 73+ 7,7,7,7,7,7,7,7,7,7,7,3,7,7,7,7,
 74+ 5,7,7,5,7,7,7,7,7,7,7,7,1,7,7,5,
 75+ 7,7,7,7,7,7,7,7,7,7,7,7,7,3,7,7,
 76+ 7,7,7,7,7,7,7,7,7,7,7,7,7,7,3,7,
 77+ 4,7,7,5,7,6,7,7,7,7,6,7,5,7,7,0
 78+};
 79+
 80+const DWORD supported_rops[8] = {
 81+ 0xFFFFFFFF,
 82+ 0xFFFFFFFF,
 83+ 0xFFFFFFFF,
 84+ 0xFFFFFFFF,
 85+ 0xFFFFFFFF,
 86+ 0xFFFFFFFF,
 87+ 0xFFFFFFFF,
 88+ 0xFFFFFFFF
 89+};
 90+
 91+const DWORD supported_rops_gl2[8] = {
 92+ 0x00008001,
 93+ 0x00080000,
 94+ 0x00200000,
 95+ 0x00000000,
 96+ 0x00000000,
 97+ 0x00000400,
 98+ 0x00001000,
 99+ 0x80010000
 100+};
Index: ddraw/const.h
@@ -24,7 +24,16 @@
2525 #endif
2626
2727 extern const RECT nullrect;
 28+ extern const DWORD valid_rop_codes[256];
 29+ extern const DWORD rop_texture_usage[256];
 30+ extern const DWORD supported_rops[8];
 31+ extern const DWORD supported_rops_gl2[8];
2832
 33+#ifdef _M_X64
 34+#define _PTR_MASK 0xFFFFFFFFFFFFFFFFui64
 35+#else
 36+#define _PTR_MASK 0xFFFFFFFF
 37+#endif
2938 #ifdef __cplusplus
3039 }
3140 #endif
Index: ddraw/glRenderer.cpp
@@ -26,6 +26,7 @@
2727 #include "ddraw.h"
2828 #include "ShaderGen3D.h"
2929 #include "matrix.h"
 30+#include "util.h"
3031
3132 extern "C" {
3233
@@ -96,8 +97,10 @@
9798 * Pointer to glRenderer object
9899 * @param cmdsize
99100 * Requested size for command buffer
 101+ * @return
 102+ * TRUE if ending command, FALSE otherwise
100103 */
101 -void CheckCmdBuffer(glRenderer *This, DWORD cmdsize, DWORD uploadsize, DWORD vertexsize, DWORD indexsize)
 104+BOOL CheckCmdBuffer(glRenderer *This, DWORD cmdsize, DWORD uploadsize, DWORD vertexsize, DWORD indexsize)
102105 {
103106 BOOL over = FALSE;
104107 if (cmdsize)
@@ -120,7 +123,12 @@
121124 if ((This->state.cmd->write_ptr_index + indexsize) > This->state.cmd->indices->size)
122125 over = TRUE;
123126 }
124 - if (over) glRenderer_EndCommand(This, FALSE, TRUE);
 127+ if (over)
 128+ {
 129+ glRenderer_EndCommand(This, FALSE, TRUE);
 130+ return TRUE;
 131+ }
 132+ else return FALSE;
125133 }
126134
127135 /**
@@ -136,12 +144,8 @@
137145 * @return
138146 * Return value specific to command, DD_OK if succeeded.
139147 */
140 -HRESULT glRenderer_AddCommand(glRenderer *This, BYTE *command, BOOL inner)
 148+HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *cmd, BOOL inner)
141149 {
142 - DWORD opcode = (DWORD)*command;
143 - DWORD cmdsize = (DWORD)*((unsigned char*)command + 4);
144 - BYTE *cmddata = command + 8;
145 - SetWndCommand *wndcmd = (SetWndCommand*)cmddata;
146150 HRESULT error;
147151 // Command specific variables
148152 RECT wndrect;
@@ -149,7 +153,7 @@
150154 LONG_PTR winstyle, winstyleex;
151155 BOOL restart_cmd = FALSE;
152156 if (!inner) EnterCriticalSection(&This->cs);
153 - switch (opcode)
 157+ switch (cmd->Generic.opcode)
154158 {
155159 case OP_NULL:
156160 error = DD_OK; // No need to write to the command buffer
@@ -164,54 +168,74 @@
165169 break;
166170 case OP_CREATE: // Creates a texture. Needs to sync in order to return the
167171 // texture object.
168 - CheckCmdBuffer(This, cmdsize + 8, 0, 0, 0);
169 - memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, command, cmdsize + 8);
170 - This->state.cmd->write_ptr_cmd += (cmdsize + 8);
 172+ CheckCmdBuffer(This, cmd->MakeTexture.size + 8, 0, 0, 0);
 173+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->MakeTexture.size + 8);
 174+ This->state.cmd->write_ptr_cmd += (cmd->MakeTexture.size + 8);
171175 error = DD_OK;
172176 break;
173177 case OP_UPLOAD: // This one can fill the upload buffer fast; upload buffer is
174178 // initialized to 2x primary for <=128MB, 1.5x for <=256MB, or
175179 // 1.25x for >256MB upload buffer size.
176 - ((UploadTextureCmd*)command)->texturesize =
177 - ((UploadTextureCmd*)command)->texture->levels[((UploadTextureCmd*)command)->level].ddsd.lPitch
178 - * ((UploadTextureCmd*)command)->texture->levels[((UploadTextureCmd*)command)->level].ddsd.dwHeight;
179 - ((UploadTextureCmd*)command)->content =
180 - (BYTE*)((UploadTextureCmd*)command)->texture->levels[((UploadTextureCmd*)command)->level].buffer;
181 - ((UploadTextureCmd*)command)->offset = This->state.cmd->write_ptr_upload;
182 - CheckCmdBuffer(This, cmdsize + 8, 0, 0, 0);
183 - memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, command, cmdsize + 8);
184 - This->state.cmd->write_ptr_cmd += (cmdsize + 8);
 180+ cmd->UploadTexture.texturesize =
 181+ cmd->UploadTexture.texture->levels[cmd->UploadTexture.level].ddsd.lPitch
 182+ * cmd->UploadTexture.texture->levels[cmd->UploadTexture.level].ddsd.dwHeight;
 183+ cmd->UploadTexture.content =
 184+ (BYTE*)cmd->UploadTexture.texture->levels[cmd->UploadTexture.level].buffer;
 185+ cmd->UploadTexture.offset = This->state.cmd->write_ptr_upload;
 186+ CheckCmdBuffer(This, cmd->UploadTexture.size + 8, 0, 0, 0);
 187+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->UploadTexture.size + 8);
 188+ This->state.cmd->write_ptr_cmd += (cmd->UploadTexture.size + 8);
185189 memcpy(This->state.cmd->uploadbuffer + This->state.cmd->write_ptr_upload,
186 - ((UploadTextureCmd*)command)->content, ((UploadTextureCmd*)command)->texturesize);
 190+ cmd->UploadTexture.content, cmd->UploadTexture.texturesize);
187191 error = DD_OK;
188192 break;
189193 case OP_DOWNLOAD: // Downloads a texture. Needs to sync in order to receive the
190194 // texture data.
191 - CheckCmdBuffer(This, cmdsize + 8, 0, 0, 0);
192 - memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, command, cmdsize + 8);
193 - This->state.cmd->write_ptr_cmd += (cmdsize + 8);
 195+ CheckCmdBuffer(This, cmd->DownloadTexture.size + 8, 0, 0, 0);
 196+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->DownloadTexture.size + 8);
 197+ This->state.cmd->write_ptr_cmd += (cmd->DownloadTexture.size + 8);
194198 error = DD_OK;
195199 break;
196200 case OP_DELETETEX: // Deletes a texture. Non-blocking becuase frontend has
197201 // forgotten the texture.
198 - CheckCmdBuffer(This, cmdsize + 8, 0, 0, 0);
199 - memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, command, cmdsize + 8);
200 - This->state.cmd->write_ptr_cmd += (cmdsize + 8);
 202+ CheckCmdBuffer(This, cmd->DeleteTexture.size + 8, 0, 0, 0);
 203+ memcpy(This->state.cmd->cmdbuffer + This->state.cmd->write_ptr_cmd, cmd, cmd->DeleteTexture.size + 8);
 204+ This->state.cmd->write_ptr_cmd += (cmd->DeleteTexture.size + 8);
201205 error = DD_OK;
202206 break;
203207 case OP_BLT: // Perform a Blt() operation, issuing necessary commands to set it
204208 // up.
205 - // Compare last command minus rotation
206 - if (This->state.last_cmd == OP_BLT)
 209+ // Check if last major command is Blt().
 210+ if (This->state.last_cmd.Generic.opcode == OP_BLT)
207211 {
208 - // Generate vertices
209 - // Rotate vertices if necessary
210 - // Write vertices to VBO
211 - // Update command in buffer
 212+ // Compare last command minus rotation
 213+ if (((cmd->Blt.cmd.flags & 0xBFABFFF) == (This->state.last_cmd.Blt.cmd.flags & 0xBFABFFF)) &&
 214+ !comp_bltfx(&This->state.last_cmd.Blt.cmd.bltfx, &cmd->Blt.cmd.bltfx, cmd->Blt.cmd.flags))
 215+ restart_cmd = FALSE;
 216+ else restart_cmd = TRUE;
 217+ if(!restart_cmd)
 218+ {
 219+ // Generate vertices
 220+ // Rotate vertices if necessary
 221+ // Write vertices to VBO
 222+ // Update command in buffer
 223+ }
 224+
212225 }
213226 if(restart_cmd)
214227 {
 228+ BOOL usedest = FALSE;
 229+ BOOL usepattern = FALSE;
 230+ if ((cmd->Blt.cmd.bltfx.dwSize == sizeof(DDBLTFX)) && (cmd->Blt.cmd.flags & DDBLT_ROP))
 231+ {
 232+ if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 2) usedest = TRUE;
 233+ if (rop_texture_usage[(cmd->Blt.cmd.bltfx.dwROP >> 16) & 0xFF] & 4) usepattern = TRUE;
 234+ }
215235 // Run backbuffer if using dest
 236+ if (usedest)
 237+ {
 238+
 239+ }
216240 // Set Src texture (Unit 8)
217241 // Set Dest texture (Unit 9)
218242 // Set Pattern texture (Unit 10)
@@ -318,7 +342,7 @@
319343 error = DDERR_INVALIDPARAMS;
320344 break;
321345 }
322 - This->state.last_cmd = opcode;
 346+ This->state.last_cmd.Generic.opcode = cmd->Generic.opcode;
323347 if (!inner) LeaveCriticalSection(&This->cs);
324348 return error;
325349 }
Index: ddraw/glRenderer.h
@@ -145,7 +145,7 @@
146146 size_t scenesize, scenesizevertex, scenesizeindex;
147147 } glRenderer;
148148
149 -HRESULT glRenderer_AddCommand(glRenderer *This, BYTE *command, BOOL inner);
 149+HRESULT glRenderer_AddCommand(glRenderer *This, QueueCmd *command, BOOL inner);
150150 void glRenderer_Init(glRenderer *This, int width, int height, int bpp, BOOL fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7, BOOL devwnd);
151151 void glRenderer_Delete(glRenderer *This);
152152 DWORD glRenderer_GetBPP(glRenderer *This);
Index: ddraw/struct.h
@@ -447,14 +447,6 @@
448448 size_t read_ptr_index;
449449 } CommandBuffer;
450450
451 -typedef struct RenderState
452 -{
453 - CommandBuffer *cmd;
454 - DWORD last_cmd;
455 - BYTE *last_cmd_start;
456 - BltCommand last_blt;
457 -} RenderState;
458 -
459451 typedef struct RenderTarget
460452 {
461453 glTexture *target;
Index: ddraw/struct_command.h
@@ -19,6 +19,11 @@
2020 #ifndef __STRUCT_COMMAND_H
2121 #define __STRUCT_COMMAND_H
2222
 23+typedef struct GenericCmd
 24+{
 25+ DWORD opcode;
 26+ DWORD size;
 27+} GenericCmd;
2328 typedef struct MakeTextureCmd
2429 {
2530 DWORD opcode;
@@ -226,6 +231,7 @@
227232
228233 typedef union QueueCmd
229234 {
 235+ GenericCmd Generic;
230236 MakeTextureCmd MakeTexture;
231237 UploadTextureCmd UploadTexture;
232238 DownloadTextureCmd DownloadTexture;
@@ -253,4 +259,11 @@
254260 MIN_STORAGE_CMD MIN_STORAGE;
255261 } QueueCmd;
256262
 263+typedef struct RenderState
 264+{
 265+ CommandBuffer *cmd;
 266+ QueueCmd last_cmd;
 267+ BYTE *last_cmd_start;
 268+} RenderState;
 269+
257270 #endif //__STRUCT_COMMAND_H
\ No newline at end of file
Index: ddraw/util.c
@@ -15,12 +15,16 @@
1616 // License along with this library; if not, write to the Free Software
1717 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
 19+// Note: Requires a SSE2 and AVX compatible compiler.
 20+
1921 #include "common.h"
2022 #include "util.h"
 23+#include "const.h"
2124
2225 #ifdef _MSC_VER
2326 #pragma optimize("g", off)
2427 #endif
 28+extern DXGLCFG dxglcfg;
2529 /**
2630 * Tests if a pointer is valid for reading from. Uses SEH on Visual C++,
2731 * non-recommended Windows API on other systems.
@@ -95,4 +99,63 @@
96100 if (IsBadWritePtr(ptr, 1)) return 0;
97101 else return 1;
98102 #endif
99 -}
\ No newline at end of file
 103+}
 104+
 105+void AndMem(void *dest, const void *a, const void *b, size_t size)
 106+{
 107+ // Buffer must be multiple of 4 and should be DWORD aligned
 108+ size_t i;
 109+ for (i = 0; i < size>>2; i++)
 110+ {
 111+ ((DWORD*)dest)[i] = ((DWORD*)a)[i] & ((DWORD*)b)[i];
 112+ }
 113+}
 114+
 115+const DDBLTFX cmp_fx =
 116+{
 117+ 0xFFFFFFFF, // dwSize
 118+ 0x00000180, // dwDDFX & (DDBLTFX_ZBUFFERBASEDEST | DDBLTFX_ZBUFFERRANGE)
 119+ 0xFFFFFFFF, // dwROP
 120+ 0xFFFFFFFF, // dwDDROP
 121+ 0x00000000, // dwRotationAngle
 122+ 0xFFFFFFFF, // dwZBufferOpCode
 123+ 0x00000000, // dwZBufferLow
 124+ 0x00000000, // dwZBufferHigh
 125+ 0x00000000, // dwZBufferBaseDest
 126+ 0xFFFFFFFF, // dwZDestConstBitDepth
 127+ (LPDIRECTDRAWSURFACE)0x00000000, // dwZDestConst and lpDDSZBufferDest
 128+ 0xFFFFFFFF, // dwZSrcConstBitDepth
 129+ (LPDIRECTDRAWSURFACE)0x00000000, // dwZSrcConst and lpDDSZBufferSrc
 130+ 0xFFFFFFFF, // dwAlphaEdgeBlendBitDepth
 131+ 0x00000000, // dwAlphaEdgeBlend
 132+ 0x00000000, // dwReserved
 133+ 0xFFFFFFFF, // dwAlphaDestConstBitDepth
 134+ (LPDIRECTDRAWSURFACE)0x00000000, // dwAlphaDestConst and lpDDSAlphaDest
 135+ 0xFFFFFFFF, // dwAlphaSrcConstBitDepth
 136+ (LPDIRECTDRAWSURFACE)0x00000000, // dwAlphaSrcConst and lpDDSAlphaSrc
 137+ 0x00000000, // dwFillColor, dwFillDepth, dwFillPixel, and lpDDSPattern
 138+ {0,0}, // ddckDestColorkey
 139+ {0,0} // ddckSrcColorkey
 140+};
 141+BOOL comp_bltfx(DDBLTFX *a, DDBLTFX *b, DWORD flags)
 142+{
 143+ DDBLTFX comp_mask;
 144+ DDBLTFX comp_a;
 145+ DDBLTFX comp_b;
 146+ if (!a && !b) return FALSE; // If both have no BLTFX
 147+ if ((!a && b) || (a && !b)) return TRUE; // One has BLTFX but not other
 148+ memcpy(&comp_mask, &cmp_fx, sizeof(DDBLTFX));
 149+ if(flags & DDBLT_ROP)
 150+ {
 151+ if (rop_texture_usage[(a->dwROP >> 16) & 0xFF] & 4)
 152+ comp_mask.lpDDSPattern = _PTR_MASK;
 153+ }
 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;
 158+ AndMem(&comp_a, a, &comp_mask, sizeof(DDBLTFX));
 159+ AndMem(&comp_b, b, &comp_mask, sizeof(DDBLTFX));
 160+ if (!memcmp(&comp_a, &comp_b, sizeof(DDBLTFX))) return FALSE;
 161+ else return TRUE;
 162+}
\ No newline at end of file
Index: ddraw/util.h
@@ -25,6 +25,8 @@
2626
2727 char IsReadablePointer(void *ptr, LONG_PTR size);
2828 char IsWritablePointer(void *ptr, LONG_PTR size, BOOL preserve);
 29+void AndMem(void *dest, const void *a, const void *b, size_t size);
 30+BOOL comp_bltfx(DDBLTFX *a, DDBLTFX *b, DWORD flags);
2931
3032 #ifdef __cplusplus
3133 }