diff --git a/cocos/renderer/backend/metal/CommandBufferMTL.mm b/cocos/renderer/backend/metal/CommandBufferMTL.mm index 460df5b1cd..2ac3dadde6 100644 --- a/cocos/renderer/backend/metal/CommandBufferMTL.mm +++ b/cocos/renderer/backend/metal/CommandBufferMTL.mm @@ -423,8 +423,8 @@ void CommandBufferMTL::doSetTextures(bool isVertex) const for(const auto& iter : bindTextureInfos) { /* About mutli textures support - * a. sampler2DArray, not implemented in Metal Renderer - * b. texture slot, one BackendTexture, multi GPU texture handlers, used by etc1 + * a. TODO: sampler2DArray, not implemented in Metal Renderer currently + * b. texture slot, one BackendTexture, multi GPU texture handlers, used by etc1, restrict: textures must have same size * c. Bind multi BackendTexture to 1 Shader Program, see the ShaderTest * d. iter.second.slots not used for Metal Renderer */ @@ -432,24 +432,22 @@ void CommandBufferMTL::doSetTextures(bool isVertex) const auto& textures = iter.second.textures; auto& indexs = iter.second.indexs; - int i = 0; - for (const auto& texture : textures) + auto texture = textures[0]; + auto index = indexs[0]; + + if (isVertex) { - if (isVertex) - { - [_mtlRenderEncoder setVertexTexture:getMTLTexture(texture, indexs[i]) - atIndex:location]; - [_mtlRenderEncoder setVertexSamplerState:getMTLSamplerState(texture) - atIndex:location]; - } - else - { - [_mtlRenderEncoder setFragmentTexture:getMTLTexture(texture, indexs[i]) - atIndex:location]; - [_mtlRenderEncoder setFragmentSamplerState:getMTLSamplerState(texture) - atIndex:location]; - } - ++i; + [_mtlRenderEncoder setVertexTexture:getMTLTexture(texture, index) + atIndex:location]; + [_mtlRenderEncoder setVertexSamplerState:getMTLSamplerState(texture) + atIndex:location]; + } + else + { + [_mtlRenderEncoder setFragmentTexture:getMTLTexture(texture, index) + atIndex:location]; + [_mtlRenderEncoder setFragmentSamplerState:getMTLSamplerState(texture) + atIndex:location]; } } } diff --git a/cocos/renderer/backend/opengl/CommandBufferGL.cpp b/cocos/renderer/backend/opengl/CommandBufferGL.cpp index 907ba069a3..e5cf0ec226 100644 --- a/cocos/renderer/backend/opengl/CommandBufferGL.cpp +++ b/cocos/renderer/backend/opengl/CommandBufferGL.cpp @@ -480,7 +480,7 @@ void CommandBufferGL::setUniforms(ProgramGL* program) const { /* About mutli textures support * a. sampler2DArray, sampler2D[2], bind BackendTexture one by one, not use GL_TEXTURE_2D_ARRAY, not used at all engine interanl - * b. texture slot, one BackendTexture, multi GPU texture handlers, used by etc1 + * b. texture slot, one BackendTexture, multi GPU texture handlers, used by etc1, restrict: textures must have same size * c. Bind multi BackendTexture to 1 Shader Program, see the ShaderTest */ auto& textures = iter.second.textures; @@ -498,7 +498,7 @@ void CommandBufferGL::setUniforms(ProgramGL* program) const } auto arrayCount = slots.size(); - if (arrayCount == 1) // If not use sampler2DArray, always 1 + if (arrayCount == 1) // Most of the timeļ¼Œ not use sampler2DArray, should be 1 glUniform1i(location, slots[0]); else glUniform1iv(location, (uint32_t)arrayCount, (GLint*)slots.data()); diff --git a/cocos/renderer/backend/opengl/TextureGL.h b/cocos/renderer/backend/opengl/TextureGL.h index 6bcf28aaa5..3b521537e4 100644 --- a/cocos/renderer/backend/opengl/TextureGL.h +++ b/cocos/renderer/backend/opengl/TextureGL.h @@ -63,7 +63,7 @@ struct TextureInfoGL } /// - /// update shader texture + /// Apply shader texture /// /// the slot in shader /// the index in meta textrues