DXGL r684 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r683‎ | r684 | r685 >
Date:01:13, 14 September 2016
Author:admin
Status:new
Tags:
Comment:
Undo disabling development code.
Move DrawScreen to texture units 8 and 9.
More planning for new renderer.
Remove obsolete unused shaders.
Expand texture stages memory.
Modified paths:
  • /ddraw/ShaderManager.cpp (modified) (history)
  • /ddraw/ShaderManager.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/struct_command.h (modified) (history)

Diff [purge]

Index: ddraw/ShaderManager.cpp
@@ -47,49 +47,6 @@
4848 gl_FragColor = texel; \n\
4949 } ";
5050
51 -const char frag_ColorKey[] = "\
52 -#version 110\n\
53 -uniform sampler2D tex0;\n\
54 -uniform ivec3 ckey;\n\
55 -void main (void)\n\
56 -{\n\
57 - vec4 value = texture2D(tex0, vec2(gl_TexCoord[0]));\n\
58 - ivec3 comp = ivec3(texture2D(tex0, vec2(gl_TexCoord[0]))*255.5);\n\
59 - if (comp == ckey)\n\
60 - discard;\n\
61 - gl_FragColor = value;\n\
62 -} ";
63 -
64 -const char frag_ColorKeyMask[] = "\
65 -#version 110\n\
66 -uniform sampler2D tex0;\n\
67 -uniform ivec4 ckey;\n\
68 -void main (void)\n\
69 -{\n\
70 - vec4 value = texture2D(tex0, vec2(gl_TexCoord[0]));\n\
71 - ivec4 comp = ivec4(texture2D(tex0, vec2(gl_TexCoord[0]))*255.5);\n\
72 - if (comp == ckey)\n\
73 - gl_FragColor[0] = 1.0;\n\
74 - else gl_FragColor[0] = 0.0;\n\
75 -} ";
76 -
77 -const char frag_2ColorKey[] = "\
78 -#version 110\n\
79 -uniform sampler2D tex0;\n\
80 -uniform sampler2D tex1;\n\
81 -uniform ivec4 ckey;\n\
82 -void main (void)\n\
83 -{\n\
84 - vec4 value = texture2D(tex0, vec2(gl_TexCoord[0]));\n\
85 - ivec4 comp = ivec4(texture2D(tex0, vec2(gl_TexCoord[0]))*255.5);\n\
86 - if (comp == ckey)\n\
87 - discard;\n\
88 - ivec4 comp2 = ivec4(texture2D(tex1,vec2(gl_TexCoord[1]))*255.5);\n\
89 - if(comp2[0] == 0)\n\
90 - discard;\n\
91 - gl_FragColor = value;\n\
92 -} ";
93 -
9451 const char frag_clipstencil[] = "\
9552 #version 110\n\
9653 void main (void)\n\
@@ -123,9 +80,6 @@
12481 {
12582 {0,0, vert_ortho, frag_Texture, 0,-1,-1,-1},
12683 {0,0, vert_ortho, frag_Pal256, 0,-1,-1,-1},
127 - {0,0, vert_ortho, frag_ColorKey, 0,-1,-1,-1},
128 - {0,0, vert_ortho, frag_ColorKeyMask, 0,-1,-1,-1},
129 - {0,0, vert_ortho, frag_2ColorKey, 0,-1,-1,-1},
13084 {0,0, vert_ortho, frag_clipstencil, 0,-1,-1,-1}
13185 };
13286 const int SHADER_END = __LINE__ - 4;
Index: ddraw/ShaderManager.h
@@ -27,10 +27,7 @@
2828
2929 #define PROG_TEXTURE 0
3030 #define PROG_PAL256 1
31 -#define PROG_CKEY 2
32 -#define PROG_CKEYMASK 3
33 -#define PROG_2CKEY 4
34 -#define PROG_CLIPSTENCIL 5
 31+#define PROG_CLIPSTENCIL 2
3532
3633 struct TEXTURESTAGE;
3734 struct ShaderGen3D;
Index: ddraw/glRenderer.cpp
@@ -203,20 +203,62 @@
204204 break;
205205 case OP_BLT: // Perform a Blt() operation, issuing necessary commands to set it
206206 // up.
 207+ // Compare last command minus rotation
207208 if (This->state.last_cmd == OP_BLT)
208209 {
209 -
 210+ // Generate vertices
 211+ // Rotate vertices if necessary
 212+ // Write vertices to VBO
 213+ // Update command in buffer
210214 }
211215 if(restart_cmd)
212216 {
213 -
 217+ // Run backbuffer if using dest
 218+ // Set Src texture (Unit 8)
 219+ // Set Dest texture (Unit 9)
 220+ // Set Pattern texture (Unit 10)
 221+ // Set clipper texture (Unit 11)
 222+ // Set shader mode and params
 223+ // Set render target
 224+ // Set viewport
 225+ // Generate vertices
 226+ // Rotate vertices if necessary
 227+ // Write vertices to VBO
 228+ // Write command to buffer
214229 }
215230 error = DDERR_CURRENTLYNOTAVAIL;
216231 break;
217232 case OP_DRAWSCREEN: // Draws the screen. Flip command buffer after executing.
 233+ // If 8 bit scaled linear:
 234+ // Set Src texture (Unit 8) to primary
 235+ // Set Palette texture (Unit 9) to palette
 236+ // Set shader mode and params
 237+ // Set render target to backbuffer
 238+ // Set viewport to backbuffer
 239+ // Generate vertices
 240+ // Write vertices to FBO
 241+ // Write Palette draw command to buffer
 242+ // Set Src texture (Unit 8) to backbuffer
 243+ // Set shader mode and params
 244+ // Set render target to null
 245+ // Set viewport to window buffer
 246+ // Generate vertices
 247+ // Write vertices to VBO
 248+ // Write Draw command to buffer
 249+ // If 8-bit unscaled or scaled nearest:
 250+ // Set Src texture (Unit 8) to primary
 251+ // Set Palette texture (Unit 9) to palette
 252+ // Set shader mode and params
 253+ // Set render target to null
 254+ // Set viewport to window buffer
 255+ // Generate vertices
 256+ // Write vertices to VBO
 257+ // Write Palette Draw command to buffer
218258 error = DDERR_UNSUPPORTED;
219259 break;
220260 case OP_INITD3D: // Initialize renderer for Direct3D rendering.
 261+ // Set initial viewport
 262+ // Post InitD3D command
221263 error = DDERR_CURRENTLYNOTAVAIL;
222264 break;
223265 case OP_CLEAR: // Clears full renderbuffer or one or more rects.
@@ -562,6 +604,11 @@
563605 */
564606 HRESULT glRenderer_Blt(glRenderer *This, BltCommand *cmd)
565607 {
 608+ /*BltCmd bltcmd;
 609+ bltcmd.opcode = OP_DELETE;
 610+ bltcmd.zise = sizeof(BltCmd) - 8;
 611+ bltcmd.cmd = *cmd;
 612+ glRenderer_AddCommand(This, (BYTE*)&bltcmd);*/
566613 EnterCriticalSection(&This->cs);
567614 RECT r,r2;
568615 if(((cmd->dest->levels[0].ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
@@ -590,15 +637,21 @@
591638 * Texture to use as the primary
592639 * @param paltex
593640 * Texture that contains the color palette for 8-bit modes
594 - * @param dest
595 - * Destination surface to be updated
596 - * @param src
597 - * Source surface to be updated
598641 * @param vsync
599642 * Vertical sync count
 643+ * @param previous
 644+ * Texture previously used as primary before a flip
600645 */
601646 void glRenderer_DrawScreen(glRenderer *This, glTexture *texture, glTexture *paltex, GLint vsync, glTexture *previous)
602647 {
 648+ /*DrawScreenCmd cmd;
 649+ cmd.opcode = OP_DRAWSCREEN;
 650+ cmd.size = sizeof(DrawScreenCmd)-8;
 651+ cmd.texture = texture;
 652+ cmd.paltex =paltex;
 653+ cmd.vsync = vsync;
 654+ cmd.previous = previous;
 655+ glRenderer_AddCommand(This, (BYTE*)&cmd);*/
603656 EnterCriticalSection(&This->cs);
604657 This->inputs[0] = texture;
605658 This->inputs[1] = paltex;
@@ -616,9 +669,21 @@
617670 * Pointer to glRenderer object
618671 * @param zbuffer
619672 * Nonzero if a Z buffer is present.
 673+ * @param x
 674+ * Width of the initial viewport
 675+ * @param y
 676+ * Height of the initial viewport
620677 */
621678 void glRenderer_InitD3D(glRenderer *This, int zbuffer, int x, int y)
622679 {
 680+ /*
 681+ InitD3DCmd cmd;
 682+ cmd.opcode = OP_INITD3D;
 683+ cmd.size = sizeof(InitD3DCmd)-8;
 684+ cmd.zbuffer = zbuffer;
 685+ cmd.x = x;
 686+ cmd.y = y;
 687+ glRenderer_AddCommand(This, (BYTE*)&bltcmd);*/
623688 EnterCriticalSection(&This->cs);
624689 This->inputs[0] = (void*)zbuffer;
625690 This->inputs[1] = (void*)x;
@@ -640,6 +705,12 @@
641706 */
642707 HRESULT glRenderer_Clear(glRenderer *This, ClearCommand *cmd)
643708 {
 709+ /*
 710+ ClearCmd cmd;
 711+ clearcmd.opcode = OP_CLEAR;
 712+ clearcmd.size = sizeof(ClearCmd) - 8;
 713+ clearcmd.cmd = *cmd;
 714+ glRenderer_AddCommand(This, (BYTE*)&clearcmd); */
644715 EnterCriticalSection(&This->cs);
645716 This->inputs[0] = cmd;
646717 This->opcode = OP_CLEAR;
@@ -651,7 +722,7 @@
652723
653724 /**
654725 * Instructs the OpenGL driver to send all queued commands to the GPU.
655 - * @param Thisf
 726+ * @param This
656727 * Pointer to glRenderer object
657728 */
658729 void glRenderer_Flush(glRenderer *This)
@@ -1404,12 +1475,12 @@
14051476 }
14061477 BufferObject_Create(&This->pbo, This->ext, This->util);
14071478 BufferObject_SetData(This->pbo, GL_PIXEL_PACK_BUFFER, width*height * 4, NULL, GL_STREAM_READ);
1408 - /*ZeroMemory(&This->state, sizeof(RenderState));
 1479+ ZeroMemory(&This->state, sizeof(RenderState));
14091480 This->state.cmd = &This->cmd1;
14101481 glRenderer__InitCommandBuffer(This, &This->cmd1, width * height * (NextMultipleOf8(bpp) / 8));
14111482 glRenderer__InitCommandBuffer(This, &This->cmd2, width * height * (NextMultipleOf8(bpp) / 8));
14121483 BufferObject_Map(This->cmd1.vertices, GL_ARRAY_BUFFER, GL_WRITE_ONLY);
1413 - BufferObject_Map(This->cmd1.indices, GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);*/
 1484+ BufferObject_Map(This->cmd1.indices, GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY);
14141485 TRACE_SYSINFO();
14151486 return TRUE;
14161487 }
@@ -1987,10 +2058,10 @@
19882059 ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,0);
19892060 progtype = PROG_PAL256;
19902061 glTexture__Upload(paltex, 0);
1991 - This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
1992 - This->ext->glUniform1i(This->shaders->shaders[progtype].pal,1);
1993 - glUtil_SetTexture(This->util,0,texture);
1994 - glUtil_SetTexture(This->util,1,paltex);
 2062+ This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,8);
 2063+ This->ext->glUniform1i(This->shaders->shaders[progtype].pal,9);
 2064+ glUtil_SetTexture(This->util,8,texture);
 2065+ glUtil_SetTexture(This->util,9,paltex);
19952066 if(dxglcfg.scalingfilter)
19962067 {
19972068 glRenderer__DrawBackbuffer(This,&texture,texture->bigwidth,texture->bigheight,progtype);
@@ -2001,8 +2072,8 @@
20022073 }
20032074 if(This->ext->GLEXT_ARB_sampler_objects)
20042075 {
2005 - glTexture__SetFilter(NULL, 0, GL_NEAREST, GL_NEAREST, This);
2006 - glTexture__SetFilter(NULL, 1, GL_NEAREST, GL_NEAREST, This);
 2076+ glTexture__SetFilter(NULL, 8, GL_NEAREST, GL_NEAREST, This);
 2077+ glTexture__SetFilter(NULL, 9, GL_NEAREST, GL_NEAREST, This);
20072078 }
20082079 }
20092080 else
@@ -2009,8 +2080,8 @@
20102081 {
20112082 ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,0);
20122083 progtype = PROG_TEXTURE;
2013 - glUtil_SetTexture(This->util,0,texture);
2014 - This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
 2084+ glUtil_SetTexture(This->util,8,texture);
 2085+ This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,8);
20152086 }
20162087 if (dxglcfg.scalingfilter && This->ext->GLEXT_ARB_sampler_objects)
20172088 glTexture__SetFilter(NULL, 0, GL_LINEAR, GL_LINEAR, This);
@@ -2198,7 +2269,8 @@
21992270 memcpy(&This->renderstate, &renderstate_default, 153 * sizeof(DWORD));
22002271 This->texstages[0] = texstagedefault0;
22012272 This->texstages[1] = This->texstages[2] = This->texstages[3] = This->texstages[4] =
2202 - This->texstages[5] = This->texstages[6] = This->texstages[7] = texstagedefault1;
 2273+ This->texstages[5] = This->texstages[6] = This->texstages[7] = This->texstages[8] =
 2274+ This->texstages[9] = This->texstages[10] = This->texstages[11] = texstagedefault1;
22032275 This->viewport.dwX = 0;
22042276 This->viewport.dwY = 0;
22052277 This->viewport.dwWidth = x;
Index: ddraw/glRenderer.h
@@ -152,7 +152,7 @@
153153 ShaderManager *shaders;
154154 DWORD renderstate[153];
155155 SHADERSTATE shaderstate3d;
156 - TEXTURESTAGE texstages[8];
 156+ TEXTURESTAGE texstages[12];
157157 D3DMATERIAL7 material;
158158 D3DLIGHT7 lights[8];
159159 D3DMATRIX transform[24];
Index: ddraw/struct_command.h
@@ -53,8 +53,28 @@
5454 DWORD opcode;
5555 DWORD size;
5656 BltCommand cmd;
57 - DWORD count;
58 - GLsizeiptr vertex_start;
59 - GLsizeiptr index_start;
6057 } BltCmd;
 58+typedef struct DrawScreenCmd
 59+{
 60+ DWORD opcode;
 61+ DWORD size;
 62+ glTexture *texture;
 63+ glTexture *paltex;
 64+ GLint vsync;
 65+ glTexture *previous;
 66+};
 67+typedef struct InitD3DCmd
 68+{
 69+ DWORD opcode;
 70+ DWORD size;
 71+ int zbuffer;
 72+ int x;
 73+ int y;
 74+};
 75+typedef struct ClearCmd
 76+{
 77+ DWORD opcode;
 78+ DWORD size;
 79+ ClearCommand cmd;
 80+};
6181 #endif //__STRUCT_COMMAND_H
\ No newline at end of file