DXGL r401 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r400‎ | r401 | r402 >
Date:18:44, 10 August 2013
Author:admin
Status:new
Tags:
Comment:
Define more variables for 2D shader generator.
Change syntax of SetShader to support generated 2D shaders.
Modified paths:
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)
  • /ddraw/shadergen.h (modified) (history)
  • /ddraw/shadergen2d.cpp (modified) (history)
  • /ddraw/shadergen2d.h (modified) (history)

Diff [purge]

Index: ddraw/glDirectDraw.cpp
@@ -18,6 +18,8 @@
1919 #include "common.h"
2020 #include "util.h"
2121 #include "shaders.h"
 22+#include <string>
 23+using namespace std;
2224 #include "shadergen2d.h"
2325 #include "ddraw.h"
2426 #include "timer.h"
Index: ddraw/glRenderer.cpp
@@ -898,7 +898,7 @@
899899 if(dest->zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
900900 if(dwFlags & DDBLT_COLORFILL)
901901 {
902 - SetShader(PROG_FILL,NULL,NULL,true);
 902+ SetShader(PROG_FILL,NULL,NULL,0);
903903 progtype = PROG_FILL;
904904 switch(ddInterface->GetBPP())
905905 {
@@ -938,7 +938,7 @@
939939 }
940940 if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
941941 {
942 - SetShader(PROG_CKEY,NULL,NULL,true);
 942+ SetShader(PROG_CKEY,NULL,NULL,0);
943943 progtype = PROG_CKEY;
944944 switch(ddInterface->GetBPP())
945945 {
@@ -969,7 +969,7 @@
970970 }
971971 else if(!(dwFlags & DDBLT_COLORFILL))
972972 {
973 - SetShader(PROG_TEXTURE,NULL,NULL,true);
 973+ SetShader(PROG_TEXTURE,NULL,NULL,0);
974974 progtype = PROG_TEXTURE;
975975 glUniform1i(shaders[progtype].tex0,0);
976976 }
@@ -1127,7 +1127,7 @@
11281128 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
11291129 if(ddInterface->GetBPP() == 8)
11301130 {
1131 - SetShader(PROG_PAL256,NULL,NULL,true);
 1131+ SetShader(PROG_PAL256,NULL,NULL,0);
11321132 progtype = PROG_PAL256;
11331133 ::_UploadTexture(paltex,0,dest->palette->GetPalette(NULL),256,1);
11341134 glUniform1i(shaders[progtype].tex0,0);
@@ -1137,7 +1137,7 @@
11381138 if(dxglcfg.scalingfilter)
11391139 {
11401140 _DrawBackbuffer(&texture,dest->fakex,dest->fakey,progtype);
1141 - SetShader(PROG_TEXTURE,NULL,NULL,true);
 1141+ SetShader(PROG_TEXTURE,NULL,NULL,0);
11421142 progtype = PROG_TEXTURE;
11431143 SetTexture(0,texture);
11441144 glUniform1i(shaders[progtype].tex0,0);
@@ -1150,7 +1150,7 @@
11511151 }
11521152 else
11531153 {
1154 - SetShader(PROG_TEXTURE,NULL,NULL,true);
 1154+ SetShader(PROG_TEXTURE,NULL,NULL,0);
11551155 progtype = PROG_TEXTURE;
11561156 SetTexture(0,texture);
11571157 glUniform1i(shaders[progtype].tex0,0);
@@ -1446,7 +1446,7 @@
14471447 return;
14481448 }
14491449 __int64 shader = device->SelectShader(vertices);
1450 - SetShader(shader,device->texstages,texformats,0);
 1450+ SetShader(shader,device->texstages,texformats,2);
14511451 device->SetDepthComp();
14521452 if(device->renderstate[D3DRENDERSTATE_ZENABLE]) DepthTest(true);
14531453 else DepthTest(false);
Index: ddraw/shadergen.cpp
@@ -145,22 +145,25 @@
146146 * Pointer to the texture stage state array, containing 8 64-bit state values
147147 * @param texcoords
148148 * Pointer to number of texture coordinates in each texture stage
149 - * @param builtin
150 - * If true, the id parameter is an index to a built-in shader for 2D blitting
 149+ * @param type
 150+ * Type of shader:
 151+ * 0 for builtin
 152+ * 1 for generated 2D
 153+ * 2 for generated 3D
151154 */
152 -void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, bool builtin)
 155+void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type)
153156 {
154157 int shaderindex = -1;
155 - if(builtin)
 158+ switch(type)
156159 {
 160+ case 0:
157161 if(isbuiltin && (shaders[id].prog == current_shader)) return;
158162 glUseProgram(shaders[id].prog);
159163 current_shader = shaders[id].prog;
160164 isbuiltin=true;
161165 current_genshader = -1;
162 - }
163 - else
164 - {
 166+ break;
 167+ case 2:
165168 if(!isbuiltin && (id == current_shader))
166169 {
167170 if(!memcmp(current_texid,texstate,8*sizeof(__int64))) return;
Index: ddraw/shadergen.h
@@ -41,7 +41,7 @@
4242 #define D3DTOP_DXGL_MODULATEMASK 0x102;
4343
4444 void ClearShaders();
45 -void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, bool builtin);
 45+void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type);
4646 GLuint GetProgram();
4747 void ZeroShaderArray();
4848 void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords);
Index: ddraw/shadergen2d.cpp
@@ -15,9 +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 #include "common.h"
 19+#include <string>
 20+using namespace std;
1921 #include "shadergen2d.h"
2022 #include "../common/version.h"
2123
 24+GenShader2D *genshaders2D = NULL;
 25+GLuint current_prog2D;
 26+int current_genshader2D;
 27+
 28+
2229 /* Bits in 2D shader ID:
2330 Bit 0: Use destination alpha (DDBLT_ALPHADEST)
2431 Bit 1: Use dest. alpha constant (DDBLT_ALPHADESTCONSTOVERRIDE)
@@ -159,6 +166,7 @@
160167 static const char var_src[] = "ivec4 src;\n";
161168 static const char var_dest[] = "ivec4 dest;\n";
162169 static const char var_pattern[] = "ivec4 pattern;\n";
 170+static const char var_pixel[] = "vec4 pixel;\n";
163171
164172 // Operations
165173 static const char op_src[] = "src = ivec4(texture2D(src,gl_TexCoord[0].st)*255.5);\n";
@@ -686,4 +694,9 @@
687695 "",
688696 "",
689697 "gl_FragColor = vec4(1.0);\n",//FF WHITENESS
690 -};
\ No newline at end of file
 698+};
 699+
 700+void CreateShader2D(int index, DWORD id)
 701+{
 702+ string tmp;
 703+}
\ No newline at end of file
Index: ddraw/shadergen2d.h
@@ -15,6 +15,25 @@
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+typedef struct
 20+{
 21+ GLint vs;
 22+ GLint fs;
 23+ string *vsrc;
 24+ string *fsrc;
 25+ GLint prog;
 26+ GLint attribs[8];
 27+ GLint uniforms[16];
 28+} _GENSHADER2D;
 29+
 30+struct GenShader2D
 31+{
 32+ _GENSHADER2D shader;
 33+ DWORD id;
 34+};
 35+
1936 extern const DWORD valid_rop_codes[256];
2037 extern const DWORD rop_texture_usage[256];
21 -extern const DWORD supported_rops[8];
\ No newline at end of file
 38+extern const DWORD supported_rops[8];
 39+extern GenShader2D *genshaders2D;
 40+extern int current_genshader2D;