25 if (!_dirty && _boundTextures[slot] == texture) {
30 _boundTextures[slot] = texture;
34 encoder->setFragmentTexture(hw->raw(), slot);
39 encoder->setFragmentTexture(
nullptr, slot);
46 if (!_dirty && _boundTextures[slot] ==
nullptr) {
50 _boundTextures[slot] =
nullptr;
51 encoder->setFragmentTexture(
nullptr, slot);
60 if (sampler && _boundSampler != sampler) {
61 encoder->setFragmentSamplerState(sampler, 0);
62 _boundSampler = sampler;
71 const std::vector<TextureSlot>& textureSlots)
74 constexpr int materialSlots[] = {0, 1, 3, 4, 5, 17};
75 for (
const int s : materialSlots) {
77 for (
const auto& [slot, tex] : textureSlots) {
78 if (slot == s) { used =
true;
break; }
86 for (
const auto& [slot, texture] : textureSlots) {
93 for (
int i = 0; i < 8; ++i) {
116 const std::array<Texture*, 8>& quadBindings)
118 for (
int i = 0; i < 8; ++i) {
147 _boundTextures.fill(
nullptr);
149 _boundSampler =
nullptr;
void bindSamplerCached(MTL::RenderCommandEncoder *encoder, MTL::SamplerState *sampler)
Bind a sampler at slot 0, skipping if already bound.
void bindSceneTextures(MTL::RenderCommandEncoder *encoder, Texture *envAtlas, Texture *shadow, Texture *sceneDepth, Texture *skyboxCubeMap, Texture *reflection=nullptr, Texture *reflectionDepth=nullptr, Texture *ssao=nullptr)
Bind scene-global textures (envAtlas, shadow, sceneDepth, skybox cubemap, reflection,...
void resetPassState()
Reset all cached state. Must be called at the start of each render pass.
void clearCached(MTL::RenderCommandEncoder *encoder, int slot)
Clear (unbind) a texture slot, skipping if already nullptr.
void bindCached(MTL::RenderCommandEncoder *encoder, int slot, Texture *texture)
Bind a texture at the given fragment slot, skipping if already bound.
void clearAllMaterialSlots(MTL::RenderCommandEncoder *encoder)
Clear all 8 texture slots (used when no material is bound).
void bindOmniShadowTextures(MTL::RenderCommandEncoder *encoder, Texture *cube0, Texture *cube1)
Bind omni shadow cubemap depth textures at slots 15 and 16 (point lights, cube).
void bindLocalShadowTextures(MTL::RenderCommandEncoder *encoder, Texture *shadow0, Texture *shadow1)
Bind local shadow depth textures at slots 11 and 12 (spot lights, 2D).
void bindMaterialTextures(MTL::RenderCommandEncoder *encoder, const std::vector< TextureSlot > &textureSlots)
void bindQuadTextures(MTL::RenderCommandEncoder *encoder, const std::array< Texture *, 8 > &quadBindings)
Bind quad render textures for all 8 slots.
static constexpr int kMaxTextureSlots
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
gpu::HardwareTexture * impl() const