2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program 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 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
2012-11-26 03:25:14 +00:00
|
|
|
|
2014-10-19 19:11:09 +00:00
|
|
|
#include <map>
|
|
|
|
|
2014-05-27 20:22:56 +00:00
|
|
|
#include "gfx_es2/gpu_features.h"
|
|
|
|
|
|
|
|
#include "Globals.h"
|
2013-05-06 05:52:01 +00:00
|
|
|
#include "GPU/GPUInterface.h"
|
2013-02-17 00:06:06 +00:00
|
|
|
#include "GPU/GPUState.h"
|
2015-09-06 11:05:18 +00:00
|
|
|
#include "GPU/GLES/FBO.h"
|
2017-01-21 21:16:30 +00:00
|
|
|
#include "GPU/GLES/TextureScalerGLES.h"
|
2014-09-13 11:15:18 +00:00
|
|
|
#include "GPU/Common/TextureCacheCommon.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-02-21 20:37:19 +00:00
|
|
|
struct VirtualFramebuffer;
|
2017-01-21 21:16:30 +00:00
|
|
|
class FramebufferManagerGLES;
|
|
|
|
class DepalShaderCacheGLES;
|
|
|
|
class ShaderManagerGLES;
|
2016-04-10 08:21:48 +00:00
|
|
|
class DrawEngineGLES;
|
2013-02-21 20:37:19 +00:00
|
|
|
|
2014-05-27 20:22:56 +00:00
|
|
|
inline bool UseBGRA8888() {
|
|
|
|
// TODO: Other platforms? May depend on vendor which is faster?
|
|
|
|
#ifdef _WIN32
|
|
|
|
return gl_extensions.EXT_bgra;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-21 21:16:30 +00:00
|
|
|
class TextureCacheGLES : public TextureCacheCommon {
|
2013-01-30 19:40:26 +00:00
|
|
|
public:
|
2017-01-21 21:16:30 +00:00
|
|
|
TextureCacheGLES();
|
|
|
|
~TextureCacheGLES();
|
2013-01-30 19:40:26 +00:00
|
|
|
|
2013-09-28 04:53:42 +00:00
|
|
|
void SetTexture(bool force = false);
|
2014-09-14 07:34:52 +00:00
|
|
|
virtual bool SetOffsetTexture(u32 offset) override;
|
2013-01-30 19:40:26 +00:00
|
|
|
|
|
|
|
void Clear(bool delete_them);
|
|
|
|
void StartFrame();
|
2016-12-26 22:59:42 +00:00
|
|
|
void Invalidate(u32 addr, int size, GPUInvalidationType type) override;
|
|
|
|
void InvalidateAll(GPUInvalidationType type) override;
|
2013-04-30 15:20:28 +00:00
|
|
|
void ClearNextFrame();
|
2013-01-31 23:18:23 +00:00
|
|
|
|
2017-01-21 21:16:30 +00:00
|
|
|
void SetFramebufferManager(FramebufferManagerGLES *fbManager) {
|
2014-01-20 01:28:11 +00:00
|
|
|
framebufferManager_ = fbManager;
|
|
|
|
}
|
2017-01-21 21:16:30 +00:00
|
|
|
void SetDepalShaderCache(DepalShaderCacheGLES *dpCache) {
|
2014-03-29 20:58:38 +00:00
|
|
|
depalShaderCache_ = dpCache;
|
|
|
|
}
|
2017-01-21 21:16:30 +00:00
|
|
|
void SetShaderManager(ShaderManagerGLES *sm) {
|
2014-06-01 01:55:00 +00:00
|
|
|
shaderManager_ = sm;
|
|
|
|
}
|
2016-04-10 08:21:48 +00:00
|
|
|
void SetTransformDrawEngine(DrawEngineGLES *td) {
|
2015-12-14 06:48:21 +00:00
|
|
|
transformDraw_ = td;
|
|
|
|
}
|
2014-01-20 01:28:11 +00:00
|
|
|
|
2013-01-30 19:40:26 +00:00
|
|
|
size_t NumLoadedTextures() const {
|
|
|
|
return cache.size();
|
|
|
|
}
|
|
|
|
|
2014-05-27 09:00:49 +00:00
|
|
|
void ForgetLastTexture() {
|
|
|
|
lastBoundTexture = -1;
|
2017-01-24 08:31:36 +00:00
|
|
|
gstate_c.textureParamsChanged = true;
|
2014-05-27 09:00:49 +00:00
|
|
|
}
|
|
|
|
|
2014-06-07 22:25:35 +00:00
|
|
|
u32 AllocTextureName();
|
|
|
|
|
2013-05-02 08:56:30 +00:00
|
|
|
// Only used by Qt UI?
|
2015-01-17 19:57:07 +00:00
|
|
|
bool DecodeTexture(u8 *output, const GPUgstate &state);
|
2013-02-21 20:37:19 +00:00
|
|
|
|
2014-06-15 20:34:58 +00:00
|
|
|
void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight);
|
|
|
|
|
2015-03-16 02:10:33 +00:00
|
|
|
void ApplyTexture();
|
|
|
|
|
2016-01-05 05:29:03 +00:00
|
|
|
protected:
|
|
|
|
void DownloadFramebufferForClut(u32 clutAddr, u32 bytes) override;
|
|
|
|
|
2014-04-01 12:14:56 +00:00
|
|
|
private:
|
2013-01-30 19:40:26 +00:00
|
|
|
void Decimate(); // Run this once per frame to get rid of old textures.
|
2014-06-08 20:52:05 +00:00
|
|
|
void DeleteTexture(TexCache::iterator it);
|
2013-01-30 19:40:26 +00:00
|
|
|
void UpdateSamplingParams(TexCacheEntry &entry, bool force);
|
2016-04-30 20:44:31 +00:00
|
|
|
void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, bool replaceImages, int scaleFactor, GLenum dstFmt);
|
2013-10-08 13:00:48 +00:00
|
|
|
GLenum GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
|
2016-06-19 14:55:38 +00:00
|
|
|
void *DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufw = 0);
|
2014-09-09 03:55:56 +00:00
|
|
|
TexCacheEntry::Status CheckAlpha(const u32 *pixelData, GLenum dstFmt, int stride, int w, int h);
|
2013-05-11 22:45:17 +00:00
|
|
|
u32 GetCurrentClutHash();
|
2015-07-29 09:38:42 +00:00
|
|
|
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple);
|
2015-11-28 20:41:37 +00:00
|
|
|
bool AttachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer, u32 texaddrOffset = 0) override;
|
2014-06-05 06:50:02 +00:00
|
|
|
void SetTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer);
|
2015-03-16 02:10:33 +00:00
|
|
|
void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer);
|
2013-01-30 19:40:26 +00:00
|
|
|
|
2016-05-01 20:11:35 +00:00
|
|
|
bool CheckFullHash(TexCacheEntry *const entry, bool &doDelete);
|
2016-05-01 20:03:40 +00:00
|
|
|
bool HandleTextureChange(TexCacheEntry *const entry, const char *reason, bool initialMatch, bool doDelete);
|
|
|
|
void BuildTexture(TexCacheEntry *const entry, bool replaceImages);
|
2016-05-01 18:17:55 +00:00
|
|
|
|
2014-06-07 22:25:35 +00:00
|
|
|
std::vector<u32> nameCache_;
|
2016-03-26 18:49:16 +00:00
|
|
|
TexCache secondCache;
|
2014-12-22 00:54:26 +00:00
|
|
|
u32 secondCacheSizeEstimate_;
|
2013-01-30 19:40:26 +00:00
|
|
|
|
2013-04-30 15:20:28 +00:00
|
|
|
bool clearCacheNextFrame_;
|
2013-05-05 07:00:22 +00:00
|
|
|
bool lowMemoryMode_;
|
2015-04-08 18:52:35 +00:00
|
|
|
|
2017-01-21 21:16:30 +00:00
|
|
|
TextureScalerGLES scaler;
|
2013-04-09 08:52:19 +00:00
|
|
|
|
2013-05-11 22:45:17 +00:00
|
|
|
u32 clutHash_;
|
2013-02-12 18:05:30 +00:00
|
|
|
|
2013-02-18 16:34:51 +00:00
|
|
|
u32 lastBoundTexture;
|
2013-02-14 23:30:02 +00:00
|
|
|
float maxAnisotropyLevel;
|
2013-07-31 22:13:58 +00:00
|
|
|
|
|
|
|
int decimationCounter_;
|
2014-06-13 20:07:26 +00:00
|
|
|
int texelsScaledThisFrame_;
|
2014-06-14 22:40:08 +00:00
|
|
|
int timesInvalidatedAllThisFrame_;
|
2014-06-13 20:07:26 +00:00
|
|
|
|
2017-01-21 21:16:30 +00:00
|
|
|
FramebufferManagerGLES *framebufferManager_;
|
|
|
|
DepalShaderCacheGLES *depalShaderCache_;
|
|
|
|
ShaderManagerGLES *shaderManager_;
|
2016-04-10 08:21:48 +00:00
|
|
|
DrawEngineGLES *transformDraw_;
|
2016-05-01 18:17:55 +00:00
|
|
|
|
2016-05-01 20:24:53 +00:00
|
|
|
const char *nextChangeReason_;
|
2016-05-01 18:17:55 +00:00
|
|
|
bool nextNeedsRehash_;
|
2016-05-01 20:24:53 +00:00
|
|
|
bool nextNeedsChange_;
|
2016-05-01 18:17:55 +00:00
|
|
|
bool nextNeedsRebuild_;
|
2013-01-30 19:40:26 +00:00
|
|
|
};
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2014-03-29 20:58:38 +00:00
|
|
|
GLenum getClutDestFormat(GEPaletteFormat format);
|