Index: ddraw/ShaderGen2D.cpp |
— | — | @@ -158,9 +158,9 @@ |
159 | 159 |
|
160 | 160 | // Uniforms
|
161 | 161 | static const char unif_view[] = "uniform vec4 view;\n";
|
162 | | -static const char unif_srctex[] = "uniform sampler2d srctex;\n";
|
163 | | -static const char unif_desttex[] = "uniform sampler2d desttex;\n";
|
164 | | -static const char unif_patterntex[] = "uniform sampler2d patterntex;\n";
|
| 162 | +static const char unif_srctex[] = "uniform sampler2D srctex;\n";
|
| 163 | +static const char unif_desttex[] = "uniform sampler2D desttex;\n";
|
| 164 | +static const char unif_patterntex[] = "uniform sampler2D patterntex;\n";
|
165 | 165 | static const char unif_ckeysrc[] = "uniform ivec3 ckeysrc;\n";
|
166 | 166 | static const char unif_ckeydest[] = "uniform ivec3 ckeydest;\n";
|
167 | 167 |
|
— | — | @@ -171,11 +171,11 @@ |
172 | 172 | static const char var_pixel[] = "ivec4 pixel;\n";
|
173 | 173 |
|
174 | 174 | // Operations
|
175 | | -static const char op_src[] = "pixel = ivec4(texture2D(src,gl_TexCoord[0].st)*255.5);\n";
|
176 | | -static const char op_color[] = "pixel = ivec4(gl_FragColor*255.5);\n";
|
177 | | -static const char op_dest[] = "dest = ivec4(texture2D(dest,gl_TexCoord[1].st)*255.5);\n";
|
178 | | -static const char op_pattern[] = "pattern = ivec4(texture2D(pattern,gl_TexCoord[2].st)*255.5);\n";
|
179 | | -static const char op_destout[] = "gl_FragColor = vec4(pixel)/255.5;\n";
|
| 175 | +static const char op_src[] = "pixel = ivec4(texture2D(srctex,gl_TexCoord[0].st)*255.0);\n";
|
| 176 | +static const char op_color[] = "pixel = ivec4(gl_FragColor*255.0);\n";
|
| 177 | +static const char op_dest[] = "dest = ivec4(texture2D(desttex,gl_TexCoord[1].st)*255.0);\n";
|
| 178 | +static const char op_pattern[] = "pattern = ivec4(texture2D(patterntex,gl_TexCoord[2].st)*255.0);\n";
|
| 179 | +static const char op_destout[] = "gl_FragColor = vec4(pixel)/255.0;\n";
|
180 | 180 | static const char op_vertex[] = "vec4 xyzw = vec4(xy[0],xy[1],0,1);\n\
|
181 | 181 | mat4 proj = mat4(\n\
|
182 | 182 | vec4(2.0 / (view[1] - view[0]), 0, 0, 0),\n\
|
— | — | @@ -185,8 +185,8 @@ |
186 | 186 | -(view[2] + view[3]) / (view[2] - view[3]), -1 , 1));\n\
|
187 | 187 | gl_Position = proj * xyzw;\n";
|
188 | 188 | static const char op_vertcolorrgb[] = "gl_FrontColor = vec4(rgb,1.0);\n";
|
189 | | -static const char op_texcoord0[] = "gl_TexCoord[0] = vec4(st,0.0,1.0);\n";
|
190 | | -static const char op_ckeysrc[] = "if(pixel == ckey) discard;\n";
|
| 189 | +static const char op_texcoord0[] = "gl_TexCoord[0] = vec4(srcst,0.0,1.0);\n";
|
| 190 | +static const char op_ckeysrc[] = "if(pixel.rgb == ckeysrc) discard;\n";
|
191 | 191 |
|
192 | 192 |
|
193 | 193 | // Functions
|
— | — | @@ -710,17 +710,29 @@ |
711 | 711 | "gl_FragColor = vec4(1.0);\n",//FF WHITENESS
|
712 | 712 | };
|
713 | 713 |
|
| 714 | +DWORD PackROPBits(DWORD rop, DWORD flags)
|
| 715 | +{
|
| 716 | + DWORD out = rop & 0xF2FAADFF;
|
| 717 | + if (rop & 0x10000) out |= 1 << 9;
|
| 718 | + if (rop & 0x20000) out |= 1 << 12;
|
| 719 | + if (rop & 0x40000) out |= 1 << 14;
|
| 720 | + if (rop & 0x80000) out |= 1 << 16;
|
| 721 | + if (rop & 0x100000) out |= 1 << 18;
|
| 722 | + if (rop & 0x200000) out |= 1 << 24;
|
| 723 | + if (rop & 0x400000) out |= 1 << 26;
|
| 724 | + if (rop & 0x800000) out |= 1 << 27;
|
| 725 | + return out;
|
| 726 | +}
|
| 727 | +
|
714 | 728 | void ShaderGen2D_Init(ShaderGen2D *gen, glExtensions *ext, ShaderManager *shaderman)
|
715 | 729 | {
|
716 | 730 | gen->ext = ext;
|
717 | 731 | gen->shaders = shaderman;
|
718 | | - gen->current_genshader2D = 0;
|
719 | 732 | gen->shadercount = 0;
|
720 | 733 | gen->genindex = 0;
|
721 | 734 | gen->maxshaders = 256;
|
722 | 735 | gen->genshaders2D = (GenShader2D *)malloc(256 * sizeof(GenShader2D));
|
723 | 736 | ZeroMemory(gen->genshaders2D, 256 * sizeof(GenShader2D));
|
724 | | - gen->current_genshader2D = 0;
|
725 | 737 | }
|
726 | 738 |
|
727 | 739 | void ShaderGen2D_Delete(ShaderGen2D *gen)
|
— | — | @@ -737,7 +749,6 @@ |
738 | 750 | }
|
739 | 751 | if (gen->genshaders2D) free(gen->genshaders2D);
|
740 | 752 | gen->genshaders2D = NULL;
|
741 | | - gen->current_genshader2D = 0;
|
742 | 753 | gen->shadercount = 0;
|
743 | 754 | gen->genindex = 0;
|
744 | 755 | }
|
— | — | @@ -754,7 +765,7 @@ |
755 | 766 | idstring[21] = 0;
|
756 | 767 | // Create vertex shader
|
757 | 768 | // Header
|
758 | | - STRING *vsrc = &gen->genshaders2D->shader.vsrc;
|
| 769 | + STRING *vsrc = &gen->genshaders2D[index].shader.vsrc;
|
759 | 770 | String_Append(vsrc, revheader);
|
760 | 771 | if (id & DDBLT_ROP)
|
761 | 772 | {
|
— | — | @@ -815,7 +826,7 @@ |
816 | 827 | #endif
|
817 | 828 |
|
818 | 829 | // Create fragment shader
|
819 | | - STRING *fsrc = &gen->genshaders2D->shader.fsrc;
|
| 830 | + STRING *fsrc = &gen->genshaders2D[index].shader.fsrc;
|
820 | 831 | String_Append(fsrc, revheader);
|
821 | 832 | if (id & DDBLT_ROP)
|
822 | 833 | {
|
Index: ddraw/ShaderGen2D.h |
— | — | @@ -40,7 +40,6 @@ |
41 | 41 |
|
42 | 42 | typedef struct ShaderGen2D
|
43 | 43 | {
|
44 | | - int current_genshader2D;
|
45 | 44 | GenShader2D *genshaders2D;
|
46 | 45 | int shadercount;
|
47 | 46 | int maxshaders;
|
— | — | @@ -54,6 +53,8 @@ |
55 | 54 | extern const DWORD supported_rops[8];
|
56 | 55 | extern const DWORD supported_rops_gl2[8];
|
57 | 56 |
|
| 57 | +DWORD PackROPBits(DWORD rop, DWORD flags);
|
| 58 | +
|
58 | 59 | void ShaderGen2D_Init(ShaderGen2D *gen, glExtensions *ext, ShaderManager *shaderman);
|
59 | 60 | void ShaderGen2D_Delete(ShaderGen2D *gen);
|
60 | 61 | void ShaderGen2D_CreateShader2D(ShaderGen2D *gen, int index, DWORD id);
|
Index: ddraw/ShaderGen3D.cpp |
— | — | @@ -165,7 +165,7 @@ |
166 | 166 | if ((current_shadertype == 1) && (id == current_shader)) return;
|
167 | 167 | current_shader = id;
|
168 | 168 | current_shadertype = 1;
|
169 | | - for (int i = 0; i < shadercount; i++)
|
| 169 | + for (int i = 0; i < gen2d->shadercount; i++)
|
170 | 170 | {
|
171 | 171 | if (shaders->gen2d->genshaders2D[i].id == id)
|
172 | 172 | {
|
Index: ddraw/ShaderManager.cpp |
— | — | @@ -174,8 +174,8 @@ |
175 | 175 | }
|
176 | 176 | gen3d = new ShaderGen3D(ext, this);
|
177 | 177 | gen2d = (ShaderGen2D*)malloc(sizeof(ShaderGen2D));
|
| 178 | + ZeroMemory(gen2d, sizeof(ShaderGen2D));
|
178 | 179 | ShaderGen2D_Init(gen2d, ext, this);
|
179 | | - ZeroMemory(gen2d, sizeof(ShaderGen2D));
|
180 | 180 | }
|
181 | 181 |
|
182 | 182 | ShaderManager::~ShaderManager()
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -872,9 +872,13 @@ |
873 | 873 | void glRenderer::_Blt(LPRECT lpDestRect, glDirectDrawSurface7 *src,
|
874 | 874 | glDirectDrawSurface7 *dest, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx)
|
875 | 875 | {
|
876 | | - int progtype;
|
877 | 876 | LONG sizes[6];
|
878 | 877 | ddInterface->GetSizes(sizes);
|
| 878 | + DWORD shaderid;
|
| 879 | + if (lpDDBltFx) shaderid = PackROPBits(lpDDBltFx->dwROP, dwFlags);
|
| 880 | + else shaderid = dwFlags & 0xF2FAADFF;
|
| 881 | + shaders->SetShader(shaderid, NULL, NULL, 1);
|
| 882 | + GenShader2D *shader = &shaders->gen2d->genshaders2D[shaders->gen3d->current_genshader];
|
879 | 883 | util->BlendEnable(false);
|
880 | 884 | util->SetFBO(dest);
|
881 | 885 | util->SetViewport(0,0,dest->fakex,dest->fakey);
|
— | — | @@ -914,8 +918,6 @@ |
915 | 919 | if(dest->zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
|
916 | 920 | if(dwFlags & DDBLT_COLORFILL)
|
917 | 921 | {
|
918 | | - shaders->SetShader(PROG_FILL,NULL,NULL,0);
|
919 | | - progtype = PROG_FILL;
|
920 | 922 | switch(ddInterface->GetBPP())
|
921 | 923 | {
|
922 | 924 | case 8:
|
— | — | @@ -954,22 +956,20 @@ |
955 | 957 | }
|
956 | 958 | if((dwFlags & DDBLT_KEYSRC) && (src && src->colorkey[0].enabled) && !(dwFlags & DDBLT_COLORFILL))
|
957 | 959 | {
|
958 | | - shaders->SetShader(PROG_CKEY,NULL,NULL,0);
|
959 | | - progtype = PROG_CKEY;
|
960 | 960 | switch(ddInterface->GetBPP())
|
961 | 961 | {
|
962 | 962 | case 8:
|
963 | | - if(ext->glver_major >= 3) ext->glUniform3i(shaders->shaders[progtype].ckey,src->colorkey[0].key.dwColorSpaceHighValue,0,0);
|
964 | | - else ext->glUniform3i(shaders->shaders[progtype].ckey,src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
|
| 963 | + if(ext->glver_major >= 3) ext->glUniform3i(shader->shader.uniforms[4],src->colorkey[0].key.dwColorSpaceHighValue,0,0);
|
| 964 | + else ext->glUniform3i(shader->shader.uniforms[4],src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
|
965 | 965 | src->colorkey[0].key.dwColorSpaceHighValue);
|
966 | 966 | break;
|
967 | 967 | case 15:
|
968 | | - ext->glUniform3i(shaders->shaders[progtype].ckey,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
|
| 968 | + ext->glUniform3i(shader->shader.uniforms[4],_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
|
969 | 969 | _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 31),
|
970 | 970 | _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
|
971 | 971 | break;
|
972 | 972 | case 16:
|
973 | | - ext->glUniform3i(shaders->shaders[progtype].ckey,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
|
| 973 | + ext->glUniform3i(shader->shader.uniforms[4],_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
|
974 | 974 | _6to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 63),
|
975 | 975 | _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
|
976 | 976 | break;
|
— | — | @@ -976,18 +976,16 @@ |
977 | 977 | case 24:
|
978 | 978 | case 32:
|
979 | 979 | default:
|
980 | | - ext->glUniform3i(shaders->shaders[progtype].ckey,(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
|
| 980 | + ext->glUniform3i(shader->shader.uniforms[4],(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
|
981 | 981 | (src->colorkey[0].key.dwColorSpaceHighValue>>8 & 255),
|
982 | 982 | (src->colorkey[0].key.dwColorSpaceHighValue & 255));
|
983 | 983 | break;
|
984 | 984 | }
|
985 | | - ext->glUniform1i(shaders->shaders[progtype].tex0,0);
|
| 985 | + ext->glUniform1i(shader->shader.uniforms[1],0);
|
986 | 986 | }
|
987 | 987 | else if(!(dwFlags & DDBLT_COLORFILL))
|
988 | 988 | {
|
989 | | - shaders->SetShader(PROG_TEXTURE,NULL,NULL,0);
|
990 | | - progtype = PROG_TEXTURE;
|
991 | | - ext->glUniform1i(shaders->shaders[progtype].tex0,0);
|
| 989 | + ext->glUniform1i(shader->shader.uniforms[1],0);
|
992 | 990 | }
|
993 | 991 | if(src)
|
994 | 992 | {
|
— | — | @@ -999,19 +997,19 @@ |
1000 | 998 | }
|
1001 | 999 | }
|
1002 | 1000 | else TextureManager_SetTexture(texman,0,NULL);
|
1003 | | - ext->glUniform4f(shaders->shaders[progtype].view,0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
|
| 1001 | + ext->glUniform4f(shader->shader.uniforms[0],0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
|
1004 | 1002 | dest->dirty |= 2;
|
1005 | | - util->EnableArray(shaders->shaders[progtype].pos,true);
|
1006 | | - ext->glVertexAttribPointer(shaders->shaders[progtype].pos,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
|
1007 | | - if(shaders->shaders[progtype].rgb != -1)
|
| 1003 | + util->EnableArray(shader->shader.attribs[0],true);
|
| 1004 | + ext->glVertexAttribPointer(shader->shader.attribs[0],2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
|
| 1005 | + if(shader->shader.attribs[1] != -1)
|
1008 | 1006 | {
|
1009 | | - util->EnableArray(shaders->shaders[progtype].rgb,true);
|
1010 | | - ext->glVertexAttribPointer(shaders->shaders[progtype].rgb,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
|
| 1007 | + util->EnableArray(shader->shader.attribs[1],true);
|
| 1008 | + ext->glVertexAttribPointer(shader->shader.attribs[0],3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
|
1011 | 1009 | }
|
1012 | 1010 | if(!(dwFlags & DDBLT_COLORFILL))
|
1013 | 1011 | {
|
1014 | | - util->EnableArray(shaders->shaders[progtype].texcoord,true);
|
1015 | | - ext->glVertexAttribPointer(shaders->shaders[progtype].texcoord,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
|
| 1012 | + util->EnableArray(shader->shader.attribs[3],true);
|
| 1013 | + ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
|
1016 | 1014 | }
|
1017 | 1015 | util->SetCull(D3DCULL_NONE);
|
1018 | 1016 | util->SetPolyMode(D3DFILL_SOLID);
|