2013-04-17 21:29:41 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2008-12-26 05:24:15 -07:00
|
|
|
#include <vector>
|
2010-04-18 21:06:18 -06:00
|
|
|
#include <cmath>
|
2008-12-26 05:24:15 -07:00
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
|
2009-05-07 01:43:56 -06:00
|
|
|
#include <fstream>
|
2008-12-07 22:25:12 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set
|
|
|
|
#define _interlockedbittestandreset workaround_ms_header_bug_platform_sdk6_reset
|
|
|
|
#define _interlockedbittestandset64 workaround_ms_header_bug_platform_sdk6_set64
|
|
|
|
#define _interlockedbittestandreset64 workaround_ms_header_bug_platform_sdk6_reset64
|
|
|
|
#include <intrin.h>
|
|
|
|
#undef _interlockedbittestandset
|
|
|
|
#undef _interlockedbittestandreset
|
|
|
|
#undef _interlockedbittestandset64
|
|
|
|
#undef _interlockedbittestandreset64
|
|
|
|
#endif
|
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
#include "BPStructs.h"
|
|
|
|
#include "CommonPaths.h"
|
|
|
|
#include "FileUtil.h"
|
|
|
|
#include "FramebufferManager.h"
|
|
|
|
#include "Globals.h"
|
2009-05-07 01:43:56 -06:00
|
|
|
#include "Hash.h"
|
2010-09-27 20:15:02 -06:00
|
|
|
#include "HiresTextures.h"
|
2011-12-29 17:00:34 -07:00
|
|
|
#include "HW/Memmap.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "ImageWrite.h"
|
|
|
|
#include "MemoryUtil.h"
|
2011-12-07 21:04:34 -07:00
|
|
|
#include "ProgramShaderCache.h"
|
2010-09-27 20:15:02 -06:00
|
|
|
#include "Render.h"
|
|
|
|
#include "Statistics.h"
|
|
|
|
#include "StringUtil.h"
|
|
|
|
#include "TextureCache.h"
|
2010-07-12 13:30:25 -06:00
|
|
|
#include "TextureConverter.h"
|
2010-09-27 20:15:02 -06:00
|
|
|
#include "TextureDecoder.h"
|
|
|
|
#include "VideoConfig.h"
|
2009-05-07 01:43:56 -06:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
namespace OGL
|
|
|
|
{
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2013-02-13 05:12:19 -07:00
|
|
|
static SHADER s_ColorMatrixProgram;
|
|
|
|
static SHADER s_DepthMatrixProgram;
|
2013-01-12 08:29:16 -07:00
|
|
|
static GLuint s_ColorMatrixUniform;
|
|
|
|
static GLuint s_DepthMatrixUniform;
|
2013-11-25 04:19:34 -07:00
|
|
|
static GLuint s_ColorCopyPositionUniform;
|
|
|
|
static GLuint s_DepthCopyPositionUniform;
|
2013-01-14 04:37:31 -07:00
|
|
|
static u32 s_ColorCbufid;
|
|
|
|
static u32 s_DepthCbufid;
|
2013-01-11 07:24:43 -07:00
|
|
|
|
2013-01-18 17:06:34 -07:00
|
|
|
static u32 s_Textures[8];
|
|
|
|
static u32 s_ActiveTexture;
|
|
|
|
|
2013-11-16 15:12:07 -07:00
|
|
|
bool SaveTexture(const std::string filename, u32 textarget, u32 tex, int virtual_width, int virtual_height, unsigned int level)
|
2008-12-26 05:24:15 -07:00
|
|
|
{
|
2014-01-01 19:25:59 -07:00
|
|
|
if (GLInterface->GetMode() != GLInterfaceMode::MODE_OPENGL)
|
|
|
|
return false;
|
2012-05-12 05:50:03 -06:00
|
|
|
int width = std::max(virtual_width >> level, 1);
|
|
|
|
int height = std::max(virtual_height >> level, 1);
|
2013-11-15 19:59:59 -07:00
|
|
|
u8* data = new u8[width * height * 4];
|
2013-01-18 16:39:31 -07:00
|
|
|
glActiveTexture(GL_TEXTURE0+9);
|
2010-10-19 16:24:27 -06:00
|
|
|
glBindTexture(textarget, tex);
|
2013-11-15 19:59:59 -07:00
|
|
|
glGetTexImage(textarget, level, GL_RGBA, GL_UNSIGNED_BYTE, data);
|
2013-01-18 16:39:31 -07:00
|
|
|
glBindTexture(textarget, 0);
|
|
|
|
TextureCache::SetStage();
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
const GLenum err = GL_REPORT_ERROR();
|
|
|
|
if (GL_NO_ERROR != err)
|
2009-05-09 01:55:30 -06:00
|
|
|
{
|
2013-12-23 16:01:34 -07:00
|
|
|
PanicAlert("Can't save texture, GL Error: %d", err);
|
2013-11-15 19:59:59 -07:00
|
|
|
delete[] data;
|
2010-10-19 16:24:27 -06:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-16 14:34:34 -07:00
|
|
|
bool success = TextureToPng(data, width * 4, filename, width, height, true);
|
|
|
|
delete[] data;
|
|
|
|
return success;
|
2008-12-26 05:24:15 -07:00
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
TextureCache::TCacheEntry::~TCacheEntry()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2011-02-06 08:02:26 -07:00
|
|
|
if (texture)
|
2009-07-19 02:17:41 -06:00
|
|
|
{
|
2013-10-28 23:09:01 -06:00
|
|
|
for(auto& gtex : s_Textures)
|
|
|
|
if(gtex == texture)
|
|
|
|
gtex = 0;
|
2010-09-27 20:15:02 -06:00
|
|
|
glDeleteTextures(1, &texture);
|
2010-10-19 16:24:27 -06:00
|
|
|
texture = 0;
|
2010-09-27 20:15:02 -06:00
|
|
|
}
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-04-08 06:36:58 -06:00
|
|
|
if (framebuffer)
|
|
|
|
{
|
|
|
|
glDeleteFramebuffers(1, &framebuffer);
|
|
|
|
framebuffer = 0;
|
|
|
|
}
|
2010-09-27 20:15:02 -06:00
|
|
|
}
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
TextureCache::TCacheEntry::TCacheEntry()
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
glGenTextures(1, &texture);
|
|
|
|
GL_REPORT_ERRORD();
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-04-08 06:36:58 -06:00
|
|
|
framebuffer = 0;
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
void TextureCache::TCacheEntry::Bind(unsigned int stage)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2013-02-19 17:22:38 -07:00
|
|
|
if (s_Textures[stage] != texture)
|
2013-01-18 17:06:34 -07:00
|
|
|
{
|
2013-02-19 17:22:38 -07:00
|
|
|
if (s_ActiveTexture != stage)
|
|
|
|
{
|
2013-01-18 17:06:34 -07:00
|
|
|
glActiveTexture(GL_TEXTURE0 + stage);
|
2013-02-19 17:22:38 -07:00
|
|
|
s_ActiveTexture = stage;
|
|
|
|
}
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-01-18 17:06:34 -07:00
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
s_Textures[stage] = texture;
|
|
|
|
}
|
2010-07-12 13:30:25 -06:00
|
|
|
}
|
|
|
|
|
2013-11-16 15:12:07 -07:00
|
|
|
bool TextureCache::TCacheEntry::Save(const std::string filename, unsigned int level)
|
2010-07-12 13:30:25 -06:00
|
|
|
{
|
2013-11-15 19:59:59 -07:00
|
|
|
return SaveTexture(filename, GL_TEXTURE_2D, texture, virtual_width, virtual_height, level);
|
2010-09-27 20:15:02 -06:00
|
|
|
}
|
2010-07-12 13:30:25 -06:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
TextureCache::TCacheEntryBase* TextureCache::CreateTexture(unsigned int width,
|
|
|
|
unsigned int height, unsigned int expanded_width,
|
|
|
|
unsigned int tex_levels, PC_TexFormat pcfmt)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
int gl_format = 0,
|
|
|
|
gl_iformat = 0,
|
|
|
|
gl_type = 0;
|
2009-02-20 19:42:35 -07:00
|
|
|
|
2010-09-27 20:15:02 -06:00
|
|
|
if (pcfmt != PC_TEX_FMT_DXT1)
|
2009-05-09 01:55:30 -06:00
|
|
|
{
|
2010-09-27 20:15:02 -06:00
|
|
|
switch (pcfmt)
|
2009-05-09 01:55:30 -06:00
|
|
|
{
|
|
|
|
default:
|
|
|
|
case PC_TEX_FMT_NONE:
|
2013-10-28 23:23:17 -06:00
|
|
|
PanicAlert("Invalid PC texture format %i", pcfmt);
|
2009-05-09 01:55:30 -06:00
|
|
|
case PC_TEX_FMT_BGRA32:
|
|
|
|
gl_format = GL_BGRA;
|
2013-01-14 09:48:38 -07:00
|
|
|
gl_iformat = GL_RGBA;
|
2009-05-09 01:55:30 -06:00
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2009-05-09 01:55:30 -06:00
|
|
|
case PC_TEX_FMT_RGBA32:
|
|
|
|
gl_format = GL_RGBA;
|
2013-01-14 09:48:38 -07:00
|
|
|
gl_iformat = GL_RGBA;
|
2009-05-09 01:55:30 -06:00
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2009-05-12 20:06:02 -06:00
|
|
|
case PC_TEX_FMT_I4_AS_I8:
|
|
|
|
gl_format = GL_LUMINANCE;
|
|
|
|
gl_iformat = GL_INTENSITY4;
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2009-05-12 20:06:02 -06:00
|
|
|
case PC_TEX_FMT_IA4_AS_IA8:
|
|
|
|
gl_format = GL_LUMINANCE_ALPHA;
|
|
|
|
gl_iformat = GL_LUMINANCE4_ALPHA4;
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2009-05-09 01:55:30 -06:00
|
|
|
case PC_TEX_FMT_I8:
|
|
|
|
gl_format = GL_LUMINANCE;
|
2009-06-20 03:29:28 -06:00
|
|
|
gl_iformat = GL_INTENSITY8;
|
2009-05-09 01:55:30 -06:00
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2009-05-09 01:55:30 -06:00
|
|
|
case PC_TEX_FMT_IA8:
|
|
|
|
gl_format = GL_LUMINANCE_ALPHA;
|
|
|
|
gl_iformat = GL_LUMINANCE8_ALPHA8;
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
break;
|
|
|
|
case PC_TEX_FMT_RGB565:
|
|
|
|
gl_format = GL_RGB;
|
|
|
|
gl_iformat = GL_RGB;
|
|
|
|
gl_type = GL_UNSIGNED_SHORT_5_6_5;
|
|
|
|
break;
|
|
|
|
}
|
2010-10-19 16:24:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
TCacheEntry &entry = *new TCacheEntry;
|
|
|
|
entry.gl_format = gl_format;
|
|
|
|
entry.gl_iformat = gl_iformat;
|
|
|
|
entry.gl_type = gl_type;
|
|
|
|
entry.pcfmt = pcfmt;
|
|
|
|
|
2014-01-21 02:34:48 -07:00
|
|
|
glActiveTexture(GL_TEXTURE0+9);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, entry.texture);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, tex_levels - 1);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-02-20 04:37:01 -07:00
|
|
|
entry.Load(width, height, expanded_width, 0);
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2014-01-21 02:34:48 -07:00
|
|
|
// This isn't needed as Load() also reset the stage in the end
|
|
|
|
//TextureCache::SetStage();
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
return &entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
2012-08-10 05:13:51 -06:00
|
|
|
unsigned int expanded_width, unsigned int level)
|
2010-10-19 16:24:27 -06:00
|
|
|
{
|
2014-01-21 02:34:48 -07:00
|
|
|
if (pcfmt != PC_TEX_FMT_DXT1)
|
2013-02-19 17:22:38 -07:00
|
|
|
{
|
2014-01-21 02:34:48 -07:00
|
|
|
glActiveTexture(GL_TEXTURE0+9);
|
2013-01-18 17:06:34 -07:00
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2013-04-15 14:28:55 -06:00
|
|
|
|
|
|
|
if (expanded_width != width)
|
2011-12-25 22:15:54 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2013-01-16 13:15:07 -07:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
2009-05-09 01:55:30 -06:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
if (expanded_width != width)
|
2011-12-25 22:15:54 -07:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2009-05-09 01:55:30 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
PanicAlert("PC_TEX_FMT_DXT1 support disabled");
|
|
|
|
//glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
|
|
|
|
//width, height, 0, expanded_width * expanded_height/2, temp);
|
2009-05-09 01:55:30 -06:00
|
|
|
}
|
2014-01-21 02:34:48 -07:00
|
|
|
TextureCache::SetStage();
|
2010-05-19 15:54:54 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
TextureCache::TCacheEntryBase* TextureCache::CreateRenderTargetTexture(
|
|
|
|
unsigned int scaled_tex_w, unsigned int scaled_tex_h)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
TCacheEntry *const entry = new TCacheEntry;
|
2013-01-18 16:39:31 -07:00
|
|
|
glActiveTexture(GL_TEXTURE0+9);
|
2010-10-19 16:24:27 -06:00
|
|
|
glBindTexture(GL_TEXTURE_2D, entry->texture);
|
2009-09-04 00:09:21 -06:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
const GLenum
|
|
|
|
gl_format = GL_RGBA,
|
2013-01-14 09:48:38 -07:00
|
|
|
gl_iformat = GL_RGBA,
|
2010-10-19 16:24:27 -06:00
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-01-16 13:15:07 -07:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
2009-11-14 16:15:09 -07:00
|
|
|
|
2013-01-16 07:12:39 -07:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, scaled_tex_w, scaled_tex_h, 0, gl_format, gl_type, NULL);
|
2013-01-18 16:39:31 -07:00
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-04-08 06:36:58 -06:00
|
|
|
glGenFramebuffers(1, &entry->framebuffer);
|
|
|
|
FramebufferManager::SetFramebuffer(entry->framebuffer);
|
|
|
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, entry->texture, 0);
|
|
|
|
GL_REPORT_FBO_ERROR();
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-01-18 16:39:31 -07:00
|
|
|
SetStage();
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-01-16 07:12:39 -07:00
|
|
|
GL_REPORT_ERRORD();
|
2009-11-14 16:15:09 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
return entry;
|
|
|
|
}
|
2009-11-14 16:15:09 -07:00
|
|
|
|
2011-02-26 16:41:02 -07:00
|
|
|
void TextureCache::TCacheEntry::FromRenderTarget(u32 dstAddr, unsigned int dstFormat,
|
|
|
|
unsigned int srcFormat, const EFBRectangle& srcRect,
|
|
|
|
bool isIntensity, bool scaleByHalf, unsigned int cbufid,
|
|
|
|
const float *colmat)
|
2010-10-19 16:24:27 -06:00
|
|
|
{
|
2013-01-28 10:16:03 -07:00
|
|
|
g_renderer->ResetAPIState(); // reset any game specific settings
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2009-05-09 01:55:30 -06:00
|
|
|
// Make sure to resolve anything we need to read from.
|
2011-02-26 16:41:02 -07:00
|
|
|
const GLuint read_texture = (srcFormat == PIXELFMT_Z24) ?
|
|
|
|
FramebufferManager::ResolveAndGetDepthTarget(srcRect) :
|
|
|
|
FramebufferManager::ResolveAndGetRenderTarget(srcRect);
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2013-04-08 06:36:58 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2012-01-29 12:24:23 -07:00
|
|
|
if (type != TCET_EC_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
|
2010-07-12 13:30:25 -06:00
|
|
|
{
|
2013-04-08 06:36:58 -06:00
|
|
|
FramebufferManager::SetFramebuffer(framebuffer);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-07-12 13:30:25 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-01-18 16:39:31 -07:00
|
|
|
glActiveTexture(GL_TEXTURE0+9);
|
2013-11-25 00:32:41 -07:00
|
|
|
glBindTexture(GL_TEXTURE_2D, read_texture);
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2011-12-26 09:35:27 -07:00
|
|
|
glViewport(0, 0, virtual_width, virtual_height);
|
2010-07-12 13:30:25 -06:00
|
|
|
|
2013-01-12 08:29:16 -07:00
|
|
|
if(srcFormat == PIXELFMT_Z24) {
|
2013-02-13 05:12:19 -07:00
|
|
|
s_DepthMatrixProgram.Bind();
|
2013-01-14 04:37:31 -07:00
|
|
|
if(s_DepthCbufid != cbufid)
|
|
|
|
glUniform4fv(s_DepthMatrixUniform, 5, colmat);
|
|
|
|
s_DepthCbufid = cbufid;
|
2013-01-12 08:29:16 -07:00
|
|
|
} else {
|
2013-02-13 05:12:19 -07:00
|
|
|
s_ColorMatrixProgram.Bind();
|
2013-01-14 04:37:31 -07:00
|
|
|
if(s_ColorCbufid != cbufid)
|
|
|
|
glUniform4fv(s_ColorMatrixUniform, 7, colmat);
|
|
|
|
s_ColorCbufid = cbufid;
|
2013-01-12 08:29:16 -07:00
|
|
|
}
|
2009-03-07 02:29:25 -07:00
|
|
|
|
2013-11-25 04:19:34 -07:00
|
|
|
TargetRectangle R = g_renderer->ConvertEFBRectangle(srcRect);
|
|
|
|
glUniform4f(srcFormat == PIXELFMT_Z24 ? s_DepthCopyPositionUniform : s_ColorCopyPositionUniform,
|
|
|
|
R.left, R.top, R.right, R.bottom);
|
2011-08-25 03:28:29 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-04-11 08:27:32 -06:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-07-12 13:30:25 -06:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
}
|
2010-10-19 16:24:27 -06:00
|
|
|
|
|
|
|
if (false == g_ActiveConfig.bCopyEFBToTexture)
|
2010-07-12 13:30:25 -06:00
|
|
|
{
|
2011-12-29 17:00:34 -07:00
|
|
|
int encoded_size = TextureConverter::EncodeToRamFromTexture(
|
2010-10-19 16:24:27 -06:00
|
|
|
addr,
|
2010-07-12 13:30:25 -06:00
|
|
|
read_texture,
|
2013-10-28 23:23:17 -06:00
|
|
|
srcFormat == PIXELFMT_Z24,
|
|
|
|
isIntensity,
|
|
|
|
dstFormat,
|
|
|
|
scaleByHalf,
|
2011-02-26 16:41:02 -07:00
|
|
|
srcRect);
|
2011-12-29 17:00:34 -07:00
|
|
|
|
|
|
|
u8* dst = Memory::GetPointer(addr);
|
2013-01-29 15:40:15 -07:00
|
|
|
u64 const new_hash = GetHash64(dst,encoded_size,g_ActiveConfig.iSafeTextureCache_ColorSamples);
|
2011-12-29 17:00:34 -07:00
|
|
|
|
|
|
|
// Mark texture entries in destination address range dynamic unless caching is enabled and the texture entry is up to date
|
|
|
|
if (!g_ActiveConfig.bEFBCopyCacheEnable)
|
|
|
|
TextureCache::MakeRangeDynamic(addr,encoded_size);
|
2013-01-29 15:40:15 -07:00
|
|
|
else if (!TextureCache::Find(addr, new_hash))
|
2011-12-29 17:00:34 -07:00
|
|
|
TextureCache::MakeRangeDynamic(addr,encoded_size);
|
2012-06-20 08:43:13 -06:00
|
|
|
|
2013-01-29 15:40:15 -07:00
|
|
|
hash = new_hash;
|
2010-07-12 13:30:25 -06:00
|
|
|
}
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2013-04-15 14:28:55 -06:00
|
|
|
FramebufferManager::SetFramebuffer(0);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2013-04-15 14:28:55 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2009-03-07 02:29:25 -07:00
|
|
|
|
2013-04-15 14:28:55 -06:00
|
|
|
if (g_ActiveConfig.bDumpEFBTarget)
|
|
|
|
{
|
2009-05-09 01:55:30 -06:00
|
|
|
static int count = 0;
|
2013-11-15 19:59:59 -07:00
|
|
|
SaveTexture(StringFromFormat("%sefb_frame_%i.png", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
|
2013-11-16 15:12:07 -07:00
|
|
|
count++), GL_TEXTURE_2D, texture, virtual_width, virtual_height, 0);
|
2013-04-15 14:28:55 -06:00
|
|
|
}
|
2013-01-28 10:16:03 -07:00
|
|
|
|
|
|
|
g_renderer->RestoreAPIState();
|
2010-10-19 16:24:27 -06:00
|
|
|
}
|
|
|
|
|
2012-12-07 16:54:38 -07:00
|
|
|
TextureCache::TextureCache()
|
|
|
|
{
|
2013-10-28 23:23:17 -06:00
|
|
|
const char *pColorMatrixProg =
|
2013-11-25 00:43:55 -07:00
|
|
|
"uniform sampler2D samp9;\n"
|
2013-01-12 08:29:16 -07:00
|
|
|
"uniform vec4 colmat[7];\n"
|
2013-04-08 06:50:58 -06:00
|
|
|
"VARYIN vec2 uv0;\n"
|
2013-11-24 17:06:29 -07:00
|
|
|
"out vec4 ocol0;\n"
|
2013-01-11 07:24:43 -07:00
|
|
|
"\n"
|
|
|
|
"void main(){\n"
|
2013-11-25 04:19:34 -07:00
|
|
|
" vec4 texcol = texture(samp9, uv0);\n"
|
2013-02-13 10:01:06 -07:00
|
|
|
" texcol = round(texcol * colmat[5]) * colmat[6];\n"
|
2013-02-15 05:13:45 -07:00
|
|
|
" ocol0 = texcol * mat4(colmat[0], colmat[1], colmat[2], colmat[3]) + colmat[4];\n"
|
2013-01-12 08:29:16 -07:00
|
|
|
"}\n";
|
2013-01-11 07:24:43 -07:00
|
|
|
|
2013-01-12 08:29:16 -07:00
|
|
|
const char *pDepthMatrixProg =
|
2013-11-25 00:43:55 -07:00
|
|
|
"uniform sampler2D samp9;\n"
|
2013-01-12 08:29:16 -07:00
|
|
|
"uniform vec4 colmat[5];\n"
|
2013-04-08 06:50:58 -06:00
|
|
|
"VARYIN vec2 uv0;\n"
|
2013-11-24 17:06:29 -07:00
|
|
|
"out vec4 ocol0;\n"
|
2013-01-11 07:24:43 -07:00
|
|
|
"\n"
|
|
|
|
"void main(){\n"
|
2013-11-25 04:19:34 -07:00
|
|
|
" vec4 texcol = texture(samp9, uv0);\n"
|
2013-10-06 02:12:13 -06:00
|
|
|
" vec4 EncodedDepth = fract((texcol.r * (16777215.0/16777216.0)) * vec4(1.0,256.0,256.0*256.0,1.0));\n"
|
|
|
|
" texcol = round(EncodedDepth * (16777216.0/16777215.0) * vec4(255.0,255.0,255.0,15.0)) / vec4(255.0,255.0,255.0,15.0);\n"
|
2013-02-15 05:13:45 -07:00
|
|
|
" ocol0 = texcol * mat4(colmat[0], colmat[1], colmat[2], colmat[3]) + colmat[4];"
|
2013-01-12 08:29:16 -07:00
|
|
|
"}\n";
|
|
|
|
|
2013-01-11 07:41:42 -07:00
|
|
|
const char *VProgram =
|
2013-04-08 06:50:58 -06:00
|
|
|
"VARYOUT vec2 uv0;\n"
|
2013-11-25 04:19:34 -07:00
|
|
|
"uniform sampler2D samp9;\n"
|
|
|
|
"uniform vec4 copy_position;\n" // left, top, right, bottom
|
2013-01-11 07:41:42 -07:00
|
|
|
"void main()\n"
|
|
|
|
"{\n"
|
2013-11-25 04:19:34 -07:00
|
|
|
" vec2 rawpos = vec2(gl_VertexID&1, gl_VertexID&2);\n"
|
2013-11-25 08:11:06 -07:00
|
|
|
" uv0 = mix(copy_position.xy, copy_position.zw, rawpos) / vec2(textureSize(samp9, 0));\n"
|
2013-11-25 04:19:34 -07:00
|
|
|
" gl_Position = vec4(rawpos*2.0-1.0, 0.0, 1.0);\n"
|
2013-01-11 07:41:42 -07:00
|
|
|
"}\n";
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-02-13 05:12:19 -07:00
|
|
|
ProgramShaderCache::CompileShader(s_ColorMatrixProgram, VProgram, pColorMatrixProg);
|
|
|
|
ProgramShaderCache::CompileShader(s_DepthMatrixProgram, VProgram, pDepthMatrixProg);
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-02-13 05:12:19 -07:00
|
|
|
s_ColorMatrixUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "colmat");
|
|
|
|
s_DepthMatrixUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "colmat");
|
2013-01-14 04:37:31 -07:00
|
|
|
s_ColorCbufid = -1;
|
|
|
|
s_DepthCbufid = -1;
|
2013-04-15 14:28:55 -06:00
|
|
|
|
2013-11-25 04:19:34 -07:00
|
|
|
s_ColorCopyPositionUniform = glGetUniformLocation(s_ColorMatrixProgram.glprogid, "copy_position");
|
|
|
|
s_DepthCopyPositionUniform = glGetUniformLocation(s_DepthMatrixProgram.glprogid, "copy_position");
|
|
|
|
|
2013-01-18 17:06:34 -07:00
|
|
|
s_ActiveTexture = -1;
|
2013-10-28 23:09:01 -06:00
|
|
|
for(auto& gtex : s_Textures)
|
|
|
|
gtex = -1;
|
2012-12-07 16:54:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
TextureCache::~TextureCache()
|
|
|
|
{
|
2013-01-11 07:24:43 -07:00
|
|
|
s_ColorMatrixProgram.Destroy();
|
|
|
|
s_DepthMatrixProgram.Destroy();
|
2010-10-19 16:24:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::DisableStage(unsigned int stage)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
|
|
|
}
|
2009-01-11 15:25:57 -07:00
|
|
|
|
2013-01-18 16:39:31 -07:00
|
|
|
void TextureCache::SetStage ()
|
|
|
|
{
|
2013-03-17 05:46:30 -06:00
|
|
|
// -1 is the initial value as we don't know which testure should be bound
|
|
|
|
if(s_ActiveTexture != (u32)-1)
|
|
|
|
glActiveTexture(GL_TEXTURE0 + s_ActiveTexture);
|
2013-01-18 16:39:31 -07:00
|
|
|
}
|
|
|
|
|
2009-01-11 15:25:57 -07:00
|
|
|
}
|