2012-11-01 16:19:01 +01: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 23:58:25 +01:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 16:19:01 +01: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/.
|
|
|
|
|
2013-02-10 13:19:01 -08:00
|
|
|
#include <algorithm>
|
2013-12-29 15:55:09 -08:00
|
|
|
#include <cstring>
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2015-09-06 13:45:17 +02:00
|
|
|
#include "ext/xxhash.h"
|
2017-03-03 14:15:27 +01:00
|
|
|
#include "gfx/gl_debug_log.h"
|
2015-12-30 13:29:29 -08:00
|
|
|
#include "i18n/i18n.h"
|
2015-09-06 13:45:17 +02:00
|
|
|
#include "math/math_util.h"
|
2015-05-13 22:28:02 +02:00
|
|
|
#include "profiler/profiler.h"
|
2017-11-19 17:37:56 +01:00
|
|
|
#include "thin3d/GLRenderManager.h"
|
2015-05-13 22:28:02 +02:00
|
|
|
|
2015-04-08 00:16:22 +02:00
|
|
|
#include "Common/ColorConv.h"
|
2015-12-30 13:29:29 -08:00
|
|
|
#include "Core/Config.h"
|
2013-12-29 23:44:35 +01:00
|
|
|
#include "Core/Host.h"
|
2013-02-21 21:37:19 +01:00
|
|
|
#include "Core/MemMap.h"
|
2013-03-24 09:42:49 -07:00
|
|
|
#include "Core/Reporting.h"
|
2013-02-21 21:37:19 +01:00
|
|
|
#include "GPU/ge_constants.h"
|
|
|
|
#include "GPU/GPUState.h"
|
2017-01-21 22:16:30 +01:00
|
|
|
#include "GPU/GLES/TextureCacheGLES.h"
|
|
|
|
#include "GPU/GLES/FramebufferManagerGLES.h"
|
|
|
|
#include "GPU/GLES/FragmentShaderGeneratorGLES.h"
|
|
|
|
#include "GPU/GLES/DepalettizeShaderGLES.h"
|
|
|
|
#include "GPU/GLES/ShaderManagerGLES.h"
|
2016-04-10 10:27:28 +02:00
|
|
|
#include "GPU/GLES/DrawEngineGLES.h"
|
2013-09-15 21:27:13 -07:00
|
|
|
#include "GPU/Common/TextureDecoder.h"
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2013-05-05 19:58:59 -07:00
|
|
|
#ifdef _M_SSE
|
2017-03-12 17:16:38 +01:00
|
|
|
#include <emmintrin.h>
|
2013-05-05 19:58:59 -07:00
|
|
|
#endif
|
|
|
|
|
2017-02-05 19:51:50 +01:00
|
|
|
TextureCacheGLES::TextureCacheGLES(Draw::DrawContext *draw)
|
2017-02-08 15:24:33 +01:00
|
|
|
: TextureCacheCommon(draw) {
|
2014-06-15 00:40:08 +02:00
|
|
|
timesInvalidatedAllThisFrame_ = 0;
|
2017-11-19 17:37:56 +01:00
|
|
|
lastBoundTexture = nullptr;
|
|
|
|
render_ = (GLRenderManager *)draw_->GetNativeObject(Draw::NativeObject::RENDER_MANAGER);
|
2014-04-01 14:14:56 +02:00
|
|
|
|
2014-03-22 21:35:16 -07:00
|
|
|
SetupTextureDecoder();
|
2015-03-15 19:10:33 -07:00
|
|
|
|
|
|
|
nextTexture_ = nullptr;
|
2017-12-14 17:50:40 +01:00
|
|
|
std::vector<GLRInputLayout::Entry> entries;
|
|
|
|
entries.push_back({ 0, 3, GL_FLOAT, GL_FALSE, 20, 0 });
|
|
|
|
entries.push_back({ 1, 2, GL_FLOAT, GL_FALSE, 20, 12 });
|
|
|
|
shadeInputLayout_ = render_->CreateInputLayout(entries);
|
2012-11-28 16:12:29 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
TextureCacheGLES::~TextureCacheGLES() {
|
2017-12-14 17:50:40 +01:00
|
|
|
render_->DeleteInputLayout(shadeInputLayout_);
|
2015-01-24 20:36:01 -08:00
|
|
|
Clear(true);
|
2012-11-28 16:12:29 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:58:46 +01:00
|
|
|
void TextureCacheGLES::SetFramebufferManager(FramebufferManagerGLES *fbManager) {
|
|
|
|
framebufferManagerGL_ = fbManager;
|
|
|
|
framebufferManager_ = fbManager;
|
|
|
|
}
|
|
|
|
|
2017-02-23 17:31:24 +01:00
|
|
|
void TextureCacheGLES::ReleaseTexture(TexCacheEntry *entry, bool delete_them) {
|
2017-12-14 17:50:40 +01:00
|
|
|
DEBUG_LOG(G3D, "Deleting texture %08x", entry->addr);
|
2017-02-23 22:41:13 +01:00
|
|
|
if (delete_them) {
|
2017-11-19 17:37:56 +01:00
|
|
|
if (entry->textureName) {
|
|
|
|
render_->DeleteTexture(entry->textureName);
|
2017-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
2017-11-19 17:37:56 +01:00
|
|
|
entry->textureName = nullptr;
|
2017-02-19 22:31:07 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::Clear(bool delete_them) {
|
2017-02-19 22:31:07 +01:00
|
|
|
TextureCacheCommon::Clear(delete_them);
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2013-01-06 12:11:47 +01:00
|
|
|
GLenum getClutDestFormat(GEPaletteFormat format) {
|
|
|
|
switch (format) {
|
2012-11-08 23:26:30 +01:00
|
|
|
case GE_CMODE_16BIT_ABGR4444:
|
2012-11-09 01:24:19 +01:00
|
|
|
return GL_UNSIGNED_SHORT_4_4_4_4;
|
2012-11-08 23:26:30 +01:00
|
|
|
case GE_CMODE_16BIT_ABGR5551:
|
2012-11-09 01:24:19 +01:00
|
|
|
return GL_UNSIGNED_SHORT_5_5_5_1;
|
2012-11-08 23:26:30 +01:00
|
|
|
case GE_CMODE_16BIT_BGR5650:
|
2012-11-09 01:24:19 +01:00
|
|
|
return GL_UNSIGNED_SHORT_5_6_5;
|
2012-11-08 23:26:30 +01:00
|
|
|
case GE_CMODE_32BIT_ABGR8888:
|
|
|
|
return GL_UNSIGNED_BYTE;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
2012-11-08 23:26:30 +01:00
|
|
|
return 0;
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2013-02-08 00:04:34 +01:00
|
|
|
static const GLuint MinFiltGL[8] = {
|
2013-01-06 17:44:14 +01:00
|
|
|
GL_NEAREST,
|
|
|
|
GL_LINEAR,
|
|
|
|
GL_NEAREST,
|
|
|
|
GL_LINEAR,
|
|
|
|
GL_NEAREST_MIPMAP_NEAREST,
|
|
|
|
GL_LINEAR_MIPMAP_NEAREST,
|
|
|
|
GL_NEAREST_MIPMAP_LINEAR,
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR,
|
|
|
|
};
|
|
|
|
|
2013-02-08 00:04:34 +01:00
|
|
|
static const GLuint MagFiltGL[2] = {
|
2013-01-06 17:44:14 +01:00
|
|
|
GL_NEAREST,
|
|
|
|
GL_LINEAR
|
|
|
|
};
|
|
|
|
|
2014-06-15 13:34:58 -07:00
|
|
|
// This should not have to be done per texture! OpenGL is silly yo
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::UpdateSamplingParams(TexCacheEntry &entry, bool force) {
|
2017-03-03 14:15:27 +01:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2014-06-15 13:34:58 -07:00
|
|
|
int minFilt;
|
|
|
|
int magFilt;
|
|
|
|
bool sClamp;
|
|
|
|
bool tClamp;
|
|
|
|
float lodBias;
|
2017-05-31 21:23:20 -07:00
|
|
|
u8 maxLevel = (entry.status & TexCacheEntry::STATUS_BAD_MIPS) ? 0 : entry.maxLevel;
|
2017-11-14 13:32:16 +01:00
|
|
|
GETexLevelMode mode;
|
|
|
|
GetSamplingParams(minFilt, magFilt, sClamp, tClamp, lodBias, maxLevel, entry.addr, mode);
|
2017-05-12 20:01:08 -07:00
|
|
|
|
|
|
|
if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
|
2017-12-13 01:05:33 +01:00
|
|
|
float minLod = 0.0f;
|
|
|
|
float maxLod = 0.0f;
|
2017-05-31 21:23:20 -07:00
|
|
|
if (maxLevel != 0) {
|
2017-05-12 20:01:08 -07:00
|
|
|
// TODO: What about a swap of autoMip mode?
|
|
|
|
if (force || entry.lodBias != lodBias) {
|
2017-11-14 13:32:16 +01:00
|
|
|
if (mode == GE_TEXLEVEL_MODE_AUTO) {
|
2017-12-13 01:05:33 +01:00
|
|
|
minLod = 0.0f;
|
|
|
|
maxLod = (float)maxLevel;
|
2017-11-14 13:32:16 +01:00
|
|
|
} else if (mode == GE_TEXLEVEL_MODE_CONST) {
|
2017-12-13 01:05:33 +01:00
|
|
|
minLod = std::max(0.0f, std::min((float)maxLevel, lodBias));
|
|
|
|
maxLod = std::max(0.0f, std::min((float)maxLevel, lodBias));
|
2017-11-14 13:32:16 +01:00
|
|
|
} else { // mode == GE_TEXLEVEL_MODE_SLOPE) {
|
|
|
|
// It's incorrect to use the slope as a bias. Instead it should be passed
|
2017-11-14 16:34:23 +01:00
|
|
|
// into the shader directly as an explicit lod level, with the bias on top. For now, we just kill the
|
2017-11-14 13:32:16 +01:00
|
|
|
// lodBias in this mode, working around #9772.
|
2017-11-14 16:34:23 +01:00
|
|
|
#ifndef USING_GLES2
|
2017-12-13 01:05:33 +01:00
|
|
|
lodBias = 0.0f;
|
2017-11-14 16:34:23 +01:00
|
|
|
#endif
|
2017-12-13 01:05:33 +01:00
|
|
|
minLod = 0.0f;
|
|
|
|
maxLod = (float)maxLevel;
|
2015-09-05 23:09:06 +02:00
|
|
|
}
|
2017-05-12 20:01:08 -07:00
|
|
|
entry.lodBias = lodBias;
|
2015-09-05 23:09:06 +02:00
|
|
|
}
|
2017-05-12 20:01:08 -07:00
|
|
|
} else {
|
2017-12-13 01:05:33 +01:00
|
|
|
minLod = 0.0f;
|
|
|
|
maxLod = 0.0f;
|
2014-06-15 13:34:58 -07:00
|
|
|
}
|
2017-12-13 01:05:33 +01:00
|
|
|
render_->SetTextureLod(minLod, maxLod, lodBias);
|
2014-06-15 13:34:58 -07:00
|
|
|
}
|
2013-06-17 20:45:08 +02:00
|
|
|
|
2017-11-19 00:43:58 +01:00
|
|
|
if (force || entry.minFilt != minFilt || entry.magFilt != magFilt || entry.sClamp != sClamp || entry.tClamp != tClamp) {
|
2017-11-19 17:37:56 +01:00
|
|
|
float aniso = 0.0f;
|
|
|
|
render_->SetTextureSampler(sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso);
|
2017-11-19 00:43:58 +01:00
|
|
|
entry.minFilt = minFilt;
|
|
|
|
entry.magFilt = magFilt;
|
|
|
|
entry.sClamp = sClamp;
|
2013-01-06 17:44:14 +01:00
|
|
|
entry.tClamp = tClamp;
|
2012-12-28 23:23:42 +08:00
|
|
|
}
|
2017-03-03 14:15:27 +01:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
2012-11-01 16:19:01 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight) {
|
2014-06-15 13:34:58 -07:00
|
|
|
int minFilt;
|
|
|
|
int magFilt;
|
|
|
|
bool sClamp;
|
|
|
|
bool tClamp;
|
|
|
|
float lodBias;
|
2017-11-14 13:32:16 +01:00
|
|
|
GETexLevelMode mode;
|
|
|
|
GetSamplingParams(minFilt, magFilt, sClamp, tClamp, lodBias, 0, 0, mode);
|
2014-06-15 13:34:58 -07:00
|
|
|
|
2014-12-14 01:24:01 +01:00
|
|
|
minFilt &= 1; // framebuffers can't mipmap.
|
|
|
|
|
2017-11-19 17:37:56 +01:00
|
|
|
float aniso = 0.0f;
|
|
|
|
render_->SetTextureSampler(sClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, tClamp ? GL_CLAMP_TO_EDGE : GL_REPEAT, MagFiltGL[magFilt], MinFiltGL[minFilt], aniso);
|
2014-06-15 13:34:58 -07:00
|
|
|
|
|
|
|
// Often the framebuffer will not match the texture size. We'll wrap/clamp in the shader in that case.
|
|
|
|
// This happens whether we have OES_texture_npot or not.
|
|
|
|
int w = gstate.getTextureWidth(0);
|
|
|
|
int h = gstate.getTextureHeight(0);
|
|
|
|
if (w != bufferWidth || h != bufferHeight) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-26 13:31:58 -07:00
|
|
|
static void ConvertColors(void *dstBuf, const void *srcBuf, GLuint dstFmt, int numPixels) {
|
|
|
|
const u32 *src = (const u32 *)srcBuf;
|
|
|
|
u32 *dst = (u32 *)dstBuf;
|
2012-11-09 01:24:19 +01:00
|
|
|
switch (dstFmt) {
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4:
|
2015-05-17 13:45:30 -07:00
|
|
|
ConvertRGBA4444ToABGR4444((u16 *)dst, (const u16 *)src, numPixels);
|
2012-11-09 01:24:19 +01:00
|
|
|
break;
|
2013-10-31 00:34:18 -07:00
|
|
|
// Final Fantasy 2 uses this heavily in animated textures.
|
2012-11-09 01:24:19 +01:00
|
|
|
case GL_UNSIGNED_SHORT_5_5_5_1:
|
2015-05-17 13:45:30 -07:00
|
|
|
ConvertRGBA5551ToABGR1555((u16 *)dst, (const u16 *)src, numPixels);
|
2012-11-09 01:24:19 +01:00
|
|
|
break;
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5:
|
2015-05-17 13:45:30 -07:00
|
|
|
ConvertRGB565ToBGR565((u16 *)dst, (const u16 *)src, numPixels);
|
2012-11-09 01:24:19 +01:00
|
|
|
break;
|
|
|
|
default:
|
2017-03-26 11:39:25 +02:00
|
|
|
// No need to convert RGBA8888, right order already
|
|
|
|
if (dst != src)
|
|
|
|
memcpy(dst, src, numPixels * sizeof(u32));
|
2012-11-09 01:24:19 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::StartFrame() {
|
2017-02-20 00:13:09 +01:00
|
|
|
InvalidateLastTexture();
|
2014-06-15 00:40:08 +02:00
|
|
|
timesInvalidatedAllThisFrame_ = 0;
|
2014-06-13 22:07:26 +02:00
|
|
|
|
2014-06-13 22:11:25 +02:00
|
|
|
if (texelsScaledThisFrame_) {
|
|
|
|
// INFO_LOG(G3D, "Scaled %i texels", texelsScaledThisFrame_);
|
|
|
|
}
|
2014-06-13 22:07:26 +02:00
|
|
|
texelsScaledThisFrame_ = 0;
|
2013-12-29 15:10:07 -08:00
|
|
|
if (clearCacheNextFrame_) {
|
2013-04-30 17:20:28 +02:00
|
|
|
Clear(true);
|
|
|
|
clearCacheNextFrame_ = false;
|
|
|
|
} else {
|
|
|
|
Decimate();
|
|
|
|
}
|
2013-01-10 23:49:33 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) {
|
2015-07-20 22:18:26 +02:00
|
|
|
const u32 clutBaseBytes = clutFormat == GE_CMODE_32BIT_ABGR8888 ? (clutBase * sizeof(u32)) : (clutBase * sizeof(u16));
|
2013-06-15 23:04:43 -07:00
|
|
|
// Technically, these extra bytes weren't loaded, but hopefully it was loaded earlier.
|
|
|
|
// If not, we're going to hash random data, which hopefully doesn't cause a performance issue.
|
2015-04-26 00:31:00 -07:00
|
|
|
//
|
|
|
|
// TODO: Actually, this seems like a hack. The game can upload part of a CLUT and reference other data.
|
|
|
|
// clutTotalBytes_ is the last amount uploaded. We should hash clutMaxBytes_, but this will often hash
|
|
|
|
// unrelated old entries for small palettes.
|
|
|
|
// Adding clutBaseBytes may just be mitigating this for some usage patterns.
|
2015-04-26 00:43:36 -07:00
|
|
|
const u32 clutExtendedBytes = std::min(clutTotalBytes_ + clutBaseBytes, clutMaxBytes_);
|
2013-06-15 23:04:43 -07:00
|
|
|
|
2014-10-26 17:49:24 -07:00
|
|
|
clutHash_ = DoReliableHash32((const char *)clutBufRaw_, clutExtendedBytes, 0xC0108888);
|
2013-05-26 12:45:53 -07:00
|
|
|
|
|
|
|
// Avoid a copy when we don't need to convert colors.
|
2017-03-26 11:39:25 +02:00
|
|
|
if (clutFormat != GE_CMODE_32BIT_ABGR8888) {
|
2015-07-20 22:18:26 +02:00
|
|
|
const int numColors = clutFormat == GE_CMODE_32BIT_ABGR8888 ? (clutMaxBytes_ / sizeof(u32)) : (clutMaxBytes_ / sizeof(u16));
|
2014-08-19 22:28:26 -07:00
|
|
|
ConvertColors(clutBufConverted_, clutBufRaw_, getClutDestFormat(clutFormat), numColors);
|
2013-05-26 12:45:53 -07:00
|
|
|
clutBuf_ = clutBufConverted_;
|
|
|
|
} else {
|
|
|
|
clutBuf_ = clutBufRaw_;
|
|
|
|
}
|
2013-05-12 10:57:41 -07:00
|
|
|
|
|
|
|
// Special optimization: fonts typically draw clut4 with just alpha values in a single color.
|
|
|
|
clutAlphaLinear_ = false;
|
|
|
|
clutAlphaLinearColor_ = 0;
|
2015-07-29 11:38:42 +02:00
|
|
|
if (clutFormat == GE_CMODE_16BIT_ABGR4444 && clutIndexIsSimple) {
|
2014-09-09 00:53:01 -07:00
|
|
|
const u16_le *clut = GetCurrentClut<u16_le>();
|
2013-05-12 10:57:41 -07:00
|
|
|
clutAlphaLinear_ = true;
|
|
|
|
clutAlphaLinearColor_ = clut[15] & 0xFFF0;
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
2016-01-01 09:02:16 -08:00
|
|
|
u16 step = clutAlphaLinearColor_ | i;
|
|
|
|
if (clut[i] != step) {
|
2013-05-12 10:57:41 -07:00
|
|
|
clutAlphaLinear_ = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-26 12:45:53 -07:00
|
|
|
|
2013-06-15 23:04:43 -07:00
|
|
|
clutLastFormat_ = gstate.clutformat;
|
2013-05-11 15:45:17 -07:00
|
|
|
}
|
|
|
|
|
2013-06-22 10:35:34 -07:00
|
|
|
// #define DEBUG_TEXTURES
|
|
|
|
|
|
|
|
#ifdef DEBUG_TEXTURES
|
|
|
|
bool SetDebugTexture() {
|
|
|
|
static const int highlightFrames = 30;
|
|
|
|
|
|
|
|
static int numTextures = 0;
|
|
|
|
static int lastFrames = 0;
|
|
|
|
static int mostTextures = 1;
|
|
|
|
|
2013-08-07 22:32:04 +02:00
|
|
|
if (lastFrames != gpuStats.numFlips) {
|
2013-06-22 10:35:34 -07:00
|
|
|
mostTextures = std::max(mostTextures, numTextures);
|
|
|
|
numTextures = 0;
|
2013-08-07 22:32:04 +02:00
|
|
|
lastFrames = gpuStats.numFlips;
|
2013-06-22 10:35:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static GLuint solidTexture = 0;
|
|
|
|
|
|
|
|
bool changed = false;
|
2013-08-07 22:32:04 +02:00
|
|
|
if (((gpuStats.numFlips / highlightFrames) % mostTextures) == numTextures) {
|
|
|
|
if (gpuStats.numFlips % highlightFrames == 0) {
|
2013-09-07 13:31:14 -07:00
|
|
|
NOTICE_LOG(G3D, "Highlighting texture # %d / %d", numTextures, mostTextures);
|
2013-06-22 10:35:34 -07:00
|
|
|
}
|
|
|
|
static const u32 solidTextureData[] = {0x99AA99FF};
|
|
|
|
|
|
|
|
if (solidTexture == 0) {
|
|
|
|
glGenTextures(1, &solidTexture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, solidTexture);
|
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, solidTextureData);
|
|
|
|
} else {
|
|
|
|
glBindTexture(GL_TEXTURE_2D, solidTexture);
|
|
|
|
}
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++numTextures;
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-02-19 23:07:00 +01:00
|
|
|
void TextureCacheGLES::BindTexture(TexCacheEntry *entry) {
|
|
|
|
if (entry->textureName != lastBoundTexture) {
|
2017-11-19 17:37:56 +01:00
|
|
|
render_->BindTexture(0, entry->textureName);
|
2017-02-19 23:07:00 +01:00
|
|
|
lastBoundTexture = entry->textureName;
|
|
|
|
}
|
2017-02-19 23:19:55 +01:00
|
|
|
UpdateSamplingParams(*entry, false);
|
2017-02-19 23:07:00 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:43:53 +01:00
|
|
|
void TextureCacheGLES::Unbind() {
|
2017-11-19 17:37:56 +01:00
|
|
|
render_->BindTexture(0, nullptr);
|
2017-03-25 11:34:21 -07:00
|
|
|
InvalidateLastTexture();
|
2013-09-01 11:40:35 -07:00
|
|
|
}
|
|
|
|
|
2016-01-03 23:44:06 -08:00
|
|
|
class TextureShaderApplier {
|
|
|
|
public:
|
|
|
|
struct Pos {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
};
|
|
|
|
struct UV {
|
|
|
|
float u;
|
|
|
|
float v;
|
|
|
|
};
|
|
|
|
|
|
|
|
TextureShaderApplier(DepalShader *shader, float bufferW, float bufferH, int renderW, int renderH)
|
|
|
|
: shader_(shader), bufferW_(bufferW), bufferH_(bufferH), renderW_(renderW), renderH_(renderH) {
|
|
|
|
static const Pos pos[4] = {
|
2015-09-13 11:14:51 -07:00
|
|
|
{-1, -1, -1},
|
|
|
|
{ 1, -1, -1},
|
|
|
|
{ 1, 1, -1},
|
|
|
|
{-1, 1, -1},
|
|
|
|
};
|
2016-01-03 23:44:06 -08:00
|
|
|
memcpy(pos_, pos, sizeof(pos_));
|
|
|
|
|
|
|
|
static const UV uv[4] = {
|
2015-09-13 11:14:51 -07:00
|
|
|
{0, 0},
|
|
|
|
{1, 0},
|
|
|
|
{1, 1},
|
|
|
|
{0, 1},
|
2015-03-15 19:10:33 -07:00
|
|
|
};
|
2016-01-03 23:44:06 -08:00
|
|
|
memcpy(uv_, uv, sizeof(uv_));
|
|
|
|
}
|
2015-03-15 19:10:33 -07:00
|
|
|
|
2016-01-03 23:44:06 -08:00
|
|
|
void ApplyBounds(const KnownVertexBounds &bounds, u32 uoff, u32 voff) {
|
2015-09-13 11:14:51 -07:00
|
|
|
// If min is not < max, then we don't have values (wasn't set during decode.)
|
2016-01-03 23:44:06 -08:00
|
|
|
if (bounds.minV < bounds.maxV) {
|
|
|
|
const float invWidth = 1.0f / bufferW_;
|
|
|
|
const float invHeight = 1.0f / bufferH_;
|
2015-09-13 11:14:51 -07:00
|
|
|
// Inverse of half = double.
|
|
|
|
const float invHalfWidth = invWidth * 2.0f;
|
|
|
|
const float invHalfHeight = invHeight * 2.0f;
|
|
|
|
|
2016-01-03 23:44:06 -08:00
|
|
|
const int u1 = bounds.minU + uoff;
|
|
|
|
const int v1 = bounds.minV + voff;
|
|
|
|
const int u2 = bounds.maxU + uoff;
|
|
|
|
const int v2 = bounds.maxV + voff;
|
2015-09-12 19:43:02 -07:00
|
|
|
|
|
|
|
const float left = u1 * invHalfWidth - 1.0f;
|
|
|
|
const float right = u2 * invHalfWidth - 1.0f;
|
2015-10-31 23:59:23 +01:00
|
|
|
const float top = v1 * invHalfHeight - 1.0f;
|
|
|
|
const float bottom = v2 * invHalfHeight - 1.0f;
|
2015-09-13 11:14:51 -07:00
|
|
|
// Points are: BL, BR, TR, TL.
|
2017-12-14 17:50:40 +01:00
|
|
|
pos_[0] = Pos{ left, bottom, -1.0f };
|
|
|
|
pos_[1] = Pos{ right, bottom, -1.0f };
|
|
|
|
pos_[2] = Pos{ right, top, -1.0f };
|
|
|
|
pos_[3] = Pos{ left, top, -1.0f };
|
2015-09-13 11:14:51 -07:00
|
|
|
|
|
|
|
// And also the UVs, same order.
|
2015-09-12 19:43:02 -07:00
|
|
|
const float uvleft = u1 * invWidth;
|
|
|
|
const float uvright = u2 * invWidth;
|
2015-10-31 23:59:23 +01:00
|
|
|
const float uvtop = v1 * invHeight;
|
|
|
|
const float uvbottom = v2 * invHeight;
|
2017-12-14 17:50:40 +01:00
|
|
|
uv_[0] = UV{ uvleft, uvbottom };
|
|
|
|
uv_[1] = UV{ uvright, uvbottom };
|
|
|
|
uv_[2] = UV{ uvright, uvtop };
|
|
|
|
uv_[3] = UV{ uvleft, uvtop };
|
2015-09-13 11:14:51 -07:00
|
|
|
}
|
2016-01-03 23:44:06 -08:00
|
|
|
}
|
2015-09-13 11:14:51 -07:00
|
|
|
|
2017-12-14 17:50:40 +01:00
|
|
|
void Use(GLRenderManager *render, DrawEngineGLES *transformDraw, GLRInputLayout *inputLayout) {
|
2017-11-19 17:37:56 +01:00
|
|
|
render->BindProgram(shader_->program);
|
2017-12-14 17:50:40 +01:00
|
|
|
struct SimpleVertex {
|
|
|
|
float pos[3];
|
|
|
|
float uv[2];
|
|
|
|
};
|
|
|
|
uint32_t bindOffset;
|
|
|
|
GLRBuffer *bindBuffer;
|
|
|
|
SimpleVertex *verts = (SimpleVertex *)transformDraw->GetPushVertexBuffer()->Push(sizeof(SimpleVertex) * 4, &bindOffset, &bindBuffer);
|
|
|
|
int order[4] = { 0 ,1, 3, 2 };
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
memcpy(verts[i].pos, &pos_[order[i]], sizeof(Pos));
|
|
|
|
memcpy(verts[i].uv, &uv_[order[i]], sizeof(UV));
|
2015-12-13 22:48:21 -08:00
|
|
|
}
|
2017-12-19 12:25:13 +01:00
|
|
|
render->BindVertexBuffer(inputLayout, bindBuffer, bindOffset);
|
2016-01-03 23:44:06 -08:00
|
|
|
}
|
2015-03-15 19:10:33 -07:00
|
|
|
|
2017-12-14 17:50:40 +01:00
|
|
|
void Shade(GLRenderManager *render) {
|
2016-01-03 23:44:06 -08:00
|
|
|
static const GLubyte indices[4] = { 0, 1, 3, 2 };
|
2017-12-14 17:50:40 +01:00
|
|
|
render->SetViewport(GLRViewport{ 0, 0, (float)renderW_, (float)renderH_, 0.0f, 1.0f });
|
|
|
|
render->Draw(GL_TRIANGLE_STRIP, 0, 4);
|
2016-01-03 23:44:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
DepalShader *shader_;
|
|
|
|
Pos pos_[4];
|
|
|
|
UV uv_[4];
|
|
|
|
float bufferW_;
|
|
|
|
float bufferH_;
|
|
|
|
int renderW_;
|
|
|
|
int renderH_;
|
|
|
|
};
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) {
|
2016-01-03 23:44:06 -08:00
|
|
|
DepalShader *depal = nullptr;
|
2017-04-04 11:09:29 +02:00
|
|
|
uint32_t clutMode = gstate.clutformat & 0xFFFFFF;
|
2016-01-03 23:44:06 -08:00
|
|
|
if ((entry->status & TexCacheEntry::STATUS_DEPALETTIZE) && !g_Config.bDisableSlowFramebufEffects) {
|
2017-04-04 11:09:29 +02:00
|
|
|
depal = depalShaderCache_->GetDepalettizeShader(clutMode, framebuffer->drawnFormat);
|
2016-01-03 23:44:06 -08:00
|
|
|
}
|
|
|
|
if (depal) {
|
2017-04-04 11:09:29 +02:00
|
|
|
const GEPaletteFormat clutFormat = gstate.getClutPaletteFormat();
|
2017-11-19 17:37:56 +01:00
|
|
|
GLRTexture *clutTexture = depalShaderCache_->GetClutTexture(clutFormat, clutHash_, clutBuf_);
|
2017-02-08 15:58:46 +01:00
|
|
|
Draw::Framebuffer *depalFBO = framebufferManagerGL_->GetTempFBO(framebuffer->renderWidth, framebuffer->renderHeight, Draw::FBO_8888);
|
2017-12-30 22:52:22 +01:00
|
|
|
draw_->BindFramebufferAsRenderTarget(depalFBO, { Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE, Draw::RPAction::DONT_CARE });
|
2016-01-03 23:44:06 -08:00
|
|
|
shaderManager_->DirtyLastShader();
|
|
|
|
|
|
|
|
TextureShaderApplier shaderApply(depal, framebuffer->bufferWidth, framebuffer->bufferHeight, framebuffer->renderWidth, framebuffer->renderHeight);
|
|
|
|
shaderApply.ApplyBounds(gstate_c.vertBounds, gstate_c.curTextureXOffset, gstate_c.curTextureYOffset);
|
2017-12-14 17:50:40 +01:00
|
|
|
shaderApply.Use(render_, drawEngine_, shadeInputLayout_);
|
2016-01-03 23:44:06 -08:00
|
|
|
|
2017-02-17 14:30:42 +01:00
|
|
|
framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_SKIP_COPY);
|
2017-12-14 17:50:40 +01:00
|
|
|
render_->BindTexture(3, clutTexture);
|
2017-12-12 14:07:52 +01:00
|
|
|
render_->SetTextureSampler(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_NEAREST, GL_NEAREST, 0.0f);
|
2016-01-03 23:44:06 -08:00
|
|
|
|
2017-12-14 17:50:40 +01:00
|
|
|
shaderApply.Shade(render_);
|
2016-01-03 23:44:06 -08:00
|
|
|
|
2017-02-06 11:26:24 +01:00
|
|
|
draw_->BindFramebufferAsTexture(depalFBO, 0, Draw::FB_COLOR_BIT, 0);
|
2016-05-21 15:40:58 -07:00
|
|
|
|
|
|
|
const u32 bytesPerColor = clutFormat == GE_CMODE_32BIT_ABGR8888 ? sizeof(u32) : sizeof(u16);
|
|
|
|
const u32 clutTotalColors = clutMaxBytes_ / bytesPerColor;
|
|
|
|
|
2017-11-19 18:22:46 +01:00
|
|
|
TexCacheEntry::TexStatus alphaStatus = CheckAlpha((const uint8_t *)clutBuf_, getClutDestFormat(clutFormat), clutTotalColors, clutTotalColors, 1);
|
2017-04-03 17:04:58 +02:00
|
|
|
gstate_c.SetTextureFullAlpha(alphaStatus == TexCacheEntry::STATUS_ALPHA_FULL);
|
2015-03-15 19:10:33 -07:00
|
|
|
} else {
|
2016-05-21 15:40:58 -07:00
|
|
|
entry->status &= ~TexCacheEntry::STATUS_DEPALETTIZE;
|
|
|
|
|
2017-02-17 14:30:42 +01:00
|
|
|
framebufferManagerGL_->BindFramebufferAsColorTexture(0, framebuffer, BINDFBCOLOR_MAY_COPY_WITH_UV | BINDFBCOLOR_APPLY_TEX_OFFSET);
|
2016-05-21 15:40:58 -07:00
|
|
|
|
2017-04-03 17:04:58 +02:00
|
|
|
gstate_c.SetTextureFullAlpha(gstate.getTextureFormat() == GE_TFMT_5650);
|
2015-03-15 19:10:33 -07:00
|
|
|
}
|
|
|
|
|
2017-02-08 15:58:46 +01:00
|
|
|
framebufferManagerGL_->RebindFramebuffer();
|
2015-03-15 19:10:33 -07:00
|
|
|
SetFramebufferSamplingParams(framebuffer->bufferWidth, framebuffer->bufferHeight);
|
|
|
|
|
2017-03-25 11:34:21 -07:00
|
|
|
InvalidateLastTexture();
|
2017-12-14 17:50:40 +01:00
|
|
|
|
|
|
|
// Since we started/ended render passes, might need these.
|
|
|
|
gstate_c.Dirty(DIRTY_BLEND_STATE | DIRTY_DEPTHSTENCIL_STATE | DIRTY_RASTER_STATE | DIRTY_VIEWPORTSCISSOR_STATE);
|
2015-03-15 19:10:33 -07:00
|
|
|
}
|
|
|
|
|
2017-03-26 11:39:25 +02:00
|
|
|
ReplacedTextureFormat FromGLESFormat(GLenum fmt) {
|
2016-04-30 13:44:31 -07:00
|
|
|
// TODO: 16-bit formats are incorrect, since swizzled.
|
|
|
|
switch (fmt) {
|
2017-02-08 15:48:36 +01:00
|
|
|
case GL_UNSIGNED_SHORT_5_6_5: return ReplacedTextureFormat::F_0565_ABGR;
|
|
|
|
case GL_UNSIGNED_SHORT_5_5_5_1: return ReplacedTextureFormat::F_1555_ABGR;
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4: return ReplacedTextureFormat::F_4444_ABGR;
|
2017-03-26 11:39:25 +02:00
|
|
|
case GL_UNSIGNED_BYTE: default: return ReplacedTextureFormat::F_8888;
|
2016-04-30 13:44:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLenum ToGLESFormat(ReplacedTextureFormat fmt) {
|
|
|
|
switch (fmt) {
|
2017-02-08 15:48:36 +01:00
|
|
|
case ReplacedTextureFormat::F_5650: return GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
case ReplacedTextureFormat::F_5551: return GL_UNSIGNED_SHORT_5_5_5_1;
|
|
|
|
case ReplacedTextureFormat::F_4444: return GL_UNSIGNED_SHORT_4_4_4_4;
|
|
|
|
case ReplacedTextureFormat::F_8888: default: return GL_UNSIGNED_BYTE;
|
2016-04-30 13:44:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::BuildTexture(TexCacheEntry *const entry, bool replaceImages) {
|
2016-05-01 11:17:55 -07:00
|
|
|
entry->status &= ~TexCacheEntry::STATUS_ALPHA_MASK;
|
|
|
|
|
2017-12-12 15:04:46 +01:00
|
|
|
// Never replace images in-place - there's no such thing, drivers have to fake it anyway, at least if
|
|
|
|
// the image has been in use within the last frame or two.
|
|
|
|
replaceImages = false;
|
|
|
|
|
2014-12-21 16:54:26 -08:00
|
|
|
// For the estimate, we assume cluts always point to 8888 for simplicity.
|
|
|
|
cacheSizeEstimate_ += EstimateTexMemoryUsage(entry);
|
|
|
|
|
2013-09-01 14:44:37 -07:00
|
|
|
if (entry->framebuffer) {
|
2016-05-21 17:53:42 -07:00
|
|
|
// Nothing else to do here.
|
2013-09-01 14:44:37 -07:00
|
|
|
return;
|
2013-09-01 11:44:49 -07:00
|
|
|
}
|
2016-05-01 11:17:55 -07:00
|
|
|
|
2017-02-23 22:41:13 +01:00
|
|
|
// Always generate a texture name unless it's a framebuffer, we might need it if the texture is replaced later.
|
|
|
|
if (!replaceImages) {
|
|
|
|
if (!entry->textureName) {
|
2017-11-19 17:37:56 +01:00
|
|
|
entry->textureName = render_->CreateTexture(GL_TEXTURE_2D);
|
2017-02-23 22:41:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 11:17:55 -07:00
|
|
|
if ((entry->bufw == 0 || (gstate.texbufwidth[0] & 0xf800) != 0) && entry->addr >= PSP_GetKernelMemoryEnd()) {
|
|
|
|
ERROR_LOG_REPORT(G3D, "Texture with unexpected bufw (full=%d)", gstate.texbufwidth[0] & 0xffff);
|
|
|
|
// Proceeding here can cause a crash.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-12 21:00:51 +01:00
|
|
|
// Adjust maxLevel to actually present levels..
|
2014-02-17 11:42:03 +01:00
|
|
|
bool badMipSizes = false;
|
2017-05-31 21:23:20 -07:00
|
|
|
bool canAutoGen = false;
|
2016-05-01 11:17:55 -07:00
|
|
|
int maxLevel = entry->maxLevel;
|
|
|
|
for (int i = 0; i <= maxLevel; i++) {
|
2013-02-12 21:00:51 +01:00
|
|
|
// If encountering levels pointing to nothing, adjust max level.
|
2013-09-15 21:39:28 -07:00
|
|
|
u32 levelTexaddr = gstate.getTextureAddress(i);
|
2013-02-12 21:00:51 +01:00
|
|
|
if (!Memory::IsValidAddress(levelTexaddr)) {
|
|
|
|
maxLevel = i - 1;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-17 11:42:03 +01:00
|
|
|
|
2017-04-01 21:17:58 +02:00
|
|
|
// If size reaches 1, stop, and override maxlevel.
|
|
|
|
int tw = gstate.getTextureWidth(i);
|
|
|
|
int th = gstate.getTextureHeight(i);
|
|
|
|
if (tw == 1 || th == 1) {
|
|
|
|
maxLevel = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-31 21:23:20 -07:00
|
|
|
if (i > 0) {
|
|
|
|
int lastW = gstate.getTextureWidth(i - 1);
|
|
|
|
int lastH = gstate.getTextureHeight(i - 1);
|
|
|
|
|
|
|
|
if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
|
|
|
|
if (tw != 1 && tw != (lastW >> 1))
|
|
|
|
badMipSizes = true;
|
|
|
|
else if (th != 1 && th != (lastH >> 1))
|
|
|
|
badMipSizes = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastW > tw || lastH > th)
|
|
|
|
canAutoGen = true;
|
2014-02-17 11:42:03 +01:00
|
|
|
}
|
2013-02-12 21:00:51 +01:00
|
|
|
}
|
2013-09-01 08:28:09 +08:00
|
|
|
|
2013-10-08 15:00:48 +02:00
|
|
|
// If GLES3 is available, we can preallocate the storage, which makes texture loading more efficient.
|
2016-05-01 11:17:55 -07:00
|
|
|
GLenum dstFmt = GetDestFormat(GETextureFormat(entry->format), gstate.getClutPaletteFormat());
|
2013-09-01 08:28:09 +08:00
|
|
|
|
2016-01-03 23:06:15 -08:00
|
|
|
int scaleFactor = standardScaleFactor_;
|
2014-04-02 00:13:50 +02:00
|
|
|
|
2015-12-30 13:23:05 -08:00
|
|
|
// Rachet down scale factor in low-memory mode.
|
|
|
|
if (lowMemoryMode_) {
|
|
|
|
// Keep it even, though, just in case of npot troubles.
|
|
|
|
scaleFactor = scaleFactor > 4 ? 4 : (scaleFactor > 2 ? 2 : 1);
|
|
|
|
}
|
|
|
|
|
2017-02-20 00:19:58 +01:00
|
|
|
u64 cachekey = replacer_.Enabled() ? entry->CacheKey() : 0;
|
2016-05-01 11:17:55 -07:00
|
|
|
int w = gstate.getTextureWidth(0);
|
|
|
|
int h = gstate.getTextureHeight(0);
|
2017-02-20 00:19:58 +01:00
|
|
|
ReplacedTexture &replaced = replacer_.FindReplacement(cachekey, entry->fullhash, w, h);
|
2016-04-30 13:44:31 -07:00
|
|
|
if (replaced.GetSize(0, w, h)) {
|
2016-06-06 23:02:56 -07:00
|
|
|
if (replaceImages) {
|
|
|
|
// Since we're replacing the texture, we can't replace the image inside.
|
2017-11-19 17:37:56 +01:00
|
|
|
render_->DeleteTexture(entry->textureName);
|
|
|
|
entry->textureName = render_->CreateTexture(GL_TEXTURE_2D);
|
2016-06-06 23:02:56 -07:00
|
|
|
replaceImages = false;
|
|
|
|
}
|
|
|
|
|
2016-04-30 13:44:31 -07:00
|
|
|
// We're replacing, so we won't scale.
|
|
|
|
scaleFactor = 1;
|
2016-06-06 19:35:58 -07:00
|
|
|
entry->status |= TexCacheEntry::STATUS_IS_SCALED;
|
2017-05-26 10:16:43 +02:00
|
|
|
maxLevel = replaced.MaxLevel();
|
|
|
|
badMipSizes = false;
|
2016-04-30 13:44:31 -07:00
|
|
|
}
|
|
|
|
|
2014-04-02 00:13:50 +02:00
|
|
|
// Don't scale the PPGe texture.
|
2016-12-16 22:53:55 +02:00
|
|
|
if (entry->addr > 0x05000000 && entry->addr < PSP_GetKernelMemoryEnd())
|
2014-04-02 00:13:50 +02:00
|
|
|
scaleFactor = 1;
|
2016-12-16 22:53:55 +02:00
|
|
|
|
2016-05-06 19:58:01 -07:00
|
|
|
if ((entry->status & TexCacheEntry::STATUS_CHANGE_FREQUENT) != 0 && scaleFactor != 1) {
|
2015-12-30 13:43:10 -08:00
|
|
|
// Remember for later that we /wanted/ to scale this texture.
|
|
|
|
entry->status |= TexCacheEntry::STATUS_TO_SCALE;
|
2015-12-30 13:23:05 -08:00
|
|
|
scaleFactor = 1;
|
2015-12-30 13:43:10 -08:00
|
|
|
}
|
2014-04-02 00:13:50 +02:00
|
|
|
|
2015-12-30 13:23:05 -08:00
|
|
|
if (scaleFactor != 1) {
|
2014-06-13 22:07:26 +02:00
|
|
|
if (texelsScaledThisFrame_ >= TEXCACHE_MAX_TEXELS_SCALED) {
|
|
|
|
entry->status |= TexCacheEntry::STATUS_TO_SCALE;
|
|
|
|
scaleFactor = 1;
|
|
|
|
} else {
|
2014-06-13 23:01:40 +02:00
|
|
|
entry->status &= ~TexCacheEntry::STATUS_TO_SCALE;
|
2016-06-06 19:35:58 -07:00
|
|
|
entry->status |= TexCacheEntry::STATUS_IS_SCALED;
|
2014-06-13 22:07:26 +02:00
|
|
|
texelsScaledThisFrame_ += w * h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 17:37:56 +01:00
|
|
|
// glBindTexture(GL_TEXTURE_2D, entry->textureName);
|
2016-06-06 23:02:56 -07:00
|
|
|
lastBoundTexture = entry->textureName;
|
2017-12-13 01:05:33 +01:00
|
|
|
|
2013-10-08 15:00:48 +02:00
|
|
|
// GLES2 doesn't have support for a "Max lod" which is critical as PSP games often
|
|
|
|
// don't specify mips all the way down. As a result, we either need to manually generate
|
|
|
|
// the bottom few levels or rely on OpenGL's autogen mipmaps instead, which might not
|
|
|
|
// be as good quality as the game's own (might even be better in some cases though).
|
|
|
|
|
2013-12-21 21:27:22 +08:00
|
|
|
// Always load base level texture here
|
2017-02-15 00:56:53 +09:00
|
|
|
if (IsFakeMipmapChange()) {
|
2017-05-31 21:42:07 -07:00
|
|
|
// NOTE: Since the level is not part of the cache key, we assume it never changes.
|
|
|
|
u8 level = std::max(0, gstate.getTexLevelOffset16() / 16);
|
2017-02-12 03:27:38 +09:00
|
|
|
LoadTextureLevel(*entry, replaced, level, replaceImages, scaleFactor, dstFmt);
|
|
|
|
} else
|
|
|
|
LoadTextureLevel(*entry, replaced, 0, replaceImages, scaleFactor, dstFmt);
|
2017-03-03 14:15:27 +01:00
|
|
|
|
2013-12-30 14:28:28 +08:00
|
|
|
// Mipmapping only enable when texture scaling disable
|
2017-11-19 18:22:46 +01:00
|
|
|
int texMaxLevel = 0;
|
2017-12-14 17:08:45 +01:00
|
|
|
bool genMips = false;
|
2015-12-30 16:54:25 -08:00
|
|
|
if (maxLevel > 0 && scaleFactor == 1) {
|
2015-09-05 23:09:06 +02:00
|
|
|
if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
|
|
|
|
if (badMipSizes) {
|
|
|
|
// WARN_LOG(G3D, "Bad mipmap for texture sized %dx%dx%d - autogenerating", w, h, (int)format);
|
2017-05-31 21:23:20 -07:00
|
|
|
if (canAutoGen) {
|
2017-12-14 17:08:45 +01:00
|
|
|
genMips = true;
|
2017-05-31 21:23:20 -07:00
|
|
|
} else {
|
2017-11-19 18:22:46 +01:00
|
|
|
texMaxLevel = 0;
|
2017-05-31 21:23:20 -07:00
|
|
|
maxLevel = 0;
|
|
|
|
}
|
2015-09-05 23:09:06 +02:00
|
|
|
} else {
|
|
|
|
for (int i = 1; i <= maxLevel; i++) {
|
2016-04-30 13:44:31 -07:00
|
|
|
LoadTextureLevel(*entry, replaced, i, replaceImages, scaleFactor, dstFmt);
|
2015-09-05 23:09:06 +02:00
|
|
|
}
|
2017-11-19 18:22:46 +01:00
|
|
|
texMaxLevel = maxLevel;
|
2013-12-21 21:27:22 +08:00
|
|
|
}
|
2014-12-14 01:24:01 +01:00
|
|
|
} else {
|
2015-09-05 23:09:06 +02:00
|
|
|
// Avoid PowerVR driver bug
|
2017-05-31 21:23:20 -07:00
|
|
|
if (canAutoGen && w > 1 && h > 1 && !(h > w && (gl_extensions.bugs & BUG_PVR_GENMIPMAP_HEIGHT_GREATER))) { // Really! only seems to fail if height > width
|
2015-09-05 23:09:06 +02:00
|
|
|
// NOTICE_LOG(G3D, "Generating mipmap for texture sized %dx%d%d", w, h, (int)format);
|
2017-12-14 17:08:45 +01:00
|
|
|
genMips = true;
|
2015-09-05 23:09:06 +02:00
|
|
|
} else {
|
2017-05-31 21:23:20 -07:00
|
|
|
maxLevel = 0;
|
2015-09-05 23:09:06 +02:00
|
|
|
}
|
2014-12-14 01:24:01 +01:00
|
|
|
}
|
2015-09-05 23:09:06 +02:00
|
|
|
} else if (gstate_c.Supports(GPU_SUPPORTS_TEXTURE_LOD_CONTROL)) {
|
2017-11-19 18:22:46 +01:00
|
|
|
texMaxLevel = 0;
|
2013-04-03 07:33:14 +08:00
|
|
|
}
|
|
|
|
|
2017-05-31 21:23:20 -07:00
|
|
|
if (maxLevel == 0) {
|
|
|
|
entry->status |= TexCacheEntry::STATUS_BAD_MIPS;
|
|
|
|
} else {
|
|
|
|
entry->status &= ~TexCacheEntry::STATUS_BAD_MIPS;
|
|
|
|
}
|
2016-04-30 13:44:31 -07:00
|
|
|
if (replaced.Valid()) {
|
2017-12-13 23:11:40 +01:00
|
|
|
entry->SetAlphaStatus(TexCacheEntry::TexStatus(replaced.AlphaStatus()));
|
2016-04-30 13:44:31 -07:00
|
|
|
}
|
|
|
|
|
2017-12-14 17:08:45 +01:00
|
|
|
render_->FinalizeTexture(entry->textureName, texMaxLevel, genMips);
|
2017-12-14 16:54:21 +01:00
|
|
|
|
2015-03-15 20:05:35 -07:00
|
|
|
// This will rebind it, but that's okay.
|
2017-12-14 16:08:55 +01:00
|
|
|
// Need to actually bind it now - it might only have gotten bound in the init phase.
|
|
|
|
render_->BindTexture(0, entry->textureName);
|
2013-02-10 14:11:53 -08:00
|
|
|
UpdateSamplingParams(*entry, true);
|
2013-02-08 00:04:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
GLenum TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const {
|
2013-10-08 15:00:48 +02:00
|
|
|
switch (format) {
|
|
|
|
case GE_TFMT_CLUT4:
|
|
|
|
case GE_TFMT_CLUT8:
|
|
|
|
case GE_TFMT_CLUT16:
|
|
|
|
case GE_TFMT_CLUT32:
|
|
|
|
return getClutDestFormat(clutFormat);
|
|
|
|
case GE_TFMT_4444:
|
|
|
|
return GL_UNSIGNED_SHORT_4_4_4_4;
|
|
|
|
case GE_TFMT_5551:
|
|
|
|
return GL_UNSIGNED_SHORT_5_5_5_1;
|
|
|
|
case GE_TFMT_5650:
|
|
|
|
return GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
case GE_TFMT_8888:
|
|
|
|
case GE_TFMT_DXT1:
|
|
|
|
case GE_TFMT_DXT3:
|
|
|
|
case GE_TFMT_DXT5:
|
|
|
|
default:
|
|
|
|
return GL_UNSIGNED_BYTE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-19 18:22:46 +01:00
|
|
|
u8 *TextureCacheGLES::DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufwout) {
|
2016-06-19 07:55:38 -07:00
|
|
|
void *finalBuf = nullptr;
|
2013-09-15 21:39:28 -07:00
|
|
|
u32 texaddr = gstate.getTextureAddress(level);
|
2013-09-15 21:27:13 -07:00
|
|
|
int bufw = GetTextureBufw(level, texaddr, format);
|
2013-10-31 02:39:46 +01:00
|
|
|
if (bufwout)
|
|
|
|
*bufwout = bufw;
|
2016-06-19 07:55:38 -07:00
|
|
|
|
2013-07-31 01:52:29 +08:00
|
|
|
int w = gstate.getTextureWidth(level);
|
|
|
|
int h = gstate.getTextureHeight(level);
|
2012-11-01 16:19:01 +01:00
|
|
|
|
2016-06-19 07:55:38 -07:00
|
|
|
int decPitch = 0;
|
|
|
|
int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
|
|
|
if (!(scaleFactor == 1 && gstate_c.Supports(GPU_SUPPORTS_UNPACK_SUBIMAGE)) && w != bufw) {
|
|
|
|
decPitch = w * pixelSize;
|
|
|
|
} else {
|
|
|
|
decPitch = bufw * pixelSize;
|
|
|
|
}
|
2012-11-08 23:26:30 +01:00
|
|
|
|
2017-11-19 18:22:46 +01:00
|
|
|
uint8_t *texBuf = new uint8_t[std::max(w, bufw) * h * pixelSize];
|
|
|
|
DecodeTextureLevel(texBuf, decPitch, format, clutformat, texaddr, level, bufw, true, false, false);
|
|
|
|
return texBuf;
|
2013-04-28 11:20:56 -07:00
|
|
|
}
|
|
|
|
|
2017-11-19 18:22:46 +01:00
|
|
|
TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h) {
|
2015-05-24 22:55:43 -07:00
|
|
|
CheckAlphaResult res;
|
2013-05-08 07:52:54 -07:00
|
|
|
switch (dstFmt) {
|
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4:
|
2017-11-19 18:22:46 +01:00
|
|
|
res = CheckAlphaABGR4444Basic((const uint32_t *)pixelData, stride, w, h);
|
2013-05-08 07:52:54 -07:00
|
|
|
break;
|
|
|
|
case GL_UNSIGNED_SHORT_5_5_5_1:
|
2017-11-19 18:22:46 +01:00
|
|
|
res = CheckAlphaABGR1555Basic((const uint32_t *)pixelData, stride, w, h);
|
2013-05-08 07:52:54 -07:00
|
|
|
break;
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5:
|
2015-05-24 22:55:43 -07:00
|
|
|
// Never has any alpha.
|
|
|
|
res = CHECKALPHA_FULL;
|
2013-05-08 07:52:54 -07:00
|
|
|
break;
|
|
|
|
default:
|
2017-11-19 18:22:46 +01:00
|
|
|
res = CheckAlphaRGBA8888Basic((const uint32_t *)pixelData, stride, w, h);
|
2013-05-08 07:52:54 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-13 23:11:40 +01:00
|
|
|
return (TexCacheEntry::TexStatus)res;
|
2013-05-08 07:52:54 -07:00
|
|
|
}
|
|
|
|
|
2017-01-21 22:16:30 +01:00
|
|
|
void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, bool replaceImages, int scaleFactor, GLenum dstFmt) {
|
2015-05-15 17:14:54 +02:00
|
|
|
int w = gstate.getTextureWidth(level);
|
|
|
|
int h = gstate.getTextureHeight(level);
|
|
|
|
bool useUnpack = false;
|
2017-11-19 18:22:46 +01:00
|
|
|
uint8_t *pixelData;
|
2015-05-13 23:46:59 +02:00
|
|
|
|
2017-03-03 14:15:27 +01:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
|
|
|
|
2013-04-28 11:20:56 -07:00
|
|
|
// TODO: only do this once
|
|
|
|
u32 texByteAlign = 1;
|
|
|
|
|
2012-12-21 21:49:09 +01:00
|
|
|
gpuStats.numTexturesDecoded++;
|
2013-07-22 19:22:21 +02:00
|
|
|
|
2016-04-30 20:17:03 -07:00
|
|
|
if (replaced.GetSize(level, w, h)) {
|
2016-04-30 13:44:31 -07:00
|
|
|
PROFILE_THIS_SCOPE("replacetex");
|
2012-12-21 21:49:09 +01:00
|
|
|
|
2016-04-30 13:44:31 -07:00
|
|
|
int bpp = replaced.Format(level) == ReplacedTextureFormat::F_8888 ? 4 : 2;
|
2017-11-19 18:22:46 +01:00
|
|
|
uint8_t *rearrange = new uint8_t[w * h * bpp];
|
|
|
|
replaced.Load(level, rearrange, bpp * w);
|
|
|
|
pixelData = rearrange;
|
2014-04-14 07:33:30 -07:00
|
|
|
|
2016-04-30 13:44:31 -07:00
|
|
|
dstFmt = ToGLESFormat(replaced.Format(level));
|
2014-01-19 20:54:48 -08:00
|
|
|
|
2016-04-30 13:44:31 -07:00
|
|
|
texByteAlign = bpp;
|
2014-06-03 00:59:34 -07:00
|
|
|
} else {
|
2016-04-30 13:44:31 -07:00
|
|
|
PROFILE_THIS_SCOPE("decodetex");
|
|
|
|
|
|
|
|
GEPaletteFormat clutformat = gstate.getClutPaletteFormat();
|
|
|
|
int bufw;
|
2017-11-19 18:22:46 +01:00
|
|
|
uint8_t *finalBuf = DecodeTextureLevelOld(GETextureFormat(entry.format), clutformat, level, dstFmt, scaleFactor, &bufw);
|
|
|
|
if (!finalBuf) {
|
2016-04-30 13:44:31 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-06-19 07:55:38 -07:00
|
|
|
// Textures are always aligned to 16 bytes bufw, so this could safely be 4 always.
|
|
|
|
texByteAlign = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
2017-11-19 18:22:46 +01:00
|
|
|
pixelData = finalBuf;
|
2016-04-30 13:44:31 -07:00
|
|
|
|
2017-11-12 16:19:28 -08:00
|
|
|
// We check before scaling since scaling shouldn't invent alpha from a full alpha texture.
|
2016-04-30 13:44:31 -07:00
|
|
|
if ((entry.status & TexCacheEntry::STATUS_CHANGE_FREQUENT) == 0) {
|
2017-12-13 23:11:40 +01:00
|
|
|
TexCacheEntry::TexStatus alphaStatus = CheckAlpha(pixelData, dstFmt, useUnpack ? bufw : w, w, h);
|
2016-04-30 13:44:31 -07:00
|
|
|
entry.SetAlphaStatus(alphaStatus, level);
|
|
|
|
} else {
|
|
|
|
entry.SetAlphaStatus(TexCacheEntry::STATUS_ALPHA_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
2017-11-19 18:22:46 +01:00
|
|
|
// TODO: Scale's buffer management doesn't work.
|
|
|
|
//if (scaleFactor > 1)
|
|
|
|
// scaler.Scale((uint32_t *)pixelData, dstFmt, w, h, scaleFactor);
|
2017-11-12 16:19:28 -08:00
|
|
|
|
2017-02-20 00:19:58 +01:00
|
|
|
if (replacer_.Enabled()) {
|
2016-05-01 08:54:43 -07:00
|
|
|
ReplacedTextureDecodeInfo replacedInfo;
|
|
|
|
replacedInfo.cachekey = entry.CacheKey();
|
|
|
|
replacedInfo.hash = entry.fullhash;
|
|
|
|
replacedInfo.addr = entry.addr;
|
|
|
|
replacedInfo.isVideo = videos_.find(entry.addr & 0x3FFFFFFF) != videos_.end();
|
|
|
|
replacedInfo.isFinal = (entry.status & TexCacheEntry::STATUS_TO_SCALE) == 0;
|
|
|
|
replacedInfo.scaleFactor = scaleFactor;
|
2017-03-26 11:39:25 +02:00
|
|
|
replacedInfo.fmt = FromGLESFormat(dstFmt);
|
2016-05-01 08:54:43 -07:00
|
|
|
|
2016-04-30 13:44:31 -07:00
|
|
|
int bpp = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
2017-02-20 00:19:58 +01:00
|
|
|
replacer_.NotifyTextureDecoded(replacedInfo, pixelData, (useUnpack ? bufw : w) * bpp, level, w, h);
|
2016-04-30 13:44:31 -07:00
|
|
|
}
|
2015-05-15 17:14:54 +02:00
|
|
|
}
|
2013-04-30 03:49:12 +02:00
|
|
|
|
2017-03-03 14:15:27 +01:00
|
|
|
CHECK_GL_ERROR_IF_DEBUG();
|
|
|
|
|
2012-11-26 01:21:14 +01:00
|
|
|
GLuint components = dstFmt == GL_UNSIGNED_SHORT_5_6_5 ? GL_RGB : GL_RGBA;
|
2013-05-05 00:00:22 -07:00
|
|
|
|
2014-04-13 18:34:40 -07:00
|
|
|
GLuint components2 = components;
|
|
|
|
|
2013-06-11 20:21:19 +02:00
|
|
|
if (replaceImages) {
|
2015-05-15 17:14:54 +02:00
|
|
|
PROFILE_THIS_SCOPE("repltex");
|
2017-11-19 18:22:46 +01:00
|
|
|
Crash();
|
|
|
|
// glTexSubImage2D(GL_TEXTURE_2D, level, 0, 0, w, h, components2, dstFmt, pixelData);
|
2013-06-11 20:21:19 +02:00
|
|
|
} else {
|
2015-05-15 17:14:54 +02:00
|
|
|
PROFILE_THIS_SCOPE("loadtex");
|
2017-12-07 14:56:19 +01:00
|
|
|
// Avoid misleading errors in texture upload, these are common.
|
|
|
|
GLenum err = glGetError();
|
|
|
|
if (err) {
|
|
|
|
WARN_LOG(G3D, "Got an error BEFORE texture upload: %08x (%s)", err, GLEnumToString(err).c_str());
|
|
|
|
}
|
2017-02-15 00:56:53 +09:00
|
|
|
if (IsFakeMipmapChange())
|
2017-11-19 18:22:46 +01:00
|
|
|
render_->TextureImage(entry.textureName, 0, w, h, components, components2, dstFmt, pixelData);
|
2017-02-12 03:27:38 +09:00
|
|
|
else
|
2017-11-19 18:22:46 +01:00
|
|
|
render_->TextureImage(entry.textureName, level, w, h, components, components2, dstFmt, pixelData);
|
2013-10-31 02:39:46 +01:00
|
|
|
}
|
2013-04-30 03:49:12 +02:00
|
|
|
}
|
|
|
|
|
2013-05-02 10:56:30 +02:00
|
|
|
// Only used by Qt UI?
|
2017-01-21 22:16:30 +01:00
|
|
|
bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) {
|
2013-02-17 01:06:06 +01:00
|
|
|
GPUgstate oldState = gstate;
|
|
|
|
gstate = state;
|
|
|
|
|
2013-09-15 21:39:28 -07:00
|
|
|
u32 texaddr = gstate.getTextureAddress(0);
|
2013-02-17 01:06:06 +01:00
|
|
|
|
|
|
|
if (!Memory::IsValidAddress(texaddr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-28 11:20:56 -07:00
|
|
|
GLenum dstFmt = 0;
|
2013-02-17 01:06:06 +01:00
|
|
|
|
2013-07-21 19:34:55 -07:00
|
|
|
GETextureFormat format = gstate.getTextureFormat();
|
|
|
|
GEPaletteFormat clutformat = gstate.getClutPaletteFormat();
|
2013-04-28 11:20:56 -07:00
|
|
|
u8 level = 0;
|
2013-02-17 01:06:06 +01:00
|
|
|
|
2013-09-15 21:27:13 -07:00
|
|
|
int bufw = GetTextureBufw(level, texaddr, format);
|
2013-07-31 01:52:29 +08:00
|
|
|
int w = gstate.getTextureWidth(level);
|
|
|
|
int h = gstate.getTextureHeight(level);
|
2013-02-17 01:06:06 +01:00
|
|
|
|
2016-06-19 07:55:38 -07:00
|
|
|
void *finalBuf = DecodeTextureLevelOld(format, clutformat, level, dstFmt, 1);
|
2013-04-28 11:20:56 -07:00
|
|
|
if (finalBuf == NULL) {
|
2013-02-17 01:06:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-08 15:00:48 +02:00
|
|
|
switch (dstFmt) {
|
2013-04-28 11:20:56 -07:00
|
|
|
case GL_UNSIGNED_SHORT_4_4_4_4:
|
2015-01-22 19:53:32 +01:00
|
|
|
for (int y = 0; y < h; y++)
|
|
|
|
for (int x = 0; x < bufw; x++) {
|
|
|
|
u32 val = ((u16*)finalBuf)[y*bufw + x];
|
|
|
|
u32 r = ((val>>12) & 0xF) * 17;
|
|
|
|
u32 g = ((val>> 8) & 0xF) * 17;
|
|
|
|
u32 b = ((val>> 4) & 0xF) * 17;
|
|
|
|
u32 a = ((val>> 0) & 0xF) * 17;
|
|
|
|
((u32*)output)[y*w + x] = (a << 24) | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
2013-04-28 11:20:56 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_UNSIGNED_SHORT_5_5_5_1:
|
2015-01-22 19:53:32 +01:00
|
|
|
for (int y = 0; y < h; y++)
|
|
|
|
for (int x = 0; x < bufw; x++) {
|
|
|
|
u32 val = ((u16*)finalBuf)[y*bufw + x];
|
|
|
|
u32 r = Convert5To8((val>>11) & 0x1F);
|
|
|
|
u32 g = Convert5To8((val>> 6) & 0x1F);
|
|
|
|
u32 b = Convert5To8((val>> 1) & 0x1F);
|
|
|
|
u32 a = (val & 0x1) * 255;
|
|
|
|
((u32*)output)[y*w + x] = (a << 24) | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
2013-04-28 11:20:56 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GL_UNSIGNED_SHORT_5_6_5:
|
2015-01-22 19:53:32 +01:00
|
|
|
for (int y = 0; y < h; y++)
|
|
|
|
for (int x = 0; x < bufw; x++) {
|
|
|
|
u32 val = ((u16*)finalBuf)[y*bufw + x];
|
|
|
|
u32 a = 0xFF;
|
|
|
|
u32 r = Convert5To8((val>>11) & 0x1F);
|
|
|
|
u32 g = Convert6To8((val>> 5) & 0x3F);
|
|
|
|
u32 b = Convert5To8((val ) & 0x1F);
|
|
|
|
((u32*)output)[y*w + x] = (a << 24) | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
2013-04-28 11:20:56 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-01-22 19:53:32 +01:00
|
|
|
for (int y = 0; y < h; y++)
|
|
|
|
for (int x = 0; x < bufw; x++) {
|
|
|
|
u32 val = ((u32*)finalBuf)[y*bufw + x];
|
|
|
|
((u32*)output)[y*w + x] = ((val & 0xFF000000)) | ((val & 0x00FF0000)>>16) | ((val & 0x0000FF00)) | ((val & 0x000000FF)<<16);
|
|
|
|
}
|
2013-04-28 11:20:56 -07:00
|
|
|
break;
|
2013-02-17 01:06:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gstate = oldState;
|
|
|
|
return true;
|
|
|
|
}
|
2017-10-18 13:03:49 +02:00
|
|
|
|
|
|
|
bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level) {
|
|
|
|
#ifndef USING_GLES2
|
|
|
|
GPUgstate saved;
|
|
|
|
if (level != 0) {
|
|
|
|
saved = gstate;
|
|
|
|
|
|
|
|
// The way we set textures is a bit complex. Let's just override level 0.
|
|
|
|
gstate.texsize[0] = gstate.texsize[level];
|
|
|
|
gstate.texaddr[0] = gstate.texaddr[level];
|
|
|
|
gstate.texbufwidth[0] = gstate.texbufwidth[level];
|
|
|
|
}
|
|
|
|
|
|
|
|
SetTexture(true);
|
|
|
|
ApplyTexture();
|
|
|
|
int w = gstate.getTextureWidth(level);
|
|
|
|
int h = gstate.getTextureHeight(level);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
|
|
|
|
|
|
|
|
if (level != 0) {
|
|
|
|
gstate = saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.Allocate(w, h, GE_FORMAT_8888, false);
|
|
|
|
glPixelStorei(GL_PACK_ALIGNMENT, 4);
|
|
|
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer.GetData());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2017-12-07 14:56:19 +01:00
|
|
|
|
|
|
|
void TextureCacheGLES::DeviceRestore(Draw::DrawContext *draw) {
|
|
|
|
draw_ = draw;
|
|
|
|
}
|