mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 06:28:19 +00:00
Do not create 2D textures, if not required
This commit is contained in:
parent
2c02314708
commit
3117a936a9
|
@ -616,21 +616,30 @@ void CCommandProcessorFragment_OpenGL::Cmd_Texture_Create(const CCommandBuffer::
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
glGenTextures(1, &m_aTextures[pCommand->m_Slot].m_Tex);
|
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0)
|
||||||
glBindTexture(GL_TEXTURE_2D, m_aTextures[pCommand->m_Slot].m_Tex);
|
{
|
||||||
|
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)
|
if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS || !m_HasMipMaps)
|
||||||
{
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
{
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData);
|
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
|
else
|
||||||
{
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, StoreOglformat, Width, Height, 0, Oglformat, GL_UNSIGNED_BYTE, pTexData);
|
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 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);
|
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);
|
IsAndUpdateTextureSlotBound(Slot, pCommand->m_Slot);
|
||||||
glActiveTexture(GL_TEXTURE0 + 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);
|
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0)
|
||||||
glBindSampler(Slot, m_aTextures[pCommand->m_Slot].m_Sampler);
|
{
|
||||||
|
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)
|
if(Oglformat == GL_RED)
|
||||||
{
|
{
|
||||||
|
@ -2173,24 +2186,30 @@ void CCommandProcessorFragment_OpenGL3_3::Cmd_Texture_Create(const CCommandBuffe
|
||||||
|
|
||||||
if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS)
|
if(pCommand->m_Flags&CCommandBuffer::TEXFLAG_NOMIPMAPS)
|
||||||
{
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
{
|
||||||
glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MIN_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);
|
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
|
else
|
||||||
{
|
{
|
||||||
glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
if((pCommand->m_Flags&CCommandBuffer::TEXFLAG_NO_2D_TEXTURE) == 0)
|
||||||
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);
|
glSamplerParameteri(m_aTextures[pCommand->m_Slot].m_Sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 5);
|
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)
|
if((pCommand->m_Flags&(CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE | CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER)) != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -445,6 +445,8 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadTextureRaw(int Width, int Heig
|
||||||
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER;
|
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER;
|
||||||
if((Flags&IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER) != 0)
|
if((Flags&IGraphics::TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER) != 0)
|
||||||
Cmd.m_Flags |= CCommandBuffer::TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER;
|
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
|
// copy texture data
|
||||||
int MemSize = Width*Height*Cmd.m_PixelSize;
|
int MemSize = Width*Height*Cmd.m_PixelSize;
|
||||||
|
|
|
@ -133,6 +133,7 @@ public:
|
||||||
TEXFLAG_TO_2D_ARRAY_TEXTURE = (1 << 4),
|
TEXFLAG_TO_2D_ARRAY_TEXTURE = (1 << 4),
|
||||||
TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5),
|
TEXFLAG_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5),
|
||||||
TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6),
|
TEXFLAG_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6),
|
||||||
|
TEXFLAG_NO_2D_TEXTURE = (1 << 7),
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -139,6 +139,7 @@ public:
|
||||||
TEXLOAD_TO_2D_ARRAY_TEXTURE = (1 << 4),
|
TEXLOAD_TO_2D_ARRAY_TEXTURE = (1 << 4),
|
||||||
TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5),
|
TEXLOAD_TO_3D_TEXTURE_SINGLE_LAYER = (1 << 5),
|
||||||
TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6),
|
TEXLOAD_TO_2D_ARRAY_TEXTURE_SINGLE_LAYER = (1 << 6),
|
||||||
|
TEXLOAD_NO_2D_TEXTURE = (1 << 7),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ CMapImages::CMapImages(int TextureSize)
|
||||||
m_TextureScale = TextureSize;
|
m_TextureScale = TextureSize;
|
||||||
m_EntitiesIsLoaded = false;
|
m_EntitiesIsLoaded = false;
|
||||||
m_SpeedupArrowIsLoaded = false;
|
m_SpeedupArrowIsLoaded = false;
|
||||||
|
|
||||||
|
mem_zero(m_aTextureUsedByTileOrQuadLayerFlag, sizeof(m_aTextureUsedByTileOrQuadLayerFlag));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMapImages::OnInit()
|
void CMapImages::OnInit()
|
||||||
|
@ -36,7 +38,7 @@ void CMapImages::OnMapLoad()
|
||||||
{
|
{
|
||||||
Graphics()->UnloadTexture(m_aTextures[i]);
|
Graphics()->UnloadTexture(m_aTextures[i]);
|
||||||
m_aTextures[i] = IGraphics::CTextureHandle();
|
m_aTextures[i] = IGraphics::CTextureHandle();
|
||||||
m_aTextureUsedByLayer[i] = false;
|
m_aTextureUsedByTileOrQuadLayerFlag[i] = 0;
|
||||||
}
|
}
|
||||||
m_Count = 0;
|
m_Count = 0;
|
||||||
|
|
||||||
|
@ -60,7 +62,15 @@ void CMapImages::OnMapLoad()
|
||||||
CMapItemLayerTilemap *pTLayer = (CMapItemLayerTilemap *)pLayer;
|
CMapItemLayerTilemap *pTLayer = (CMapItemLayerTilemap *)pLayer;
|
||||||
if(pTLayer->m_Image != -1 && pTLayer->m_Image < (int)(sizeof(m_aTextures) / sizeof(m_aTextures[0])))
|
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
|
// load new textures
|
||||||
for(int i = 0; i < m_Count; i++)
|
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);
|
CMapItemImage *pImg = (CMapItemImage *)pMap->GetItem(Start+i, 0, 0);
|
||||||
if(pImg->m_External)
|
if(pImg->m_External)
|
||||||
{
|
{
|
||||||
char Buf[256];
|
char Buf[256];
|
||||||
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
|
char *pName = (char *)pMap->GetData(pImg->m_ImageName);
|
||||||
str_format(Buf, sizeof(Buf), "mapres/%s.png", pName);
|
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
|
else
|
||||||
{
|
{
|
||||||
void *pData = pMap->GetData(pImg->m_ImageData);
|
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);
|
pMap->UnloadData(pImg->m_ImageData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +140,7 @@ IGraphics::CTextureHandle CMapImages::GetSpeedupArrow()
|
||||||
{
|
{
|
||||||
if(!m_SpeedupArrowIsLoaded)
|
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_SpeedupArrowTexture = Graphics()->LoadTexture(g_pData->m_aImages[IMAGE_SPEEDUP_ARROW].m_pFilename, IStorage::TYPE_ALL, CImageInfo::FORMAT_AUTO, TextureLoadFlag);
|
||||||
|
|
||||||
m_SpeedupArrowIsLoaded = true;
|
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, 1);
|
||||||
UpdateEntityLayerText(pMem, 4, 1024, 1024, TextureSize, YOffset, 2, 255);
|
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);
|
IGraphics::CTextureHandle Texture = Graphics()->LoadTextureRaw(1024, 1024, CImageInfo::FORMAT_RGBA, pMem, CImageInfo::FORMAT_RGBA, TextureLoadFlag);
|
||||||
free(pMem);
|
free(pMem);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class CMapImages : public CComponent
|
||||||
friend class CBackground;
|
friend class CBackground;
|
||||||
|
|
||||||
IGraphics::CTextureHandle m_aTextures[64];
|
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;
|
int m_Count;
|
||||||
|
|
||||||
const char *m_pEntitiesGameType;
|
const char *m_pEntitiesGameType;
|
||||||
|
|
Loading…
Reference in a new issue