mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-23 05:45:51 +12:00
use depth stencil render target
This commit is contained in:
parent
9241306d4d
commit
d977f7ef85
4 changed files with 224 additions and 94 deletions
55
include/renderer_mtl/mtl_depth_stencil_cache.hpp
Normal file
55
include/renderer_mtl/mtl_depth_stencil_cache.hpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#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
|
Loading…
Add table
Add a link
Reference in a new issue