DXGL r238 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r237‎ | r238 | r239 >
Date:19:39, 12 August 2012
Author:admin
Status:new
Tags:
Comment:
Cache 2D shader uniforms
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/shaders.cpp (modified) (history)
  • /ddraw/shaders.h (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -929,20 +929,19 @@
930930 {
931931 SetShader(PROG_CKEY,NULL,NULL,true);
932932 progtype = PROG_CKEY;
933 - GLint keyloc = glGetUniformLocation(shaders[PROG_CKEY].prog,"keyIn");
934933 switch(ddInterface->GetBPP())
935934 {
936935 case 8:
937 - glUniform3i(keyloc,src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
 936+ glUniform3i(shaders[progtype].ckey,src->colorkey[0].key.dwColorSpaceHighValue,src->colorkey[0].key.dwColorSpaceHighValue,
938937 src->colorkey[0].key.dwColorSpaceHighValue);
939938 break;
940939 case 15:
941 - glUniform3i(keyloc,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
 940+ glUniform3i(shaders[progtype].ckey,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>10 & 31),
942941 _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 31),
943942 _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
944943 break;
945944 case 16:
946 - glUniform3i(keyloc,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
 945+ glUniform3i(shaders[progtype].ckey,_5to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>11 & 31),
947946 _6to8bit(src->colorkey[0].key.dwColorSpaceHighValue>>5 & 63),
948947 _5to8bit(src->colorkey[0].key.dwColorSpaceHighValue & 31));
949948 break;
@@ -949,26 +948,22 @@
950949 case 24:
951950 case 32:
952951 default:
953 - glUniform3i(keyloc,(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
 952+ glUniform3i(shaders[progtype].ckey,(src->colorkey[0].key.dwColorSpaceHighValue>>16 & 255),
954953 (src->colorkey[0].key.dwColorSpaceHighValue>>8 & 255),
955954 (src->colorkey[0].key.dwColorSpaceHighValue & 255));
956955 break;
957956 }
958 - GLint texloc = glGetUniformLocation(shaders[PROG_CKEY].prog,"myTexture");
959 - glUniform1i(texloc,0);
 957+ glUniform1i(shaders[progtype].tex0,0);
960958 }
961959 else if(!(dwFlags & DDBLT_COLORFILL))
962960 {
963961 SetShader(PROG_TEXTURE,NULL,NULL,true);
964962 progtype = PROG_TEXTURE;
965 - GLint texloc = glGetUniformLocation(shaders[PROG_TEXTURE].prog,"Texture");
966 - glUniform1i(texloc,0);
 963+ glUniform1i(shaders[progtype].tex0,0);
967964 }
968965 SetActiveTexture(0);
969966 if(src) glBindTexture(GL_TEXTURE_2D,src->GetTexture());
970 - GLuint prog = GetProgram()&0xffffffff;
971 - GLint viewloc = glGetUniformLocation(prog,"view");
972 - glUniform4f(viewloc,0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
 967+ glUniform4f(shaders[progtype].view,0,(GLfloat)dest->fakex,0,(GLfloat)dest->fakey);
973968 dest->dirty |= 2;
974969 EnableArray(shaders[progtype].pos,true);
975970 glVertexAttribPointer(shaders[progtype].pos,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
@@ -1030,10 +1025,7 @@
10311026 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
10321027 glBindTexture(GL_TEXTURE_2D,*texture);
10331028 *texture = backbuffer;
1034 - GLuint prog = GetProgram();
1035 - GLint viewloc = glGetUniformLocation(prog,"view");
1036 - glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
1037 -
 1029+ glUniform4f(shaders[progtype].view,view[0],view[1],view[2],view[3]);
10381030 bltvertices[0].s = bltvertices[0].t = bltvertices[1].t = bltvertices[2].s = 1.;
10391031 bltvertices[1].s = bltvertices[2].t = bltvertices[3].s = bltvertices[3].t = 0.;
10401032 bltvertices[0].y = bltvertices[1].y = bltvertices[1].x = bltvertices[3].x = 0.;
@@ -1113,10 +1105,8 @@
11141106 progtype = PROG_PAL256;
11151107 glBindTexture(GL_TEXTURE_2D,paltex);
11161108 glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,1,0,GL_RGBA,GL_UNSIGNED_BYTE,dest->palette->GetPalette(NULL));
1117 - GLint palloc = glGetUniformLocation(shaders[PROG_PAL256].prog,"ColorTable");
1118 - GLint texloc = glGetUniformLocation(shaders[PROG_PAL256].prog,"IndexTexture");
1119 - glUniform1i(texloc,0);
1120 - glUniform1i(palloc,1);
 1109+ glUniform1i(shaders[progtype].tex0,0);
 1110+ glUniform1i(shaders[progtype].pal,1);
11211111 SetActiveTexture(0);
11221112 glBindTexture(GL_TEXTURE_2D,texture);
11231113 SetActiveTexture(1);
@@ -1128,9 +1118,7 @@
11291119 SetShader(PROG_TEXTURE,NULL,NULL,true);
11301120 progtype = PROG_TEXTURE;
11311121 glBindTexture(GL_TEXTURE_2D,texture);
1132 - GLuint prog = GetProgram() & 0xFFFFFFFF;
1133 - GLint texloc = glGetUniformLocation(prog,"Texture");
1134 - glUniform1i(texloc,0);
 1122+ glUniform1i(shaders[progtype].tex0,0);
11351123 }
11361124 }
11371125 else
@@ -1138,14 +1126,10 @@
11391127 SetShader(PROG_TEXTURE,NULL,NULL,true);
11401128 progtype = PROG_TEXTURE;
11411129 glBindTexture(GL_TEXTURE_2D,texture);
1142 - GLuint prog = GetProgram() & 0xFFFFFFFF;
1143 - GLint texloc = glGetUniformLocation(prog,"Texture");
1144 - glUniform1i(texloc,0);
 1130+ glUniform1i(shaders[progtype].tex0,0);
11451131 }
11461132 SetViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
1147 - GLuint prog = GetProgram();
1148 - GLint viewloc = glGetUniformLocation(prog,"view");
1149 - glUniform4f(viewloc,view[0],view[1],view[2],view[3]);
 1133+ glUniform4f(shaders[progtype].view,view[0],view[1],view[2],view[3]);
11501134 if(ddInterface->GetFullscreen())
11511135 {
11521136 bltvertices[0].x = bltvertices[2].x = (float)sizes[0];
Index: ddraw/shaders.cpp
@@ -32,32 +32,32 @@
3333
3434 const char frag_Texture[] = "\
3535 #version 110\n\
36 -uniform sampler2D Texture;\n\
 36+uniform sampler2D tex0;\n\
3737 void main() \n\
3838 { \n\
39 - gl_FragColor = texture2D( Texture, gl_TexCoord[0].st ); \n\
 39+ gl_FragColor = texture2D( tex0, gl_TexCoord[0].st ); \n\
4040 } ";
4141
4242 const char frag_Pal256[] = "\
4343 #version 110\n\
44 -uniform sampler2D ColorTable; \n\
45 -uniform sampler2D IndexTexture; \n\
 44+uniform sampler2D pal; \n\
 45+uniform sampler2D tex0; \n\
4646 void main() \n\
4747 { \n\
48 - vec4 myindex = texture2D(IndexTexture, gl_TexCoord[0].xy); \n\
49 - vec4 texel = texture2D(ColorTable, myindex.xy); \n\
 48+ vec4 myindex = texture2D(tex0, gl_TexCoord[0].xy); \n\
 49+ vec4 texel = texture2D(pal, myindex.xy); \n\
5050 gl_FragColor = texel; \n\
5151 } ";
5252
5353 const char frag_ColorKey[] = "\
5454 #version 110\n\
55 -uniform sampler2D myTexture;\n\
56 -uniform ivec3 keyIn;\n\
 55+uniform sampler2D tex0;\n\
 56+uniform ivec3 ckey;\n\
5757 void main (void)\n\
5858 {\n\
59 - vec4 value = texture2D(myTexture, vec2(gl_TexCoord[0]));\n\
60 - ivec3 comp = ivec3(texture2D(myTexture, vec2(gl_TexCoord[0]))*255.0);\n\
61 - if (comp == keyIn)\n\
 59+ vec4 value = texture2D(tex0, vec2(gl_TexCoord[0]));\n\
 60+ ivec3 comp = ivec3(texture2D(tex0, vec2(gl_TexCoord[0]))*255.0);\n\
 61+ if (comp == ckey)\n\
6262 discard;\n\
6363 gl_FragColor = value;\n\
6464 } ";
@@ -64,13 +64,13 @@
6565
6666 const char frag_ColorKeyMask[] = "\
6767 #version 110\n\
68 -uniform sampler2D myTexture;\n\
69 -uniform ivec4 keyIn;\n\
 68+uniform sampler2D tex0;\n\
 69+uniform ivec4 ckey;\n\
7070 void main (void)\n\
7171 {\n\
72 - vec4 value = texture2D(myTexture, vec2(gl_TexCoord[0]));\n\
73 - ivec4 comp = ivec4(texture2D(myTexture, vec2(gl_TexCoord[0]))*255.0);\n\
74 - if (comp == keyIn)\n\
 72+ vec4 value = texture2D(tex0, vec2(gl_TexCoord[0]));\n\
 73+ ivec4 comp = ivec4(texture2D(tex0, vec2(gl_TexCoord[0]))*255.0);\n\
 74+ if (comp == ckey)\n\
7575 gl_FragColor[0] = 1.0;\n\
7676 else gl_FragColor[0] = 0.0;\n\
7777 } ";
@@ -77,16 +77,16 @@
7878
7979 const char frag_2ColorKey[] = "\
8080 #version 110\n\
81 -uniform sampler2D myTexture;\n\
82 -uniform sampler2D maskTexture;\n\
83 -uniform ivec4 keyIn;\n\
 81+uniform sampler2D tex0;\n\
 82+uniform sampler2D tex1;\n\
 83+uniform ivec4 ckey;\n\
8484 void main (void)\n\
8585 {\n\
86 - vec4 value = texture2D(myTexture, vec2(gl_TexCoord[0]));\n\
87 - ivec4 comp = ivec4(texture2D(myTexture, vec2(gl_TexCoord[0]))*255.0);\n\
88 - if (comp == keyIn)\n\
 86+ vec4 value = texture2D(tex0, vec2(gl_TexCoord[0]));\n\
 87+ ivec4 comp = ivec4(texture2D(tex0, vec2(gl_TexCoord[0]))*255.0);\n\
 88+ if (comp == ckey)\n\
8989 discard;\n\
90 - ivec4 comp2 = ivec4(texture2D(maskTexture,vec2(gl_TexCoord[1]))*255.0);\n\
 90+ ivec4 comp2 = ivec4(texture2D(tex1,vec2(gl_TexCoord[1]))*255.0);\n\
9191 if(comp2[0] == 0)\n\
9292 discard;\n\
9393 gl_FragColor = value;\n\
@@ -160,6 +160,11 @@
161161 shaders[i].pos = glGetAttribLocation(shaders[i].prog,"xy");
162162 shaders[i].rgb = glGetAttribLocation(shaders[i].prog,"rgb");
163163 shaders[i].texcoord = glGetAttribLocation(shaders[i].prog,"st");
 164+ shaders[i].tex0 = glGetUniformLocation(shaders[i].prog,"tex0");
 165+ shaders[i].tex1 = glGetUniformLocation(shaders[i].prog,"tex1");
 166+ shaders[i].ckey = glGetUniformLocation(shaders[i].prog,"ckey");
 167+ shaders[i].pal = glGetUniformLocation(shaders[i].prog,"pal");
 168+ shaders[i].view = glGetUniformLocation(shaders[i].prog,"view");
164169 }
165170 }
166171
Index: ddraw/shaders.h
@@ -29,6 +29,11 @@
3030 GLint pos;
3131 GLint rgb;
3232 GLint texcoord;
 33+ GLint tex0;
 34+ GLint tex1;
 35+ GLint ckey;
 36+ GLint pal;
 37+ GLint view;
3338 } SHADER;
3439
3540 extern SHADER shaders[];