DXGL r396 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r395‎ | r396 | r397 >
Date:00:34, 29 July 2013
Author:admin
Status:new
Tags:
Comment:
Move stencil texture to surface.
Begin work on 2D shader generator.
Map all 256 valid ROP codes.
Map texture usage for first 64 ROP codes.
Modified paths:
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj.filters (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glutil.h (modified) (history)
  • /ddraw/shadergen2d.cpp (added) (history)
  • /ddraw/shadergen2d.h (added) (history)

Diff [purge]

Index: ddraw/ddraw.vcxproj
@@ -295,6 +295,7 @@
296296 <ClInclude Include="resource.h" />
297297 <ClInclude Include="scalers.h" />
298298 <ClInclude Include="shadergen.h" />
 299+ <ClInclude Include="shadergen2d.h" />
299300 <ClInclude Include="shaders.h" />
300301 <ClInclude Include="texture.h" />
301302 <ClInclude Include="timer.h" />
@@ -360,6 +361,7 @@
361362 </ClCompile>
362363 <ClCompile Include="scalers.cpp" />
363364 <ClCompile Include="shadergen.cpp" />
 365+ <ClCompile Include="shadergen2d.cpp" />
364366 <ClCompile Include="shaders.cpp" />
365367 <ClCompile Include="texture.cpp" />
366368 <ClCompile Include="timer.cpp" />
Index: ddraw/ddraw.vcxproj.filters
@@ -134,6 +134,9 @@
135135 <ClInclude Include="timer.h">
136136 <Filter>Header Files</Filter>
137137 </ClInclude>
 138+ <ClInclude Include="shadergen2d.h">
 139+ <Filter>Header Files</Filter>
 140+ </ClInclude>
138141 </ItemGroup>
139142 <ItemGroup>
140143 <ClCompile Include="ddraw.cpp">
@@ -226,6 +229,9 @@
227230 <ClCompile Include="timer.cpp">
228231 <Filter>Source Files</Filter>
229232 </ClCompile>
 233+ <ClCompile Include="shadergen2d.cpp">
 234+ <Filter>Source Files</Filter>
 235+ </ClCompile>
230236 </ItemGroup>
231237 <ItemGroup>
232238 <ResourceCompile Include="ddraw.rc">
Index: ddraw/glDirectDrawSurface.cpp
@@ -53,7 +53,9 @@
5454 bitmapinfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+(255*sizeof(RGBQUAD)));
5555 ZeroMemory(bitmapinfo,sizeof(BITMAPINFO)+(255*sizeof(RGBQUAD)));
5656 ZeroMemory(&fbo,sizeof(FBO));
 57+ ZeroMemory(&stencilfbo,sizeof(FBO));
5758 palette = NULL;
 59+ stencil = NULL;
5860 paltex = NULL;
5961 texture = NULL;
6062 clipper = NULL;
@@ -364,7 +366,13 @@
365367 renderer->DeleteTexture(texture);
366368 delete texture;
367369 }
 370+ if(stencil)
 371+ {
 372+ renderer->DeleteTexture(stencil);
 373+ delete stencil;
 374+ }
368375 if(fbo.fbo) renderer->DeleteFBO(&fbo);
 376+ if(stencilfbo.fbo) renderer->DeleteFBO(&stencilfbo);
369377 if(bitmapinfo) free(bitmapinfo);
370378 if(palette) palette->Release();
371379 if(backbuffer) backbuffer->Release();
Index: ddraw/glDirectDrawSurface.h
@@ -125,6 +125,7 @@
126126 CKEY colorkey[4];
127127 TEXTURE *texture;
128128 TEXTURE *paltex;
 129+ TEXTURE *stencil;
129130 bool hasstencil;
130131 char *buffer;
131132 char *bigbuffer;
@@ -135,6 +136,7 @@
136137 glDirectDrawSurface7 *zbuffer;
137138 D3DMATERIALHANDLE handle;
138139 FBO fbo;
 140+ FBO stencilfbo;
139141 private:
140142 int swapinterval;
141143 ULONG refcount;
Index: ddraw/glRenderer.cpp
@@ -193,7 +193,6 @@
194194 glRenderer::glRenderer(int width, int height, int bpp, bool fullscreen, unsigned int frequency, HWND hwnd, glDirectDraw7 *glDD7)
195195 {
196196 backbuffer = NULL;
197 - stenciltex = NULL;
198197 hDC = NULL;
199198 hRC = NULL;
200199 PBO = 0;
Index: ddraw/glRenderer.h
@@ -140,9 +140,6 @@
141141 TEXTURE *backbuffer;
142142 int backx;
143143 int backy;
144 - TEXTURE *stenciltex;
145 - int stencilx;
146 - int stencily;
147144 };
148145
149146 #endif //_GLRENDERER_H
\ No newline at end of file
Index: ddraw/glutil.h
@@ -33,7 +33,8 @@
3434 GLfloat x, y;
3535 GLubyte r, g, b, a;
3636 GLfloat s, t;
37 - GLfloat padding[3];
 37+ GLfloat dests, destt;
 38+ GLfloat padding;
3839 } BltVertex;
3940
4041 extern FBO *currentfbo;
Index: ddraw/shadergen2d.cpp
@@ -0,0 +1,100 @@
 2+// DXGL
 3+// Copyright (C) 2013 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+#include "common.h"
 19+#include "shadergen2d.h"
 20+
 21+/* Bits in 2D shader ID:
 22+Bit 0: Use destination alpha (DDBLT_ALPHADEST)
 23+Bit 1: Use dest. alpha constant (DDBLT_ALPHADESTCONSTOVERRIDE)
 24+Bit 2: Reverse dest. alpha (DDLBT_ALPHADESTNEG)
 25+Bit 3: Use dest. alpha surface (DDBLT_ALPHADESTSURFACEOVERRIDE)
 26+Bit 4: Use alpha edge blend (DDBLT_ALPHAEDGEBLEND)
 27+Bit 5: Use source alpha (DDBLT_ALPHASRC)
 28+Bit 6: Use soure alpha constant (DDBLT_ALPHASRCCONSTOVERRIDE)
 29+Bit 7: Reverse source alpha (DDBLT_ALPHASRCSURFACEOVERRIDE)
 30+Bit 8: Use source alpha surface (DDBLT_ALPHASRCSURFACEOVERRIDE)
 31+Bit 9: ROP index bit 0
 32+Bit 10: Color fill (DDBLT_COLORFILL)
 33+Bit 11: Use DDBLTFX (DDBLT_DDFX)
 34+Bit 12: ROP index bit 1
 35+Bit 13: Use destination color key (DDBLT_KEYDEST)
 36+Bit 14: ROP index bit 2
 37+Bit 15: Use source color key (DDBLT_KEYSRC)
 38+Bit 16: ROP index bit 3
 39+Bit 17: Use ROP (DDBLT_ROP)
 40+Bit 18: ROP index bit 4
 41+Bit 19: Z-buffer blit (DDBLT_ZBUFFER)
 42+Bit 20: Use dest. Z constant (DDBLT_ZBUFFERDESTCONSTOVERRIDE)
 43+Bit 21: Use dest. Z surface (DDBLT_ZBUFFERDESTOVERRIDE)
 44+Bit 22: Use source Z constant (DDBLT_ZBUFFERSRCCONSTOVERRIDE)
 45+Bit 23: Use source Z surface (DDBLT_ZBUFFERSRCOVERRIDE)
 46+Bit 24: ROP index bit 5
 47+Bit 25: Depth fill (DDBLT_DEPTHFILL)
 48+Bit 26: ROP index bit 6
 49+Bit 27: ROP index bit 7
 50+Bit 28: reserved
 51+Bit 29: reserved
 52+Bit 30: reserved
 53+Bit 31: reserved
 54+AND the dwFlags by 0x02FAADFF before packing ROP index bits
 55+*/
 56+
 57+const DWORD valid_rop_codes[256] = {
 58+ 0x00000042,0x00010289,0x00020C89,0x000300AA,0x00040C88,0x000500A9,0x00060865,0x000702C5,
 59+ 0x00080F08,0x00090245,0x000A0329,0x000B0B2A,0x000C0324,0x000D0B25,0x000E08A5,0x000F0001,
 60+ 0x00100C85,0x001100A6,0x00120868,0x001302C8,0x00140869,0x001502C9,0x00165CCA,0x00171D54,
 61+ 0x00180D59,0x00191CC8,0x001A06C5,0x001B0768,0x001C06CA,0x001D0766,0x001E01A5,0x001F0385,
 62+ 0x00200F09,0x00210248,0x00220326,0x00230B24,0x00240D55,0x00251CC5,0x002606C8,0x00271868,
 63+ 0x00280369,0x002916CA,0x002A0CC9,0x002B1D58,0x002C0784,0x002D060A,0x002E064A,0x002F0E2A,
 64+ 0x0030032A,0x00310B28,0x00320688,0x00330008,0x003406C4,0x00351864,0x003601A8,0x00370388,
 65+ 0x0038078A,0x00390604,0x003A0644,0x003B0E24,0x003C004A,0x003D18A4,0x003E1B24,0x003F00EA,
 66+ 0x00400F0A,0x00410249,0x00420D5D,0x00431CC4,0x00440328,0x00450B29,0x004606C6,0x0047076A,
 67+ 0x00480368,0x004916C5,0x004A0789,0x004B0605,0x004C0CC8,0x004D1954,0x004E0645,0x004F0E25,
 68+ 0x00500325,0x00510B26,0x005206C9,0x00530764,0x005408A9,0x00550009,0x005601A9,0x00570389,
 69+ 0x00580785,0x00590609,0x005A0049,0x005B18A9,0x005C0649,0x005D0E29,0x005E1B29,0x005F00E9,
 70+ 0x00600365,0x006116C6,0x00620786,0x00630608,0x00640788,0x00650606,0x00660046,0x006718A8,
 71+ 0x006858A6,0x00690145,0x006A01E9,0x006B178A,0x006C01E8,0x006D1785,0x006E1E28,0x006F0C65,
 72+ 0x00700CC5,0x00711D5C,0x00720648,0x00730E28,0x00740646,0x00750E26,0x00761B28,0x007700E6,
 73+ 0x007801E5,0x00791786,0x007A1E29,0x007B0C68,0x007C1E24,0x007D0C69,0x007E0955,0x007F03C9,
 74+ 0x008003E9,0x00810975,0x00820C49,0x00831E04,0x00840C48,0x00851E05,0x008617A6,0x008701C5,
 75+ 0x008800C6,0x00891B08,0x008A0E06,0x008B0666,0x008C0E08,0x008D0668,0x008E1D7C,0x008F0CE5,
 76+ 0x00900C45,0x00911E08,0x009217A9,0x009301C4,0x009417AA,0x009501C9,0x00960169,0x0097588A,
 77+ 0x00981888,0x00990066,0x009A0709,0x009B07A8,0x009C0704,0x009D07A6,0x009E16E6,0x009F0345,
 78+ 0x00A000C9,0x00A11B05,0x00A20E09,0x00A30669,0x00A41885,0x00A50065,0x00A60706,0x00A707A5,
 79+ 0x00A803A9,0x00A90189,0x00AA0029,0x00AB0889,0x00AC0744,0x00AD06E9,0x00AE0B06,0x00AF0229,
 80+ 0x00B00E05,0x00B10665,0x00B21974,0x00B30CE8,0x00B4070A,0x00B507A9,0x00B616E9,0x00B70348,
 81+ 0x00B8074A,0x00B906E6,0x00BA0B09,0x00BB0226,0x00BC1CE4,0x00BD0D7D,0x00BE0269,0x00BF08C9,
 82+ 0x00C000CA,0x00C11B04,0x00C21884,0x00C3006A,0x00C40E04,0x00C50664,0x00C60708,0x00C707AA,
 83+ 0x00C803A8,0x00C90184,0x00CA0749,0x00CB06E4,0x00CC0020,0x00CD0888,0x00CE0B08,0x00CF0224,
 84+ 0x00D00E0A,0x00D1066A,0x00D20705,0x00D307A4,0x00D41D78,0x00D50CE9,0x00D616EA,0x00D70349,
 85+ 0x00D80745,0x00D906E8,0x00DA1CE9,0x00DB0D75,0x00DC0B04,0x00DD0228,0x00DE0268,0x00DF08C8,
 86+ 0x00E003A5,0x00E10185,0x00E20746,0x00E306EA,0x00E40748,0x00E506E5,0x00E61CE8,0x00E70D79,
 87+ 0x00E81D74,0x00E95CE6,0x00EA02E9,0x00EB0849,0x00EC02E8,0x00ED0848,0x00EE0086,0x00EF0A08,
 88+ 0x00F00021,0x00F10885,0x00F20B05,0x00F3022A,0x00F40B0A,0x00F50225,0x00F60265,0x00F708C5,
 89+ 0x00F802E5,0x00F90845,0x00FA0089,0x00FB0A09,0x00FC008A,0x00FD0A0A,0x00FE02A9,0x00FF0062
 90+};
 91+
 92+/*
 93+1 - Source
 94+2 - Dest
 95+4 - Pattern */
 96+const DWORD rop_texture_usage[256] = {
 97+ 0,7,7,5,7,6,7,7,7,7,6,7,5,7,7,4,
 98+ 7,3,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
 99+ 7,7,3,7,7,7,7,7,7,7,7,7,7,7,7,7,
 100+ 5,7,7,1,7,7,7,7,7,7,7,7,5,7,7,5,
 101+};
\ No newline at end of file
Index: ddraw/shadergen2d.h
@@ -0,0 +1,16 @@
 2+// DXGL
 3+// Copyright (C) 2013 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA