Make multi-meta-textures support works on Metal.

This commit is contained in:
halx99 2020-02-14 21:40:33 +08:00
parent 55f96054b7
commit 67c153f589
3 changed files with 22 additions and 21 deletions

View File

@ -178,12 +178,12 @@ namespace
return mtlDescritpor;
}
id<MTLTexture> getMTLTexture(TextureBackend* texture)
id<MTLTexture> getMTLTexture(TextureBackend* texture, int index = 0)
{
switch (texture->getTextureType())
{
case TextureType::TEXTURE_2D:
return static_cast<TextureMTL*>(texture)->getMTLTexture();
return static_cast<TextureMTL*>(texture)->getMTLTexture(index);
case TextureType::TEXTURE_CUBE:
return static_cast<TextureCubeMTL*>(texture)->getMTLTexture();
default:
@ -422,27 +422,29 @@ void CommandBufferMTL::doSetTextures(bool isVertex) const
for(const auto& iter : bindTextureInfos)
{
//FIXME: should support texture array.
int i = 0;
auto location = iter.first;
const auto& textures = iter.second.textures;
const auto& slot = iter.second.slot;
if (isVertex)
int i = 0;
for (const auto& texture: textures)
{
[_mtlRenderEncoder setVertexTexture:getMTLTexture(textures[i])
atIndex:location];
[_mtlRenderEncoder setVertexSamplerState:getMTLSamplerState(textures[i])
atIndex:location];
int metaIdx = slot[i++];
if (isVertex)
{
[_mtlRenderEncoder setVertexTexture:getMTLTexture(texture, metaIdx)
atIndex:location];
[_mtlRenderEncoder setVertexSamplerState:getMTLSamplerState(texture)
atIndex:location];
}
else
{
[_mtlRenderEncoder setFragmentTexture:getMTLTexture(texture, metaIdx)
atIndex:location];
[_mtlRenderEncoder setFragmentSamplerState:getMTLSamplerState(texture)
atIndex:location];
}
}
else
{
[_mtlRenderEncoder setFragmentTexture:getMTLTexture(textures[i])
atIndex:location];
[_mtlRenderEncoder setFragmentSamplerState:getMTLSamplerState(textures[i])
atIndex:location];
}
++i;
}
}

View File

@ -124,7 +124,7 @@ public:
* Get MTLTexture object.
* @return A MTLTexture object.
*/
inline id<MTLTexture> getMTLTexture() const { return _mtlTextures[0]; }
inline id<MTLTexture> getMTLTexture(int index = 0) const { return _mtlTextures[index]; }
/**
* Get MTLSamplerState object

View File

@ -487,8 +487,7 @@ void CommandBufferGL::setUniforms(ProgramGL* program) const
int i = 0;
for (const auto& texture: textures)
{
applyTexture(texture, slot[i]);
++i;
applyTexture(texture, slot[i++]);
}
auto arrayCount = slot.size();