From 0127a71974171b311a7e67f89abc46feb23e673f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 1 Apr 2018 17:16:53 +0200 Subject: [PATCH] - fixed last commit. --- src/gl/renderer/gl_postprocess.cpp | 2 +- src/gl/system/gl_system.h | 11 +---------- src/gl/system/gl_wipe.cpp | 6 +++--- src/gl/textures/gl_hwtexture.cpp | 19 +++++++++---------- src/gl/textures/gl_hwtexture.h | 6 +++--- src/gl/textures/gl_material.cpp | 7 +++---- src/textures/texture.cpp | 2 -- 7 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 22854cd4d..b36da7f22 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -625,7 +625,7 @@ void FGLRenderer::CreateTonemapPalette() } } - mTonemapPalette = new FHardwareTexture(512, 512, true); + mTonemapPalette = new FHardwareTexture(true); mTonemapPalette->CreateTexture(&lut[0], 512, 512, 0, false, 0, "mTonemapPalette"); } } diff --git a/src/gl/system/gl_system.h b/src/gl/system/gl_system.h index a8dcd129e..0ad2f3303 100644 --- a/src/gl/system/gl_system.h +++ b/src/gl/system/gl_system.h @@ -6,7 +6,6 @@ #include #include #include -//#include #include #include #include @@ -20,20 +19,12 @@ #endif #include -#ifdef _MSC_VER -#define F_OK 0 /* Check for file existence */ -#define W_OK 2 /* Check for write permission */ -#define R_OK 4 /* Check for read permission */ -#include -#else -#include -#endif #include #include #include //GL headers -#include "gl_load.h" +#include "gl_load/gl_load.h" #if defined(__APPLE__) #include diff --git a/src/gl/system/gl_wipe.cpp b/src/gl/system/gl_wipe.cpp index f00dcfeb0..5e88c210e 100644 --- a/src/gl/system/gl_wipe.cpp +++ b/src/gl/system/gl_wipe.cpp @@ -120,7 +120,7 @@ bool OpenGLFrameBuffer::WipeStartScreen(int type) } const auto &viewport = GLRenderer->mScreenViewport; - wipestartscreen = new FHardwareTexture(viewport.width, viewport.height, true); + wipestartscreen = new FHardwareTexture(true); wipestartscreen->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeStartScreen"); GLRenderer->mSamplerManager->Bind(0, CLAMP_NOFILTER, -1); GLRenderer->mSamplerManager->Bind(1, CLAMP_NONE, -1); @@ -167,7 +167,7 @@ bool OpenGLFrameBuffer::WipeStartScreen(int type) void OpenGLFrameBuffer::WipeEndScreen() { const auto &viewport = GLRenderer->mScreenViewport; - wipeendscreen = new FHardwareTexture(viewport.width, viewport.height, true); + wipeendscreen = new FHardwareTexture(true); wipeendscreen->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeEndScreen"); GLRenderer->mSamplerManager->Bind(0, CLAMP_NOFILTER, -1); glFinish(); @@ -511,7 +511,7 @@ bool OpenGLFrameBuffer::Wiper_Burn::Run(int ticks, OpenGLFrameBuffer *fb) } if (BurnTexture != NULL) delete BurnTexture; - BurnTexture = new FHardwareTexture(WIDTH, HEIGHT, true); + BurnTexture = new FHardwareTexture(true); // Update the burn texture with the new burn data uint8_t rgb_buffer[WIDTH*HEIGHT*4]; diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index f6edec687..577e73390 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -85,7 +85,7 @@ static void ResampleBoxPrecalc(TArray& boxes, int oldDim) } } -void FHardwareTexture::Resize(int width, int height, unsigned char *src_data, unsigned char *dst_data) +void FHardwareTexture::Resize(int swidth, int sheight, int width, int height, unsigned char *src_data, unsigned char *dst_data) { // This function implements a simple pre-blur/box averaging method for @@ -96,8 +96,8 @@ void FHardwareTexture::Resize(int width, int height, unsigned char *src_data, un TArray vPrecalcs(height, true); TArray hPrecalcs(width, true); - ResampleBoxPrecalc(vPrecalcs, texheight); - ResampleBoxPrecalc(hPrecalcs, texwidth); + ResampleBoxPrecalc(vPrecalcs, sheight); + ResampleBoxPrecalc(hPrecalcs, swidth); int averaged_pixels, averaged_alpha, src_pixel_index; double sum_r, sum_g, sum_b, sum_a; @@ -122,7 +122,7 @@ void FHardwareTexture::Resize(int width, int height, unsigned char *src_data, un for (int i = hPrecalc.boxStart; i <= hPrecalc.boxEnd; ++i) { // Calculate the actual index in our source pixels - src_pixel_index = j * texwidth + i; + src_pixel_index = j * swidth + i; int a = src_data[src_pixel_index * 4 + 3]; if (a > 0) // do not use color from fully transparent pixels @@ -179,8 +179,6 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int if (!buffer) { - w=texwidth; - h=abs(texheight); rw = GetTexDimension (w); rh = GetTexDimension (h); @@ -201,12 +199,15 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int unsigned char * scaledbuffer=(unsigned char *)calloc(4,rw * (rh+1)); if (scaledbuffer) { - Resize(rw, rh, buffer, scaledbuffer); + Resize(w, h, rw, rh, buffer, scaledbuffer); deletebuffer=true; buffer=scaledbuffer; } } } + // store the physical size. + texwidth = rw; + texheight = rh; glTexImage2D(GL_TEXTURE_2D, 0, texformat, rw, rh, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer); if (deletebuffer) free(buffer); @@ -227,11 +228,9 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int // Creates a texture // //=========================================================================== -FHardwareTexture::FHardwareTexture(int _width, int _height, bool nocompression) +FHardwareTexture::FHardwareTexture(bool nocompression) { forcenocompression = nocompression; - texwidth=_width; - texheight=_height; glDefTex.glTexID = 0; glDefTex.translation = 0; diff --git a/src/gl/textures/gl_hwtexture.h b/src/gl/textures/gl_hwtexture.h index 59fc98169..2bbc41f8b 100644 --- a/src/gl/textures/gl_hwtexture.h +++ b/src/gl/textures/gl_hwtexture.h @@ -60,7 +60,7 @@ public: private: - short texwidth, texheight; + short texwidth = 0, texheight = 0; bool forcenocompression; TranslatedTexture glDefTex; @@ -70,10 +70,10 @@ private: TranslatedTexture * GetTexID(int translation); int GetDepthBuffer(); - void Resize(int width, int height, unsigned char *src_data, unsigned char *dst_data); + void Resize(int swidth, int sheight, int width, int height, unsigned char *src_data, unsigned char *dst_data); public: - FHardwareTexture(int w, int h, bool nocompress); + FHardwareTexture(bool nocompress); ~FHardwareTexture(); static void Unbind(int texunit); diff --git a/src/gl/textures/gl_material.cpp b/src/gl/textures/gl_material.cpp index c5d64a4ef..a851f88cd 100644 --- a/src/gl/textures/gl_material.cpp +++ b/src/gl/textures/gl_material.cpp @@ -69,7 +69,6 @@ FGLTexture::FGLTexture(FTexture * tx, bool expandpatches) tex = tx; mHwTexture = NULL; - bExpandFlag = expandpatches; lastSampler = 254; lastTranslation = -1; tex->gl_info.SystemTexture[expandpatches] = this; @@ -131,7 +130,7 @@ FHardwareTexture *FGLTexture::CreateHwTexture() if (tex->UseType==ETextureType::Null) return NULL; // Cannot register a NULL texture if (mHwTexture == NULL) { - mHwTexture = new FHardwareTexture(tex->GetWidth() + bExpandFlag*2, tex->GetHeight() + bExpandFlag*2, tex->gl_info.bNoCompress); + mHwTexture = new FHardwareTexture(tex->gl_info.bNoCompress); } return mHwTexture; } @@ -627,7 +626,7 @@ void FMaterial::Bind(int clampmode, int translation) { layer = mTextureLayers[i].texture; } - layer->gl_info.SystemTexture[mExpanded]->Bind(i+1, clampmode, 0, NULL); + layer->gl_info.SystemTexture[mExpanded]->Bind(i+1, clampmode, 0, 0); maxbound = i+1; } } @@ -738,7 +737,7 @@ void FMaterial::BindToFrameBuffer() if (mBaseLayer->mHwTexture == NULL) { // must create the hardware texture first - mBaseLayer->Bind(0, 0, 0, NULL); + mBaseLayer->Bind(0, 0, 0, 0); FHardwareTexture::Unbind(0); ClearLastTexture(); } diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 8a8d00449..6f91b33b0 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -1353,8 +1353,6 @@ unsigned char * FTexture::CreateTexBuffer(int translation, int & w, int & h, int int isTransparent = -1; - // Textures that are already scaled in the texture lump will not get replaced - // by hires textures if ((flags & CTF_CheckHires) && translation != STRange_AlphaTexture) { buffer = LoadHiresTexture(&w, &h);