Line data Source code
1 : /* Copyright (C) 2025 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #include "precompiled.h" 19 : 20 : #include "Overlay.h" 21 : 22 : #include "graphics/TextureManager.h" 23 : #include "lib/debug.h" 24 : #include "renderer/Renderer.h" 25 : #include "renderer/TexturedLineRData.h" 26 : #include "renderer/backend/Sampler.h" 27 : 28 0 : SOverlayTexturedLine::LineCapType SOverlayTexturedLine::StrToLineCapType(const std::wstring& str) 29 : { 30 0 : if (str == L"round") 31 : return LINECAP_ROUND; 32 0 : else if (str == L"sharp") 33 : return LINECAP_SHARP; 34 0 : else if (str == L"square") 35 : return LINECAP_SQUARE; 36 0 : else if (str == L"flat") 37 : return LINECAP_FLAT; 38 : else { 39 0 : debug_warn(L"[Overlay] Unrecognized line cap type identifier"); 40 0 : return LINECAP_FLAT; 41 : } 42 : } 43 : 44 0 : void SOverlayTexturedLine::CreateOverlayTexture(const SOverlayDescriptor* overlayDescriptor) 45 : { 46 0 : CTextureProperties texturePropsBase(overlayDescriptor->m_LineTexture.c_str()); 47 0 : texturePropsBase.SetAddressMode( 48 : Renderer::Backend::Sampler::AddressMode::CLAMP_TO_BORDER, 49 : Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE); 50 0 : texturePropsBase.SetAnisotropicFilter(true); 51 : 52 0 : CTextureProperties texturePropsMask(overlayDescriptor->m_LineTextureMask.c_str()); 53 0 : texturePropsMask.SetAddressMode( 54 : Renderer::Backend::Sampler::AddressMode::CLAMP_TO_BORDER, 55 : Renderer::Backend::Sampler::AddressMode::CLAMP_TO_EDGE); 56 0 : texturePropsMask.SetAnisotropicFilter(true); 57 : 58 0 : m_AlwaysVisible = false; 59 0 : m_Closed = true; 60 0 : m_Thickness = overlayDescriptor->m_LineThickness; 61 0 : m_TextureBase = g_Renderer.GetTextureManager().CreateTexture(texturePropsBase); 62 0 : m_TextureMask = g_Renderer.GetTextureManager().CreateTexture(texturePropsMask); 63 : 64 0 : ENSURE(m_TextureBase); 65 0 : } 66 : 67 0 : bool SOverlayTexturedLine::IsVisibleInFrustum(const CFrustum& frustum) const 68 : { 69 : // If we don't have render data, we don't have actual bounds and we need 70 : // to calculate them on a prerendering stage. 71 0 : if (!m_RenderData) 72 : return true; 73 0 : return m_RenderData->IsVisibleInFrustum(frustum); 74 : }