From 304a906aa7e654f70d332f9e5ef15b90a1171956 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 17 Oct 2019 14:21:51 +0200 Subject: [PATCH] copy code --- source/build/src/polymost.cpp | 57 +---------------------------- source/glbackend/glbackend.cpp | 66 +++++++++++++++++++++++++++++++++- source/glbackend/glbackend.h | 1 + 3 files changed, 67 insertions(+), 57 deletions(-) diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 0c1076c65..c10e74949 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -717,59 +717,11 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 polymost_bindPth(pth, mSampler); } - - VSMatrix texmat; - // texture scale by parkar request - if (pth->hicr && !drawingskybox && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) - { - texmat.loadIdentity(); - texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); - GLInterface.SetMatrix(Matrix_Texture, &texmat); - } - - if (videoGetRenderMode() == REND_POLYMOST) + if (videoGetRenderMode() == REND_POLYMOST) { polymost_updatePalette(); } - // detail texture - if (r_detailmapping) - { - pthtyp *detailpth = NULL; - - if (usehightile && !drawingskybox && hicfindsubst(globalpicnum, DETAILPAL, 1) && - (detailpth = texcache_fetch(globalpicnum, DETAILPAL, 0, method & ~DAMETH_MASKPROPS)) && - detailpth->hicr && detailpth->hicr->palnum == DETAILPAL) - { - GLInterface.UseDetailMapping(true); - polymost_setupdetailtexture(3, detailpth->glpic); - - texmat.loadIdentity(); - - if (pth->hicr && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) - texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); - - if ((detailpth->hicr->scale.x != 1.0f) || (detailpth->hicr->scale.y != 1.0f)) - texmat.scale(detailpth->hicr->scale.x, detailpth->hicr->scale.y, 1.0f); - - GLInterface.SetMatrix(Matrix_Detail, &texmat); - } - } - - // glow texture - if (r_glowmapping) - { - pthtyp *glowpth = NULL; - - if (usehightile && !drawingskybox && hicfindsubst(globalpicnum, GLOWPAL, 1) && - (glowpth = texcache_fetch(globalpicnum, GLOWPAL, 0, (method & ~DAMETH_MASKPROPS) | DAMETH_MASK)) && - glowpth->hicr && (glowpth->hicr->palnum == GLOWPAL)) - { - GLInterface.UseGlowMapping(true); - polymost_setupglowtexture(4, glowpth->glpic); - } - } - if ((method & DAMETH_WALL) != 0) { int32_t size = tilesize.y; @@ -872,13 +824,6 @@ static void polymost_drawpoly(vec2f_t const * const dpxy, int32_t const n, int32 GLInterface.UseGlowMapping(false); GLInterface.SetNpotEmulation(false, 1.f, 0.f); - if (pth->hicr) - { - VSMatrix identity(0); - GLInterface.SetMatrix(Matrix_Texture, &identity); - GLInterface.SetMatrix(Matrix_Detail, &identity); - } - if (skyzbufferhack && skyzbufferhack_pass == 0) { vec3d_t const bxtex = xtex, bytex = ytex, botex = otex; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index 5bcbb648d..c563c790d 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -201,7 +201,68 @@ std::pair GLInstance::AllocVertices(size_t num) return std::make_pair((size_t)0, Buffer.data()); } -static GLint primtypes[] = +void GLInstance::ApplyTextureProps() +{ + + VSMatrix texmat; + // texture scale by parkar request + if (pth->hicr && !drawingskybox && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) + { + texmat.loadIdentity(); + texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); + GLInterface.SetMatrix(Matrix_Texture, &texmat); + } + + // detail texture + if (r_detailmapping) + { + pthtyp *detailpth = NULL; + + if (usehightile && !drawingskybox && hicfindsubst(globalpicnum, DETAILPAL, 1) && + (detailpth = texcache_fetch(globalpicnum, DETAILPAL, 0, method & ~DAMETH_MASKPROPS)) && + detailpth->hicr && detailpth->hicr->palnum == DETAILPAL) + { + GLInterface.UseDetailMapping(true); + polymost_setupdetailtexture(3, detailpth->glpic); + + texmat.loadIdentity(); + + if (pth->hicr && ((pth->hicr->scale.x != 1.0f) || (pth->hicr->scale.y != 1.0f))) + texmat.scale(pth->hicr->scale.x, pth->hicr->scale.y, 1.0f); + + if ((detailpth->hicr->scale.x != 1.0f) || (detailpth->hicr->scale.y != 1.0f)) + texmat.scale(detailpth->hicr->scale.x, detailpth->hicr->scale.y, 1.0f); + + GLInterface.SetMatrix(Matrix_Detail, &texmat); + } + } + + // glow texture + if (r_glowmapping) + { + pthtyp *glowpth = NULL; + + if (usehightile && !drawingskybox && hicfindsubst(globalpicnum, GLOWPAL, 1) && + (glowpth = texcache_fetch(globalpicnum, GLOWPAL, 0, (method & ~DAMETH_MASKPROPS) | DAMETH_MASK)) && + glowpth->hicr && (glowpth->hicr->palnum == GLOWPAL)) + { + GLInterface.UseGlowMapping(true); + polymost_setupglowtexture(4, glowpth->glpic); + } + } + return true; // true if the matrices were changed, false otherwise +} + +void GLInstance::RestoreTextureProps() +{ + // todo: reset everything that's needed to ensure proper functionality + VSMatrix identity(0); + GLInterface.SetMatrix(Matrix_Texture, &identity); + GLInterface.SetMatrix(Matrix_Detail, &identity); +} + + +static GLint primtypes[] = { GL_TRIANGLES, GL_TRIANGLE_STRIP, @@ -213,9 +274,11 @@ static GLint primtypes[] = void GLInstance::Draw(EDrawType type, size_t start, size_t count) { // Todo: Based on the current tinting flags and the texture type (indexed texture and APPLYOVERPALSWAP not set) this may have to reset the palette for the draw call / texture creation. + bool applied = false; if (activeShader == polymostShader) { + applied = ApplyTextureProps(); renderState.UsePalette = texv && texv->isIndexed(); renderState.Apply(polymostShader); } @@ -227,6 +290,7 @@ void GLInstance::Draw(EDrawType type, size_t start, size_t count) glVertexAttrib3f(0, p->x, p->y, p->z); } glEnd(); + if (applied) RestoreTextureProps(); } int GLInstance::GetTextureID() diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index 1055057df..3aec7987e 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -277,6 +277,7 @@ public: void SetSurfaceShader(); void SetVPXShader(); void SetPalette(int palette); + void ApplyTextureProps(); void ReadPixels(int w, int h, uint8_t* buffer);