Changeset 27109

Timestamp:
Oct 4, 2022, 9:32:42 PM (22 months ago)
Author:
Vladislav Belov
Message:

Removes drawing via IDeviceCommandContext from CMinimap.

Comments By: phosit

Differential Revision: https://code.wildfiregames.com/D4779

Location:
ps/trunk/source
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ps/trunk/source/graphics/Canvas2D.cpp

    r26901 r27109  
    332332}
    333333
    334 void CCanvas2D::DrawTexture(CTexturePtr texture, const CRect& destination)
     334void CCanvas2D::DrawTexture( texture, const CRect& destination)
    335335{
    336336    DrawTexture(texture,
     
    340340
    341341void CCanvas2D::DrawTexture(
    342     CTexturePtr texture, const CRect& destination, const CRect& source,
     342    texture, const CRect& destination, const CRect& source,
    343343    const CColor& multiply, const CColor& add, const float grayscaleFactor)
    344344{
     
    368368}
    369369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     404
     405
     406
     407
     408
    370409void CCanvas2D::DrawText(CTextRenderer& textRenderer)
    371410{
  • ps/trunk/source/graphics/Canvas2D.h

    r26858 r27109  
    6363     * the grayscale factor.
    6464     */
    65     void DrawTexture(CTexturePtr texture,
    66         const CRect& destination, const CRect& source,
     65    void DrawTexture(
     66        const CRect& destination, const CRect& source,
    6767        const CColor& multiply, const CColor& add, const float grayscaleFactor);
    6868
     
    7171     * destination rect without color modifications.
    7272     */
    73     void DrawTexture(CTexturePtr texture, const CRect& destination);
     73    void DrawTexture(const CTexturePtr& texture, const CRect& destination);
     74
     75    /**
     76     * A similar to the original one, draws the texture into the
     77     * destination rect but rotates it first around the origin point by angle
     78     * radians (a positive angle denotes a clockwise rotation).
     79     */
     80    void DrawRotatedTexture(
     81        const CTexturePtr& texture, const CRect& destination, const CRect& source,
     82        const CColor& multiply, const CColor& add, const float grayscaleFactor,
     83        const CVector2D& origin, const float angle);
    7484
    7585    /**
  • ps/trunk/source/graphics/MiniMapTexture.cpp

    r27041 r27109  
    345345    m_TerrainData = std::make_unique<u32[]>((m_MapSize - 1) * (m_MapSize - 1));
    346346
    347     m_FinalTexture = backendDevice->CreateTexture2D("MiniMapFinalTexture",
    348         Renderer::Backend::Format::R8G8B8A8_UNORM, FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE, defaultSamplerDesc);
     347    m_FinalTexture = g_Renderer.GetTextureManager().WrapBackendTexture(
     348        backendDevice->CreateTexture2D("MiniMapFinalTexture",
     349            Renderer::Backend::Format::R8G8B8A8_UNORM,
     350            FINAL_TEXTURE_SIZE, FINAL_TEXTURE_SIZE, defaultSamplerDesc));
    349351
    350352    m_FinalTextureFramebuffer = backendDevice->CreateFramebuffer("MiniMapFinalFramebuffer",
    351         m_FinalTexture.get(), nullptr);
     353        m_FinalTexture(), nullptr);
    352354    ENSURE(m_FinalTextureFramebuffer);
    353355}
  • ps/trunk/source/graphics/MiniMapTexture.h

    r26949 r27109  
    5151    void Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
    5252
    53     Renderer::Backend::ITexture* GetTexture() const { return m_FinalTexture.get(); }
     53    ; }
    5454
    5555    /**
     
    8686
    8787    // minimap texture handles
    88     std::unique_ptr<Renderer::Backend::ITexture>
    89         m_TerrainTexture, m_FinalTexture;
     88    std::unique_ptr<Renderer::Backend::ITexture> m_TerrainTexture;
     89
     90    CTexturePtr m_FinalTexture;
    9091
    9192    std::unique_ptr<Renderer::Backend::IFramebuffer>
  • ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp

    r26906 r27109  
    2424#include "graphics/MiniMapTexture.h"
    2525#include "graphics/MiniPatch.h"
    26 #include "graphics/ShaderManager.h"
    27 #include "graphics/ShaderProgramPtr.h"
    2826#include "graphics/Terrain.h"
    2927#include "graphics/TerrainTextureEntry.h"
     
    3230#include "gui/CGUI.h"
    3331#include "gui/GUIManager.h"
    34 #include "gui/GUIMatrix.h"
    3532#include "lib/bits.h"
    3633#include "lib/external_libraries/libsdl.h"
     
    3936#include "ps/CLogger.h"
    4037#include "ps/ConfigDB.h"
    41 #include "ps/CStrInternStatic.h"
    4238#include "ps/Filesystem.h"
    4339#include "ps/Game.h"
     
    4642#include "ps/World.h"
    4743#include "renderer/Renderer.h"
    48 #include "renderer/RenderingOptions.h"
    4944#include "renderer/SceneRenderer.h"
    5045#include "renderer/WaterManager.h"
     
    9489}
    9590
    96 void DrawTexture(
    97     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
    98     float angle, float x, float y, float x2, float y2, float mapScale)
    99 {
    100     // Rotate the texture coordinates (0,0)-(coordMax,coordMax) around their center point (m,m)
    101     // Scale square maps to fit in circular minimap area
    102     const float s = sin(angle) * mapScale;
    103     const float c = cos(angle) * mapScale;
    104     const float m = 0.5f;
    105 
    106     float quadTex[] =
    107     {
    108         m*(-c + s + 1.f), m*(-c + -s + 1.f),
    109         m*(c + s + 1.f), m*(-c + s + 1.f),
    110         m*(c + -s + 1.f), m*(c + s + 1.f),
    111 
    112         m*(c + -s + 1.f), m*(c + s + 1.f),
    113         m*(-c + -s + 1.f), m*(c + -s + 1.f),
    114         m*(-c + s + 1.f), m*(-c + -s + 1.f)
    115     };
    116     float quadVerts[] =
    117     {
    118         x, y, 0.0f,
    119         x2, y, 0.0f,
    120         x2, y2, 0.0f,
    121 
    122         x2, y2, 0.0f,
    123         x, y2, 0.0f,
    124         x, y, 0.0f
    125     };
    126 
    127     deviceCommandContext->SetVertexAttributeFormat(
    128         Renderer::Backend::VertexAttributeStream::POSITION,
    129         Renderer::Backend::Format::R32G32B32_SFLOAT, 0, 0,
    130         Renderer::Backend::VertexAttributeRate::PER_VERTEX, 0);
    131     deviceCommandContext->SetVertexAttributeFormat(
    132         Renderer::Backend::VertexAttributeStream::UV0,
    133         Renderer::Backend::Format::R32G32_SFLOAT, 0, 0,
    134         Renderer::Backend::VertexAttributeRate::PER_VERTEX, 1);
    135 
    136     deviceCommandContext->SetVertexBufferData(
    137         0, quadVerts, std::size(quadVerts) * sizeof(quadVerts[0]));
    138     deviceCommandContext->SetVertexBufferData(
    139         1, quadTex, std::size(quadTex) * sizeof(quadTex[0]));
    140 
    141     deviceCommandContext->Draw(0, 6);
    142 }
    143 
    14491} // anonymous namespace
    14592
     
    403350        canvas.DrawRect(m_CachedActualSize, CColor(0.0f, 0.0f, 0.0f, 1.0f));
    404351
    405     canvas.Flush();
    406 
    407352    CSimulation2* sim = g_Game->GetSimulation2();
    408353    CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY);
     
    418363    if (miniMapTexture.GetTexture())
    419364    {
    420         CShaderDefines baseDefines;
    421         baseDefines.Add(str_MINIMAP_BASE, str_1);
    422 
    423         CShaderTechniquePtr tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, baseDefines);
    424         Renderer::Backend::GraphicsPipelineStateDesc pipelineStateDesc =
    425             tech->GetGraphicsPipelineStateDesc();
    426         pipelineStateDesc.blendState.enabled = true;
    427         pipelineStateDesc.blendState.srcColorBlendFactor = pipelineStateDesc.blendState.srcAlphaBlendFactor =
    428             Renderer::Backend::BlendFactor::SRC_ALPHA;
    429         pipelineStateDesc.blendState.dstColorBlendFactor = pipelineStateDesc.blendState.dstAlphaBlendFactor =
    430             Renderer::Backend::BlendFactor::ONE_MINUS_SRC_ALPHA;
    431         pipelineStateDesc.blendState.colorBlendOp = pipelineStateDesc.blendState.alphaBlendOp =
    432             Renderer::Backend::BlendOp::ADD;
    433         Renderer::Backend::IDeviceCommandContext* deviceCommandContext =
    434             g_Renderer.GetDeviceCommandContext();
    435         deviceCommandContext->SetGraphicsPipelineState(pipelineStateDesc);
    436         deviceCommandContext->BeginPass();
    437 
    438         Renderer::Backend::IShaderProgram* shader = tech->GetShader();
    439 
    440         deviceCommandContext->SetTexture(
    441             shader->GetBindingSlot(str_baseTex), miniMapTexture.GetTexture());
    442 
    443         const CMatrix3D baseTransform = GetDefaultGuiMatrix();
    444         CMatrix3D baseTextureTransform;
    445         baseTextureTransform.SetIdentity();
    446 
    447         deviceCommandContext->SetUniform(
    448             shader->GetBindingSlot(str_transform), baseTransform.AsFloatArray());
    449         deviceCommandContext->SetUniform(
    450             shader->GetBindingSlot(str_textureTransform), baseTextureTransform.AsFloatArray());
    451 
    452         const float x = m_CachedActualSize.left, y = m_CachedActualSize.bottom;
    453         const float x2 = m_CachedActualSize.right, y2 = m_CachedActualSize.top;
    454         const float angle = GetAngle();
    455         DrawTexture(deviceCommandContext, angle, x, y, x2, y2, m_MapScale);
    456 
    457         deviceCommandContext->EndPass();
     365        const CVector2D center = m_CachedActualSize.CenterPoint();
     366        const CRect source(
     367            0, miniMapTexture.GetTexture()->GetHeight(),
     368            miniMapTexture.GetTexture()->GetWidth(), 0);
     369        const CSize2D size(m_CachedActualSize.GetSize() / m_MapScale);
     370        const CRect destination(center - size / 2.0f, size);
     371        canvas.DrawRotatedTexture(
     372            miniMapTexture.GetTexture(), destination, source,
     373            CColor(1.0f, 1.0f, 1.0f, 1.0f), CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f,
     374            center, GetAngle());
    458375    }
    459376
Note: See TracChangeset for help on using the changeset viewer.