1 // Copyright (c) 2012- PPSSPP Project.
2 
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, version 2.0 or later versions.
6 
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License 2.0 for more details.
11 
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
14 
15 // Official git repository and contact information can be found at
16 // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17 
18 #pragma once
19 
20 #include <map>
21 
22 #include <d3d9.h>
23 
24 #include "GPU/GPU.h"
25 #include "GPU/GPUInterface.h"
26 #include "GPU/Directx9/TextureScalerDX9.h"
27 #include "GPU/Common/TextureCacheCommon.h"
28 
29 struct VirtualFramebuffer;
30 
31 namespace DX9 {
32 
33 class FramebufferManagerDX9;
34 class DepalShaderCacheDX9;
35 class ShaderManagerDX9;
36 
37 class TextureCacheDX9 : public TextureCacheCommon {
38 public:
39 	TextureCacheDX9(Draw::DrawContext *draw);
40 	~TextureCacheDX9();
41 
42 	void StartFrame();
43 
44 	void SetFramebufferManager(FramebufferManagerDX9 *fbManager);
SetDepalShaderCache(DepalShaderCacheDX9 * dpCache)45 	void SetDepalShaderCache(DepalShaderCacheDX9 *dpCache) {
46 		depalShaderCache_ = dpCache;
47 	}
SetShaderManager(ShaderManagerDX9 * sm)48 	void SetShaderManager(ShaderManagerDX9 *sm) {
49 		shaderManager_ = sm;
50 	}
51 
ForgetLastTexture()52 	void ForgetLastTexture() override {
53 		InvalidateLastTexture();
54 	}
55 	void InvalidateLastTexture() override;
56 
57 	bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override;
58 
59 protected:
60 	void BindTexture(TexCacheEntry *entry) override;
61 	void Unbind() override;
62 	void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
63 
64 private:
65 	void ApplySamplingParams(const SamplerCacheKey &key);
66 
67 	void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int maxLevel, int scaleFactor, u32 dstFmt);
68 	D3DFORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
69 	static TexCacheEntry::TexStatus CheckAlpha(const u32 *pixelData, u32 dstFmt, int stride, int w, int h);
70 	void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
71 
72 	void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override;
73 	void BuildTexture(TexCacheEntry *const entry) override;
74 
DxTex(TexCacheEntry * entry)75 	LPDIRECT3DTEXTURE9 &DxTex(TexCacheEntry *entry) {
76 		return *(LPDIRECT3DTEXTURE9 *)&entry->texturePtr;
77 	}
78 
79 	LPDIRECT3DDEVICE9 device_;
80 	LPDIRECT3DDEVICE9EX deviceEx_;
81 
82 	TextureScalerDX9 scaler;
83 
84 	LPDIRECT3DVERTEXDECLARATION9 pFramebufferVertexDecl;
85 
86 	LPDIRECT3DTEXTURE9 lastBoundTexture;
87 	float maxAnisotropyLevel;
88 
89 	FramebufferManagerDX9 *framebufferManagerDX9_;
90 	DepalShaderCacheDX9 *depalShaderCache_;
91 	ShaderManagerDX9 *shaderManager_;
92 };
93 
94 D3DFORMAT getClutDestFormat(GEPaletteFormat format);
95 
96 };
97