forked from organicmaps/organicmaps
Removed conditional compilation from debug rect renderer
This commit is contained in:
parent
32bce6ea7f
commit
d686686319
8 changed files with 66 additions and 123 deletions
|
@ -1,14 +1,12 @@
|
|||
#include "drape/debug_rect_renderer.hpp"
|
||||
|
||||
#include "drape/gpu_program_manager.hpp"
|
||||
#include "drape/glfunctions.hpp"
|
||||
#include "drape/gpu_program_manager.hpp"
|
||||
|
||||
namespace dp
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
m2::PointF PixelPointToScreenSpace(ScreenBase const & screen, m2::PointF const & pt)
|
||||
{
|
||||
float const szX = static_cast<float>(screen.isPerspective() ? screen.PixelRectIn3d().SizeX() :
|
||||
|
@ -17,8 +15,7 @@ m2::PointF PixelPointToScreenSpace(ScreenBase const & screen, m2::PointF const &
|
|||
screen.PixelRect().SizeY());
|
||||
return m2::PointF(pt.x / szX - 0.5f, -pt.y / szY + 0.5f) * 2.0f;
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
DebugRectRenderer & DebugRectRenderer::Instance()
|
||||
{
|
||||
|
@ -29,9 +26,8 @@ DebugRectRenderer & DebugRectRenderer::Instance()
|
|||
DebugRectRenderer::DebugRectRenderer()
|
||||
: m_VAO(0)
|
||||
, m_vertexBuffer(0)
|
||||
, m_isEnabled(true)
|
||||
{
|
||||
}
|
||||
, m_isEnabled(false)
|
||||
{}
|
||||
|
||||
DebugRectRenderer::~DebugRectRenderer()
|
||||
{
|
||||
|
@ -51,7 +47,8 @@ void DebugRectRenderer::Init(ref_ptr<dp::GpuProgramManager> mng, int programId)
|
|||
int8_t attributeLocation = m_program->GetAttributeLocation("a_position");
|
||||
ASSERT_NOT_EQUAL(attributeLocation, -1, ());
|
||||
GLFunctions::glEnableVertexAttribute(attributeLocation);
|
||||
GLFunctions::glVertexAttributePointer(attributeLocation, 2, gl_const::GLFloatType, false, sizeof(float) * 2, 0);
|
||||
GLFunctions::glVertexAttributePointer(attributeLocation, 2, gl_const::GLFloatType, false,
|
||||
sizeof(float) * 2, 0);
|
||||
|
||||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
@ -83,8 +80,8 @@ void DebugRectRenderer::SetEnabled(bool enabled)
|
|||
{
|
||||
m_isEnabled = enabled;
|
||||
}
|
||||
|
||||
void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & rect, dp::Color const & color) const
|
||||
void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & rect,
|
||||
dp::Color const & color) const
|
||||
{
|
||||
if (!m_isEnabled)
|
||||
return;
|
||||
|
@ -102,14 +99,16 @@ void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & re
|
|||
vertices[3] = PixelPointToScreenSpace(screen, rect.RightBottom());
|
||||
vertices[4] = vertices[0];
|
||||
|
||||
GLFunctions::glBufferData(gl_const::GLArrayBuffer, vertices.size() * sizeof(vertices[0]),
|
||||
GLFunctions::glBufferData(gl_const::GLArrayBuffer,
|
||||
static_cast<uint32_t>(vertices.size() * sizeof(vertices[0])),
|
||||
vertices.data(), gl_const::GLStaticDraw);
|
||||
|
||||
int8_t const location = m_program->GetUniformLocation("u_color");
|
||||
if (location >= 0)
|
||||
GLFunctions::glUniformValuef(location, color.GetRedF(), color.GetGreenF(), color.GetBlueF(), color.GetAlfaF());
|
||||
GLFunctions::glUniformValuef(location, color.GetRedF(), color.GetGreenF(),
|
||||
color.GetBlueF(), color.GetAlfaF());
|
||||
|
||||
GLFunctions::glDrawArrays(gl_const::GLLineStrip, 0, vertices.size());
|
||||
GLFunctions::glDrawArrays(gl_const::GLLineStrip, 0, static_cast<uint32_t>(vertices.size()));
|
||||
|
||||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
@ -117,9 +116,8 @@ void DebugRectRenderer::DrawRect(ScreenBase const & screen, m2::RectF const & re
|
|||
m_program->Unbind();
|
||||
}
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
|
||||
void DebugRectRenderer::DrawArrow(ScreenBase const & screen, OverlayTree::DisplacementData const & data) const
|
||||
void DebugRectRenderer::DrawArrow(ScreenBase const & screen,
|
||||
OverlayTree::DisplacementData const & data) const
|
||||
{
|
||||
if (!m_isEnabled)
|
||||
return;
|
||||
|
@ -142,7 +140,8 @@ void DebugRectRenderer::DrawArrow(ScreenBase const & screen, OverlayTree::Displa
|
|||
vertices[3] = vertices[1];
|
||||
vertices[4] = PixelPointToScreenSpace(screen, data.m_arrowEnd - dir * 20 - side * 10);
|
||||
|
||||
GLFunctions::glBufferData(gl_const::GLArrayBuffer, vertices.size() * sizeof(vertices[0]),
|
||||
GLFunctions::glBufferData(gl_const::GLArrayBuffer,
|
||||
static_cast<uint32_t>(vertices.size() * sizeof(vertices[0])),
|
||||
vertices.data(), gl_const::GLStaticDraw);
|
||||
|
||||
int8_t const location = m_program->GetUniformLocation("u_color");
|
||||
|
@ -150,14 +149,11 @@ void DebugRectRenderer::DrawArrow(ScreenBase const & screen, OverlayTree::Displa
|
|||
GLFunctions::glUniformValuef(location, data.m_arrowColor.GetRedF(), data.m_arrowColor.GetGreenF(),
|
||||
data.m_arrowColor.GetBlueF(), data.m_arrowColor.GetAlfaF());
|
||||
|
||||
GLFunctions::glDrawArrays(gl_const::GLLineStrip, 0, vertices.size());
|
||||
GLFunctions::glDrawArrays(gl_const::GLLineStrip, 0, static_cast<uint32_t>(vertices.size()));
|
||||
|
||||
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
|
||||
GLFunctions::glBindVertexArray(0);
|
||||
|
||||
m_program->Unbind();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace dp
|
||||
} // namespace dp
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include "drape/drape_diagnostics.hpp"
|
||||
|
||||
#include "drape/gpu_program_manager.hpp"
|
||||
#include "drape/overlay_tree.hpp"
|
||||
#include "drape/pointers.hpp"
|
||||
|
@ -23,17 +21,14 @@ public:
|
|||
void SetEnabled(bool enabled);
|
||||
|
||||
void DrawRect(ScreenBase const & screen, m2::RectF const & rect, dp::Color const & color) const;
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
void DrawArrow(ScreenBase const & screen, OverlayTree::DisplacementData const & data) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
DebugRectRenderer();
|
||||
~DebugRectRenderer();
|
||||
|
||||
int m_VAO;
|
||||
int m_vertexBuffer;
|
||||
uint32_t m_VAO;
|
||||
uint32_t m_vertexBuffer;
|
||||
ref_ptr<dp::GpuProgram> m_program;
|
||||
bool m_isEnabled;
|
||||
};
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
//#define DRAW_TILE_NET
|
||||
//#define RENDER_DEBUG_RECTS
|
||||
//#define COLLECT_DISPLACEMENT_INFO
|
||||
//#define RENDER_DEBUG_DISPLACEMENT
|
||||
//#define DEBUG_OVERLAYS_OUTPUT
|
||||
|
||||
//#define DRAPE_MEASURER
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
#include "drape/overlay_tree.hpp"
|
||||
|
||||
#include "drape/constants.hpp"
|
||||
#include "drape/debug_rect_renderer.hpp"
|
||||
|
||||
#include "std/algorithm.hpp"
|
||||
#include "std/bind.hpp"
|
||||
|
||||
namespace dp
|
||||
{
|
||||
|
||||
int const kFrameUpdatePeriod = 10;
|
||||
size_t const kAverageHandlesCount[dp::OverlayRanksCount] = { 300, 200, 50 };
|
||||
int const kInvalidFrame = -1;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class HandleComparator
|
||||
{
|
||||
public:
|
||||
|
@ -59,7 +58,25 @@ private:
|
|||
bool m_enableMask;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
void StoreDisplacementInfo(ScreenBase const & modelView, int caseIndex,
|
||||
ref_ptr<OverlayHandle> displacingHandle,
|
||||
ref_ptr<OverlayHandle> displacedHandle,
|
||||
OverlayTree::TDisplacementInfo & displacementInfo)
|
||||
{
|
||||
#ifdef DEBUG_OVERLAYS_OUTPUT
|
||||
LOG(LINFO, ("Displace (", caseIndex, "):", displacingHandle->GetOverlayDebugInfo(),
|
||||
"->", displacedHandle->GetOverlayDebugInfo()));
|
||||
#else
|
||||
UNUSED_VALUE(caseIndex);
|
||||
#endif
|
||||
|
||||
if (!dp::DebugRectRenderer::Instance().IsEnabled())
|
||||
return;
|
||||
displacementInfo.emplace_back(displacingHandle->GetExtendedPixelRect(modelView).Center(),
|
||||
displacedHandle->GetExtendedPixelRect(modelView).Center(),
|
||||
dp::Color(0, 0, 255, 255));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
OverlayTree::OverlayTree()
|
||||
: m_frameCounter(kInvalidFrame)
|
||||
|
@ -93,10 +110,7 @@ void OverlayTree::StartOverlayPlacing(ScreenBase const & screen)
|
|||
Clear();
|
||||
m_handlesCache.clear();
|
||||
m_traits.m_modelView = screen;
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
m_displacementInfo.clear();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OverlayTree::Remove(ref_ptr<OverlayHandle> handle)
|
||||
|
@ -223,27 +237,9 @@ void OverlayTree::InsertHandle(ref_ptr<OverlayHandle> handle, int currentRank,
|
|||
if (boundToParent)
|
||||
{
|
||||
DeleteHandleWithParents(parentOverlay, currentRank - 1);
|
||||
|
||||
#ifdef DEBUG_OVERLAYS_OUTPUT
|
||||
LOG(LINFO, ("Displace (0):", handle->GetOverlayDebugInfo(), "->", parentOverlay->GetOverlayDebugInfo()));
|
||||
#endif
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
m_displacementInfo.emplace_back(DisplacementData(handle->GetExtendedPixelRect(modelView).Center(),
|
||||
parentOverlay->GetExtendedPixelRect(modelView).Center(),
|
||||
dp::Color(0, 255, 0, 255)));
|
||||
#endif
|
||||
StoreDisplacementInfo(modelView, 0 /* case index */, handle, parentOverlay, m_displacementInfo);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_OVERLAYS_OUTPUT
|
||||
LOG(LINFO, ("Displace (1):", rivalHandle->GetOverlayDebugInfo(), "->", handle->GetOverlayDebugInfo()));
|
||||
#endif
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
m_displacementInfo.emplace_back(DisplacementData(rivalHandle->GetExtendedPixelRect(modelView).Center(),
|
||||
handle->GetExtendedPixelRect(modelView).Center(),
|
||||
dp::Color(0, 0, 255, 255)));
|
||||
#endif
|
||||
StoreDisplacementInfo(modelView, 1 /* case index */, rivalHandle, handle, m_displacementInfo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -260,17 +256,7 @@ void OverlayTree::InsertHandle(ref_ptr<OverlayHandle> handle, int currentRank,
|
|||
if ((*it)->GetOverlayID() == rivalHandle->GetOverlayID())
|
||||
{
|
||||
Erase(*it);
|
||||
|
||||
#ifdef DEBUG_OVERLAYS_OUTPUT
|
||||
LOG(LINFO, ("Displace (2):", handle->GetOverlayDebugInfo(), "->", (*it)->GetOverlayDebugInfo()));
|
||||
#endif
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
m_displacementInfo.emplace_back(DisplacementData(handle->GetExtendedPixelRect(modelView).Center(),
|
||||
(*it)->GetExtendedPixelRect(modelView).Center(),
|
||||
dp::Color(0, 0, 255, 255)));
|
||||
#endif
|
||||
|
||||
StoreDisplacementInfo(modelView, 2 /* case index */, handle, *it, m_displacementInfo);
|
||||
it = m_handlesCache.erase(it);
|
||||
}
|
||||
else
|
||||
|
@ -282,16 +268,7 @@ void OverlayTree::InsertHandle(ref_ptr<OverlayHandle> handle, int currentRank,
|
|||
else
|
||||
{
|
||||
DeleteHandle(rivalHandle);
|
||||
|
||||
#ifdef DEBUG_OVERLAYS_OUTPUT
|
||||
LOG(LINFO, ("Displace (3):", handle->GetOverlayDebugInfo(), "->", rivalHandle->GetOverlayDebugInfo()));
|
||||
#endif
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
m_displacementInfo.emplace_back(DisplacementData(handle->GetExtendedPixelRect(modelView).Center(),
|
||||
rivalHandle->GetExtendedPixelRect(modelView).Center(),
|
||||
dp::Color(0, 0, 255, 255)));
|
||||
#endif
|
||||
StoreDisplacementInfo(modelView, 3 /* case index */, handle, rivalHandle, m_displacementInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,13 +427,8 @@ void OverlayTree::SetSelectedFeature(FeatureID const & featureID)
|
|||
m_selectedFeatureID = featureID;
|
||||
}
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
|
||||
OverlayTree::TDisplacementInfo const & OverlayTree::GetDisplacementInfo() const
|
||||
{
|
||||
return m_displacementInfo;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace dp
|
||||
} // namespace dp
|
||||
|
|
|
@ -14,10 +14,8 @@
|
|||
|
||||
namespace dp
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct OverlayTraits
|
||||
{
|
||||
ScreenBase m_modelView;
|
||||
|
@ -37,8 +35,7 @@ struct OverlayHasher
|
|||
return m_hasher(handle.get());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
using TOverlayContainer = buffer_vector<ref_ptr<OverlayHandle>, 8>;
|
||||
|
||||
|
@ -70,19 +67,18 @@ public:
|
|||
void SetSelectedFeature(FeatureID const & featureID);
|
||||
bool GetSelectedFeatureRect(ScreenBase const & screen, m2::RectD & featureRect);
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
struct DisplacementData
|
||||
{
|
||||
m2::PointF m_arrowStart;
|
||||
m2::PointF m_arrowEnd;
|
||||
dp::Color m_arrowColor;
|
||||
DisplacementData(m2::PointF const & arrowStart, m2::PointF const & arrowEnd, dp::Color const & arrowColor)
|
||||
DisplacementData(m2::PointF const & arrowStart, m2::PointF const & arrowEnd,
|
||||
dp::Color const & arrowColor)
|
||||
: m_arrowStart(arrowStart), m_arrowEnd(arrowEnd), m_arrowColor(arrowColor)
|
||||
{}
|
||||
};
|
||||
using TDisplacementInfo = vector<DisplacementData>;
|
||||
using TDisplacementInfo = std::vector<DisplacementData>;
|
||||
TDisplacementInfo const & GetDisplacementInfo() const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
ScreenBase const & GetModelView() const { return m_traits.m_modelView; }
|
||||
|
@ -104,9 +100,6 @@ private:
|
|||
|
||||
FeatureID m_selectedFeatureID;
|
||||
|
||||
#ifdef COLLECT_DISPLACEMENT_INFO
|
||||
TDisplacementInfo m_displacementInfo;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace dp
|
||||
} // namespace dp
|
||||
|
|
|
@ -116,26 +116,24 @@ void RenderBucket::SetFeatureMinZoom(int minZoom)
|
|||
|
||||
void RenderBucket::RenderDebug(ScreenBase const & screen) const
|
||||
{
|
||||
#ifdef RENDER_DEBUG_RECTS
|
||||
if (!m_overlay.empty())
|
||||
if (!DebugRectRenderer::Instance().IsEnabled() || m_overlay.empty())
|
||||
return;
|
||||
|
||||
for (auto const & handle : m_overlay)
|
||||
{
|
||||
for (auto const & handle : m_overlay)
|
||||
if (!screen.PixelRect().IsIntersect(handle->GetPixelRect(screen, false)))
|
||||
continue;
|
||||
|
||||
OverlayHandle::Rects const & rects = handle->GetExtendedPixelShape(screen);
|
||||
for (auto const & rect : rects)
|
||||
{
|
||||
if (!screen.PixelRect().IsIntersect(handle->GetPixelRect(screen, false)))
|
||||
if (screen.isPerspective() && !screen.PixelRectIn3d().IsIntersect(m2::RectD(rect)))
|
||||
continue;
|
||||
|
||||
OverlayHandle::Rects const & rects = handle->GetExtendedPixelShape(screen);
|
||||
for (auto const & rect : rects)
|
||||
{
|
||||
if (screen.isPerspective() && !screen.PixelRectIn3d().IsIntersect(m2::RectD(rect)))
|
||||
continue;
|
||||
|
||||
DebugRectRenderer::Instance().DrawRect(screen, rect, handle->IsVisible() ?
|
||||
dp::Color::Green() : dp::Color::Red());
|
||||
}
|
||||
DebugRectRenderer::Instance().DrawRect(screen, rect, handle->IsVisible() ?
|
||||
dp::Color::Green() : dp::Color::Red());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace dp
|
||||
|
|
|
@ -1187,10 +1187,8 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
|
|||
modelView);
|
||||
}
|
||||
|
||||
#if defined(RENDER_DEBUG_RECTS) && defined(COLLECT_DISPLACEMENT_INFO)
|
||||
for (auto const & arrow : m_overlayTree->GetDisplacementInfo())
|
||||
dp::DebugRectRenderer::Instance().DrawArrow(modelView, arrow);
|
||||
#endif
|
||||
|
||||
m_postprocessRenderer->EndFrame(make_ref(m_gpuProgramManager));
|
||||
|
||||
|
@ -1684,9 +1682,7 @@ void FrontendRenderer::OnContextDestroy()
|
|||
m_drapeApiRenderer->Clear();
|
||||
m_postprocessRenderer->ClearGLDependentResources();
|
||||
|
||||
#ifdef RENDER_DEBUG_RECTS
|
||||
dp::DebugRectRenderer::Instance().Destroy();
|
||||
#endif
|
||||
|
||||
m_gpuProgramManager.reset();
|
||||
m_contextFactory->getDrawContext()->doneCurrent();
|
||||
|
@ -1724,8 +1720,9 @@ void FrontendRenderer::OnContextCreate()
|
|||
dp::BlendingParams blendingParams;
|
||||
blendingParams.Apply();
|
||||
|
||||
#ifdef RENDER_DEBUG_RECTS
|
||||
dp::DebugRectRenderer::Instance().Init(make_ref(m_gpuProgramManager), gpu::DEBUG_RECT_PROGRAM);
|
||||
#ifdef RENDER_DEBUG_DISPLACEMENT
|
||||
dp::DebugRectRenderer::Instance().SetEnabled(true);
|
||||
#endif
|
||||
|
||||
// Resources recovering.
|
||||
|
@ -1844,11 +1841,6 @@ void FrontendRenderer::Routine::Do()
|
|||
}
|
||||
|
||||
m_renderer.CollectShowOverlaysEvents();
|
||||
|
||||
#ifdef RENDER_DEBUG_RECTS
|
||||
dp::DebugRectRenderer::Instance().Destroy();
|
||||
#endif
|
||||
|
||||
m_renderer.ReleaseResources();
|
||||
}
|
||||
|
||||
|
|
|
@ -139,10 +139,8 @@ void RenderGroup::Render(ScreenBase const & screen)
|
|||
renderBucket->Render(m_state.GetDrawAsLine());
|
||||
}
|
||||
|
||||
#ifdef RENDER_DEBUG_RECTS
|
||||
for(auto const & renderBucket : m_renderBuckets)
|
||||
renderBucket->RenderDebug(screen);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RenderGroup::AddBucket(drape_ptr<dp::RenderBucket> && bucket)
|
||||
|
|
Loading…
Add table
Reference in a new issue