diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index 8573a21ddb..08a9cc0301 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -510,7 +510,7 @@ FTexture *OpenGLFrameBuffer::WipeStartScreen() auto tex = new FWrapperTexture(viewport.width, viewport.height, 1); tex->GetSystemTexture()->CreateTexture(nullptr, viewport.width, viewport.height, 0, false, 0, "WipeStartScreen"); glFinish(); - static_cast(tex->GetSystemTexture())->Bind(0, false, false); + static_cast(tex->GetSystemTexture())->Bind(0, false); GLRenderer->mBuffers->BindCurrentFB(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height); @@ -532,7 +532,7 @@ FTexture *OpenGLFrameBuffer::WipeEndScreen() auto tex = new FWrapperTexture(viewport.width, viewport.height, 1); tex->GetSystemTexture()->CreateTexture(NULL, viewport.width, viewport.height, 0, false, 0, "WipeEndScreen"); glFinish(); - static_cast(tex->GetSystemTexture())->Bind(0, false, false); + static_cast(tex->GetSystemTexture())->Bind(0, false); GLRenderer->mBuffers->BindCurrentFB(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, viewport.left, viewport.top, viewport.width, viewport.height); return tex; diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index b9034b101e..9c5f7b8943 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -96,17 +96,16 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int texformat = GL_RGBA8; } */ - TranslatedTexture * glTex=GetTexID(translation); - bool firstCall = glTex->glTexID == 0; - if (firstCall) glGenTextures(1,&glTex->glTexID); + bool firstCall = glTexID == 0; + if (firstCall) glGenTextures(1,&glTexID); int textureBinding = UINT_MAX; if (texunit == -1) glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding); if (texunit > 0) glActiveTexture(GL_TEXTURE0+texunit); - if (texunit >= 0) lastbound[texunit] = glTex->glTexID; - glBindTexture(GL_TEXTURE_2D, glTex->glTexID); + if (texunit >= 0) lastbound[texunit] = glTexID; + glBindTexture(GL_TEXTURE_2D, glTexID); - FGLDebug::LabelObject(GL_TEXTURE, glTex->glTexID, name); + FGLDebug::LabelObject(GL_TEXTURE, glTexID, name); rw = GetTexDimension(w); rh = GetTexDimension(h); @@ -118,7 +117,7 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int else if (!buffer) { // The texture must at least be initialized if no data is present. - glTex->mipmapped = false; + mipmapped = false; buffer=(unsigned char *)calloc(4,rw * (rh+1)); deletebuffer=true; //texheight=-h; @@ -169,12 +168,12 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int if (mipmap && TexFilter[gl_texture_filter].mipmapping) { glGenerateMipmap(GL_TEXTURE_2D); - glTex->mipmapped = true; + mipmapped = true; } if (texunit > 0) glActiveTexture(GL_TEXTURE0); else if (texunit == -1) glBindTexture(GL_TEXTURE_2D, textureBinding); - return glTex->glTexID; + return glTexID; } @@ -205,66 +204,6 @@ uint8_t *FHardwareTexture::MapBuffer() return (uint8_t*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY); } -//=========================================================================== -// -// Creates a texture -// -//=========================================================================== -FHardwareTexture::FHardwareTexture(bool nocompression) -{ - forcenocompression = nocompression; - - glDefTex.glTexID = 0; - glDefTex.translation = 0; - glDefTex.mipmapped = false; - glDepthID = 0; -} - - -//=========================================================================== -// -// Deletes a texture id and unbinds it from the texture units -// -//=========================================================================== -void FHardwareTexture::TranslatedTexture::Delete() -{ - if (glTexID != 0) - { - for(int i = 0; i < MAX_TEXTURES; i++) - { - if (lastbound[i] == glTexID) - { - lastbound[i] = 0; - } - } - glDeleteTextures(1, &glTexID); - glTexID = 0; - mipmapped = false; - } -} - -//=========================================================================== -// -// Frees all associated resources -// -//=========================================================================== -void FHardwareTexture::Clean(bool all) -{ - int cm_arraysize = CM_FIRSTSPECIALCOLORMAP + SpecialColormaps.Size(); - - if (all) - { - glDefTex.Delete(); - } - for(unsigned int i=0;iglTexID != 0) + if (glTexID != 0) { - if (lastbound[texunit] == pTex->glTexID) return pTex->glTexID; - lastbound[texunit] = pTex->glTexID; + if (lastbound[texunit] == glTexID) return glTexID; + lastbound[texunit] = glTexID; if (texunit != 0) glActiveTexture(GL_TEXTURE0 + texunit); - glBindTexture(GL_TEXTURE_2D, pTex->glTexID); + glBindTexture(GL_TEXTURE_2D, glTexID); // Check if we need mipmaps on a texture that was creted without them. - if (needmipmap && !pTex->mipmapped && TexFilter[gl_texture_filter].mipmapping) + if (needmipmap && !mipmapped && TexFilter[gl_texture_filter].mipmapping) { glGenerateMipmap(GL_TEXTURE_2D); - pTex->mipmapped = true; + mipmapped = true; } if (texunit != 0) glActiveTexture(GL_TEXTURE0); - return pTex->glTexID; + return glTexID; } return 0; } unsigned int FHardwareTexture::GetTextureHandle(int translation) { - TranslatedTexture *pTex = GetTexID(translation); - return pTex->glTexID; + return glTexID; } void FHardwareTexture::Unbind(int texunit) @@ -390,7 +295,7 @@ void FHardwareTexture::BindToFrameBuffer(int width, int height) { width = GetTexDimension(width); height = GetTexDimension(height); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glDefTex.glTexID, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, glTexID, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer(width, height)); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, GetDepthBuffer(width, height)); } @@ -419,7 +324,7 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i bool needmipmap = (clampmode <= CLAMP_XY); // Bind it to the system. - if (!Bind(texunit, translation, needmipmap)) + if (!Bind(texunit, needmipmap)) { int w = 0, h = 0; @@ -450,29 +355,4 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i return true; } -//=========================================================================== -// -// Binds a texture to the renderer -// -//=========================================================================== - -bool FHardwareTexture::Exists(int translation) -{ - int usebright = false; - - if (translation <= 0) - { - translation = -translation; - } - else - { - auto remap = TranslationToTable(translation); - translation = remap == nullptr ? 0 : remap->GetUniqueIndex(); - } - - TranslatedTexture *pTex = GetTexID(translation); - return (pTex->glTexID != 0); -} - - } diff --git a/src/gl/textures/gl_hwtexture.h b/src/gl/textures/gl_hwtexture.h index 46e9cfde4b..db01f36376 100644 --- a/src/gl/textures/gl_hwtexture.h +++ b/src/gl/textures/gl_hwtexture.h @@ -19,31 +19,8 @@ class AActor; namespace OpenGLRenderer { - -// For error catching while changing parameters. -enum EInvalid -{ - Invalid = 0 -}; - class FHardwareTexture : public IHardwareTexture { -public: - enum - { - MAX_TEXTURES = 16 - }; - -private: - struct TranslatedTexture - { - unsigned int glTexID; - int translation; - bool mipmapped; - - void Delete(); - }; - public: static unsigned int lastbound[MAX_TEXTURES]; @@ -60,18 +37,20 @@ private: bool forcenocompression; - TranslatedTexture glDefTex; - TArray glTex_Translated; - unsigned int glDepthID; // only used by camera textures + unsigned int glTexID = 0; + unsigned int glDepthID = 0; // only used by camera textures unsigned int glBufferID = 0; int glTextureBytes = 4; - - TranslatedTexture * GetTexID(int translation); + bool mipmapped = false; int GetDepthBuffer(int w, int h); public: - FHardwareTexture(bool nocompress); + FHardwareTexture(bool nocompress) + { + forcenocompression = nocompress; + } + ~FHardwareTexture(); static void Unbind(int texunit); @@ -79,18 +58,14 @@ public: void BindToFrameBuffer(int w, int h); - unsigned int Bind(int texunit, int translation, bool needmipmap); + unsigned int Bind(int texunit, bool needmipmap); bool BindOrCreate(FTexture *tex, int texunit, int clampmode, int translation, int flags); - bool Exists(int translation); void AllocateBuffer(int w, int h, int texelsize); uint8_t *MapBuffer(); - unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const FString &name) = delete; unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name); unsigned int GetTextureHandle(int translation); - - void Clean(bool all); }; } diff --git a/src/hwrenderer/textures/hw_ihwtexture.h b/src/hwrenderer/textures/hw_ihwtexture.h index 07486e147f..f05baf47d5 100644 --- a/src/hwrenderer/textures/hw_ihwtexture.h +++ b/src/hwrenderer/textures/hw_ihwtexture.h @@ -25,8 +25,6 @@ public: virtual uint8_t *MapBuffer() = 0; virtual unsigned int CreateTexture(unsigned char * buffer, int w, int h, int texunit, bool mipmap, int translation, const char *name) = 0; - virtual void Clean(bool all) = 0; - void Resize(int swidth, int sheight, int width, int height, unsigned char *src_data, unsigned char *dst_data); };