mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-07-16 04:07:08 +12:00
use sampler states
This commit is contained in:
parent
9527c2acdb
commit
b6c72e72e4
6 changed files with 50 additions and 14 deletions
|
@ -1,4 +1,5 @@
|
|||
#include "renderer_mtl/mtl_texture.hpp"
|
||||
#include "renderer_mtl/pica_to_mtl.hpp"
|
||||
#include "colour.hpp"
|
||||
#include <array>
|
||||
|
||||
|
@ -23,7 +24,22 @@ void Texture::allocate() {
|
|||
void Texture::setNewConfig(u32 cfg) {
|
||||
config = cfg;
|
||||
|
||||
// TODO: implement this
|
||||
if (sampler) {
|
||||
sampler->release();
|
||||
}
|
||||
|
||||
const auto magFilter = (cfg & 0x2) != 0 ? MTL::SamplerMinMagFilterLinear : MTL::SamplerMinMagFilterNearest;
|
||||
const auto minFilter = (cfg & 0x4) != 0 ? MTL::SamplerMinMagFilterLinear : MTL::SamplerMinMagFilterNearest;
|
||||
const auto wrapT = PICA::toMTLSamplerAddressMode(getBits<8, 3>(cfg));
|
||||
const auto wrapS = PICA::toMTLSamplerAddressMode(getBits<12, 3>(cfg));
|
||||
|
||||
MTL::SamplerDescriptor* samplerDescriptor = MTL::SamplerDescriptor::alloc()->init();
|
||||
samplerDescriptor->setMinFilter(minFilter);
|
||||
samplerDescriptor->setMagFilter(magFilter);
|
||||
samplerDescriptor->setSAddressMode(wrapS);
|
||||
samplerDescriptor->setTAddressMode(wrapT);
|
||||
|
||||
sampler = device->newSamplerState(samplerDescriptor);
|
||||
}
|
||||
|
||||
void Texture::free() {
|
||||
|
@ -32,6 +48,9 @@ void Texture::free() {
|
|||
if (texture) {
|
||||
texture->release();
|
||||
}
|
||||
if (sampler) {
|
||||
sampler->release();
|
||||
}
|
||||
}
|
||||
|
||||
u64 Texture::sizeInBytes() {
|
||||
|
|
|
@ -453,17 +453,17 @@ Metal::DepthStencilRenderTarget& RendererMTL::getDepthRenderTarget() {
|
|||
}
|
||||
}
|
||||
|
||||
MTL::Texture* RendererMTL::getTexture(Metal::Texture& tex) {
|
||||
Metal::Texture& RendererMTL::getTexture(Metal::Texture& tex) {
|
||||
auto buffer = textureCache.find(tex);
|
||||
|
||||
if (buffer.has_value()) {
|
||||
return buffer.value().get().texture;
|
||||
return buffer.value().get();
|
||||
} else {
|
||||
const auto textureData = std::span{gpu.getPointerPhys<u8>(tex.location), tex.sizeInBytes()}; // Get pointer to the texture data in 3DS memory
|
||||
Metal::Texture& newTex = textureCache.add(tex);
|
||||
newTex.decodeTexture(textureData);
|
||||
|
||||
return newTex.texture;
|
||||
return newTex;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -518,8 +518,9 @@ void RendererMTL::bindTexturesToSlots(MTL::RenderCommandEncoder* encoder) {
|
|||
|
||||
if (addr != 0) [[likely]] {
|
||||
Metal::Texture targetTex(device, addr, static_cast<PICA::TextureFmt>(format), width, height, config);
|
||||
MTL::Texture* tex = getTexture(targetTex);
|
||||
encoder->setFragmentTexture(tex, i);
|
||||
auto tex = getTexture(targetTex);
|
||||
encoder->setFragmentTexture(tex.texture, i);
|
||||
encoder->setFragmentSamplerState(tex.sampler ? tex.sampler : basicSampler, i);
|
||||
} else {
|
||||
// TODO: bind a dummy texture?
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue