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