[drape, MAP-30] Rewrite simple_vertex_shared.

This commit is contained in:
Dmitry Kunin 2014-01-13 16:20:45 +03:00 committed by Alex Zolotarev
parent 31bf3f51b1
commit ab1183d9e3
2 changed files with 26 additions and 19 deletions

View file

@ -13,16 +13,21 @@ namespace df
void AreaShape::SetDepth(float depth)
{
m_depth = depth;
if (m_depth != depth)
{
m_depth = depth;
for (size_t i = 0; i < m_vertexes.size() ; ++i)
m_vertexes[i].m_z = m_depth;
}
}
void AreaShape::AddTriangle(const m2::PointF & v1,
const m2::PointF & v2,
const m2::PointF & v3)
{
m_vertexes.push_back(v1);
m_vertexes.push_back(v2);
m_vertexes.push_back(v3);
m_vertexes.push_back(Point3D(v1.x, v1.y, m_depth));
m_vertexes.push_back(Point3D(v2.x, v2.y, m_depth));
m_vertexes.push_back(Point3D(v3.x, v3.y, m_depth));
}
void AreaShape::Draw(RefPointer<Batcher> batcher) const
@ -32,30 +37,18 @@ namespace df
::Convert(m_color, r, g, b, a);
state.GetUniformValues().SetFloatValue("color", r, g, b, a);
AttributeProvider provider(2, m_vertexes.size());
AttributeProvider provider(1, m_vertexes.size());
{
BindingInfo info(1);
BindingDecl & decl = info.GetBindingDecl(0);
decl.m_attributeName = "position";
decl.m_componentCount = 2;
decl.m_componentCount = 3;
decl.m_componentType = GLConst::GLFloatType;
decl.m_offset = 0;
decl.m_stride = 0;
provider.InitStream(0, info, MakeStackRefPointer((void *)&m_vertexes[0]));
}
vector<float> depthMemory(m_vertexes.size(), m_depth);
{
BindingInfo info(1);
BindingDecl & decl = info.GetBindingDecl(0);
decl.m_attributeName = "depth";
decl.m_componentCount = 1;
decl.m_componentType = GLConst::GLFloatType;
decl.m_offset = 0;
decl.m_stride = 0;
provider.InitStream(1, info, MakeStackRefPointer((void *)&depthMemory[0]));
}
batcher->InsertTriangleList(state, MakeStackRefPointer(&provider));
}
}

View file

@ -23,8 +23,22 @@ namespace df
virtual void Draw(RefPointer<Batcher> batcher) const;
private:
struct Point3D
{
float m_x;
float m_y;
float m_z;
Point3D(float x, float y, float z)
: m_x(x)
, m_y(y)
, m_z(z)
{}
};
Color m_color;
vector<m2::PointF> m_vertexes;
vector<Point3D> m_vertexes;
float m_depth;
};
}