Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/drape
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2018-09-12 10:00:31 +0300
committerAleksey Belousov <beloal@users.noreply.github.com>2018-09-25 12:33:08 +0300
commitd7b3116a3867729657f75bc6edaf5a8a1c12b5fe (patch)
tree4e66269962c3e598df93a5164b0f3e34c5a499f3 /drape
parent9ae8a98d15f76a7ea1504a89ccc6f8a303c6f414 (diff)
[drape][metal] Added vertex attributes usage.
Diffstat (limited to 'drape')
-rw-r--r--drape/metal/metal_base_context.mm1
-rw-r--r--drape/metal/metal_cleaner.mm2
-rw-r--r--drape/metal/metal_gpu_program.hpp36
-rw-r--r--drape/metal/metal_states.mm1
-rw-r--r--drape/metal/render_state_metal.mm33
5 files changed, 58 insertions, 15 deletions
diff --git a/drape/metal/metal_base_context.mm b/drape/metal/metal_base_context.mm
index 0f19cb706f..e0362647df 100644
--- a/drape/metal/metal_base_context.mm
+++ b/drape/metal/metal_base_context.mm
@@ -160,6 +160,7 @@ void MetalBaseContext::ApplyFramebuffer(std::string const & framebufferLabel)
CHECK(m_currentCommandEncoder == nil, ("Current command encoder was not finished."));
m_currentCommandEncoder = [m_frameCommandBuffer renderCommandEncoderWithDescriptor:m_renderPassDescriptor];
+ m_currentCommandEncoder.label = @(framebufferLabel.c_str());
[m_currentCommandEncoder pushDebugGroup:@(framebufferLabel.c_str())];
// Default rendering options.
diff --git a/drape/metal/metal_cleaner.mm b/drape/metal/metal_cleaner.mm
index e99f57913e..e0526ab174 100644
--- a/drape/metal/metal_cleaner.mm
+++ b/drape/metal/metal_cleaner.mm
@@ -2,6 +2,8 @@
#include "drape/metal/metal_base_context.hpp"
#include "drape/metal/metal_gpu_program.hpp"
+#include <vector>
+
namespace dp
{
namespace metal
diff --git a/drape/metal/metal_gpu_program.hpp b/drape/metal/metal_gpu_program.hpp
index 5329d316ba..f2f314b6c4 100644
--- a/drape/metal/metal_gpu_program.hpp
+++ b/drape/metal/metal_gpu_program.hpp
@@ -26,13 +26,17 @@ public:
MetalGpuProgram(std::string const & programName,
id<MTLFunction> vertexShader, id<MTLFunction> fragmentShader,
int8_t vsUniformsBindingIndex, int8_t fsUniformsBindingIndex,
- TexturesBindingInfo && textureBindingInfo)
+ TexturesBindingInfo && vertexTextureBindingInfo,
+ TexturesBindingInfo && fragmentTextureBindingInfo,
+ MTLVertexDescriptor * vertexDescriptor)
: GpuProgram(programName)
, m_vertexShader(vertexShader)
, m_fragmentShader(fragmentShader)
, m_vsUniformsBindingIndex(vsUniformsBindingIndex)
, m_fsUniformsBindingIndex(fsUniformsBindingIndex)
- , m_textureBindingInfo(std::move(textureBindingInfo))
+ , m_vertexTextureBindingInfo(std::move(vertexTextureBindingInfo))
+ , m_fragmentTextureBindingInfo(std::move(fragmentTextureBindingInfo))
+ , m_vertexDescriptor(vertexDescriptor)
{}
void Bind() override {}
@@ -44,22 +48,36 @@ public:
int8_t GetVertexShaderUniformsBindingIndex() const { return m_vsUniformsBindingIndex; }
int8_t GetFragmentShaderUniformsBindingIndex() const { return m_fsUniformsBindingIndex; }
- // Now textures can be bound only in fragment shaders.
- TextureBindingInfo const & GetTextureBindingInfo(std::string const & textureName) const
+ TextureBindingInfo const & GetVertexTextureBindingInfo(std::string const & textureName) const
+ {
+ return GetTextureBindingInfo(m_vertexTextureBindingInfo, textureName);
+ }
+
+ TextureBindingInfo const & GetFragmentTextureBindingInfo(std::string const & textureName) const
+ {
+ return GetTextureBindingInfo(m_fragmentTextureBindingInfo, textureName);
+ }
+
+ MTLVertexDescriptor * GetVertexDescriptor() const { return m_vertexDescriptor; }
+
+private:
+ TextureBindingInfo const & GetTextureBindingInfo(TexturesBindingInfo const & bindingInfo,
+ std::string const & textureName) const
{
static TextureBindingInfo kEmptyBinding;
- auto const it = m_textureBindingInfo.find(textureName);
- if (it == m_textureBindingInfo.cend())
+ auto const it = bindingInfo.find(textureName);
+ if (it == bindingInfo.cend())
return kEmptyBinding;
return it->second;
}
-
-private:
+
id<MTLFunction> m_vertexShader;
id<MTLFunction> m_fragmentShader;
int8_t const m_vsUniformsBindingIndex;
int8_t const m_fsUniformsBindingIndex;
- TexturesBindingInfo const m_textureBindingInfo;
+ TexturesBindingInfo const m_vertexTextureBindingInfo;
+ TexturesBindingInfo const m_fragmentTextureBindingInfo;
+ MTLVertexDescriptor * m_vertexDescriptor;
};
} // namespace metal
} // namespace dp
diff --git a/drape/metal/metal_states.mm b/drape/metal/metal_states.mm
index 34145c89f7..f3634da99e 100644
--- a/drape/metal/metal_states.mm
+++ b/drape/metal/metal_states.mm
@@ -290,6 +290,7 @@ MTLRenderPipelineDescriptor * MetalStates::PipelineKey::BuildDescriptor() const
ref_ptr<MetalGpuProgram> metalProgram = m_program;
desc.vertexFunction = metalProgram->GetVertexShader();
desc.fragmentFunction = metalProgram->GetFragmentShader();
+ desc.vertexDescriptor = metalProgram->GetVertexDescriptor();
MTLRenderPipelineColorAttachmentDescriptor * colorAttachment = desc.colorAttachments[0];
colorAttachment.pixelFormat = m_colorFormat;
desc.depthAttachmentPixelFormat = m_depthStencilFormat;
diff --git a/drape/metal/render_state_metal.mm b/drape/metal/render_state_metal.mm
index c3a2a06ea6..8ab6517f39 100644
--- a/drape/metal/render_state_metal.mm
+++ b/drape/metal/render_state_metal.mm
@@ -35,17 +35,38 @@ void ApplyTexturesForMetal(ref_ptr<GraphicsContext> context, ref_ptr<GpuProgram>
id<MTLRenderCommandEncoder> encoder = metalContext->GetCommandEncoder();
for (auto const & texture : state.GetTextures())
{
- auto const & bindingInfo = p->GetTextureBindingInfo(texture.first);
+ if (texture.second == nullptr)
+ continue;
+
ref_ptr<dp::metal::MetalTexture> t = texture.second->GetHardwareTexture();
- if (t != nullptr && bindingInfo.m_textureBindingIndex >= 0)
+ if (t == nullptr)
+ continue;
+
+ dp::HWTexture::Params const & params = t->GetParams();
+
+ // Set texture to the vertex shader.
+ auto const & vsBindingInfo = p->GetVertexTextureBindingInfo(texture.first);
+ if (vsBindingInfo.m_textureBindingIndex >= 0)
{
- [encoder setFragmentTexture:t->GetTexture() atIndex:bindingInfo.m_textureBindingIndex];
- if (bindingInfo.m_samplerBindingIndex >= 0)
+ [encoder setVertexTexture:t->GetTexture() atIndex:vsBindingInfo.m_textureBindingIndex];
+ if (vsBindingInfo.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];
+ [encoder setVertexSamplerState:samplerState atIndex:vsBindingInfo.m_samplerBindingIndex];
+ }
+ }
+
+ // Set texture to the fragment shader.
+ auto const & fsBindingInfo = p->GetFragmentTextureBindingInfo(texture.first);
+ if (fsBindingInfo.m_textureBindingIndex >= 0)
+ {
+ [encoder setFragmentTexture:t->GetTexture() atIndex:fsBindingInfo.m_textureBindingIndex];
+ if (fsBindingInfo.m_samplerBindingIndex >= 0)
+ {
+ id<MTLSamplerState> samplerState = metalContext->GetSamplerState(params.m_filter, params.m_wrapSMode,
+ params.m_wrapTMode);
+ [encoder setFragmentSamplerState:samplerState atIndex:fsBindingInfo.m_samplerBindingIndex];
}
}
}