diff --git a/src/gl/textures/gl_hwtexture.cpp b/src/gl/textures/gl_hwtexture.cpp index f3c78b6e6..7018e61c9 100644 --- a/src/gl/textures/gl_hwtexture.cpp +++ b/src/gl/textures/gl_hwtexture.cpp @@ -99,10 +99,14 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int TranslatedTexture * glTex=GetTexID(translation); bool firstCall = glTex->glTexID == 0; if (firstCall) glGenTextures(1,&glTex->glTexID); - if (texunit != 0) glActiveTexture(GL_TEXTURE0+texunit); + + unsigned 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); + FGLDebug::LabelObject(GL_TEXTURE, glTex->glTexID, name); - lastbound[texunit] = glTex->glTexID; rw = GetTexDimension(w); rh = GetTexDimension(h); @@ -168,7 +172,8 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int glTex->mipmapped = true; } - if (texunit != 0) glActiveTexture(GL_TEXTURE0); + if (texunit > 0) glActiveTexture(GL_TEXTURE0); + else if (texunit == -1) glBindTexture(GL_TEXTURE_2D, textureBinding); return glTex->glTexID; } diff --git a/src/hwrenderer/textures/hw_material.cpp b/src/hwrenderer/textures/hw_material.cpp index 712a8e7af..0ee2f3bb9 100644 --- a/src/hwrenderer/textures/hw_material.cpp +++ b/src/hwrenderer/textures/hw_material.cpp @@ -140,7 +140,7 @@ IHardwareTexture * FMaterial::ValidateSysTexture(FTexture * tex, bool expand) IHardwareTexture *gltex = tex->SystemTexture[expand]; if (gltex == nullptr) { - gltex = tex->SystemTexture[expand] = screen->CreateHardwareTexture(tex); + gltex = tex->SystemTexture[expand] = screen->CreateHardwareTexture(); } return gltex; } diff --git a/src/textures/texture.cpp b/src/textures/texture.cpp index 0b22866ef..f91f7acc9 100644 --- a/src/textures/texture.cpp +++ b/src/textures/texture.cpp @@ -774,7 +774,7 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits) Format = bits; UseType = ETextureType::SWCanvas; bNoCompress = true; - SystemTexture[0] = screen->CreateHardwareTexture(this); + SystemTexture[0] = screen->CreateHardwareTexture(); } //=========================================================================== diff --git a/src/textures/textures.h b/src/textures/textures.h index c5249cd15..52cf9b97a 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -42,6 +42,7 @@ #include "colormatcher.h" #include "r_data/renderstyle.h" #include "r_data/r_translate.h" +#include "hwrenderer/textures/hw_texmanager.h" #include // 15 because 0th texture is our texture