drape_ptr<ShapeRenderer> Watermark::Draw(ref_ptr<dp::GraphicsContext> context, m2::PointF & size, ref_ptr<dp::TextureManager> tex) const { dp::TextureManager::SymbolRegion region; tex->GetSymbolRegion("watermark", region); glsl::vec2 const halfSize = glsl::ToVec2(region.GetPixelSize() * 0.5f); m2::RectF const texRect = region.GetTexRect(); WatermarkVertex vertexes[] = { WatermarkVertex(glsl::vec2(-halfSize.x, halfSize.y), glsl::ToVec2(texRect.LeftTop())), WatermarkVertex(glsl::vec2(-halfSize.x, -halfSize.y), glsl::ToVec2(texRect.LeftBottom())), WatermarkVertex(glsl::vec2(halfSize.x, halfSize.y), glsl::ToVec2(texRect.RightTop())), WatermarkVertex(glsl::vec2(halfSize.x, -halfSize.y), glsl::ToVec2(texRect.RightBottom())) }; auto state = df::CreateRenderState(gpu::Program::TexturingGui, df::DepthLayer::GuiLayer); state.SetColorTexture(region.GetTexture()); state.SetDepthTestEnabled(false); dp::AttributeProvider provider(1 /* streamCount */, 4 /* vertexCount */); dp::BindingInfo info(2 /* count */); dp::BindingDecl & posDecl = info.GetBindingDecl(0); posDecl.m_attributeName = "a_position"; posDecl.m_componentCount = 2; posDecl.m_componentType = gl_const::GLFloatType; posDecl.m_offset = 0; posDecl.m_stride = sizeof(WatermarkVertex); dp::BindingDecl & texDecl = info.GetBindingDecl(1); texDecl.m_attributeName = "a_colorTexCoords"; texDecl.m_componentCount = 2; texDecl.m_componentType = gl_const::GLFloatType; texDecl.m_offset = sizeof(glsl::vec2); texDecl.m_stride = posDecl.m_stride; provider.InitStream(0, info, make_ref(&vertexes)); size = region.GetPixelSize(); drape_ptr<dp::OverlayHandle> handle = make_unique_dp<WatermarkVertexHandle>( EGuiHandle::GuiHandleWatermark, m_position.m_pixelPivot, m_position.m_anchor, size); drape_ptr<ShapeRenderer> renderer = make_unique_dp<ShapeRenderer>(); dp::Batcher batcher(dp::Batcher::IndexPerQuad, dp::Batcher::VertexPerQuad); batcher.SetBatcherHash(static_cast<uint64_t>(df::BatcherBucket::Default)); dp::SessionGuard guard(context, batcher, std::bind(&ShapeRenderer::AddShape, renderer.get(), _1, _2)); batcher.InsertTriangleStrip(context, state, make_ref(&provider), std::move(handle)); return renderer; }
void TextShape::DrawSubStringOutlined(ref_ptr<dp::GraphicsContext> context, StraightTextLayout const & layout, dp::FontDecl const & font, glm::vec2 const & baseOffset, ref_ptr<dp::Batcher> batcher, ref_ptr<dp::TextureManager> textures, bool isPrimary, bool isOptional) const { gpu::TTextOutlinedStaticVertexBuffer staticBuffer; gpu::TTextDynamicVertexBuffer dynamicBuffer; dp::TextureManager::ColorRegion color, outline; textures->GetColorRegion(font.m_color, color); textures->GetColorRegion(font.m_outlineColor, outline); auto const finalOffset = layout.GetTextOffset(m_symbolSizes.front(), m_params.m_titleDecl.m_anchor, m_symbolAnchor); layout.CacheDynamicGeometry(finalOffset, dynamicBuffer); layout.CacheStaticGeometry(color, outline, staticBuffer); auto state = CreateRenderState(gpu::Program::TextOutlined, m_params.m_depthLayer); state.SetProgram3d(gpu::Program::TextOutlinedBillboard); state.SetDepthTestEnabled(m_params.m_depthTestEnabled); ASSERT(color.GetTexture() == outline.GetTexture(), ()); state.SetColorTexture(color.GetTexture()); state.SetMaskTexture(layout.GetMaskTexture()); gpu::TTextDynamicVertexBuffer initialDynBuffer(dynamicBuffer.size()); m2::PointF const & pixelSize = layout.GetPixelSize(); auto overlayId = dp::OverlayID(m_params.m_featureID, m_tileCoords, m_textIndex); drape_ptr<StraightTextHandle> handle = make_unique_dp<StraightTextHandle>(overlayId, layout.GetText(), m_params.m_titleDecl.m_anchor, glsl::ToVec2(m_basePoint), glsl::vec2(pixelSize.x, pixelSize.y), finalOffset, GetOverlayPriority(), layout.GetFixedHeight(), textures, isOptional, std::move(dynamicBuffer), m_params.m_minVisibleScale, true); if (m_symbolSizes.size() > 1) handle->SetDynamicSymbolSizes(layout, m_symbolSizes, m_symbolAnchor); handle->SetPivotZ(m_params.m_posZ); ASSERT_LESS(m_params.m_startOverlayRank + 1, dp::OverlayRanksCount, ()); handle->SetOverlayRank(isPrimary ? m_params.m_startOverlayRank : m_params.m_startOverlayRank + 1); handle->SetExtendingSize(m_params.m_extendingSize); if (m_params.m_specialDisplacement == SpecialDisplacement::UserMark || m_params.m_specialDisplacement == SpecialDisplacement::SpecialModeUserMark) { handle->SetSpecialLayerOverlay(true); } dp::AttributeProvider provider(2, static_cast<uint32_t>(staticBuffer.size())); provider.InitStream(0, gpu::TextOutlinedStaticVertex::GetBindingInfo(), make_ref(staticBuffer.data())); provider.InitStream(1, gpu::TextDynamicVertex::GetBindingInfo(), make_ref(initialDynBuffer.data())); batcher->InsertListOfStrip(context, state, make_ref(&provider), std::move(handle), 4); }
static std::shared_ptr<asd::Mesh> CreateMesh(asd::Graphics* graphics) { uint8_t weights1[4]; weights1[0] = 255; weights1[1] = 0; weights1[2] = 0; weights1[3] = 0; int* pweights1 = (int*) weights1; uint8_t weights2[4]; weights2[0] = 0; weights2[1] = 255; weights2[2] = 0; weights2[3] = 0; int* pweights2 = (int*) weights2; uint8_t indexes[4]; indexes[0] = 0; indexes[1] = 1; indexes[2] = 0; indexes[3] = 0; int* pindexes = (int*) indexes; auto mesh = graphics->CreateMesh(); mesh->AddVertex(asd::Vector3DF(-0.5, 0.5, 0.5), asd::Vector3DF(0, 0, 1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 0), asd::Vector2DF(0, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, -0.5, 0.5), asd::Vector3DF(0, 0, 1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 1), asd::Vector2DF(0, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, 0.5, 0.5), asd::Vector3DF(0, 0, 1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 0), asd::Vector2DF(1, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, -0.5, 0.5), asd::Vector3DF(0, 0, 1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 1), asd::Vector2DF(1, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, 0.5, -0.5), asd::Vector3DF(1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 0), asd::Vector2DF(1, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, -0.5, -0.5), asd::Vector3DF(1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 1), asd::Vector2DF(1, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, 0.5, -0.5), asd::Vector3DF(0, 0, -1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 0), asd::Vector2DF(1, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, -0.5, -0.5), asd::Vector3DF(0, 0, -1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 1), asd::Vector2DF(1, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, 0.5, 0.5), asd::Vector3DF(-1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 0), asd::Vector2DF(1, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, 0.5, 0.5), asd::Vector3DF(0, 1, 0), asd::Vector3DF(0, 0, -1), asd::Vector2DF(0, 1), asd::Vector2DF(0, 1), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, -0.5, 0.5), asd::Vector3DF(-1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(1, 1), asd::Vector2DF(1, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, -0.5, 0.5), asd::Vector3DF(0, -1, 0), asd::Vector3DF(0, 0, 1), asd::Vector2DF(0, 0), asd::Vector2DF(0, 0), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, 0.5, 0.5), asd::Vector3DF(1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 0), asd::Vector2DF(0, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, 0.5, 0.5), asd::Vector3DF(0, 1, 0), asd::Vector3DF(0, 0, -1), asd::Vector2DF(1, 1), asd::Vector2DF(1, 1), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, -0.5, 0.5), asd::Vector3DF(1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 1), asd::Vector2DF(0, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, -0.5, 0.5), asd::Vector3DF(0, -1, 0), asd::Vector3DF(0, 0, 1), asd::Vector2DF(1, 0), asd::Vector2DF(1, 0), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, 0.5, -0.5), asd::Vector3DF(0, 0, -1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 0), asd::Vector2DF(0, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, 0.5, -0.5), asd::Vector3DF(0, 1, 0), asd::Vector3DF(0, 0, -1), asd::Vector2DF(1, 0), asd::Vector2DF(1, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, -0.5, -0.5), asd::Vector3DF(0, 0, -1), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 1), asd::Vector2DF(0, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(0.5, -0.5, -0.5), asd::Vector3DF(0, -1, 0), asd::Vector3DF(0, 0, 1), asd::Vector2DF(1, 1), asd::Vector2DF(1, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, 0.5, -0.5), asd::Vector3DF(-1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 0), asd::Vector2DF(0, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, 0.5, -0.5), asd::Vector3DF(0, 1, 0), asd::Vector3DF(0, 0, -1), asd::Vector2DF(0, 0), asd::Vector2DF(0, 0), asd::Color(255, 255, 255, 255), *pweights1, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, -0.5, -0.5), asd::Vector3DF(-1, 0, 0), asd::Vector3DF(0, 1, 0), asd::Vector2DF(0, 1), asd::Vector2DF(0, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddVertex(asd::Vector3DF(-0.5, -0.5, -0.5), asd::Vector3DF(0, -1, 0), asd::Vector3DF(0, 0, 1), asd::Vector2DF(0, 1), asd::Vector2DF(0, 1), asd::Color(255, 255, 255, 255), *pweights2, *pindexes); mesh->AddFace(0, 2, 3, 0); mesh->AddFace(0, 3, 1, 0); mesh->AddFace(12, 4, 5, 0); mesh->AddFace(12, 5, 14, 0); mesh->AddFace(16, 6, 7, 0); mesh->AddFace(16, 7, 18, 0); mesh->AddFace(20, 8, 10, 0); mesh->AddFace(20, 10, 22, 0); mesh->AddFace(21, 17, 13, 0); mesh->AddFace(21, 13, 9, 0); mesh->AddFace(11, 15, 19, 0); mesh->AddFace(11, 19, 23, 0); mesh->AddMaterial(); auto texture = graphics->CreateTexture2D(asd::ToAString(L"Data/Texture/Sample1.png").c_str()); mesh->SetColorTexture(0, texture.get()); return mesh; }