mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-17 03:09:47 +12:00
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "pica_to_mtl.hpp"
|
|
|
|
using namespace PICA;
|
|
|
|
namespace Metal {
|
|
|
|
struct DepthStencilHash {
|
|
bool depthWrite;
|
|
u8 depthFunc;
|
|
};
|
|
|
|
class DepthStencilCache {
|
|
public:
|
|
DepthStencilCache() = default;
|
|
|
|
~DepthStencilCache() {
|
|
clear();
|
|
}
|
|
|
|
void set(MTL::Device* dev) {
|
|
device = dev;
|
|
}
|
|
|
|
MTL::DepthStencilState* get(DepthStencilHash hash) {
|
|
u8 intHash = hash.depthWrite | (hash.depthFunc << 1);
|
|
auto& depthStencilState = depthStencilCache[intHash];
|
|
if (!depthStencilState) {
|
|
MTL::DepthStencilDescriptor* desc = MTL::DepthStencilDescriptor::alloc()->init();
|
|
desc->setDepthWriteEnabled(hash.depthWrite);
|
|
desc->setDepthCompareFunction(toMTLCompareFunc(hash.depthFunc));
|
|
|
|
depthStencilState = device->newDepthStencilState(desc);
|
|
|
|
desc->release();
|
|
}
|
|
|
|
return depthStencilState;
|
|
}
|
|
|
|
void clear() {
|
|
for (auto& pair : depthStencilCache) {
|
|
pair.second->release();
|
|
}
|
|
depthStencilCache.clear();
|
|
}
|
|
|
|
private:
|
|
std::unordered_map<u8, MTL::DepthStencilState*> depthStencilCache;
|
|
|
|
MTL::Device* device;
|
|
};
|
|
|
|
} // namespace Metal
|