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 "Common/GPU/OpenGL/GLFeatures.h" 23 #include "Common/GPU/OpenGL/GLCommon.h" 24 #include "Common/GPU/OpenGL/GLRenderManager.h" 25 #include "GPU/GPUInterface.h" 26 #include "GPU/GPUState.h" 27 #include "GPU/GLES/TextureScalerGLES.h" 28 #include "GPU/Common/TextureCacheCommon.h" 29 30 struct VirtualFramebuffer; 31 class FramebufferManagerGLES; 32 class DepalShaderCacheGLES; 33 class ShaderManagerGLES; 34 class DrawEngineGLES; 35 class GLRTexture; 36 37 class TextureCacheGLES : public TextureCacheCommon { 38 public: 39 TextureCacheGLES(Draw::DrawContext *draw); 40 ~TextureCacheGLES(); 41 42 void Clear(bool delete_them) override; 43 void StartFrame(); 44 45 void SetFramebufferManager(FramebufferManagerGLES *fbManager); SetDepalShaderCache(DepalShaderCacheGLES * dpCache)46 void SetDepalShaderCache(DepalShaderCacheGLES *dpCache) { 47 depalShaderCache_ = dpCache; 48 } SetShaderManager(ShaderManagerGLES * sm)49 void SetShaderManager(ShaderManagerGLES *sm) { 50 shaderManager_ = sm; 51 } SetDrawEngine(DrawEngineGLES * td)52 void SetDrawEngine(DrawEngineGLES *td) { 53 drawEngine_ = td; 54 } 55 ForgetLastTexture()56 void ForgetLastTexture() override { 57 lastBoundTexture = nullptr; 58 } InvalidateLastTexture()59 void InvalidateLastTexture() override { 60 lastBoundTexture = nullptr; 61 } 62 63 bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) override; 64 65 void DeviceLost(); 66 void DeviceRestore(Draw::DrawContext *draw); 67 68 protected: 69 void BindTexture(TexCacheEntry *entry) override; 70 void Unbind() override; 71 void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override; 72 73 private: 74 void ApplySamplingParams(const SamplerCacheKey &key); 75 void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, int scaleFactor, Draw::DataFormat dstFmt); 76 Draw::DataFormat GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const; 77 78 static TexCacheEntry::TexStatus CheckAlpha(const uint8_t *pixelData, Draw::DataFormat dstFmt, int stride, int w, int h); 79 void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override; 80 void ApplyTextureFramebuffer(VirtualFramebuffer *framebuffer, GETextureFormat texFormat, FramebufferNotificationChannel channel) override; 81 82 void BuildTexture(TexCacheEntry *const entry) override; 83 84 GLRenderManager *render_; 85 86 TextureScalerGLES scaler; 87 88 GLRTexture *lastBoundTexture = nullptr; 89 90 FramebufferManagerGLES *framebufferManagerGL_; 91 DepalShaderCacheGLES *depalShaderCache_; 92 ShaderManagerGLES *shaderManager_; 93 DrawEngineGLES *drawEngine_; 94 95 GLRInputLayout *shadeInputLayout_ = nullptr; 96 97 enum { INVALID_TEX = -1 }; 98 }; 99 100 Draw::DataFormat getClutDestFormat(GEPaletteFormat format); 101