diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 0c6489e44..5e31296a2 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -616,21 +616,30 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer:: } } - glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); - glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); + if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0) + { + glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); + } if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS || !m_HasMipMaps) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + } } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + } int Flag2DArrayTexture = (CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE | CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER); int Flag3DTexture = (CCommandBuffer::TEXFLAG_TO_3D_TEXTURE | CCommandBuffer::TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER); @@ -2157,11 +2166,15 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe IsAndUpdateTextureSlotBound(Slot, pCommand->m_Slot); glActiveTexture(GL_TEXTURE0 + Slot); } - glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); - glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); - glGenSamplers(1, &m_aTextures[pCommand->m_Slot].m_Sampler); - glBindSampler(Slot, m_aTextures[pCommand->m_Slot].m_Sampler); + if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0) + { + glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex); + glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex); + + glGenSamplers(1, &m_aTextures[pCommand->m_Slot].m_Sampler); + glBindSampler(Slot, m_aTextures[pCommand->m_Slot].m_Sampler); + } if(Oglformat == GL_RED) { @@ -2173,24 +2186,30 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + } } else { - glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - //prevent mipmap display bugs, when zooming out far - if(Width >= 1024 && Height >= 1024) + if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0) { - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5.f); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); + glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); + //prevent mipmap display bugs, when zooming out far + if(Width >= 1024 && Height >= 1024) + { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5.f); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5); + } + glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); + glGenerateMipmap(GL_TEXTURE_2D); } - glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData); - glGenerateMipmap(GL_TEXTURE_2D); if((pCommand->m_Flags&(CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE | CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER)) != 0) { diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 9041ada30..46bcc16a3 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -445,6 +445,8 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Heig Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER; if((Flags&IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER) != 0) Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER; + if((Flags&IGraphics::TEXLOAD_NO_2D_TEXTURE) != 0) + Cmd.m_Flags |= CCommandBuffer::TEXFLAG_NO_2D_TEXTURE; // copy texture data int MemSize = Width*Height*Cmd.m_PixelSize; diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index f3390c25a..576b1d82d 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -133,6 +133,7 @@ public: TEXFLAG_TO_2D_ARRAY_TEXTURE = (1 << 4), TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5), TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6), + TEXFLAG_NO_2D_TEXTURE = (1 << 7), }; enum diff --git a/src/engine/graphics.h b/src/engine/graphics.h index 9a220761e..abc5a5ca0 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -139,6 +139,7 @@ public: TEXLOAD_TO_2D_ARRAY_TEXTURE = (1 << 4), TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5), TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6), + TEXLOAD_NO_2D_TEXTURE = (1 << 7), }; diff --git a/src/game/client/components/mapimages.cpp b/src/game/client/components/mapimages.cpp index e71d0006d..f0b8f77e3 100644 --- a/src/game/client/components/mapimages.cpp +++ b/src/game/client/components/mapimages.cpp @@ -20,6 +20,8 @@ CMapImages::CMapImages(int TextureSize) m_TextureScale = TextureSize; m_EntitiesIsLoaded = false; m_SpeedupArrowIsLoaded = false; + + mem_zero(m_aTextureUsedByTileOrQuadLayerFlag, sizeof(m_aTextureUsedByTileOrQuadLayerFlag)); } void CMapImages::OnInit() @@ -36,7 +38,7 @@ void CMapImages::OnMapLoad() { Graphics()->UnloadTexture(m_aTextures[i]); m_aTextures[i] = IGraphics::CTextureHandle(); - m_aTextureUsedByLayer[i] = false; + m_aTextureUsedByTileOrQuadLayerFlag[i] = 0; } m_Count = 0; @@ -60,7 +62,15 @@ void CMapImages::OnMapLoad() CMapItemLayerTilemap *pTLayer = (CMapItemLayerTilemap *)pLayer; if(pTLayer->m_Image != -1 && pTLayer->m_Image < (int)(sizeof(m_aTextures) / sizeof(m_aTextures[0]))) { - m_aTextureUsedByLayer[(size_t)pTLayer->m_Image] = true; + m_aTextureUsedByTileOrQuadLayerFlag[(size_t)pTLayer->m_Image] |= 1; + } + } + else if(pLayer->m_Type == LAYERTYPE_QUADS) + { + CMapItemLayerQuads *pQLayer = (CMapItemLayerQuads *)pLayer; + if(pQLayer->m_Image != -1 && pQLayer->m_Image < (int)(sizeof(m_aTextures) / sizeof(m_aTextures[0]))) + { + m_aTextureUsedByTileOrQuadLayerFlag[(size_t)pQLayer->m_Image] |= 2; } } } @@ -71,18 +81,19 @@ void CMapImages::OnMapLoad() // load new textures for(int i = 0; i < m_Count; i++) { + int LoadFlag = (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 1) != 0) ? TextureLoadFlag : 0) | (((m_aTextureUsedByTileOrQuadLayerFlag[i] & 2) != 0) ? 0 : (Graphics()->IsTileBufferingEnabled() ? IGraphics::TEXLOAD_NO_2D_TEXTURE : 0)); CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0); if(pImg->m_External) { char Buf[256]; char *pName = (char *)pMap->GetData(pImg->m_ImageName); str_format(Buf, sizeof(Buf), "mapres/%s.png", pName); - m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, m_aTextureUsedByLayer[i] ? TextureLoadFlag : 0); + m_aTextures[i] = Graphics()->LoadTexture(Buf, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, LoadFlag); } else { void *pData = pMap->GetData(pImg->m_ImageData); - m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, m_aTextureUsedByLayer[i] ? TextureLoadFlag : 0); + m_aTextures[i] = Graphics()->LoadTextureRaw(pImg->m_Width, pImg->m_Height, CImageInfo::FORMAT_RGBA, pData, CImageInfo::FORMAT_RGBA, LoadFlag); pMap->UnloadData(pImg->m_ImageData); } } @@ -129,7 +140,7 @@ IGraphics::CTextureHandle CMapImages::GetSpeedupArrow() { if(!m_SpeedupArrowIsLoaded) { - int TextureLoadFlag = Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER : IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER; + int TextureLoadFlag = (Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER : IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER) | IGraphics::TEXLOAD_NO_2D_TEXTURE; m_SpeedupArrowTexture = Graphics()->LoadTexture(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_pFilename, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, TextureLoadFlag); m_SpeedupArrowIsLoaded = true; @@ -184,7 +195,7 @@ IGraphics::CTextureHandle CMapImages::UploadEntityLayerText(int TextureSize, int UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, YOffset, 1); UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, YOffset, 2, 255); - int TextureLoadFlag = Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; + int TextureLoadFlag = (Graphics()->HasTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE) | IGraphics::TEXLOAD_NO_2D_TEXTURE; IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_RGBA, pMem, CImageInfo::FORMAT_RGBA, TextureLoadFlag); free(pMem); diff --git a/src/game/client/components/mapimages.h b/src/game/client/components/mapimages.h index d63626c5e..099730f5f 100644 --- a/src/game/client/components/mapimages.h +++ b/src/game/client/components/mapimages.h @@ -9,7 +9,7 @@ class CMapImages : public CComponent friend class CBackground; IGraphics::CTextureHandle m_aTextures[64]; - bool m_aTextureUsedByLayer[64]; + int m_aTextureUsedByTileOrQuadLayerFlag[64]; // 0: nothing, 1(as flag): tile layer, 2(as flag): quad layer int m_Count; const char *m_pEntitiesGameType;