/*
Copyright 2021 flyinghead
This file is part of Flycast.
Flycast is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
Flycast is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Flycast. If not, see .
*/
#pragma once
#include
#include
#include
#include
#include "types.h"
#include "windows/comptr.h"
#include "../dx11_shaders.h"
class DX11OITShaders : CachedDX11Shaders
{
public:
enum Pass { Depth, Color, OIT };
void init(const ComPtr& device, pD3DCompile D3DCompile);
const ComPtr& getShader(bool pp_Texture, bool pp_UseAlpha, bool pp_IgnoreTexA, u32 pp_ShadInstr,
bool pp_Offset, u32 pp_FogCtrl, bool pp_BumpMap, bool fog_clamping,
int palette, bool gouraud, bool alphaTest, bool clipInside, bool twoVolumes, Pass pass);
const ComPtr& getVertexShader(bool gouraud, bool naomi2, bool positionOnly, bool lightOn, bool twoVolumes = true);
const ComPtr& getModVolShader();
const ComPtr& getMVVertexShader(bool naomi2);
const ComPtr& getFinalShader(bool dithering);
const ComPtr& getTrModVolShader(int type);
const ComPtr& getFinalVertexShader();
void term()
{
saveCache(CacheFile);
shaders.clear();
vertexShaders.clear();
for (auto& shader : modVolVertexShaders)
shader.reset();
for (auto& shader : modVolShaders)
shader.reset();
for (auto& shader : trModVolShaders)
shader.reset();
for (auto& shader : finalShaders)
shader.reset();
clearShader.reset();
finalVertexShader.reset();
device.reset();
}
ComPtr getVertexShaderBlob();
ComPtr getMVVertexShaderBlob();
ComPtr getFinalVertexShaderBlob();
private:
ComPtr compileShader(const char *source, const char* function, const char* profile, const D3D_SHADER_MACRO *pDefines);
ComPtr compileVS(const char *source, const char* function, const D3D_SHADER_MACRO *pDefines);
ComPtr compilePS(const char *source, const char* function, const D3D_SHADER_MACRO *pDefines);
ComPtr device;
std::unordered_map> shaders;
std::unordered_map> vertexShaders;
ComPtr modVolShaders[2];
ComPtr modVolVertexShaders[4];
ComPtr trModVolShaders[16];
ComPtr finalShaders[2];
ComPtr clearShader;
ComPtr finalVertexShader;
pD3DCompile D3DCompile = nullptr;
int maxLayers = 0;
constexpr static const char *CacheFile = "dx11oit_shader_cache.bin";
};