Transparent houses.

This commit is contained in:
Daria Volvenkova 2015-12-13 13:35:18 +03:00
parent 48ed2527eb
commit 5d4edb6b5c
6 changed files with 45 additions and 49 deletions

View file

@ -1,7 +1,10 @@
uniform sampler2D tex;
varying vec2 v_tcoord;
const float opacity = 0.7;
void main()
{
gl_FragColor = texture2D(tex, v_tcoord);
gl_FragColor.a = gl_FragColor.a * opacity;
}

View file

@ -1,13 +1,11 @@
attribute vec2 a_pos;
attribute vec2 a_tcoord;
uniform mat4 m_transform;
varying vec2 v_tcoord;
void main()
{
v_tcoord = a_tcoord;
gl_Position = m_transform * vec4(a_pos, 0.0, 1.0);
gl_Position = vec4(a_pos, 0.0, 1.0);
}

View file

@ -1,7 +1,9 @@
#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"
@ -42,6 +44,8 @@ FrontendRenderer::FrontendRenderer(Params const & params)
: BaseRenderer(ThreadsCommutator::RenderThread, params)
, m_gpuProgramManager(new dp::GpuProgramManager())
, m_routeRenderer(new RouteRenderer())
, m_framebuffer(new Framebuffer())
, m_renderer3d(new Renderer3d())
, m_overlayTree(new dp::OverlayTree())
, m_enable3dInNavigation(false)
, m_viewport(params.m_viewport)
@ -550,6 +554,9 @@ void FrontendRenderer::OnResize(ScreenBase const & screen)
m_contextFactory->getDrawContext()->resize(viewportRect.SizeX(), viewportRect.SizeY());
RefreshProjection(screen);
RefreshPivotTransform(screen);
if (screen.isPerspective())
m_framebuffer->SetSize(viewportRect.SizeX(), viewportRect.SizeY());
}
void FrontendRenderer::AddToRenderGroup(vector<drape_ptr<RenderGroup>> & groups,
@ -801,6 +808,9 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
if (isPerspective && has3dAreas)
{
m_framebuffer->Enable();
GLFunctions::glClear();
for (size_t index = area3dRenderGroupStart; index <= area3dRenderGroupEnd; ++index)
{
drape_ptr<RenderGroup> const & group = m_renderGroups[index];
@ -808,6 +818,8 @@ void FrontendRenderer::RenderScene(ScreenBase const & modelView)
RenderSingleGroup(modelView, make_ref(group));
}
GLFunctions::glClearDepth();
m_framebuffer->Disable();
m_renderer3d->Render(m_framebuffer->GetTextureId(), make_ref(m_gpuProgramManager));
}
if (isPerspective && hasSelectedPOI)
@ -911,7 +923,8 @@ void FrontendRenderer::RefreshBgColor()
{
uint32_t color = drule::rules().GetBgColor(df::GetDrawTileScale(m_userEventStream.GetCurrentScreen()));
dp::Color c = dp::Extract(color, 255 - (color >> 24));
GLFunctions::glClearColor(c.GetRedF(), c.GetGreenF(), c.GetBlueF(), 1.0f);
// TODO: Make sure that zero alpha doesn't affect anything.
GLFunctions::glClearColor(c.GetRedF(), c.GetGreenF(), c.GetBlueF(), 0.0f);
}
int FrontendRenderer::GetCurrentZoomLevel() const
@ -1106,6 +1119,7 @@ void FrontendRenderer::Routine::Do()
dp::OGLContext * context = m_renderer.m_contextFactory->getDrawContext();
context->makeCurrent();
m_renderer.m_framebuffer->SetDefaultContext(context);
GLFunctions::Init();
GLFunctions::AttachCache(this_thread::get_id());

View file

@ -46,6 +46,8 @@ namespace df
{
class SelectionShape;
class Framebuffer;
class Renderer3d;
struct TapInfo
{
@ -225,6 +227,8 @@ private:
drape_ptr<MyPositionController> m_myPositionController;
drape_ptr<SelectionShape> m_selectionShape;
drape_ptr<RouteRenderer> m_routeRenderer;
drape_ptr<Framebuffer> m_framebuffer;
drape_ptr<Renderer3d> m_renderer3d;
drape_ptr<dp::OverlayTree> m_overlayTree;

View file

@ -27,70 +27,50 @@ Renderer3d::~Renderer3d()
{
if (m_bufferId != 0)
GLFunctions::glDeleteBuffer(m_bufferId);
if (m_VAO != 0)
GLFunctions::glDeleteVertexArray(m_VAO);
}
void Renderer3d::SetSize(uint32_t width, uint32_t height)
{
m_width = width;
m_height = height;
}
void Renderer3d::Build(ref_ptr<dp::GpuProgram> prg)
{
m_attributePosition = prg->GetAttributeLocation("a_pos");
ASSERT_NOT_EQUAL(m_attributePosition, -1, ());
m_attributeTexCoord = prg->GetAttributeLocation("a_tcoord");
ASSERT_NOT_EQUAL(m_attributeTexCoord, -1, ());
m_bufferId = GLFunctions::glGenBuffer();
GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
m_VAO = GLFunctions::glGenVertexArray();
GLFunctions::glBindVertexArray(m_VAO);
int8_t attributeLocation = prg->GetAttributeLocation("a_pos");
ASSERT_NOT_EQUAL(attributeLocation, -1, ());
GLFunctions::glEnableVertexAttribute(attributeLocation);
GLFunctions::glVertexAttributePointer(attributeLocation, 2, gl_const::GLFloatType, false,
sizeof(float) * 4, 0);
attributeLocation = prg->GetAttributeLocation("a_tcoord");
ASSERT_NOT_EQUAL(attributeLocation, -1, ());
GLFunctions::glEnableVertexAttribute(attributeLocation);
GLFunctions::glVertexAttributePointer(attributeLocation, 2, gl_const::GLFloatType, false,
sizeof(float) * 4, sizeof(float) * 2);
GLFunctions::glBufferData(gl_const::GLArrayBuffer, m_vertices.size() * sizeof(m_vertices[0]),
m_vertices.data(), gl_const::GLStaticDraw);
GLFunctions::glBindVertexArray(0);
GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
}
void Renderer3d::Render(ScreenBase const & screen, uint32_t textureId, ref_ptr<dp::GpuProgramManager> mng)
void Renderer3d::Render(uint32_t textureId, ref_ptr<dp::GpuProgramManager> mng)
{
// Unbind current VAO, because glVertexAttributePointer and glEnableVertexAttribute can affect it.
GLFunctions::glBindVertexArray(0);
ref_ptr<dp::GpuProgram> prg = mng->GetProgram(gpu::PLANE_3D_PROGRAM);
prg->Bind();
if (m_VAO == 0)
if (m_bufferId == 0)
Build(prg);
math::Matrix<float, 4, 4> const transform(screen.Pto3dMatrix());
dp::UniformValuesStorage uniforms;
uniforms.SetIntValue("tex", 0);
uniforms.SetMatrix4x4Value("m_transform", transform.m_data);
dp::ApplyUniforms(uniforms, prg);
GLFunctions::glDisable(gl_const::GLDepthTest);
GLFunctions::glActiveTexture(gl_const::GLTexture0);
GLFunctions::glBindTexture(textureId);
GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
GLFunctions::glBindVertexArray(m_VAO);
GLFunctions::glViewport(0, 0, m_width, m_height);
GLFunctions::glClear();
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);
GLFunctions::glEnable(gl_const::GLBlending);
GLFunctions::glDrawArrays(gl_const::GLTriangleStrip, 0, 4);
GLFunctions::glDisable(gl_const::GLBlending);
prg->Unbind();
GLFunctions::glBindTexture(0);

View file

@ -21,17 +21,14 @@ public:
Renderer3d();
~Renderer3d();
void SetSize(uint32_t width, uint32_t height);
void Render(ScreenBase const & screen, uint32_t textureId, ref_ptr<dp::GpuProgramManager> mng);
void Render(uint32_t textureId, ref_ptr<dp::GpuProgramManager> mng);
private:
void Build(ref_ptr<dp::GpuProgram> prg);
uint32_t m_width = 0;
uint32_t m_height = 0;
uint32_t m_VAO = 0;
uint32_t m_bufferId = 0;
int8_t m_attributePosition;
int8_t m_attributeTexCoord;
vector<float> m_vertices;
};