Changeset 27109
- Timestamp:
- Oct 4, 2022, 9:32:42 PM (22 months ago)
- Location:
- ps/trunk/source
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
ps/trunk/source/graphics/Canvas2D.cpp
r26901 r27109 332 332 } 333 333 334 void CCanvas2D::DrawTexture( CTexturePtrtexture, const CRect& destination)334 void CCanvas2D::DrawTexture( texture, const CRect& destination) 335 335 { 336 336 DrawTexture(texture, … … 340 340 341 341 void CCanvas2D::DrawTexture( 342 CTexturePtrtexture, const CRect& destination, const CRect& source,342 texture, const CRect& destination, const CRect& source, 343 343 const CColor& multiply, const CColor& add, const float grayscaleFactor) 344 344 { … … 368 368 } 369 369 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 370 409 void CCanvas2D::DrawText(CTextRenderer& textRenderer) 371 410 { -
ps/trunk/source/graphics/Canvas2D.h
r26858 r27109 63 63 * the grayscale factor. 64 64 */ 65 void DrawTexture( CTexturePtr texture,66 const C Rect& destination, const CRect& source,65 void DrawTexture( 66 const CRect& destination, const CRect& source, 67 67 const CColor& multiply, const CColor& add, const float grayscaleFactor); 68 68 … … 71 71 * destination rect without color modifications. 72 72 */ 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); 74 84 75 85 /** -
ps/trunk/source/graphics/MiniMapTexture.cpp
r27041 r27109 345 345 m_TerrainData = std::make_unique<u32[]>((m_MapSize - 1) * (m_MapSize - 1)); 346 346 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)); 349 351 350 352 m_FinalTextureFramebuffer = backendDevice->CreateFramebuffer("MiniMapFinalFramebuffer", 351 m_FinalTexture .get(), nullptr);353 m_FinalTexture(), nullptr); 352 354 ENSURE(m_FinalTextureFramebuffer); 353 355 } -
ps/trunk/source/graphics/MiniMapTexture.h
r26949 r27109 51 51 void Render(Renderer::Backend::IDeviceCommandContext* deviceCommandContext); 52 52 53 Renderer::Backend::ITexture* GetTexture() const { return m_FinalTexture.get(); }53 ; } 54 54 55 55 /** … … 86 86 87 87 // 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; 90 91 91 92 std::unique_ptr<Renderer::Backend::IFramebuffer> -
ps/trunk/source/gui/ObjectTypes/CMiniMap.cpp
r26906 r27109 24 24 #include "graphics/MiniMapTexture.h" 25 25 #include "graphics/MiniPatch.h" 26 #include "graphics/ShaderManager.h"27 #include "graphics/ShaderProgramPtr.h"28 26 #include "graphics/Terrain.h" 29 27 #include "graphics/TerrainTextureEntry.h" … … 32 30 #include "gui/CGUI.h" 33 31 #include "gui/GUIManager.h" 34 #include "gui/GUIMatrix.h"35 32 #include "lib/bits.h" 36 33 #include "lib/external_libraries/libsdl.h" … … 39 36 #include "ps/CLogger.h" 40 37 #include "ps/ConfigDB.h" 41 #include "ps/CStrInternStatic.h"42 38 #include "ps/Filesystem.h" 43 39 #include "ps/Game.h" … … 46 42 #include "ps/World.h" 47 43 #include "renderer/Renderer.h" 48 #include "renderer/RenderingOptions.h"49 44 #include "renderer/SceneRenderer.h" 50 45 #include "renderer/WaterManager.h" … … 94 89 } 95 90 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 area102 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.0f125 };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 144 91 } // anonymous namespace 145 92 … … 403 350 canvas.DrawRect(m_CachedActualSize, CColor(0.0f, 0.0f, 0.0f, 1.0f)); 404 351 405 canvas.Flush();406 407 352 CSimulation2* sim = g_Game->GetSimulation2(); 408 353 CmpPtr<ICmpRangeManager> cmpRangeManager(*sim, SYSTEM_ENTITY); … … 418 363 if (miniMapTexture.GetTexture()) 419 364 { 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()); 458 375 } 459 376
Note:
See TracChangeset
for help on using the changeset viewer.