Skip to content

Commit

Permalink
Rendering poi, bookmarks and straight text with ortho view in 3d mode.
Browse files Browse the repository at this point in the history
Conflicts:
	drape_frontend/frontend_renderer.cpp
	drape_frontend/render_group.cpp
  • Loading branch information
darina committed Dec 29, 2015
1 parent 02ef5bf commit 3a0d040
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 89 deletions.
4 changes: 4 additions & 0 deletions drape/shaders/shader_index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ ROUTE_PROGRAM route_vertex_shader.vsh route_fragment_shader.fsh
ROUTE_ARROW_PROGRAM route_vertex_shader.vsh route_arrow_fragment_shader.fsh
DEBUG_RECT_PROGRAM debug_rect_vertex_shader.vsh debug_rect_fragment_shader.fsh
TEXTURING_3D_PROGRAM texturing3d_vertex_shader.vsh texturing3d_fragment_shader.fsh
TEXTURING_SPRITE_PROGRAM texturing_sprite_vertex_shader.vsh texturing_fragment_shader.fsh
TEXT_OUTLINED_SPRITE_PROGRAM text_outlined_sprite_vertex_shader.vsh text_fragment_shader.fsh
TEXT_SPRITE_PROGRAM text_sprite_vertex_shader.vsh text_fragment_shader.fsh
BOOKMARK_SPRITE_PROGRAM user_mark_sprite.vsh texturing_fragment_shader.fsh
51 changes: 51 additions & 0 deletions drape/shaders/text_outlined_sprite_vertex_shader.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
attribute vec4 a_position;
attribute vec2 a_normal;
attribute vec2 a_colorTexCoord;
attribute vec2 a_outlineColorTexCoord;
attribute vec2 a_maskTexCoord;

uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;
uniform float u_isOutlinePass;

#ifdef ENABLE_VTF
uniform sampler2D u_colorTex;
varying lowp vec4 v_color;
#else
varying vec2 v_colorTexCoord;
#endif

varying vec2 v_maskTexCoord;

const float Zero = 0.0;
const float One = 1.0;
const float BaseDepthShift = -10.0;

void main()
{
float isOutline = step(0.5, u_isOutlinePass);
float notOutline = One - isOutline;
float depthShift = BaseDepthShift * isOutline;

// Here we intentionally decrease precision of 'pos' calculation
// to eliminate jittering effect in process of billboard reconstruction.
lowp vec4 pivot = (a_position + vec4(Zero, Zero, depthShift, Zero)) * modelView;
vec4 offset = vec4(a_normal, Zero, Zero);

pivot = pivot * projection;
offset = offset * projection;

gl_Position = pivotTransform * vec4(pivot.xy, Zero, One);

vec4 scale = pivotTransform * vec4(One, -One, Zero, One);
gl_Position = gl_Position + vec4(offset.xy * gl_Position.w / scale.w * scale.x, Zero, Zero);

vec2 colorTexCoord = a_colorTexCoord * notOutline + a_outlineColorTexCoord * isOutline;
#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, colorTexCoord);
#else
v_colorTexCoord = colorTexCoord;
#endif
v_maskTexCoord = a_maskTexCoord;
}
44 changes: 44 additions & 0 deletions drape/shaders/text_sprite_vertex_shader.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
attribute vec4 a_position;
attribute vec2 a_normal;
attribute vec2 a_colorTexCoord;
attribute vec2 a_maskTexCoord;

uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;
uniform float u_isOutlinePass;

#ifdef ENABLE_VTF
uniform sampler2D u_colorTex;
varying lowp vec4 v_color;
#else
varying vec2 v_colorTexCoord;
#endif

varying vec2 v_maskTexCoord;

const float Zero = 0.0;
const float One = 1.0;

void main()
{
// Here we intentionally decrease precision of 'pivot' calculation
// to eliminate jittering effect in process of billboard reconstruction.
lowp vec4 pivot = a_position * modelView;
vec4 offset = vec4(a_normal, Zero, Zero);

pivot = pivot * projection;
offset = offset * projection;

gl_Position = pivotTransform * vec4(pivot.xy, Zero, One);

vec4 scale = pivotTransform * vec4(One, -One, Zero, One);
gl_Position = gl_Position + vec4(offset.xy * gl_Position.w / scale.w * scale.x, Zero, Zero);

#ifdef ENABLE_VTF
v_color = texture2D(u_colorTex, a_colorTexCoord);
#else
v_colorTexCoord = a_colorTexCoord;
#endif
v_maskTexCoord = a_maskTexCoord;
}
7 changes: 2 additions & 5 deletions drape/shaders/texturing3d_vertex_shader.vsh
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
attribute vec2 a_pos;
attribute vec2 a_tcoord;

uniform mat4 rotate;
uniform mat4 translate;
uniform mat4 projection;
uniform mat4 m_transform;

varying vec2 v_tcoord;

void main()
{

v_tcoord = a_tcoord;
gl_Position = projection * translate * rotate * vec4(a_pos, 0.0, 1.0);
gl_Position = m_transform * vec4(a_pos, 0.0, 1.0);
}

27 changes: 27 additions & 0 deletions drape/shaders/texturing_sprite_vertex_shader.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
attribute vec3 a_position;
attribute vec2 a_normal;
attribute vec2 a_colorTexCoords;

uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;

varying vec2 v_colorTexCoords;

void main(void)
{
// Here we intentionally decrease precision of 'pivot' calculation
// to eliminate jittering effect in process of billboard reconstruction.
lowp vec4 pivot = vec4(a_position, 1) * modelView;
vec4 offset = vec4(a_normal, 0, 0);

pivot = pivot * projection;
offset = offset * projection;

gl_Position = pivotTransform * vec4(pivot.xy, 0, 1);

vec4 scale = pivotTransform * vec4(1.0, -1.0, 0, 1.0);
gl_Position = gl_Position + vec4(offset.xy * gl_Position.w / scale.w * scale.x, 0, 0);

v_colorTexCoords = a_colorTexCoords;
}
31 changes: 31 additions & 0 deletions drape/shaders/user_mark_sprite.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
attribute vec3 a_position;
attribute vec2 a_normal;
attribute vec2 a_colorTexCoords;
attribute float a_animate;

uniform mat4 modelView;
uniform mat4 projection;
uniform mat4 pivotTransform;
uniform float u_interpolationT;

varying vec2 v_colorTexCoords;

void main(void)
{
vec2 normal = a_normal;
if (a_animate > 0.0)
normal = u_interpolationT * normal;

vec4 pivot = vec4(a_position.xyz, 1) * modelView;
vec4 offset = vec4(normal, 0, 0);

pivot = pivot * projection;
offset = offset * projection;

gl_Position = pivotTransform * vec4(pivot.xy, 0, 1);

vec4 scale = pivotTransform * vec4(1.0, -1.0, 0, 1.0);
gl_Position = gl_Position + vec4(offset.xy * gl_Position.w / scale.w * scale.x, 0, 0);

v_colorTexCoords = a_colorTexCoords;
}
72 changes: 62 additions & 10 deletions drape_frontend/frontend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "drape_frontend/renderer3d.hpp"

#include "drape/debug_rect_renderer.hpp"
#include "drape/shader_def.hpp"
#include "drape/support_manager.hpp"

#include "drape/utils/glyph_usage_tracker.hpp"
Expand Down Expand Up @@ -45,7 +46,8 @@ FrontendRenderer::FrontendRenderer(Params const & params)
, m_routeRenderer(new RouteRenderer())
, m_overlayTree(new dp::OverlayTree())
, m_useFramebuffer(false)
, m_3dModeChanged(false)
, m_isSpriteRenderPass(false)
, m_3dModeChanged(true)
, m_framebuffer(new Framebuffer())
, m_renderer3d(new Renderer3d())
, m_viewport(params.m_viewport)
Expand Down Expand Up @@ -464,20 +466,26 @@ void FrontendRenderer::AcceptMessage(ref_ptr<Message> message)
}
case Message::Enable3dMode:
{
ref_ptr<Enable3dModeMessage> msg = message;
m_renderer3d->SetVerticalFOV(msg->GetAngleFOV());
m_renderer3d->SetPlaneAngleX(msg->GetAngleX());
m_useFramebuffer = true;
m_3dModeChanged = true;
AddUserEvent(Enable3dModeEvent(max(m_renderer3d->GetScaleX(), m_renderer3d->GetScaleY())));
if (!m_useFramebuffer)
{
ref_ptr<Enable3dModeMessage> msg = message;
m_renderer3d->SetVerticalFOV(msg->GetAngleFOV());
m_renderer3d->SetPlaneAngleX(msg->GetAngleX());
m_useFramebuffer = true;
m_3dModeChanged = true;
AddUserEvent(Enable3dModeEvent(max(m_renderer3d->GetScaleX(), m_renderer3d->GetScaleY())));
}
break;
}

case Message::Disable3dMode:
{
m_useFramebuffer = false;
m_3dModeChanged = true;
AddUserEvent(Disable3dMode(false));
if (m_useFramebuffer)
{
m_useFramebuffer = false;
m_3dModeChanged = true;
AddUserEvent(Disable3dMode(false));
}
break;
}

Expand Down Expand Up @@ -522,6 +530,8 @@ void FrontendRenderer::OnResize(ScreenBase const & screen)
m_renderer3d->SetSize(m_pixelRect.SizeX(), m_pixelRect.SizeY());
m_framebuffer->SetDefaultContext(m_contextFactory->getDrawContext());
m_framebuffer->SetSize(width, height);

RefreshPivotTransform();
}
}

Expand Down Expand Up @@ -784,6 +794,24 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
{
m_framebuffer->Disable();
m_renderer3d->Render(m_framebuffer->GetTextureId(), make_ref(m_gpuProgramManager));
// Test code to check ortho overlays in 3d mode
m_isSpriteRenderPass = true;
GLFunctions::glDisable(gl_const::GLDepthTest);
for (currentRenderGroup = 0; currentRenderGroup < m_renderGroups.size(); ++currentRenderGroup)
{
drape_ptr<RenderGroup> const & group = m_renderGroups[currentRenderGroup];
RenderSingleGroup(modelView, make_ref(group));
}

for (drape_ptr<UserMarkRenderGroup> const & group : m_userMarkRenderGroups)
{
ASSERT(group.get() != nullptr, ());
group->UpdateAnimation();
if (m_userMarkVisibility.find(group->GetTileKey()) != m_userMarkVisibility.end())
RenderSingleGroup(modelView, make_ref(group));
}
m_isSpriteRenderPass = false;
// End of test code
}

GLFunctions::glEnable(gl_const::GLDepthTest);
Expand All @@ -793,8 +821,23 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
#endif
}

bool FrontendRenderer::IsSpriteProgram(int programIndex) const
{
return programIndex == gpu::TEXTURING_SPRITE_PROGRAM
|| programIndex == gpu::TEXT_SPRITE_PROGRAM
|| programIndex == gpu::TEXT_OUTLINED_SPRITE_PROGRAM
|| programIndex == gpu::BOOKMARK_SPRITE_PROGRAM;
}

void FrontendRenderer::RenderSingleGroup(ScreenBase const & modelView, ref_ptr<BaseRenderGroup> group)
{
dp::GLState const & state = group->GetState();
bool isSpriteProgram = IsSpriteProgram(state.GetProgramIndex());

if ((m_isSpriteRenderPass && !isSpriteProgram) ||
(m_useFramebuffer && !m_isSpriteRenderPass && isSpriteProgram))
return;

group->UpdateAnimation();
group->Render(modelView);
}
Expand Down Expand Up @@ -822,6 +865,14 @@ void FrontendRenderer::RefreshModelView(ScreenBase const & screen)
m_generalUniforms.SetMatrix4x4Value("modelView", mv.m_data);
}

void FrontendRenderer::RefreshPivotTransform()
{
if (m_useFramebuffer)
m_generalUniforms.SetMatrix4x4Value("pivotTransform", m_renderer3d->GetTransform().m_data);
else
m_generalUniforms.SetMatrix4x4Value("pivotTransform", math::Identity<float, 4>().m_data);
}

void FrontendRenderer::RefreshBgColor()
{
uint32_t color = drule::rules().GetBgColor(df::GetDrawTileScale(m_userEventStream.GetCurrentScreen()));
Expand Down Expand Up @@ -1175,6 +1226,7 @@ void FrontendRenderer::PrepareScene(ScreenBase const & modelView)
{
RefreshModelView(modelView);
RefreshBgColor();
RefreshPivotTransform();
}

void FrontendRenderer::UpdateScene(ScreenBase const & modelView)
Expand Down
4 changes: 4 additions & 0 deletions drape_frontend/frontend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class FrontendRenderer : public BaseRenderer
void RenderSingleGroup(ScreenBase const & modelView, ref_ptr<BaseRenderGroup> group);
void RefreshProjection();
void RefreshModelView(ScreenBase const & screen);
void RefreshPivotTransform();
void RefreshBgColor();

ScreenBase const & ProcessEvents(bool & modelViewChanged, bool & viewportChanged);
Expand Down Expand Up @@ -209,6 +210,8 @@ class FrontendRenderer : public BaseRenderer
FeatureID GetVisiblePOI(m2::PointD const & pixelPoint) const;
FeatureID GetVisiblePOI(m2::RectD const & pixelRect) const;

bool IsSpriteProgram(int programIndex) const;

private:
drape_ptr<dp::GpuProgramManager> m_gpuProgramManager;

Expand All @@ -227,6 +230,7 @@ class FrontendRenderer : public BaseRenderer
dp::UniformValuesStorage m_generalUniforms;

bool m_useFramebuffer;
bool m_isSpriteRenderPass;
bool m_3dModeChanged;
drape_ptr<Framebuffer> m_framebuffer;
drape_ptr<Renderer3d> m_renderer3d;
Expand Down
2 changes: 1 addition & 1 deletion drape_frontend/poi_symbol_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void PoiSymbolShape::Draw(ref_ptr<dp::Batcher> batcher, ref_ptr<dp::TextureManag
glsl::vec2(texRect.maxX(), texRect.minY())},
};

dp::GLState state(gpu::TEXTURING_PROGRAM, dp::GLState::OverlayLayer);
dp::GLState state(gpu::TEXTURING_SPRITE_PROGRAM, dp::GLState::OverlayLayer);
state.SetColorTexture(region.GetTexture());
state.SetTextureFilter(gl_const::GLNearest);

Expand Down
6 changes: 4 additions & 2 deletions drape_frontend/render_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ void RenderGroup::Render(ScreenBase const & screen)

auto const & params = df::VisualParams::Instance().GetGlyphVisualParams();
int programIndex = m_state.GetProgramIndex();
if (programIndex == gpu::TEXT_OUTLINED_PROGRAM)
if (programIndex == gpu::TEXT_OUTLINED_PROGRAM ||
programIndex == gpu::TEXT_OUTLINED_SPRITE_PROGRAM)
{
m_uniforms.SetFloatValue("u_contrastGamma", params.m_outlineContrast, params.m_outlineGamma);
m_uniforms.SetFloatValue("u_isOutlinePass", 1.0f);
Expand All @@ -90,7 +91,8 @@ void RenderGroup::Render(ScreenBase const & screen)
for(auto & renderBucket : m_renderBuckets)
renderBucket->Render(screen);
}
else if(programIndex == gpu::TEXT_PROGRAM)
else if (programIndex == gpu::TEXT_PROGRAM ||
programIndex == gpu::TEXT_SPRITE_PROGRAM)
{
m_uniforms.SetFloatValue("u_contrastGamma", params.m_contrast, params.m_gamma);
dp::ApplyUniforms(m_uniforms, m_shader);
Expand Down
Loading

0 comments on commit 3a0d040

Please sign in to comment.