diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2018-09-06 10:57:09 +0300 |
---|---|---|
committer | Aleksey Belousov <beloal@users.noreply.github.com> | 2018-09-25 12:33:08 +0300 |
commit | c2e13ae8d6d39ef659dad657828bde165e31ea78 (patch) | |
tree | cf8501d7c186162c6c28225e0b9657aeec59da9f /drape | |
parent | d1074729e0d0c63ab887efb866903bc99181f919 (diff) |
[drape][metal] Added params setting up.
Diffstat (limited to 'drape')
-rw-r--r-- | drape/mesh_object.cpp | 5 | ||||
-rw-r--r-- | drape/mesh_object.hpp | 11 | ||||
-rw-r--r-- | drape/metal/metal_mesh_object_impl.mm | 11 | ||||
-rw-r--r-- | drape/metal/render_state_metal.mm | 20 | ||||
-rw-r--r-- | drape/render_state.cpp | 1 | ||||
-rw-r--r-- | drape/texture_manager.cpp | 4 |
6 files changed, 37 insertions, 15 deletions
diff --git a/drape/mesh_object.cpp b/drape/mesh_object.cpp index edd92a7266..fa76639193 100644 --- a/drape/mesh_object.cpp +++ b/drape/mesh_object.cpp @@ -6,7 +6,6 @@ #include "drape/gl_functions.hpp" #include "drape/glsl_func.hpp" #include "drape/glsl_types.hpp" -#include "drape/gpu_program.hpp" #include "drape/texture_manager.hpp" namespace @@ -126,7 +125,7 @@ public: } } - void Unbind(ref_ptr<dp::GpuProgram> program) override + void Unbind() override { if (GLFunctions::ExtensionsList.IsSupported(dp::GLExtensionsList::VertexArrayObject)) GLFunctions::glBindVertexArray(0); @@ -261,7 +260,7 @@ void MeshObject::Unbind(ref_ptr<dp::GpuProgram> program) program->Unbind(); CHECK(m_impl != nullptr, ()); - m_impl->Unbind(program); + m_impl->Unbind(); } // static diff --git a/drape/mesh_object.hpp b/drape/mesh_object.hpp index d8660ed81f..06e1d1c65c 100644 --- a/drape/mesh_object.hpp +++ b/drape/mesh_object.hpp @@ -1,8 +1,8 @@ #pragma once #include "drape/graphics_context.hpp" -#include "drape/render_state.hpp" #include "drape/pointers.hpp" +#include "drape/render_state.hpp" #include <functional> #include <string> @@ -13,12 +13,13 @@ namespace dp class GpuProgram; class GraphicsContext; class MeshObjectImpl; + namespace metal { class MetalMeshObjectImpl; } // namespace metal -// This class implement simple mesh object which does not use an index buffer. +// This class implements a simple mesh object which does not use an index buffer. // Use this class only for simple geometry. class MeshObject { @@ -50,7 +51,7 @@ public: Bind(context, program); ApplyState(context, program, state); - paramsSetter->Apply(program, params); + paramsSetter->Apply(context, program, params); DrawPrimitives(context); @@ -98,7 +99,7 @@ private: }; void InitForOpenGL(); - // Definition of this method is in separate .mm-file. + // Definition of this method is in a .mm-file. void InitForMetal(); void Bind(ref_ptr<dp::GraphicsContext> context, ref_ptr<dp::GpuProgram> program); @@ -120,7 +121,7 @@ public: virtual void Reset() = 0; virtual void UpdateBuffer(uint32_t bufferInd) = 0; virtual void Bind(ref_ptr<dp::GpuProgram> program) = 0; - virtual void Unbind(ref_ptr<dp::GpuProgram> program) = 0; + virtual void Unbind() = 0; virtual void DrawPrimitives(ref_ptr<dp::GraphicsContext> context, uint32_t verticesCount) = 0; }; } // namespace dp diff --git a/drape/metal/metal_mesh_object_impl.mm b/drape/metal/metal_mesh_object_impl.mm index 0a42af2e9a..f1f8645795 100644 --- a/drape/metal/metal_mesh_object_impl.mm +++ b/drape/metal/metal_mesh_object_impl.mm @@ -80,14 +80,17 @@ public: void Bind(ref_ptr<dp::GpuProgram> program) override {} - void Unbind(ref_ptr<dp::GpuProgram> program) override {} + void Unbind() override {} void DrawPrimitives(ref_ptr<dp::GraphicsContext> context, uint32_t verticesCount) override { ref_ptr<dp::metal::MetalBaseContext> metalContext = context; - [metalContext->GetCommandEncoder() drawPrimitives:GetPrimitiveType(m_mesh->m_drawPrimitive) - vertexStart:0 - vertexCount:verticesCount]; + id<MTLRenderCommandEncoder> encoder = metalContext->GetCommandEncoder(); + for (size_t i = 0; i < m_geometryBuffers.size(); i++) + [encoder setVertexBuffer:m_geometryBuffers[i] offset:0 atIndex:i]; + + [encoder drawPrimitives:GetPrimitiveType(m_mesh->m_drawPrimitive) vertexStart:0 + vertexCount:verticesCount]; } private: diff --git a/drape/metal/render_state_metal.mm b/drape/metal/render_state_metal.mm index 1498a09591..c3a2a06ea6 100644 --- a/drape/metal/render_state_metal.mm +++ b/drape/metal/render_state_metal.mm @@ -2,6 +2,7 @@ #include "drape/metal/metal_base_context.hpp" #include "drape/metal/metal_gpu_program.hpp" +#include "drape/metal/metal_texture.hpp" #include "drape/pointers.hpp" #include "drape/render_state.hpp" @@ -30,6 +31,23 @@ void ApplyTexturesForMetal(ref_ptr<GraphicsContext> context, ref_ptr<GpuProgram> RenderState const & state) { ref_ptr<dp::metal::MetalBaseContext> metalContext = context; - //TODO(@rokuz,@darina) + ref_ptr<dp::metal::MetalGpuProgram> p = program; + id<MTLRenderCommandEncoder> encoder = metalContext->GetCommandEncoder(); + for (auto const & texture : state.GetTextures()) + { + auto const & bindingInfo = p->GetTextureBindingInfo(texture.first); + ref_ptr<dp::metal::MetalTexture> t = texture.second->GetHardwareTexture(); + if (t != nullptr && bindingInfo.m_textureBindingIndex >= 0) + { + [encoder setFragmentTexture:t->GetTexture() atIndex:bindingInfo.m_textureBindingIndex]; + if (bindingInfo.m_samplerBindingIndex >= 0) + { + dp::HWTexture::Params const & params = t->GetParams(); + id<MTLSamplerState> samplerState = metalContext->GetSamplerState(params.m_filter, params.m_wrapSMode, + params.m_wrapTMode); + [encoder setFragmentSamplerState:samplerState atIndex:bindingInfo.m_samplerBindingIndex]; + } + } + } } } // namespace dp diff --git a/drape/render_state.cpp b/drape/render_state.cpp index a9b409080c..9765486922 100644 --- a/drape/render_state.cpp +++ b/drape/render_state.cpp @@ -13,6 +13,7 @@ std::string const kMaskTextureName = "u_maskTex"; } // namespace #if defined(OMIM_OS_IPHONE) +// Definitions of these methods are in a .mm-file. extern void ApplyDepthStencilStateForMetal(ref_ptr<GraphicsContext> context); extern void ApplyPipelineStateForMetal(ref_ptr<GraphicsContext> context, ref_ptr<GpuProgram> program, bool blendingEnabled); diff --git a/drape/texture_manager.cpp b/drape/texture_manager.cpp index e8f1f68934..9e77acbd83 100644 --- a/drape/texture_manager.cpp +++ b/drape/texture_manager.cpp @@ -522,7 +522,7 @@ void TextureManager::Init(ref_ptr<dp::GraphicsContext> context, Params const & p }); m_stipplePenTexture = make_unique_dp<StipplePenTexture>(StipplePenTextureSize(patterns.size(), m_maxTextureSize), make_ref(m_textureAllocator)); - LOG(LDEBUG, ("Patterns texture size = ", m_stipplePenTexture->GetWidth(), m_stipplePenTexture->GetHeight())); + LOG(LDEBUG, ("Patterns texture size =", m_stipplePenTexture->GetWidth(), m_stipplePenTexture->GetHeight())); ref_ptr<StipplePenTexture> stipplePenTextureTex = make_ref(m_stipplePenTexture); for (auto it = patterns.begin(); it != patterns.end(); ++it) @@ -536,7 +536,7 @@ void TextureManager::Init(ref_ptr<dp::GraphicsContext> context, Params const & p }); m_colorTexture = make_unique_dp<ColorTexture>(ColorTextureSize(colors.size(), m_maxTextureSize), make_ref(m_textureAllocator)); - LOG(LDEBUG, ("Colors texture size = ", m_colorTexture->GetWidth(), m_colorTexture->GetHeight())); + LOG(LDEBUG, ("Colors texture size =", m_colorTexture->GetWidth(), m_colorTexture->GetHeight())); ref_ptr<ColorTexture> colorTex = make_ref(m_colorTexture); for (auto it = colors.begin(); it != colors.end(); ++it) |