Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaria Volvenkova <d.volvenkova@corp.mail.ru>2018-08-06 17:32:00 +0300
committerRoman Kuznetsov <r.kuznetsow@gmail.com>2018-08-17 13:11:53 +0300
commitd4673530fedab33c81e0a5453c43001a2b4ac983 (patch)
tree01253de39473013438b218ef11fcac94db0ed2e3 /drape_frontend
parent11d12df2618b1902416afc6ff11a3e102d853dd7 (diff)
Mesh object added into the drape library.
Diffstat (limited to 'drape_frontend')
-rw-r--r--drape_frontend/arrow3d.cpp105
-rw-r--r--drape_frontend/arrow3d.hpp16
-rwxr-xr-xdrape_frontend/frontend_renderer.cpp7
-rw-r--r--drape_frontend/screen_quad_renderer.cpp79
-rw-r--r--drape_frontend/screen_quad_renderer.hpp17
5 files changed, 47 insertions, 177 deletions
diff --git a/drape_frontend/arrow3d.cpp b/drape_frontend/arrow3d.cpp
index b725ef6427..eb1c160cf4 100644
--- a/drape_frontend/arrow3d.cpp
+++ b/drape_frontend/arrow3d.cpp
@@ -27,6 +27,7 @@ double const kArrow3dMinZoom = 16;
float const kOutlineScale = 1.2f;
int constexpr kComponentsInVertex = 4;
+int constexpr kComponentsInNormal = 3;
df::ColorConstant const kArrow3DShadowColor = "Arrow3DShadow";
df::ColorConstant const kArrow3DObsoleteColor = "Arrow3DObsolete";
@@ -34,10 +35,11 @@ df::ColorConstant const kArrow3DColor = "Arrow3D";
df::ColorConstant const kArrow3DOutlineColor = "Arrow3DOutline";
Arrow3d::Arrow3d()
- : m_state(CreateRenderState(gpu::Program::Arrow3d, DepthLayer::OverlayLayer))
+ : TBase(DrawPrimitive::Triangles)
+ , m_state(CreateRenderState(gpu::Program::Arrow3d, DepthLayer::OverlayLayer))
{
m_state.SetDepthTestEnabled(false);
- m_vertices = {
+ std::vector<float> vertices = {
0.0f, 0.0f, -1.0f, 1.0f, -1.2f, -1.0f, 0.0f, 1.0f, 0.0f, 2.0f, 0.0f, 1.0f,
0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 2.0f, 0.0f, 1.0f, 1.2f, -1.0f, 0.0f, 1.0f,
0.0f, 0.0f, -1.0f, 1.0f, 0.0f, -0.5f, 0.0f, 1.0f, -1.2f, -1.0f, 0.0f, 1.0f,
@@ -55,15 +57,16 @@ Arrow3d::Arrow3d()
};
int constexpr kVerticesInRow = 12;
- m_normals.reserve(m_vertices.size());
- for (size_t triangle = 0; triangle < m_vertices.size() / kVerticesInRow; ++triangle)
+ std::vector<float> normals;
+ normals.reserve(vertices.size());
+ for (size_t triangle = 0; triangle < vertices.size() / kVerticesInRow; ++triangle)
{
glsl::vec4 v[3];
for (size_t vertex = 0; vertex < 3; ++vertex)
{
size_t const offset = triangle * kVerticesInRow + vertex * kComponentsInVertex;
- v[vertex] = glsl::vec4(m_vertices[offset], m_vertices[offset + 1],
- m_vertices[offset + 2], m_vertices[offset + 3]);
+ v[vertex] = glsl::vec4(vertices[offset], vertices[offset + 1],
+ vertices[offset + 2], vertices[offset + 3]);
}
glsl::vec3 normal = glsl::cross(glsl::vec3(v[1].x - v[0].x, v[1].y - v[0].y, v[1].z - v[0].z),
@@ -72,23 +75,19 @@ Arrow3d::Arrow3d()
for (size_t vertex = 0; vertex < 3; ++vertex)
{
- m_normals.push_back(normal.x);
- m_normals.push_back(normal.y);
- m_normals.push_back(normal.z);
+ normals.push_back(normal.x);
+ normals.push_back(normal.y);
+ normals.push_back(normal.z);
}
}
-}
-
-Arrow3d::~Arrow3d()
-{
- if (m_bufferId != 0)
- GLFunctions::glDeleteBuffer(m_bufferId);
- if (m_bufferNormalsId != 0)
- GLFunctions::glDeleteBuffer(m_bufferNormalsId);
+ auto const verticesBufferInd = 0;
+ SetBuffer(verticesBufferInd, std::move(vertices), sizeof(float) * kComponentsInVertex);
+ SetAttribute("a_pos", verticesBufferInd, 0 /* offset */, kComponentsInVertex);
- if (m_VAO != 0)
- GLFunctions::glDeleteVertexArray(m_VAO);
+ auto const normalsBufferInd = 1;
+ SetBuffer(normalsBufferInd, std::move(normals), sizeof(float) * kComponentsInNormal);
+ SetAttribute("a_normal", normalsBufferInd, 0 /* offset */, kComponentsInNormal);
}
void Arrow3d::SetPosition(const m2::PointD & position)
@@ -106,28 +105,6 @@ void Arrow3d::SetTexture(ref_ptr<dp::TextureManager> texMng)
m_state.SetColorTexture(texMng->GetSymbolsTexture());
}
-void Arrow3d::Build()
-{
- if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
- {
- m_VAO = GLFunctions::glGenVertexArray();
- GLFunctions::glBindVertexArray(m_VAO);
- }
- m_bufferId = GLFunctions::glGenBuffer();
- GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
- GLFunctions::glBufferData(gl_const::GLArrayBuffer, static_cast<uint32_t>(m_vertices.size()) * sizeof(m_vertices[0]),
- m_vertices.data(), gl_const::GLStaticDraw);
-
- m_bufferNormalsId = GLFunctions::glGenBuffer();
- GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer);
- GLFunctions::glBufferData(gl_const::GLArrayBuffer, static_cast<uint32_t>(m_normals.size()) * sizeof(m_normals[0]),
- m_normals.data(), gl_const::GLStaticDraw);
-
- if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
- GLFunctions::glBindVertexArray(0);
- GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
-}
-
void Arrow3d::SetPositionObsolete(bool obsolete)
{
m_obsoletePosition = obsolete;
@@ -135,12 +112,6 @@ void Arrow3d::SetPositionObsolete(bool obsolete)
void Arrow3d::Render(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng, bool routingMode)
{
- if (!m_isInitialized)
- {
- Build();
- m_isInitialized = true;
- }
-
// Render shadow.
if (screen.isPerspective())
{
@@ -164,49 +135,25 @@ void Arrow3d::Render(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng
// Render arrow.
RenderArrow(screen, mng, gpu::Program::Arrow3d, color, 0.0f /* dz */, 1.0f /* scaleFactor */,
true /* hasNormals */);
-
- if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
- GLFunctions::glBindVertexArray(0);
- GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
}
void Arrow3d::RenderArrow(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
gpu::Program program, dp::Color const & color, float dz,
float scaleFactor, bool hasNormals)
{
- auto prg = mng->GetProgram(program);
-
- prg->Bind();
-
- if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
- GLFunctions::glBindVertexArray(m_VAO);
-
- GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
- int8_t const attributePosition = prg->GetAttributeLocation("a_pos");
- ASSERT_NOT_EQUAL(attributePosition, -1, ());
- GLFunctions::glEnableVertexAttribute(attributePosition);
- GLFunctions::glVertexAttributePointer(attributePosition, kComponentsInVertex,
- gl_const::GLFloatType, false, 0, 0);
-
- if (hasNormals)
- {
- GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer);
- int8_t const attributeNormal = prg->GetAttributeLocation("a_normal");
- ASSERT_NOT_EQUAL(attributeNormal, -1, ());
- GLFunctions::glEnableVertexAttribute(attributeNormal);
- GLFunctions::glVertexAttributePointer(attributeNormal, 3, gl_const::GLFloatType, false, 0, 0);
- }
-
gpu::Arrow3dProgramParams params;
math::Matrix<float, 4, 4> const modelTransform = CalculateTransform(screen, dz, scaleFactor);
params.m_transform = glsl::make_mat4(modelTransform.m_data);
params.m_color = glsl::ToVec4(color);
- dp::ApplyState(m_state, prg);
- mng->GetParamsSetter()->Apply(prg, params);
- GLFunctions::glDrawArrays(gl_const::GLTriangles, 0,
- static_cast<uint32_t>(m_vertices.size()) / kComponentsInVertex);
- prg->Unbind();
+ auto gpuProgram = mng->GetProgram(program);
+ TBase::Render(gpuProgram,
+ [this, mng, gpuProgram, &params]()
+ {
+ dp::ApplyState(m_state, gpuProgram);
+ mng->GetParamsSetter()->Apply(gpuProgram, params);
+ },
+ nullptr);
}
math::Matrix<float, 4, 4> Arrow3d::CalculateTransform(ScreenBase const & screen, float dz, float scaleFactor) const
diff --git a/drape_frontend/arrow3d.hpp b/drape_frontend/arrow3d.hpp
index fbad65540e..3224f8b8fa 100644
--- a/drape_frontend/arrow3d.hpp
+++ b/drape_frontend/arrow3d.hpp
@@ -3,7 +3,7 @@
#include "drape_frontend/render_state_extension.hpp"
#include "drape/color.hpp"
-#include "drape/pointers.hpp"
+#include "drape/mesh_object.hpp"
#include "geometry/rect2d.hpp"
@@ -24,11 +24,11 @@ class ScreenBase;
namespace df
{
-class Arrow3d
+class Arrow3d: public dp::MeshObject
{
+ using TBase = dp::MeshObject;
public:
Arrow3d();
- ~Arrow3d();
void SetPosition(m2::PointD const & position);
void SetAzimuth(double azimuth);
@@ -39,7 +39,6 @@ public:
bool routingMode);
private:
- void Build();
math::Matrix<float, 4, 4> CalculateTransform(ScreenBase const & screen, float dz,
float scaleFactor) const;
void RenderArrow(ScreenBase const & screen, ref_ptr<gpu::ProgramManager> mng,
@@ -50,15 +49,6 @@ private:
double m_azimuth = 0.0;
bool m_obsoletePosition = false;
- uint32_t m_VAO = 0;
- uint32_t m_bufferId = 0;
- uint32_t m_bufferNormalsId = 0;
-
- std::vector<float> m_vertices;
- std::vector<float> m_normals;
-
dp::RenderState m_state;
-
- bool m_isInitialized = false;
};
} // namespace df
diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp
index beaa64ddff..1267a01c58 100755
--- a/drape_frontend/frontend_renderer.cpp
+++ b/drape_frontend/frontend_renderer.cpp
@@ -1409,11 +1409,8 @@ void FrontendRenderer::RenderTransitBackground()
dp::TextureManager::ColorRegion region;
m_texMng->GetColorRegion(df::GetColorConstant(kTransitBackgroundColor), region);
CHECK(region.GetTexture() != nullptr, ("Texture manager is not initialized"));
- if (!m_transitBackground->IsInitialized())
- {
- auto prg = m_gpuProgramManager->GetProgram(gpu::Program::ScreenQuad);
- m_transitBackground->SetTextureRect(region.GetTexRect(), prg);
- }
+ //if (!m_transitBackground->IsInitialized())
+ m_transitBackground->SetTextureRect(region.GetTexRect());
m_transitBackground->RenderTexture(make_ref(m_gpuProgramManager),
static_cast<uint32_t>(region.GetTexture()->GetID()), 1.0f);
}
diff --git a/drape_frontend/screen_quad_renderer.cpp b/drape_frontend/screen_quad_renderer.cpp
index 80cfff7e9a..dfc8c8ac5c 100644
--- a/drape_frontend/screen_quad_renderer.cpp
+++ b/drape_frontend/screen_quad_renderer.cpp
@@ -69,75 +69,28 @@ void RendererContext::BindTexture(uint32_t textureId, ref_ptr<dp::GpuProgram> pr
}
ScreenQuadRenderer::ScreenQuadRenderer()
- : m_textureRendererContext(make_unique_dp<TextureRendererContext>())
-{}
-
-ScreenQuadRenderer::~ScreenQuadRenderer()
+ : TBase(DrawPrimitive::TriangleStrip)
+ , m_textureRendererContext(make_unique_dp<TextureRendererContext>())
{
- if (m_bufferId != 0)
- GLFunctions::glDeleteBuffer(m_bufferId);
-
- if (m_VAO != 0)
- GLFunctions::glDeleteVertexArray(m_VAO);
+ Rebuild();
}
-void ScreenQuadRenderer::Build(ref_ptr<dp::GpuProgram> prg)
+void ScreenQuadRenderer::Rebuild()
{
- if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
- {
- m_VAO = GLFunctions::glGenVertexArray();
- GLFunctions::glBindVertexArray(m_VAO);
- }
- m_attributePosition = prg->GetAttributeLocation("a_pos");
- ASSERT_NOT_EQUAL(m_attributePosition, -1, ());
-
- m_attributeTexCoord = prg->GetAttributeLocation("a_tcoord");
- ASSERT_NOT_EQUAL(m_attributeTexCoord, -1, ());
-
std::vector<float> vertices = {-1.0f, 1.0f, m_textureRect.minX(), m_textureRect.maxY(),
1.0f, 1.0f, m_textureRect.maxX(), m_textureRect.maxY(),
-1.0f, -1.0f, m_textureRect.minX(), m_textureRect.minY(),
1.0f, -1.0f, m_textureRect.maxX(), m_textureRect.minY()};
-
- m_bufferId = GLFunctions::glGenBuffer();
- GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
- GLFunctions::glBufferData(gl_const::GLArrayBuffer,
- static_cast<uint32_t>(vertices.size()) * sizeof(vertices[0]),
- vertices.data(), gl_const::GLStaticDraw);
- if (dp::GLExtensionsList::Instance().IsSupported(dp::GLExtensionsList::VertexArrayObject))
- GLFunctions::glBindVertexArray(0);
- GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
+ auto const bufferIndex = 0;
+ SetBuffer(bufferIndex, std::move(vertices), sizeof(float) * 4 /* stride */);
+ SetAttribute("a_pos", bufferIndex, 0 /* offset */, 2 /* componentsCount */);
+ SetAttribute("a_tcoord", bufferIndex, sizeof(float) * 2 /* offset */, 2 /* componentsCount */);
}
void ScreenQuadRenderer::Render(ref_ptr<gpu::ProgramManager> mng, ref_ptr<RendererContext> context)
{
ref_ptr<dp::GpuProgram> prg = mng->GetProgram(context->GetGpuProgram());
- prg->Bind();
-
- if (m_bufferId == 0)
- Build(prg);
-
- if (m_VAO != 0)
- GLFunctions::glBindVertexArray(m_VAO);
-
- GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
-
- GLFunctions::glEnableVertexAttribute(m_attributePosition);
- GLFunctions::glVertexAttributePointer(m_attributePosition, 2, gl_const::GLFloatType, false,
- sizeof(float) * 4, 0);
- GLFunctions::glEnableVertexAttribute(m_attributeTexCoord);
- GLFunctions::glVertexAttributePointer(m_attributeTexCoord, 2, gl_const::GLFloatType, false,
- sizeof(float) * 4, sizeof(float) * 2);
-
- context->PreRender(mng);
- GLFunctions::glDrawArrays(gl_const::GLTriangleStrip, 0, 4);
- context->PostRender();
-
- prg->Unbind();
- GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
-
- if (m_VAO != 0)
- GLFunctions::glBindVertexArray(0);
+ TBase::Render(prg, [context, mng](){ context->PreRender(mng); }, [context](){ context->PostRender(); });
}
void ScreenQuadRenderer::RenderTexture(ref_ptr<gpu::ProgramManager> mng, uint32_t textureId,
@@ -151,19 +104,9 @@ void ScreenQuadRenderer::RenderTexture(ref_ptr<gpu::ProgramManager> mng, uint32_
Render(mng, make_ref(m_textureRendererContext));
}
-void ScreenQuadRenderer::SetTextureRect(m2::RectF const & rect, ref_ptr<dp::GpuProgram> prg)
+void ScreenQuadRenderer::SetTextureRect(m2::RectF const & rect)
{
m_textureRect = rect;
- Rebuild(prg);
-}
-
-void ScreenQuadRenderer::Rebuild(ref_ptr<dp::GpuProgram> prg)
-{
- if (m_bufferId != 0)
- GLFunctions::glDeleteBuffer(m_bufferId);
-
- prg->Bind();
- Build(prg);
- prg->Unbind();
+ Rebuild();
}
} // namespace df
diff --git a/drape_frontend/screen_quad_renderer.hpp b/drape_frontend/screen_quad_renderer.hpp
index b467ae038a..6a5fb91fcc 100644
--- a/drape_frontend/screen_quad_renderer.hpp
+++ b/drape_frontend/screen_quad_renderer.hpp
@@ -2,7 +2,7 @@
#include "shaders/programs.hpp"
-#include "drape/pointers.hpp"
+#include "drape/mesh_object.hpp"
#include "geometry/rect2d.hpp"
@@ -33,28 +33,21 @@ protected:
uint32_t filteringMode, uint32_t wrappingMode);
};
-class ScreenQuadRenderer
+class ScreenQuadRenderer: public dp::MeshObject
{
+ using TBase = dp::MeshObject;
public:
ScreenQuadRenderer();
- ~ScreenQuadRenderer();
- void SetTextureRect(m2::RectF const & rect, ref_ptr<dp::GpuProgram> prg);
- void Rebuild(ref_ptr<dp::GpuProgram> prg);
-
- bool IsInitialized() const { return m_bufferId != 0; }
+ void SetTextureRect(m2::RectF const & rect);
m2::RectF const & GetTextureRect() const { return m_textureRect; }
void Render(ref_ptr<gpu::ProgramManager> mng, ref_ptr<RendererContext> context);
void RenderTexture(ref_ptr<gpu::ProgramManager> mng, uint32_t textureId, float opacity);
private:
- void Build(ref_ptr<dp::GpuProgram> prg);
+ void Rebuild();
- uint32_t m_bufferId = 0;
- uint32_t m_VAO = 0;
- int8_t m_attributePosition = -1;
- int8_t m_attributeTexCoord = -1;
m2::RectF m_textureRect = m2::RectF(0.0f, 0.0f, 1.0f, 1.0f);
drape_ptr<RendererContext> m_textureRendererContext;