Working on texture compatibility with Shadertoy

This commit is contained in:
Brad Davis 2015-10-02 19:09:43 -07:00
parent 83c9ebf06c
commit c8aea67505
2 changed files with 29 additions and 4 deletions

View file

@ -343,9 +343,22 @@ bool Texture::assignStoredMipFace(uint16 level, const Element& format, Size size
} }
uint16 Texture::autoGenerateMips(uint16 maxMip) { uint16 Texture::autoGenerateMips(uint16 maxMip) {
_autoGenerateMips = true; bool changed = false;
_maxMip = std::min((uint16) (evalNumMips() - 1), maxMip); if (!_autoGenerateMips) {
_stamp++; changed = true;
_autoGenerateMips = true;
}
auto newMaxMip = std::min((uint16)(evalNumMips() - 1), maxMip);
if (newMaxMip != _maxMip) {
changed = true;
_maxMip = newMaxMip;;
}
if (changed) {
_stamp++;
}
return _maxMip; return _maxMip;
} }

View file

@ -223,9 +223,21 @@ void Procedural::prepare(gpu::Batch& batch, const glm::vec3& position, const glm
lambda(batch); lambda(batch);
} }
static gpu::Sampler sampler;
static std::once_flag once;
std::call_once(once, [&] {
gpu::Sampler::Desc desc;
desc._filter = gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR;
});
for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) { for (size_t i = 0; i < MAX_PROCEDURAL_TEXTURE_CHANNELS; ++i) {
if (_channels[i] && _channels[i]->isLoaded()) { if (_channels[i] && _channels[i]->isLoaded()) {
batch.setResourceTexture(i, _channels[i]->getGPUTexture()); auto gpuTexture = _channels[i]->getGPUTexture();
if (gpuTexture) {
gpuTexture->setSampler(sampler);
gpuTexture->autoGenerateMips(-1);
}
batch.setResourceTexture(i, gpuTexture);
} }
} }
} }