mirror of https://github.com/axmolengine/axmol.git
Make multi-meta-textures support works on Metal.
This commit is contained in:
parent
55f96054b7
commit
67c153f589
|
@ -178,12 +178,12 @@ namespace
|
||||||
return mtlDescritpor;
|
return mtlDescritpor;
|
||||||
}
|
}
|
||||||
|
|
||||||
id<MTLTexture> getMTLTexture(TextureBackend* texture)
|
id<MTLTexture> getMTLTexture(TextureBackend* texture, int index = 0)
|
||||||
{
|
{
|
||||||
switch (texture->getTextureType())
|
switch (texture->getTextureType())
|
||||||
{
|
{
|
||||||
case TextureType::TEXTURE_2D:
|
case TextureType::TEXTURE_2D:
|
||||||
return static_cast<TextureMTL*>(texture)->getMTLTexture();
|
return static_cast<TextureMTL*>(texture)->getMTLTexture(index);
|
||||||
case TextureType::TEXTURE_CUBE:
|
case TextureType::TEXTURE_CUBE:
|
||||||
return static_cast<TextureCubeMTL*>(texture)->getMTLTexture();
|
return static_cast<TextureCubeMTL*>(texture)->getMTLTexture();
|
||||||
default:
|
default:
|
||||||
|
@ -422,27 +422,29 @@ void CommandBufferMTL::doSetTextures(bool isVertex) const
|
||||||
|
|
||||||
for(const auto& iter : bindTextureInfos)
|
for(const auto& iter : bindTextureInfos)
|
||||||
{
|
{
|
||||||
//FIXME: should support texture array.
|
|
||||||
int i = 0;
|
|
||||||
auto location = iter.first;
|
auto location = iter.first;
|
||||||
const auto& textures = iter.second.textures;
|
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])
|
int metaIdx = slot[i++];
|
||||||
atIndex:location];
|
if (isVertex)
|
||||||
[_mtlRenderEncoder setVertexSamplerState:getMTLSamplerState(textures[i])
|
{
|
||||||
atIndex:location];
|
[_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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ public:
|
||||||
* Get MTLTexture object.
|
* Get MTLTexture object.
|
||||||
* @return A 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
|
* Get MTLSamplerState object
|
||||||
|
|
|
@ -487,8 +487,7 @@ void CommandBufferGL::setUniforms(ProgramGL* program) const
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const auto& texture: textures)
|
for (const auto& texture: textures)
|
||||||
{
|
{
|
||||||
applyTexture(texture, slot[i]);
|
applyTexture(texture, slot[i++]);
|
||||||
++i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto arrayCount = slot.size();
|
auto arrayCount = slot.size();
|
||||||
|
|
Loading…
Reference in New Issue