2009-07-28 15:32:10 -06:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// 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 SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
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"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "ImageWrite.h"
|
|
|
|
#include "MemoryUtil.h"
|
2008-12-26 04:23:59 -07:00
|
|
|
#include "PixelShaderCache.h"
|
2008-12-07 22:25:12 -07:00
|
|
|
#include "PixelShaderManager.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 "VertexShaderManager.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
|
|
|
|
|
|
|
static u32 s_TempFramebuffer = 0;
|
|
|
|
|
2009-03-22 05:21:44 -06:00
|
|
|
static const GLint c_MinLinearFilter[8] = {
|
2009-05-09 01:55:30 -06:00
|
|
|
GL_NEAREST,
|
|
|
|
GL_NEAREST_MIPMAP_NEAREST,
|
|
|
|
GL_NEAREST_MIPMAP_LINEAR,
|
|
|
|
GL_NEAREST,
|
|
|
|
GL_LINEAR,
|
|
|
|
GL_LINEAR_MIPMAP_NEAREST,
|
|
|
|
GL_LINEAR_MIPMAP_LINEAR,
|
|
|
|
GL_LINEAR,
|
2008-12-07 22:25:12 -07:00
|
|
|
};
|
|
|
|
|
2009-03-22 05:21:44 -06:00
|
|
|
static const GLint c_WrapSettings[4] = {
|
2009-05-09 01:55:30 -06:00
|
|
|
GL_CLAMP_TO_EDGE,
|
|
|
|
GL_REPEAT,
|
|
|
|
GL_MIRRORED_REPEAT,
|
|
|
|
GL_REPEAT,
|
2008-12-26 05:24:15 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height)
|
|
|
|
{
|
2009-05-09 01:55:30 -06:00
|
|
|
std::vector<u32> data(width * height);
|
2010-10-19 16:24:27 -06:00
|
|
|
glBindTexture(textarget, tex);
|
|
|
|
glGetTexImage(textarget, 0, GL_BGRA, GL_UNSIGNED_BYTE, &data[0]);
|
|
|
|
|
|
|
|
const GLenum err = GL_REPORT_ERROR();
|
|
|
|
if (GL_NO_ERROR != err)
|
2009-05-09 01:55:30 -06:00
|
|
|
{
|
|
|
|
PanicAlert("Can't save texture, GL Error: %s", gluErrorString(err));
|
2010-10-19 16:24:27 -06:00
|
|
|
return false;
|
|
|
|
}
|
2009-03-07 02:29:25 -07:00
|
|
|
|
2008-12-26 05:24:15 -07:00
|
|
|
return SaveTGA(filename, width, height, &data[0]);
|
|
|
|
}
|
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
|
|
|
{
|
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
|
|
|
}
|
|
|
|
}
|
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();
|
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
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
GL_REPORT_ERRORD();
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
// TODO: is this already done somewhere else?
|
|
|
|
TexMode0 &tm0 = bpmem.tex[stage >> 2].texMode0[stage & 3];
|
|
|
|
TexMode1 &tm1 = bpmem.tex[stage >> 2].texMode1[stage & 3];
|
|
|
|
SetTextureParameters(tm0, tm1);
|
2010-07-12 13:30:25 -06:00
|
|
|
}
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
bool TextureCache::TCacheEntry::Save(const char filename[])
|
2010-07-12 13:30:25 -06:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
// TODO: make ogl dump PNGs
|
|
|
|
std::string tga_filename(filename);
|
|
|
|
tga_filename.replace(tga_filename.size() - 3, 3, "tga");
|
2009-03-08 13:19:51 -06:00
|
|
|
|
2011-12-26 09:35:27 -07:00
|
|
|
return SaveTexture(tga_filename.c_str(), GL_TEXTURE_2D, texture, virtual_width, virtual_height);
|
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:
|
2010-09-27 20:15:02 -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;
|
|
|
|
gl_iformat = 4;
|
|
|
|
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;
|
|
|
|
gl_iformat = 4;
|
|
|
|
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_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;
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2009-05-09 01:55:30 -06:00
|
|
|
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;
|
|
|
|
|
|
|
|
entry.bHaveMipMaps = tex_levels != 1;
|
|
|
|
|
|
|
|
return &entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::TCacheEntry::Load(unsigned int width, unsigned int height,
|
2010-11-24 12:13:19 -07:00
|
|
|
unsigned int expanded_width, unsigned int level, bool autogen_mips)
|
2010-10-19 16:24:27 -06:00
|
|
|
{
|
|
|
|
//glEnable(GL_TEXTURE_2D);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
//GL_REPORT_ERRORD();
|
|
|
|
|
|
|
|
if (pcfmt != PC_TEX_FMT_DXT1)
|
|
|
|
{
|
|
|
|
if (expanded_width != width)
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, expanded_width);
|
|
|
|
|
2010-11-24 12:13:19 -07:00
|
|
|
if (bHaveMipMaps && autogen_mips)
|
2009-12-03 13:09:15 -07:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
|
|
|
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
|
2009-05-09 01:55:30 -06:00
|
|
|
}
|
|
|
|
else
|
2009-12-03 13:09:15 -07:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, level, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
2009-12-03 13:09:15 -07:00
|
|
|
}
|
2009-05-09 01:55:30 -06:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
if (expanded_width != width)
|
|
|
|
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
|
|
|
}
|
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;
|
|
|
|
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,
|
|
|
|
gl_iformat = 4,
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
2009-11-14 16:15:09 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, scaled_tex_w, scaled_tex_h, 0, gl_format, gl_type, NULL);
|
2010-07-17 18:18:31 -06:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2009-12-07 11:48:31 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2009-12-07 11:48:31 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
2009-11-14 16:15:09 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
if (GL_REPORT_ERROR() != GL_NO_ERROR)
|
2009-11-14 16:15:09 -07:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
2010-02-06 09:05:48 -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
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, texture);
|
2009-11-14 16:15:09 -07: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
|
|
|
|
2008-12-07 22:25:12 -07:00
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
|
2011-12-26 16:05:26 -07:00
|
|
|
if (efbcopy_state != EC_VRAM_DYNAMIC || g_ActiveConfig.bCopyEFBToTexture)
|
2010-07-12 13:30:25 -06:00
|
|
|
{
|
|
|
|
if (s_TempFramebuffer == 0)
|
2010-10-19 16:24:27 -06:00
|
|
|
glGenFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-11-14 16:31:53 -07:00
|
|
|
FramebufferManager::SetFramebuffer(s_TempFramebuffer);
|
2010-07-12 13:30:25 -06:00
|
|
|
// Bind texture to temporary framebuffer
|
2010-10-19 16:24:27 -06:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);
|
2010-07-12 13:30:25 -06:00
|
|
|
GL_REPORT_FBO_ERROR();
|
|
|
|
GL_REPORT_ERRORD();
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2010-07-12 13:30:25 -06:00
|
|
|
glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
|
|
|
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 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
|
|
|
|
2011-02-26 16:41:02 -07:00
|
|
|
PixelShaderCache::SetCurrentShader((srcFormat == PIXELFMT_Z24) ? PixelShaderCache::GetDepthMatrixProgram() : PixelShaderCache::GetColorMatrixProgram());
|
2011-01-07 12:23:57 -07:00
|
|
|
PixelShaderManager::SetColorMatrix(colmat); // set transformation
|
2010-07-12 13:30:25 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2009-03-07 02:29:25 -07:00
|
|
|
|
2011-02-26 16:41:02 -07:00
|
|
|
TargetRectangle targetSource = g_renderer->ConvertEFBRectangle(srcRect);
|
2009-07-14 18:51:24 -06:00
|
|
|
|
2010-07-12 13:30:25 -06:00
|
|
|
glBegin(GL_QUADS);
|
|
|
|
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.bottom); glVertex2f(-1, 1);
|
|
|
|
glTexCoord2f((GLfloat)targetSource.left, (GLfloat)targetSource.top ); glVertex2f(-1, -1);
|
|
|
|
glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.top ); glVertex2f( 1, -1);
|
|
|
|
glTexCoord2f((GLfloat)targetSource.right, (GLfloat)targetSource.bottom); glVertex2f( 1, 1);
|
|
|
|
glEnd();
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-07-12 13:30:25 -06:00
|
|
|
GL_REPORT_ERRORD();
|
2008-12-07 22:25:12 -07:00
|
|
|
|
2010-07-12 13:30:25 -06:00
|
|
|
// Unbind texture from temporary framebuffer
|
2010-08-28 22:56:53 -06:00
|
|
|
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0);
|
2010-07-12 13:30:25 -06:00
|
|
|
}
|
2010-10-19 16:24:27 -06:00
|
|
|
|
|
|
|
if (false == g_ActiveConfig.bCopyEFBToTexture)
|
2010-07-12 13:30:25 -06:00
|
|
|
{
|
2010-10-19 16:24:27 -06:00
|
|
|
hash = TextureConverter::EncodeToRamFromTexture(
|
|
|
|
addr,
|
2010-07-12 13:30:25 -06:00
|
|
|
read_texture,
|
2011-02-26 16:41:02 -07:00
|
|
|
srcFormat == PIXELFMT_Z24,
|
|
|
|
isIntensity,
|
|
|
|
dstFormat,
|
|
|
|
scaleByHalf,
|
|
|
|
srcRect);
|
2010-07-12 13:30:25 -06:00
|
|
|
}
|
2010-10-19 16:24:27 -06:00
|
|
|
|
2010-11-14 16:31:53 -07:00
|
|
|
FramebufferManager::SetFramebuffer(0);
|
2008-12-26 03:43:18 -07:00
|
|
|
VertexShaderManager::SetViewportChanged();
|
2010-10-19 16:24:27 -06:00
|
|
|
DisableStage(0);
|
2008-12-07 22:25:12 -07:00
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
2009-03-07 02:29:25 -07:00
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
if (g_ActiveConfig.bDumpEFBTarget)
|
|
|
|
{
|
2009-05-09 01:55:30 -06:00
|
|
|
static int count = 0;
|
2011-02-28 13:40:15 -07:00
|
|
|
SaveTexture(StringFromFormat("%sefb_frame_%i.tga", File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
|
2011-12-26 09:35:27 -07:00
|
|
|
count++).c_str(), GL_TEXTURE_2D, texture, virtual_width, virtual_height);
|
2010-10-19 16:24:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::TCacheEntry::SetTextureParameters(const TexMode0 &newmode, const TexMode1 &newmode1)
|
|
|
|
{
|
|
|
|
// TODO: not used anywhere
|
|
|
|
TexMode0 mode = newmode;
|
|
|
|
//mode1 = newmode1;
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
|
2011-03-31 19:46:18 -06:00
|
|
|
(newmode.mag_filter || g_Config.bForceFiltering) ? GL_LINEAR : GL_NEAREST);
|
2010-10-19 16:24:27 -06:00
|
|
|
|
|
|
|
if (bHaveMipMaps)
|
|
|
|
{
|
|
|
|
// TODO: not used anywhere
|
|
|
|
if (g_ActiveConfig.bForceFiltering && newmode.min_filter < 4)
|
|
|
|
mode.min_filter += 4; // take equivalent forced linear
|
|
|
|
|
|
|
|
int filt = newmode.min_filter;
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, c_MinLinearFilter[filt & 7]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, newmode1.min_lod >> 4);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, newmode1.max_lod >> 4);
|
|
|
|
glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, (newmode.lod_bias / 32.0f));
|
2009-05-09 01:55:30 -06:00
|
|
|
}
|
2010-10-19 16:24:27 -06:00
|
|
|
else
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
2011-03-31 19:46:18 -06:00
|
|
|
(g_ActiveConfig.bForceFiltering || newmode.min_filter >= 4) ? GL_LINEAR : GL_NEAREST);
|
2010-10-19 16:24:27 -06:00
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, c_WrapSettings[newmode.wrap_s]);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, c_WrapSettings[newmode.wrap_t]);
|
|
|
|
|
|
|
|
if (g_Config.iMaxAnisotropy >= 1)
|
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
|
|
|
|
(float)(1 << g_ActiveConfig.iMaxAnisotropy));
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 16:24:27 -06:00
|
|
|
TextureCache::~TextureCache()
|
|
|
|
{
|
|
|
|
if (s_TempFramebuffer)
|
|
|
|
{
|
|
|
|
glDeleteFramebuffersEXT(1, (GLuint*)&s_TempFramebuffer);
|
|
|
|
s_TempFramebuffer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCache::DisableStage(unsigned int stage)
|
2008-12-07 22:25:12 -07:00
|
|
|
{
|
2009-05-09 01:55:30 -06:00
|
|
|
glActiveTexture(GL_TEXTURE0 + stage);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDisable(GL_TEXTURE_RECTANGLE_ARB);
|
2008-12-07 22:25:12 -07:00
|
|
|
}
|
2009-01-11 15:25:57 -07:00
|
|
|
|
|
|
|
}
|