diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 89f35222d..3b90ec61f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1051,7 +1051,6 @@ set (PCH_SOURCES gl/system/gl_debug.cpp gl/system/gl_wipe.cpp gl/textures/gl_hwtexture.cpp - gl/textures/gl_texture.cpp gl/textures/gl_samplers.cpp hwrenderer/data/flatvertices.cpp hwrenderer/dynlights/hw_aabbtree.cpp diff --git a/src/gl/renderer/gl_renderer.h b/src/gl/renderer/gl_renderer.h index 571793253..53c39f605 100644 --- a/src/gl/renderer/gl_renderer.h +++ b/src/gl/renderer/gl_renderer.h @@ -9,6 +9,10 @@ #include "gl/dynlights/gl_shadowmap.h" #include +#ifdef _MSC_VER +#pragma warning(disable:4244) +#endif + struct particle_t; class FCanvasTexture; class FFlatVertexBuffer; diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index d98bab181..64ac23b4d 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -403,6 +403,16 @@ void OpenGLFrameBuffer::UnbindTexUnit(int no) FHardwareTexture::Unbind(no); } +void OpenGLFrameBuffer::FlushTextures() +{ + if (GLRenderer) GLRenderer->FlushTextures(); +} + +void OpenGLFrameBuffer::TextureFilterChanged() +{ + if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); +} + void OpenGLFrameBuffer::UpdatePalette() diff --git a/src/gl/system/gl_framebuffer.h b/src/gl/system/gl_framebuffer.h index 26dbf1635..6c04fbdcf 100644 --- a/src/gl/system/gl_framebuffer.h +++ b/src/gl/system/gl_framebuffer.h @@ -46,6 +46,8 @@ public: IHardwareTexture *CreateHardwareTexture(FTexture *tex) override; FModelRenderer *CreateModelRenderer(int mli) override; void UnbindTexUnit(int no) override; + void FlushTextures() override; + void TextureFilterChanged() override; // Retrieves a buffer containing image data for a screenshot. // Hint: Pitch can be negative for upside-down images, in which case buffer diff --git a/src/gl/textures/gl_texture.cpp b/src/gl/textures/gl_texture.cpp deleted file mode 100644 index 594b0c77f..000000000 --- a/src/gl/textures/gl_texture.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// -//--------------------------------------------------------------------------- -// -// Copyright(C) 2004-2016 Christoph Oelckers -// All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with this program. If not, see http://www.gnu.org/licenses/ -// -//-------------------------------------------------------------------------- -// -/* -** Global texture data -** -*/ - -#include "gl/system/gl_system.h" -#include "c_cvars.h" -#include "w_wad.h" -#include "r_data/r_translate.h" -#include "c_dispatch.h" -#include "r_state.h" -#include "actor.h" -#include "textures/skyboxtexture.h" -#include "hwrenderer/textures/hw_material.h" - -#include "gl/system/gl_interface.h" -#include "gl/renderer/gl_renderer.h" -#include "gl/textures/gl_samplers.h" -#include "gl/models/gl_models.h" - -//========================================================================== -// -// Texture CVARs -// -//========================================================================== -CUSTOM_CVAR(Float,gl_texture_filter_anisotropic,8.0f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) -{ - if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); -} - -CCMD(gl_flush) -{ - if (GLRenderer != NULL) GLRenderer->FlushTextures(); -} - -CUSTOM_CVAR(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) -{ - if (self < 0 || self > 6) self=4; - if (GLRenderer != NULL && GLRenderer->mSamplerManager != NULL) GLRenderer->mSamplerManager->SetTextureFilterMode(); -} - -CUSTOM_CVAR(Bool, gl_texture_usehires, true, CVAR_ARCHIVE|CVAR_NOINITCALL) -{ - if (GLRenderer != NULL) GLRenderer->FlushTextures(); -} - -CVAR(Bool, gl_precache, false, CVAR_ARCHIVE) - -CVAR(Bool, gl_trimsprites, true, CVAR_ARCHIVE); - diff --git a/src/hwrenderer/utility/hw_cvars.cpp b/src/hwrenderer/utility/hw_cvars.cpp index 2d4b23a26..148d77c36 100644 --- a/src/hwrenderer/utility/hw_cvars.cpp +++ b/src/hwrenderer/utility/hw_cvars.cpp @@ -22,6 +22,7 @@ #include "c_cvars.h" +#include "c_dispatch.h" #include "v_video.h" #include "hw_cvars.h" #include "menu/menu.h" @@ -77,3 +78,34 @@ CUSTOM_CVAR (Float, vid_saturation, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) } CVAR(Int, gl_satformula, 1, CVAR_ARCHIVE|CVAR_GLOBALCONFIG); + +//========================================================================== +// +// Texture CVARs +// +//========================================================================== +CUSTOM_CVAR(Float,gl_texture_filter_anisotropic,8.0f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) +{ + screen->TextureFilterChanged(); +} + +CCMD(gl_flush) +{ + screen->FlushTextures(); +} + +CUSTOM_CVAR(Int, gl_texture_filter, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL) +{ + if (self < 0 || self > 6) self=4; + screen->TextureFilterChanged(); +} + +CUSTOM_CVAR(Bool, gl_texture_usehires, true, CVAR_ARCHIVE|CVAR_NOINITCALL) +{ + screen->FlushTextures(); +} + +CVAR(Bool, gl_precache, false, CVAR_ARCHIVE) + +CVAR(Bool, gl_trimsprites, true, CVAR_ARCHIVE); + diff --git a/src/textures/hires/hqresize.cpp b/src/textures/hires/hqresize.cpp index 3061726f3..9c176974d 100644 --- a/src/textures/hires/hqresize.cpp +++ b/src/textures/hires/hqresize.cpp @@ -34,16 +34,14 @@ ** */ -#include "gl/system/gl_system.h" -#include "gl/system/gl_interface.h" -#include "gl/renderer/gl_renderer.h" +#include "c_cvars.h" +#include "v_video.h" #include "hqnx/hqx.h" #ifdef HAVE_MMX #include "hqnx_asm/hqnx_asm.h" #endif #include "xbr/xbrz.h" #include "xbr/xbrz_old.h" - #include "parallel_for.h" CUSTOM_CVAR(Int, gl_texture_hqresize, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) @@ -58,18 +56,18 @@ CUSTOM_CVAR(Int, gl_texture_hqresize, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR if (self == 8) self = 10; if (self == 9) self = 6; #endif - GLRenderer->FlushTextures(); + screen->FlushTextures(); } CUSTOM_CVAR(Int, gl_texture_hqresize_maxinputsize, 512, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { if (self > 1024) self = 1024; - GLRenderer->FlushTextures(); + screen->FlushTextures(); } CUSTOM_CVAR(Int, gl_texture_hqresize_targets, 7, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { - GLRenderer->FlushTextures(); + screen->FlushTextures(); } CVAR (Flag, gl_texture_hqresize_textures, gl_texture_hqresize_targets, 1); @@ -327,10 +325,6 @@ unsigned char *FTexture::CreateUpsampledTextureBuffer (unsigned char *inputBuffe if ( bHasCanvas ) return inputBuffer; - // [BB] Don't upsample non-shader handled warped textures. Needs too much memory and time - if (gl.legacyMode && bWarped) - return inputBuffer; - // already scaled? if (Scale.X >= 2 && Scale.Y >= 2) return inputBuffer; diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index f719aec26..637b921b4 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -1373,72 +1373,63 @@ unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int if ((flags & CTF_CheckHires) && translation != STRange_AlphaTexture) { - buffer = LoadHiresTexture(&w, &h); + return LoadHiresTexture(&w, &h); } - if (buffer == nullptr) + int exx = !!(flags & CTF_Expand); + + W = w = GetWidth() + 2 * exx; + H = h = GetHeight() + 2 * exx; + + + buffer = new unsigned char[W*(H + 1) * 4]; + memset(buffer, 0, W * (H + 1) * 4); + + FBitmap bmp(buffer, W * 4, W, H); + + if (translation <= 0 || translation >= STRange_Min) { - - int exx = !!(flags & CTF_Expand); - - W = w = GetWidth() + 2 * exx; - H = h = GetHeight() + 2 * exx; - - - buffer = new unsigned char[W*(H + 1) * 4]; - memset(buffer, 0, W * (H + 1) * 4); - - FBitmap bmp(buffer, W * 4, W, H); - - if (translation <= 0 || translation >= STRange_Min) + // Allow creation of desaturated or special-colormapped textures for the legacy renderer. + FCopyInfo inf = { OP_COPY, BLEND_NONE,{ 0 }, 0, 0 }; + if (translation >= STRange_Desaturate && translation < STRange_Desaturate + 31) // there are 31 ranges of desaturations available { - // Allow creation of desaturated or special-colormapped textures for the legacy renderer. - FCopyInfo inf = { OP_COPY, BLEND_NONE,{ 0 }, 0, 0 }; - if (translation >= STRange_Desaturate && translation < STRange_Desaturate + 31) // there are 31 ranges of desaturations available - { - inf.blend = (EBlend)(BLEND_DESATURATE1 + translation - STRange_Desaturate); - } - else if (translation >= STRange_Specialcolormap && translation < STRange_Specialcolormap + (int)SpecialColormaps.Size()) - { - inf.blend = (EBlend)(BLEND_SPECIALCOLORMAP1 + translation - STRange_Specialcolormap); - } - - int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, translation >= STRange_Min ? &inf : nullptr); - CheckTrans(buffer, W*H, trans); - isTransparent = bTranslucent; - // alpha texture for legacy mode - if (translation == STRange_AlphaTexture) - { - for (int i = 0; i < W*H; i++) - { - int b = buffer[4 * i]; - int g = buffer[4 * i + 1]; - int r = buffer[4 * i + 2]; - int gray = Luminance(r, g, b); - buffer[4 * i] = 255; - buffer[4 * i + 1] = 255; - buffer[4 * i + 2] = 255; - buffer[4 * i + 3] = (buffer[4 * i + 3] * gray) >> 8; - } - } + inf.blend = (EBlend)(BLEND_DESATURATE1 + translation - STRange_Desaturate); } - else + else if (translation >= STRange_Specialcolormap && translation < STRange_Specialcolormap + (int)SpecialColormaps.Size()) { - // When using translations everything must be mapped to the base palette. - // so use CopyTrueColorTranslated - CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation)); - isTransparent = 0; - // This is not conclusive for setting the texture's transparency info. + inf.blend = (EBlend)(BLEND_SPECIALCOLORMAP1 + translation - STRange_Specialcolormap); } - // [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it. - // [BB] Potentially upsample the buffer. - if (flags & CTF_ProcessData) + int trans = CopyTrueColorPixels(&bmp, exx, exx, 0, translation >= STRange_Min ? &inf : nullptr); + CheckTrans(buffer, W*H, trans); + isTransparent = bTranslucent; + // alpha texture for legacy mode + if (translation == STRange_AlphaTexture) { - buffer = CreateUpsampledTextureBuffer(buffer, W, H, w, h, !!isTransparent); - ProcessData(buffer, w, h, false); + for (int i = 0; i < W*H; i++) + { + int b = buffer[4 * i]; + int g = buffer[4 * i + 1]; + int r = buffer[4 * i + 2]; + int gray = Luminance(r, g, b); + buffer[4 * i] = 255; + buffer[4 * i + 1] = 255; + buffer[4 * i + 2] = 255; + buffer[4 * i + 3] = (buffer[4 * i + 3] * gray) >> 8; + } } } + else + { + // When using translations everything must be mapped to the base palette. + // so use CopyTrueColorTranslated + CopyTrueColorTranslated(&bmp, exx, exx, 0, FUniquePalette::GetPalette(translation)); + isTransparent = 0; + // This is not conclusive for setting the texture's transparency info. + } + + // [BB] The hqnx upsampling (not the scaleN one) destroys partial transparency, don't upsamle textures using it. + // [BB] Potentially upsample the buffer. if ((flags & CTF_MaybeWarped) && bWarped && w*h <= 256 * 256) // do not software-warp larger textures, especially on the old systems that still need this fallback. { // need to do software warping @@ -1449,6 +1440,14 @@ unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int buffer = warpbuffer; wt->GenTime[0] = screen->FrameTime; } + else + { + if (flags & CTF_ProcessData) + buffer = CreateUpsampledTextureBuffer(buffer, W, H, w, h, !!isTransparent); + } + + if (flags & CTF_ProcessData) + ProcessData(buffer, w, h, false); return buffer; } diff --git a/src/v_video.h b/src/v_video.h index 49869a605..0c4ecce69 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -357,6 +357,8 @@ public: virtual IHardwareTexture *CreateHardwareTexture(FTexture *tex) { return nullptr; } virtual FModelRenderer *CreateModelRenderer(int mli) { return nullptr; } virtual void UnbindTexUnit(int no) {} + virtual void FlushTextures() {} + virtual void TextureFilterChanged() {} // Begin 2D drawing operations. // Returns true if hardware-accelerated 2D has been entered, false if not.