diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 3893e564a..09d3cbd17 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -62,7 +62,7 @@ int32_t r_enablepolymost2 = 0; int32_t r_pogoDebug = 0; int32_t r_usenewshading = 4; int32_t r_usetileshades = 2; -int32_t r_npotwallmode = 0; +int32_t r_npotwallmode = 2; static float gviewxrange; static float ghoriz; @@ -72,7 +72,7 @@ float gcosang, gsinang, gcosang2, gsinang2; float gchang, gshang, gctang, gstang, gvisibility; float gtang = 0.f; -static vec3d_t xtex, ytex, otex; +static vec3d_t xtex, ytex, otex, xtex2, ytex2, otex2; float fcosglobalang, fsinglobalang; float fxdim, fydim, fydimen, fviewingrange; @@ -204,6 +204,12 @@ static GLint polymost1UseDetailMappingLoc = -1; static float polymost1UseDetailMapping = 0.f; static GLint polymost1UseGlowMappingLoc = -1; static float polymost1UseGlowMapping = 0.f; +static GLint polymost1NPOTEmulationLoc = -1; +static float polymost1NPOTEmulation = 0.f; +static GLint polymost1NPOTEmulationFactorLoc = -1; +static float polymost1NPOTEmulationFactor = 1.f; +static GLint polymost1NPOTEmulationXOffsetLoc = -1; +static float polymost1NPOTEmulationXOffset = 0.f; static GLint polymost1RotMatrixLoc = -1; static float polymost1RotMatrix[16] = { 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, @@ -621,6 +627,9 @@ static void polymost_setCurrentShaderProgram(uint32_t programID) polymost1UseColorOnlyLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useColorOnly"); polymost1UseDetailMappingLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useDetailMapping"); polymost1UseGlowMappingLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_useGlowMapping"); + polymost1NPOTEmulationLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulation"); + polymost1NPOTEmulationFactorLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationFactor"); + polymost1NPOTEmulationXOffsetLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_npotEmulationXOffset"); polymost1RotMatrixLoc = glGetUniformLocation(polymost1CurrentShaderProgramID, "u_rotMatrix"); //set the uniforms to the current values @@ -636,6 +645,9 @@ static void polymost_setCurrentShaderProgram(uint32_t programID) glUniform1f(polymost1UsePaletteLoc, polymost1UsePalette); glUniform1f(polymost1UseDetailMappingLoc, polymost1UseDetailMapping); glUniform1f(polymost1UseGlowMappingLoc, polymost1UseGlowMapping); + glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation); + glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor); + glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset); glUniformMatrix4fv(polymost1RotMatrixLoc, 1, false, polymost1RotMatrix); } @@ -790,6 +802,19 @@ void polymost_useGlowMapping(char useGlowMapping) } } +void polymost_npotEmulation(char npotEmulation, float factor, float xOffset) +{ + if (currentShaderProgramID == polymost1CurrentShaderProgramID) + { + polymost1NPOTEmulation = npotEmulation; + glUniform1f(polymost1NPOTEmulationLoc, polymost1NPOTEmulation); + polymost1NPOTEmulationFactor = factor; + glUniform1f(polymost1NPOTEmulationFactorLoc, polymost1NPOTEmulationFactor); + polymost1NPOTEmulationXOffset = xOffset; + glUniform1f(polymost1NPOTEmulationXOffsetLoc, polymost1NPOTEmulationXOffset); + } +} + void polymost_activeTexture(GLenum texture) { currentActiveTexture = texture; @@ -1103,6 +1128,9 @@ void polymost_glinit() \n\ uniform float u_useColorOnly;\n\ uniform float u_usePalette;\n\ + uniform float u_npotEmulation;\n\ + uniform float u_npotEmulationFactor;\n\ + uniform float u_npotEmulationXOffset;\n\ \n\ varying vec4 v_color;\n\ varying float v_distance;\n\ @@ -1118,10 +1146,16 @@ void polymost_glinit() \n\ void main()\n\ {\n\ + float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);\n\ + float coordX = mix(gl_TexCoord[0].x,gl_TexCoord[0].y,u_usePalette);\n\ + float period = floor(coordY/u_npotEmulationFactor);\n\ + coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));\n\ + coordY = period+mod(coordY,u_npotEmulationFactor);\n\ + vec2 newCoord = mix(gl_TexCoord[0].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);\n\ //GLSL 130+ could alternatively use texture2DGrad()\n\ - vec2 transitionBlend = fwidth(floor(gl_TexCoord[0].xy));\n\ + vec2 transitionBlend = fwidth(floor(newCoord.xy));\n\ transitionBlend = fwidth(transitionBlend)+transitionBlend;\n\ - vec2 texCoord = mix(fract(gl_TexCoord[0].xy), abs(c_one-mod(gl_TexCoord[0].xy+c_one, c_two)), transitionBlend);\n\ + vec2 texCoord = mix(fract(newCoord.xy), abs(c_one-mod(newCoord.xy+c_one, c_two)), transitionBlend);\n\ texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);\n\ vec4 color = texture2D(s_texture, u_texturePosSize.xy+texCoord);\n\ \n\ @@ -1178,6 +1212,9 @@ void polymost_glinit() \n\ uniform float u_useColorOnly;\n\ uniform float u_usePalette;\n\ + uniform float u_npotEmulation;\n\ + uniform float u_npotEmulationFactor;\n\ + uniform float u_npotEmulationXOffset;\n\ \n\ uniform float u_useDetailMapping;\n\ uniform float u_useGlowMapping;\n\ @@ -1196,10 +1233,16 @@ void polymost_glinit() \n\ void main()\n\ {\n\ + float coordY = mix(gl_TexCoord[0].y,gl_TexCoord[0].x,u_usePalette);\n\ + float coordX = mix(gl_TexCoord[0].x,gl_TexCoord[0].y,u_usePalette);\n\ + float period = floor(coordY/u_npotEmulationFactor);\n\ + coordX += u_npotEmulationXOffset*floor(mod(coordY,u_npotEmulationFactor));\n\ + coordY = period+mod(coordY,u_npotEmulationFactor);\n\ + vec2 newCoord = mix(gl_TexCoord[0].xy,mix(vec2(coordX,coordY),vec2(coordY,coordX),u_usePalette),u_npotEmulation);\n\ //GLSL 130+ could alternatively use texture2DGrad()\n\ - vec2 transitionBlend = fwidth(floor(gl_TexCoord[0].xy));\n\ + vec2 transitionBlend = fwidth(floor(newCoord.xy));\n\ transitionBlend = fwidth(transitionBlend)+transitionBlend;\n\ - vec2 texCoord = mix(fract(gl_TexCoord[0].xy), abs(c_one-mod(gl_TexCoord[0].xy+c_one, c_two)), transitionBlend);\n\ + vec2 texCoord = mix(fract(newCoord.xy), abs(c_one-mod(newCoord.xy+c_one, c_two)), transitionBlend);\n\ texCoord = clamp(u_texturePosSize.zw*texCoord, u_halfTexelSize, u_texturePosSize.zw-u_halfTexelSize);\n\ vec4 color = texture2D(s_texture, u_texturePosSize.xy+texCoord);\n\ \n\ @@ -3263,6 +3306,24 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 glActiveTexture(GL_TEXTURE0); } } + + if (glinfo.texnpot && r_npotwallmode == 2 && (method & DAMETH_WALL) != 0) + { + int32_t size = tilesiz[globalpicnum].y; + int32_t size2; + for (size2 = 1; size2 < size; size2 += size2) {} + if (size == size2) + polymost_npotEmulation(false, 1.f, 0.f); + else + { + float xOffset = 1.f / tilesiz[globalpicnum].x; + polymost_npotEmulation(true, (1.f*size2) / size, xOffset); + } + } + else + { + polymost_npotEmulation(false, 1.f, 0.f); + } #endif vec2f_t hacksc = { 1.f, 1.f }; @@ -3567,6 +3628,7 @@ do polymost_useDetailMapping(false); polymost_useGlowMapping(false); + polymost_npotEmulation(false, 1.f, 0.f); #endif if (pth->hicr) { @@ -4820,7 +4882,7 @@ static void calc_ypanning(int32_t refposz, float ryp0, float ryp1, t *= (float)tilesiz[globalpicnum].y / i; i = tilesiz[globalpicnum].y; } - else if (dopancor) + else if (!(glinfo.texnpot && r_npotwallmode == 2) && dopancor) { // Carry out panning "correction" to make it look like classic in some // cases, but failing in the general case. @@ -4938,13 +5000,20 @@ static void polymost_drawalls(int32_t const bunch) getzsofslope(sectnum,/*Blrintf(nx1)*/(int)n1.x,/*Blrintf(ny1)*/(int)n1.y,&cz,&fz); float const cy1 = ((float)(cz-globalposz))*ryp1 + ghoriz, fy1 = ((float)(fz-globalposz))*ryp1 + ghoriz; - // Floor + xtex2.d = (ryp0 - ryp1)*gxyaspect / (x0 - x1); + ytex2.d = 0; + otex2.d = ryp0 * gxyaspect - xtex2.d*x0; + + xtex2.u = ytex2.u = otex2.u = 0; + xtex2.v = ytex2.v = otex2.v = 0; #ifdef YAX_ENABLE yax_holencf[YAX_FLOOR] = 0; yax_drawcf = YAX_FLOOR; #endif + // Floor + globalpicnum = sec->floorpicnum; globalshade = sec->floorshade; globalpal = sec->floorpal; @@ -6436,11 +6505,11 @@ void polymost_drawmaskwall(int32_t damaskwallcnt) // | / // fsy1/ - vec2f_t dpxy[4] = { { x0, csy[1] }, { x1, csy[3] }, { x1, fsy[3] }, { x0, fsy[1] } }; + vec2f_t dpxy[8] = { { x0, csy[1] }, { x1, csy[3] }, { x1, fsy[3] }, { x0, fsy[1] } }; //Clip to (x0,csy[0])-(x1,csy[2]) - vec2f_t dp2[4]; + vec2f_t dp2[8]; int n2 = 0; t1 = -((dpxy[0].x - x0) * (csy[2] - csy[0]) - (dpxy[0].y - csy[0]) * (x1 - x0)); @@ -8732,7 +8801,7 @@ void polymost_initosdfuncs(void) { "r_swapinterval","sets the GL swap interval (VSync)",(void *) &vsync, CVAR_INT|CVAR_FUNCPTR, -1, 1 }, { "r_npotwallmode", "enable/disable emulation of walls with non-power-of-two height textures (Polymost, r_hightile 0)", - (void *) &r_npotwallmode, CVAR_BOOL, 0, 1 + (void *) &r_npotwallmode, CVAR_INT, 0, 2 }, { "r_anisotropy", "changes the OpenGL texture anisotropy setting", (void *) &glanisotropy, CVAR_INT|CVAR_FUNCPTR, 0, 16 }, { "r_texturemaxsize","changes the maximum OpenGL texture size limit",(void *) &gltexmaxsize, CVAR_INT | CVAR_NOSAVE, 0, 4096 },