Index: source/graphics/TextureManager.h =================================================================== --- source/graphics/TextureManager.h +++ source/graphics/TextureManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -112,10 +112,16 @@ bool GenerateCachedTexture(const VfsPath& path, VfsPath& outputPath); /** - * Returns total number of bytes uploaded for all current texture. + * Returns total number of bytes uploaded for all current textures. */ size_t GetBytesUploaded() const; + /** + * Create and set the properties for the base and mask of an overlay texture. + */ + void PrepareOverlayTexture(const VfsPath& texturePath, const VfsPath& textureMaskPath, + CTexturePtr& texture, CTexturePtr& textureMask, float maxAnisotropy); + private: CTextureManagerImpl* m; }; Index: source/graphics/TextureManager.cpp =================================================================== --- source/graphics/TextureManager.cpp +++ source/graphics/TextureManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2017 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -500,6 +500,20 @@ return size; } + void PrepareOverlayTexture(const VfsPath& texturePath, const VfsPath& textureMaskPath, + CTexturePtr& texture, CTexturePtr& textureMask, float maxAnisotropy) + { + CTextureProperties texturePropsBase(texturePath); + texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); + texturePropsBase.SetMaxAnisotropy(maxAnisotropy); + texture = CreateTexture(texturePropsBase); + + CTextureProperties texturePropsMask(textureMaskPath); + texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); + texturePropsMask.SetMaxAnisotropy(maxAnisotropy); + textureMask = CreateTexture(texturePropsMask); + } + private: PIVFS m_VFS; CCacheLoader m_CacheLoader; @@ -672,3 +686,9 @@ { return m->GetBytesUploaded(); } + +void CTextureManager::PrepareOverlayTexture(const VfsPath& texturePath, const VfsPath& textureMaskPath, + CTexturePtr& texture, CTexturePtr& textureMask, float maxAnisotropy) +{ + m->PrepareOverlayTexture(texturePath, textureMaskPath, texture, textureMask, maxAnisotropy); +} Index: source/simulation2/components/CCmpRallyPointRenderer.cpp =================================================================== --- source/simulation2/components/CCmpRallyPointRenderer.cpp +++ source/simulation2/components/CCmpRallyPointRenderer.cpp @@ -483,17 +483,8 @@ // load some textures if (CRenderer::IsInitialised()) - { - CTextureProperties texturePropsBase(m_LineTexturePath); - texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsBase.SetMaxAnisotropy(4.f); - m_Texture = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); - - CTextureProperties texturePropsMask(m_LineTextureMaskPath); - texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsMask.SetMaxAnisotropy(4.f); - m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); - } + g_Renderer.GetTextureManager().PrepareOverlayTexture(m_LineTexturePath, m_LineTextureMaskPath, + m_Texture, m_TextureMask, 4.f); } void CCmpRallyPointRenderer::UpdateMarkers() Index: source/simulation2/components/CCmpSelectable.cpp =================================================================== --- source/simulation2/components/CCmpSelectable.cpp +++ source/simulation2/components/CCmpSelectable.cpp @@ -466,20 +466,13 @@ cmpPosition->GetInterpolatedPosition2D(frameOffset, origin.X, origin.Y, rotY); CFixedVector3D rotation = cmpPosition->GetRotation(); - CTextureProperties texturePropsBase(overlayDescriptor->m_LineTexture.c_str()); - texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsBase.SetMaxAnisotropy(4.f); - - CTextureProperties texturePropsMask(overlayDescriptor->m_LineTextureMask.c_str()); - texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsMask.SetMaxAnisotropy(4.f); + g_Renderer.GetTextureManager().PrepareOverlayTexture(overlayDescriptor->m_LineTexture.c_str(), + overlayDescriptor->m_LineTextureMask.c_str(), overlay.m_TextureBase, overlay.m_TextureMask, 4.f); overlay.m_AlwaysVisible = false; overlay.m_Closed = true; overlay.m_SimContext = &GetSimContext(); overlay.m_Thickness = overlayDescriptor->m_LineThickness; - overlay.m_TextureBase = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); - overlay.m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); overlay.m_Color = m_Color; if (buildingOverlay && fpShape == ICmpFootprint::SQUARE) @@ -561,16 +554,8 @@ m_UnitOverlay = new SOverlayQuad; // Assuming we don't need the capability of swapping textures on-demand. - CTextureProperties texturePropsBase(m_OverlayDescriptor.m_QuadTexture.c_str()); - texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsBase.SetMaxAnisotropy(4.f); - - CTextureProperties texturePropsMask(m_OverlayDescriptor.m_QuadTextureMask.c_str()); - texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsMask.SetMaxAnisotropy(4.f); - - m_UnitOverlay->m_Texture = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); - m_UnitOverlay->m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); + g_Renderer.GetTextureManager().PrepareOverlayTexture(m_OverlayDescriptor.m_QuadTexture.c_str(), + m_OverlayDescriptor.m_QuadTextureMask.c_str(), m_UnitOverlay->m_Texture, m_UnitOverlay->m_TextureMask, 4.f); } m_UnitOverlay->m_Color = m_Color; Index: source/simulation2/components/CCmpTerritoryManager.cpp =================================================================== --- source/simulation2/components/CCmpTerritoryManager.cpp +++ source/simulation2/components/CCmpTerritoryManager.cpp @@ -571,15 +571,9 @@ std::vector boundaries = ComputeBoundaries(); - CTextureProperties texturePropsBase("art/textures/misc/territory_border.png"); - texturePropsBase.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsBase.SetMaxAnisotropy(2.f); - CTexturePtr textureBase = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); - - CTextureProperties texturePropsMask("art/textures/misc/territory_border_mask.png"); - texturePropsMask.SetWrap(GL_CLAMP_TO_BORDER, GL_CLAMP_TO_EDGE); - texturePropsMask.SetMaxAnisotropy(2.f); - CTexturePtr textureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); + CTexturePtr textureBase, textureMask; + g_Renderer.GetTextureManager().PrepareOverlayTexture("art/textures/misc/territory_border.png", + "art/textures/misc/territory_border_mask.png", textureBase, textureMask, 2.f); CmpPtr cmpPlayerManager(GetSystemEntity()); if (!cmpPlayerManager)