forked from organicmaps/organicmaps
Don't use intermediate framebuffer texture for perspective mode.
Conflicts: drape_frontend/frontend_renderer.cpp
This commit is contained in:
parent
0753114f7b
commit
928448cfd5
18 changed files with 113 additions and 33 deletions
|
@ -3,6 +3,7 @@ attribute vec2 a_colorTexCoords;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
#ifdef ENABLE_VTF
|
||||
uniform sampler2D u_colorTex;
|
||||
|
@ -13,7 +14,11 @@ varying vec2 v_colorTexCoords;
|
|||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = vec4(a_position, 1) * modelView * projection;
|
||||
vec4 pos = vec4(a_position, 1) * modelView * projection;
|
||||
float w = pos.w;
|
||||
pos.xyw = (pivotTransform * pos).xyw;
|
||||
pos.z *= pos.w / w;
|
||||
gl_Position = pos;
|
||||
#ifdef ENABLE_VTF
|
||||
v_color = texture2D(u_colorTex, a_colorTexCoords);
|
||||
#else
|
||||
|
|
|
@ -4,6 +4,7 @@ attribute vec2 a_colorTexCoords;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
varying vec3 v_radius;
|
||||
#ifdef ENABLE_VTF
|
||||
|
@ -15,7 +16,11 @@ varying vec2 v_colorTexCoords;
|
|||
|
||||
void main(void)
|
||||
{
|
||||
gl_Position = (vec4(a_normal.xy, 0, 0) + vec4(a_position, 1) * modelView) * projection;
|
||||
vec4 pos = (vec4(a_normal.xy, 0, 0) + vec4(a_position, 1) * modelView) * projection;
|
||||
float w = pos.w;
|
||||
pos.xyw = (pivotTransform * pos).xyw;
|
||||
pos.z *= pos.w / w;
|
||||
gl_Position = pos;
|
||||
#ifdef ENABLE_VTF
|
||||
v_color = texture2D(u_colorTex, a_colorTexCoords);
|
||||
#else
|
||||
|
|
|
@ -5,6 +5,7 @@ attribute vec4 a_maskTexCoord;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
varying vec2 v_colorTexCoord;
|
||||
varying vec2 v_maskTexCoord;
|
||||
|
@ -26,5 +27,9 @@ void main(void)
|
|||
v_colorTexCoord = a_colorTexCoord;
|
||||
v_maskTexCoord = vec2(a_maskTexCoord.y + uOffset * a_maskTexCoord.z, a_maskTexCoord.w);
|
||||
v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z));
|
||||
gl_Position = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
|
||||
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
|
||||
float w = pos.w;
|
||||
pos.xyw = (pivotTransform * pos).xyw;
|
||||
pos.z *= pos.w / w;
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ attribute vec2 a_colorTexCoord;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
#ifdef ENABLE_VTF
|
||||
uniform sampler2D u_colorTex;
|
||||
|
@ -32,5 +33,9 @@ void main(void)
|
|||
v_colorTexCoord = a_colorTexCoord;
|
||||
#endif
|
||||
v_halfLength = vec2(sign(a_normal.z) * halfWidth, abs(a_normal.z));
|
||||
gl_Position = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
|
||||
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
|
||||
float w = pos.w;
|
||||
pos.xyw = (pivotTransform * pos).xyw;
|
||||
pos.z *= pos.w / w;
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ uniform float u_azimut;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
varying vec2 v_colorTexCoords;
|
||||
|
||||
|
@ -24,6 +25,10 @@ void main(void)
|
|||
highp vec4 normal = vec4(a_normal, 0, 0);
|
||||
highp vec4 shiftedPos = normal * rotation + pos;
|
||||
|
||||
gl_Position = shiftedPos * projection;
|
||||
shiftedPos = shiftedPos * projection;
|
||||
float w = shiftedPos.w;
|
||||
shiftedPos.xyw = (pivotTransform * shiftedPos).xyw;
|
||||
shiftedPos.z *= shiftedPos.w / w;
|
||||
gl_Position = shiftedPos;
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ attribute vec2 a_colorTexCoords;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
varying vec2 v_colorTexCoords;
|
||||
|
||||
|
@ -12,6 +13,10 @@ void main(void)
|
|||
lowp vec4 pos = vec4(a_position, 1) * modelView;
|
||||
highp vec4 norm = vec4(a_normal, 0, 0) * modelView;
|
||||
highp vec4 shiftedPos = norm + pos;
|
||||
gl_Position = shiftedPos * projection;
|
||||
shiftedPos = shiftedPos * projection;
|
||||
float w = shiftedPos.w;
|
||||
shiftedPos.xyw = (pivotTransform * pos).xyw;
|
||||
shiftedPos.z *= shiftedPos.w / w;
|
||||
gl_Position = shiftedPos;
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ uniform float u_accuracy;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
varying vec2 v_colorTexCoords;
|
||||
|
||||
|
@ -13,7 +14,11 @@ void main(void)
|
|||
{
|
||||
vec4 position = vec4(u_position, 1.0) * modelView;
|
||||
vec4 normal = vec4(normalize(a_normal) * u_accuracy, 0.0, 0.0);
|
||||
gl_Position = (position + normal) * projection;
|
||||
position = (position + normal) * projection;
|
||||
float w = position.w;
|
||||
position.xyw = (pivotTransform * position).xyw;
|
||||
position.z *= position.w / w;
|
||||
gl_Position = position;
|
||||
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ attribute vec3 a_length;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
uniform vec3 u_routeParams;
|
||||
|
||||
|
@ -28,5 +29,9 @@ void main(void)
|
|||
}
|
||||
|
||||
v_length = vec3(len, u_routeParams.z);
|
||||
gl_Position = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
|
||||
vec4 pos = vec4(transformedAxisPos, a_position.z, 1.0) * projection;
|
||||
float w = pos.w;
|
||||
pos.xyw = (pivotTransform * pos).xyw;
|
||||
pos.z *= pos.w / w;
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ void main()
|
|||
vec4 offset = vec4(a_normal, Zero, Zero) * projection;
|
||||
|
||||
vec4 projectedPivot = pivot * projection;
|
||||
vec4 transformedPivot = pivotTransform * vec4(projectedPivot.xy, Zero, One);
|
||||
vec4 transformedPivot = pivotTransform * projectedPivot;
|
||||
|
||||
vec4 scale = pivotTransform * vec4(One, -One, Zero, One);
|
||||
gl_Position = transformedPivot + vec4(offset.xy * transformedPivot.w / scale.w * scale.x, Zero, Zero);
|
||||
|
|
|
@ -30,16 +30,14 @@ void main()
|
|||
|
||||
// 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);
|
||||
lowp vec4 pivot = a_position * modelView;
|
||||
vec4 offset = vec4(a_normal, Zero, Zero) * projection;
|
||||
|
||||
pivot = pivot * projection;
|
||||
offset = offset * projection;
|
||||
|
||||
gl_Position = pivotTransform * vec4(pivot.xy, Zero, One);
|
||||
vec4 projectedPivot = pivot * projection;
|
||||
vec4 transformedPivot = pivotTransform * projectedPivot;
|
||||
|
||||
vec4 scale = pivotTransform * vec4(One, -One, Zero, One);
|
||||
gl_Position = gl_Position + vec4(offset.xy * gl_Position.w / scale.w * scale.x, Zero, Zero);
|
||||
gl_Position = transformedPivot + vec4(offset.xy * transformedPivot.w / scale.w * scale.x, Zero, Zero);
|
||||
|
||||
vec2 colorTexCoord = a_colorTexCoord * notOutline + a_outlineColorTexCoord * isOutline;
|
||||
#ifdef ENABLE_VTF
|
||||
|
|
|
@ -6,6 +6,7 @@ attribute vec2 a_maskTexCoord;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
uniform float u_isOutlinePass;
|
||||
|
||||
#ifdef ENABLE_VTF
|
||||
|
@ -31,7 +32,11 @@ void main()
|
|||
// to eliminate jittering effect in process of billboard reconstruction.
|
||||
lowp vec4 pos = (a_position + vec4(Zero, Zero, depthShift, Zero)) * modelView;
|
||||
highp vec4 shiftedPos = vec4(a_normal, Zero, Zero) + pos;
|
||||
gl_Position = shiftedPos * projection;
|
||||
shiftedPos = shiftedPos * projection;
|
||||
float w = shiftedPos.w;
|
||||
shiftedPos.xyw = (pivotTransform * shiftedPos).xyw;
|
||||
shiftedPos.z *= shiftedPos.w / w;
|
||||
gl_Position = shiftedPos;
|
||||
vec2 colorTexCoord = a_colorTexCoord * notOutline + a_outlineColorTexCoord * isOutline;
|
||||
#ifdef ENABLE_VTF
|
||||
v_color = texture2D(u_colorTex, colorTexCoord);
|
||||
|
|
|
@ -5,6 +5,7 @@ attribute vec2 a_maskTexCoord;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
uniform float u_isOutlinePass;
|
||||
|
||||
#ifdef ENABLE_VTF
|
||||
|
@ -25,7 +26,12 @@ void main()
|
|||
// to eliminate jittering effect in process of billboard reconstruction.
|
||||
lowp vec4 pos = a_position * modelView;
|
||||
highp vec4 shiftedPos = vec4(a_normal, Zero, Zero) + pos;
|
||||
gl_Position = shiftedPos * projection;
|
||||
shiftedPos = shiftedPos * projection;
|
||||
float w = shiftedPos.w;
|
||||
shiftedPos.xyw = (pivotTransform * shiftedPos).xyw;
|
||||
shiftedPos.z *= shiftedPos.w / w;
|
||||
gl_Position = shiftedPos;
|
||||
|
||||
#ifdef ENABLE_VTF
|
||||
v_color = texture2D(u_colorTex, a_colorTexCoord);
|
||||
#else
|
||||
|
|
|
@ -16,7 +16,7 @@ void main(void)
|
|||
vec4 offset = vec4(a_normal, 0, 0) * projection;
|
||||
|
||||
vec4 projectedPivot = pivot * projection;
|
||||
vec4 transformedPivot = pivotTransform * vec4(projectedPivot.xy, 0, 1);
|
||||
vec4 transformedPivot = pivotTransform * projectedPivot;
|
||||
|
||||
vec4 scale = pivotTransform * vec4(1.0, -1.0, 0, 1.0);
|
||||
gl_Position = transformedPivot + vec4(offset.xy * transformedPivot.w / scale.w * scale.x, 0, 0);
|
||||
|
|
|
@ -4,6 +4,7 @@ attribute vec2 a_colorTexCoords;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
|
||||
varying vec2 v_colorTexCoords;
|
||||
|
||||
|
@ -13,6 +14,10 @@ void main(void)
|
|||
// to eliminate jittering effect in process of billboard reconstruction.
|
||||
lowp vec4 pos = vec4(a_position, 1) * modelView;
|
||||
highp vec4 shiftedPos = vec4(a_normal, 0, 0) + pos;
|
||||
gl_Position = shiftedPos * projection;
|
||||
shiftedPos = shiftedPos * projection;
|
||||
float w = shiftedPos.w;
|
||||
shiftedPos.xyw = (pivotTransform * shiftedPos).xyw;
|
||||
shiftedPos.z *= shiftedPos.w / w;
|
||||
gl_Position = shiftedPos;
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ attribute float a_animate;
|
|||
|
||||
uniform mat4 modelView;
|
||||
uniform mat4 projection;
|
||||
uniform mat4 pivotTransform;
|
||||
uniform float u_interpolationT;
|
||||
|
||||
varying vec2 v_colorTexCoords;
|
||||
|
@ -14,6 +15,11 @@ void main(void)
|
|||
vec2 normal = a_normal;
|
||||
if (a_animate > 0.0)
|
||||
normal = u_interpolationT * normal;
|
||||
gl_Position = (vec4(normal, 0, 0) + vec4(a_position, 1) * modelView) * projection;
|
||||
|
||||
vec4 pos = (vec4(normal, 0, 0) + vec4(a_position, 1) * modelView) * projection;
|
||||
float w = pos.w;
|
||||
pos.xyw = (pivotTransform * pos).xyw;
|
||||
pos.z *= pos.w / w;
|
||||
gl_Position = pos;
|
||||
v_colorTexCoords = a_colorTexCoords;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ void main(void)
|
|||
vec4 offset = vec4(normal, 0, 0) * projection;
|
||||
|
||||
vec4 projectedPivot = pivot * projection;
|
||||
vec4 transformedPivot = pivotTransform * vec4(projectedPivot.xy, 0, 1);
|
||||
vec4 transformedPivot = pivotTransform * projectedPivot;
|
||||
|
||||
vec4 scale = pivotTransform * vec4(1.0, -1.0, 0, 1.0);
|
||||
gl_Position = transformedPivot + vec4(offset.xy * transformedPivot.w / scale.w * scale.x, 0, 0);
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
#include "drape_frontend/animation/interpolation_holder.hpp"
|
||||
#include "drape_frontend/gui/drape_gui.hpp"
|
||||
#include "drape_frontend/framebuffer.hpp"
|
||||
#include "drape_frontend/frontend_renderer.hpp"
|
||||
#include "drape_frontend/message_subclasses.hpp"
|
||||
#include "drape_frontend/renderer3d.hpp"
|
||||
#include "drape_frontend/visual_params.hpp"
|
||||
#include "drape_frontend/user_mark_shapes.hpp"
|
||||
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
#include "drape_frontend/framebuffer.hpp"
|
||||
#include "drape_frontend/renderer3d.hpp"
|
||||
#endif
|
||||
|
||||
#include "drape/debug_rect_renderer.hpp"
|
||||
#include "drape/shader_def.hpp"
|
||||
#include "drape/support_manager.hpp"
|
||||
|
@ -47,8 +50,10 @@ FrontendRenderer::FrontendRenderer(Params const & params)
|
|||
, m_overlayTree(new dp::OverlayTree())
|
||||
, m_enable3dInNavigation(false)
|
||||
, m_isBillboardRenderPass(false)
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
, m_framebuffer(new Framebuffer())
|
||||
, m_renderer3d(new Renderer3d())
|
||||
#endif
|
||||
, m_viewport(params.m_viewport)
|
||||
, m_userEventStream(params.m_isCountryLoadedFn)
|
||||
, m_modelViewChangedFn(params.m_modelViewChangedFn)
|
||||
|
@ -532,10 +537,12 @@ void FrontendRenderer::OnResize(ScreenBase const & screen)
|
|||
m_myPositionController->UpdatePixelPosition(screen);
|
||||
m_myPositionController->SetPixelRect(viewportRect);
|
||||
|
||||
m_viewport.SetViewport(0, 0, screen.GetWidth(), screen.GetHeight());
|
||||
m_viewport.SetViewport(0, 0, viewportRect.SizeX(), viewportRect.SizeY());
|
||||
m_contextFactory->getDrawContext()->resize(viewportRect.SizeX(), viewportRect.SizeY());
|
||||
RefreshProjection();
|
||||
RefreshProjection(screen);
|
||||
RefreshPivotTransform(screen);
|
||||
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
if (screen.isPerspective())
|
||||
{
|
||||
int width = screen.GetWidth();
|
||||
|
@ -550,15 +557,13 @@ void FrontendRenderer::OnResize(ScreenBase const & screen)
|
|||
LOG(LINFO, ("Max texture size:", maxTextureSize, ", expanded screen size:", maxSide,
|
||||
", scale:", scale));
|
||||
}
|
||||
|
||||
m_viewport.SetViewport(0, 0, width, height);
|
||||
|
||||
m_renderer3d->SetSize(viewportRect.SizeX(), viewportRect.SizeY());
|
||||
m_framebuffer->SetDefaultContext(m_contextFactory->getDrawContext());
|
||||
m_framebuffer->SetSize(width, height);
|
||||
|
||||
RefreshPivotTransform(screen);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrontendRenderer::AddToRenderGroup(vector<drape_ptr<RenderGroup>> & groups,
|
||||
|
@ -714,11 +719,13 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
|
|||
#endif
|
||||
|
||||
bool const isPerspective = modelView.isPerspective();
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
if (isPerspective)
|
||||
{
|
||||
m_framebuffer->SetDefaultContext(m_contextFactory->getDrawContext());
|
||||
m_framebuffer->Enable();
|
||||
}
|
||||
#endif
|
||||
|
||||
RenderGroupComparator comparator;
|
||||
sort(m_renderGroups.begin(), m_renderGroups.end(), bind(&RenderGroupComparator::operator (), &comparator, _1, _2));
|
||||
|
@ -827,8 +834,10 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
|
|||
|
||||
if (isPerspective)
|
||||
{
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
m_framebuffer->Disable();
|
||||
m_renderer3d->Render(modelView, m_framebuffer->GetTextureId(), make_ref(m_gpuProgramManager));
|
||||
#endif
|
||||
|
||||
m_isBillboardRenderPass = true;
|
||||
|
||||
|
@ -888,11 +897,11 @@ void FrontendRenderer::RenderSingleGroup(ScreenBase const & modelView, ref_ptr<B
|
|||
group->Render(modelView);
|
||||
}
|
||||
|
||||
void FrontendRenderer::RefreshProjection()
|
||||
void FrontendRenderer::RefreshProjection(ScreenBase const & screen)
|
||||
{
|
||||
array<float, 16> m;
|
||||
|
||||
dp::MakeProjection(m, 0.0f, m_viewport.GetWidth(), m_viewport.GetHeight(), 0.0f);
|
||||
dp::MakeProjection(m, 0.0f, screen.GetWidth(), screen.GetHeight(), 0.0f);
|
||||
m_generalUniforms.SetMatrix4x4Value("projection", m.data());
|
||||
}
|
||||
|
||||
|
@ -915,7 +924,11 @@ void FrontendRenderer::RefreshPivotTransform(ScreenBase const & screen)
|
|||
{
|
||||
if (screen.isPerspective())
|
||||
{
|
||||
math::Matrix<float, 4, 4> const transform(screen.Pto3dMatrix());
|
||||
math::Matrix<float, 4, 4> transform(screen.Pto3dMatrix());
|
||||
math::Matrix<float, 4, 4> scaleM = math::Identity<float, 4>();
|
||||
scaleM(2, 2) = 0.0;
|
||||
|
||||
transform = scaleM * transform;
|
||||
m_generalUniforms.SetMatrix4x4Value("pivotTransform", transform.m_data);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -36,6 +36,8 @@
|
|||
#include "std/function.hpp"
|
||||
#include "std/map.hpp"
|
||||
|
||||
//#define USE_TEXTURE_IN_3D
|
||||
|
||||
namespace dp
|
||||
{
|
||||
class RenderBucket;
|
||||
|
@ -46,8 +48,11 @@ namespace df
|
|||
{
|
||||
|
||||
class SelectionShape;
|
||||
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
class Framebuffer;
|
||||
class Renderer3d;
|
||||
#endif
|
||||
|
||||
struct TapInfo
|
||||
{
|
||||
|
@ -138,7 +143,7 @@ private:
|
|||
void OnResize(ScreenBase const & screen);
|
||||
void RenderScene(ScreenBase const & modelView);
|
||||
void RenderSingleGroup(ScreenBase const & modelView, ref_ptr<BaseRenderGroup> group);
|
||||
void RefreshProjection();
|
||||
void RefreshProjection(ScreenBase const & screen);
|
||||
void RefreshModelView(ScreenBase const & screen);
|
||||
void RefreshPivotTransform(ScreenBase const & screen);
|
||||
void RefreshBgColor();
|
||||
|
@ -232,8 +237,10 @@ private:
|
|||
|
||||
bool m_enable3dInNavigation;
|
||||
bool m_isBillboardRenderPass;
|
||||
#ifdef USE_TEXTURE_IN_3D
|
||||
drape_ptr<Framebuffer> m_framebuffer;
|
||||
drape_ptr<Renderer3d> m_renderer3d;
|
||||
#endif
|
||||
|
||||
Viewport m_viewport;
|
||||
UserEventStream m_userEventStream;
|
||||
|
|
Loading…
Add table
Reference in a new issue