added an option to copy textures from the EFB to system memory. this is slower but shouldn't cause the compatibility issues the previous method of copying them directly to a GL texture has. the new method can be tested by disabling "copy EFB to texture" in the hacks section. the new method still needs some tweaks.

fixed some off-by-one errors in the EFB to texture copy and the scissor box. also fixed a couple asserts I was getting in the volume directory stuff.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1853 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
donkopunchstania
2009-01-11 22:25:57 +00:00
parent 394b040f61
commit d6e8c1f5d0
15 changed files with 928 additions and 57 deletions
+4 -1
View File
@@ -332,7 +332,7 @@ void CVolumeDirectory::BuildFST()
}
// overflow check
_dbg_assert_(DVDINTERFACE, nameOffset == m_fstSize);
_dbg_assert_(DVDINTERFACE, nameOffset == m_totalNameSize);
// write FST size and location
_dbg_assert_(DVDINTERFACE, m_diskHeader);
@@ -344,6 +344,9 @@ void CVolumeDirectory::BuildFST()
void CVolumeDirectory::WriteToBuffer(u64 _SrcStartAddress, u64 _SrcLength, u8* _Src,
u64& _Address, u64& _Length, u8*& _pBuffer) const
{
if(_Length == 0)
return;
_dbg_assert_(DVDINTERFACE, _Address >= _SrcStartAddress);
u64 srcOffset = _Address - _SrcStartAddress;
@@ -1013,6 +1013,14 @@
RelativePath=".\Src\stdafx.h"
>
</File>
<File
RelativePath=".\Src\TextureConversionShader.cpp"
>
</File>
<File
RelativePath=".\Src\TextureConversionShader.h"
>
</File>
<File
RelativePath=".\Src\TextureConverter.cpp"
>
@@ -30,6 +30,7 @@
#include "OpcodeDecoding.h"
#include "TextureMngr.h"
#include "TextureDecoder.h"
#include "TextureConverter.h"
#include "VertexShaderManager.h"
#include "PixelShaderManager.h"
#include "XFB.h"
@@ -431,8 +432,8 @@ void BPWritten(int addr, int changes, int newval)
TRectangle rc = {
(int)(bpmem.copyTexSrcXY.x),
(int)(bpmem.copyTexSrcXY.y),
(int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x)),
(int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y))
(int)((bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1)),
(int)((bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1))
};
float MValueX = OpenGL_GetXmax();
float MValueY = OpenGL_GetYmax();
@@ -449,16 +450,21 @@ void BPWritten(int addr, int changes, int newval)
PE_copy.Hex = bpmem.triggerEFBCopy;
if (PE_copy.copy_to_xfb == 0) {
if(g_Config.bEFBToTextureDisable) {
// EFB to texture
// for some reason it sets bpmem.zcontrol.pixel_format to PIXELFMT_Z24 every time a zbuffer format is given as a dest to GXSetTexCopyDst
if (g_Config.bEFBCopyDisable) {
glViewport(rc.left,rc.bottom,rc.right,rc.top);
glScissor(rc.left,rc.bottom,rc.right,rc.top);
}
else
// EFB to texture
// for some reason it sets bpmem.zcontrol.pixel_format to PIXELFMT_Z24 every time a zbuffer format is given as a dest to GXSetTexCopyDst
TextureMngr::CopyRenderTargetToTexture(bpmem.copyTexDest<<5, bpmem.zcontrol.pixel_format==PIXELFMT_Z24, PE_copy.intensity_fmt>0,
else if (g_Config.bEFBToTextureEnable) {
TextureMngr::CopyRenderTargetToTexture(bpmem.copyTexDest<<5, bpmem.zcontrol.pixel_format==PIXELFMT_Z24, PE_copy.intensity_fmt>0,
(PE_copy.target_pixel_format/2)+((PE_copy.target_pixel_format&1)*8), PE_copy.half_scale>0, &rc);
}
}
else {
TextureConverter::EncodeToRam(bpmem.copyTexDest<<5, bpmem.zcontrol.pixel_format==PIXELFMT_Z24, PE_copy.intensity_fmt>0,
(PE_copy.target_pixel_format/2)+((PE_copy.target_pixel_format&1)*8), PE_copy.half_scale>0, rc);
}
}
else {
// EFB to XFB
if (g_Config.bUseXFB)
@@ -78,10 +78,11 @@ void Config::Load()
iniFile.Get("Enhancements", "ForceFiltering", &bForceFiltering, 0);
iniFile.Get("Enhancements", "MaxAnisotropy", &iMaxAnisotropy, 3); // NOTE - this is x in (1 << x)
iniFile.Get("Hacks", "EFBToTextureDisable", &bEFBToTextureDisable, 0);
iniFile.Get("Hacks", "EFBToTextureDisableHotKey", &bEFBToTextureDisableHotKey, 0);
iniFile.Get("Hacks", "EFBCopyDisable", &bEFBCopyDisable, 0);
iniFile.Get("Hacks", "EFBCopyDisableHotKey", &bEFBCopyDisableHotKey, 0);
iniFile.Get("Hacks", "ProjectionHax1", &bProjectionHax1, 0);
iniFile.Get("Hacks", "ProjectionHax2", &bProjectionHax2, 0);
iniFile.Get("Hacks", "EFBToTextureEnable", &bEFBToTextureEnable, 1);
}
void Config::Save()
@@ -116,10 +117,11 @@ void Config::Save()
iniFile.Set("Enhancements", "ForceFiltering", bForceFiltering);
iniFile.Set("Enhancements", "MaxAnisotropy", iMaxAnisotropy);
iniFile.Set("Hacks", "EFBToTextureDisable", bEFBToTextureDisable);
iniFile.Set("Hacks", "EFBToTextureDisableHotKey", bEFBToTextureDisableHotKey);
iniFile.Set("Hacks", "EFBCopyDisable", bEFBCopyDisable);
iniFile.Set("Hacks", "EFBCopyDisableHotKey", bEFBCopyDisableHotKey);
iniFile.Set("Hacks", "ProjectionHax1", bProjectionHax1);
iniFile.Set("Hacks", "ProjectionHax2", bProjectionHax2);
iniFile.Set("Hacks", "EFBToTextureEnable", bEFBToTextureEnable);
iniFile.Save(FULL_CONFIG_DIR "gfx_opengl.ini");
}
+3 -2
View File
@@ -64,10 +64,11 @@ struct Config
bool bDumpTextures;
// Hacks
bool bEFBToTextureDisable;
bool bEFBToTextureDisableHotKey;
bool bEFBCopyDisable;
bool bEFBCopyDisableHotKey;
bool bProjectionHax1;
bool bProjectionHax2;
bool bEFBToTextureEnable;
int iLog; // CONF_ bits
int iSaveTargetId;
@@ -49,11 +49,12 @@ BEGIN_EVENT_TABLE(ConfigDialog,wxDialog)
EVT_CHECKBOX(ID_DUMPTEXTURES, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_DISABLELIGHTING, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_DISABLETEXTURING, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_EFBTOTEXTUREDISABLE, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_EFBTOTEXTUREDISABLEHOTKEY, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_EFBCOPYDISABLE, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_EFBCOPYDISABLEHOTKEY, ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_PROJECTIONHACK1,ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_PROJECTIONHACK2,ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_SAFETEXTURECACHE,ConfigDialog::AdvancedSettingsChanged)
EVT_CHECKBOX(ID_EFBTOTEXTUREENABLE, ConfigDialog::AdvancedSettingsChanged)
EVT_DIRPICKER_CHANGED(ID_TEXTUREPATH, ConfigDialog::TexturePathChange)
END_EVENT_TABLE()
@@ -226,26 +227,31 @@ void ConfigDialog::CreateGUIControls()
// Hacks
sbHacks = new wxStaticBoxSizer(wxVERTICAL, m_PageAdvanced, wxT("Hacks"));
m_EFBToTextureDisable = new wxCheckBox(m_PageAdvanced,
ID_EFBTOTEXTUREDISABLE, wxT("Disable copy EFB to texture"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_EFBToTextureDisable->SetToolTip(wxT("Do not copy the Embedded Framebuffer (EFB)"
" to the\nTexture. This may result in a speed increase."));
m_EFBToTextureDisable->Enable(true);
m_EFBToTextureDisable->SetValue(g_Config.bEFBToTextureDisable);
m_EFBToTextureDisableHotKey = new wxCheckBox(m_PageAdvanced,
ID_EFBTOTEXTUREDISABLEHOTKEY, wxT("With hotkey E"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_EFBToTextureDisableHotKey->SetToolTip(wxT("Use the E key to turn this option on and off"));
m_EFBCopyDisable = new wxCheckBox(m_PageAdvanced,
ID_EFBCOPYDISABLE, wxT("Disable copy EFB"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_EFBCopyDisable->SetToolTip(wxT("Do not copy the Embedded Framebuffer (EFB)."
" This may result in a speed increase."));
m_EFBCopyDisable->Enable(true);
m_EFBCopyDisable->SetValue(g_Config.bEFBCopyDisable);
m_EFBCopyDisableHotKey = new wxCheckBox(m_PageAdvanced,
ID_EFBCOPYDISABLEHOTKEY, wxT("With hotkey E"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_EFBCopyDisableHotKey->SetToolTip(wxT("Use the E key to turn this option on and off"));
#ifndef _WIN32
// JPeterson set the hot key to be Win32-specific
m_EFBToTextureDisableHotKey->Enable(false);
m_EFBCopyDisableHotKey->Enable(false);
#endif
m_EFBToTextureDisableHotKey->SetValue(g_Config.bEFBToTextureDisableHotKey);
m_EFBCopyDisableHotKey->SetValue(g_Config.bEFBCopyDisableHotKey);
m_SafeTextureCache = new wxCheckBox(m_PageAdvanced, ID_SAFETEXTURECACHE, wxT("Safe texture cache"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_SafeTextureCache->SetToolTip(wxT("This is useful to prevent Metroid Prime from crashing, but can cause problems in other games."));
m_SafeTextureCache->Enable(true);
m_SafeTextureCache->SetValue(g_Config.bSafeTextureCache);
m_EFBToTextureEnable = new wxCheckBox(m_PageAdvanced, ID_EFBTOTEXTUREENABLE, wxT("Copy EFB to texture"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_EFBToTextureEnable->SetToolTip(wxT("This is faster than copying the EFB to RAM, but may cause missing/corrupt textures or effects."));
m_EFBToTextureEnable->Enable(true);
m_EFBToTextureEnable->SetValue(g_Config.bEFBToTextureEnable);
m_ProjectionHax1 = new wxCheckBox(m_PageAdvanced, ID_PROJECTIONHACK1, wxT("Projection before R945"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_ProjectionHax1->SetToolTip(wxT("This may reveal otherwise invisible graphics"
" in\ngames like Mario Galaxy or Ikaruga."));
@@ -281,11 +287,12 @@ void ConfigDialog::CreateGUIControls()
sAdvanced->Add(sbUtilities, 0, wxEXPAND|wxALL, 5);
sHacks = new wxGridBagSizer(0, 0);
sHacks->Add(m_EFBToTextureDisable, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALL, 5);
sHacks->Add(m_EFBToTextureDisableHotKey, wxGBPosition(0, 1), wxGBSpan(1, 1), wxALL, 5);
sHacks->Add(m_EFBCopyDisable, wxGBPosition(0, 0), wxGBSpan(1, 1), wxALL, 5);
sHacks->Add(m_EFBCopyDisableHotKey, wxGBPosition(0, 1), wxGBSpan(1, 1), wxALL, 5);
sHacks->Add(m_ProjectionHax1, wxGBPosition(1, 0), wxGBSpan(1, 1), wxALL, 5);
sHacks->Add(m_ProjectionHax2, wxGBPosition(2, 0), wxGBSpan(1, 2), wxALL, 5);
sHacks->Add(m_SafeTextureCache, wxGBPosition(3, 0), wxGBSpan(1, 1), wxALL, 5);
sHacks->Add(m_EFBToTextureEnable, wxGBPosition(1, 1), wxGBSpan(1, 1), wxALL, 5);
sbHacks->Add(sHacks);
sAdvanced->Add(sbHacks, 0, wxEXPAND|wxALL, 5);
m_PageAdvanced->SetSizer(sAdvanced);
@@ -421,11 +428,11 @@ void ConfigDialog::AdvancedSettingsChanged(wxCommandEvent& event)
break;
case ID_TEXTUREPATH:
break;
case ID_EFBTOTEXTUREDISABLE:
g_Config.bEFBToTextureDisable = m_EFBToTextureDisable->IsChecked();
case ID_EFBCOPYDISABLE:
g_Config.bEFBCopyDisable = m_EFBCopyDisable->IsChecked();
break;
case ID_EFBTOTEXTUREDISABLEHOTKEY:
g_Config.bEFBToTextureDisableHotKey = m_EFBToTextureDisableHotKey->IsChecked();
case ID_EFBCOPYDISABLEHOTKEY:
g_Config.bEFBCopyDisableHotKey = m_EFBCopyDisableHotKey->IsChecked();
break;
case ID_PROJECTIONHACK1:
g_Config.bProjectionHax1 = m_ProjectionHax1->IsChecked();
@@ -436,6 +443,14 @@ void ConfigDialog::AdvancedSettingsChanged(wxCommandEvent& event)
case ID_SAFETEXTURECACHE:
g_Config.bSafeTextureCache = m_SafeTextureCache->IsChecked();
break;
case ID_EFBTOTEXTUREENABLE:
{
bool wasEnabled = g_Config.bEFBToTextureEnable;
g_Config.bEFBToTextureEnable = m_EFBToTextureEnable->IsChecked();
if(wasEnabled && !g_Config.bEFBToTextureEnable)
TextureMngr::ClearRenderTargets();
}
break;
default:
break;
}
@@ -97,10 +97,11 @@ class ConfigDialog : public wxDialog
wxCheckBox *m_DisableTexturing;
wxCheckBox *m_DumpTextures;
wxDirPickerCtrl *m_TexturePath;
wxCheckBox *m_EFBToTextureDisable, *m_EFBToTextureDisableHotKey;
wxCheckBox *m_EFBCopyDisable, *m_EFBCopyDisableHotKey;
wxCheckBox *m_ProjectionHax1;
wxCheckBox *m_ProjectionHax2;
wxCheckBox *m_SafeTextureCache;
wxCheckBox *m_EFBToTextureEnable;
enum
{
@@ -143,9 +144,10 @@ class ConfigDialog : public wxDialog
ID_DUMPTEXTURES,
ID_TEXTUREPATH,
ID_EFBTOTEXTUREDISABLE, ID_EFBTOTEXTUREDISABLEHOTKEY,
ID_EFBCOPYDISABLE, ID_EFBCOPYDISABLEHOTKEY,
ID_PROJECTIONHACK1,
ID_PROJECTIONHACK2
ID_PROJECTIONHACK2,
ID_EFBTOTEXTUREENABLE
};
void OnClose(wxCloseEvent& event);
@@ -173,11 +173,11 @@ namespace EmuWindow
hypotheticalScene->sendMessage(KEYDOWN...);
*/
case 'E': // EFB hotkey
if(g_Config.bEFBToTextureDisableHotKey)
if(g_Config.bEFBCopyDisableHotKey)
{
g_Config.bEFBToTextureDisable = !g_Config.bEFBToTextureDisable;
g_Config.bEFBCopyDisable = !g_Config.bEFBCopyDisable;
Renderer::AddMessage(StringFromFormat("Copy EFB was turned %s",
g_Config.bEFBToTextureDisable ? "off" : "on").c_str(), 5000);
g_Config.bEFBCopyDisable ? "off" : "on").c_str(), 5000);
}
break;
}
@@ -571,6 +571,8 @@ void Renderer::SetColorMask()
// bpmem.scissorTL.x, y = 342x342
// bpmem.scissorBR.x, y = 981x821
// Renderer::GetTargetHeight() = the fixed ini file setting
// donkopunchstania - it appears scissorBR is the bottom right pixel inside the scissor box
// therefore the width and height are (scissorBR + 1) - scissorTL
bool Renderer::SetScissorRect()
{
int xoff = bpmem.scissorOffset.x * 2 - 342;
@@ -585,11 +587,11 @@ bool Renderer::SetScissorRect()
rc_top *= MValueY;
if (rc_top < 0) rc_top = 0;
float rc_right = bpmem.scissorBR.x - xoff - 342; // right = 640
float rc_right = bpmem.scissorBR.x - xoff - 341; // right = 640
rc_right *= MValueX;
if (rc_right > 640 * MValueX) rc_right = 640 * MValueX;
float rc_bottom = bpmem.scissorBR.y - yoff - 342; // bottom = 480
float rc_bottom = bpmem.scissorBR.y - yoff - 341; // bottom = 480
rc_bottom *= MValueY;
if (rc_bottom > 480 * MValueY) rc_bottom = 480 * MValueY;
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,41 @@
// Copyright (C) 2003-2008 Dolphin 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
// 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/
#ifndef _TEXTURECONVERSIONSHADER_H
#define _TEXTURECONVERSIONSHADER_H
#include "Common.h"
#include "TextureDecoder.h"
#include <Cg/cg.h>
namespace TextureConversionShader
{
u16 GetBlockWidthInTexels(u32 format);
u16 GetBlockHeightInTexels(u32 format);
u16 GetEncodedSampleCount(u32 format);
char *GenerateEncodingShader(u32 format);
void SetShaderParameters(u32 width, u32 height, u32 offsetX, u32 offsetY, float pixelStride, u32 format);
}
#endif
@@ -16,9 +16,12 @@
// http://code.google.com/p/dolphin-emu/
#include "TextureConverter.h"
#include "TextureConversionShader.h"
#include "PixelShaderCache.h"
#include "VertexShaderManager.h"
#include "Globals.h"
#include "Config.h"
#include "ImageWrite.h"
#include "GLUtil.h"
#include "Render.h"
@@ -35,6 +38,11 @@ const int renderBufferHeight = 1024;
static FRAGMENTSHADER s_rgbToYuyvProgram;
static FRAGMENTSHADER s_yuyvToRgbProgram;
// todo - store shaders in a smarter way - there are not 64 different copy texture formats
const u32 NUM_ENCODING_PROGRAMS = 64;
static FRAGMENTSHADER s_encodingPrograms[NUM_ENCODING_PROGRAMS];
void CreateRgbToYuyvProgram()
{
// output is BGRA because that is slightly faster than RGBA
@@ -50,10 +58,12 @@ void CreateRgbToYuyvProgram()
" float y0 = (0.257f * c0.r) + (0.504f * c0.g) + (0.098f * c0.b) + 0.0625f;\n"
" float u0 =-(0.148f * c0.r) - (0.291f * c0.g) + (0.439f * c0.b) + 0.5f;\n"
" float v0 = (0.439f * c0.r) - (0.368f * c0.g) - (0.071f * c0.b) + 0.5f;\n"
" float y1 = (0.257f * c1.r) + (0.504f * c1.g) + (0.098f * c1.b) + 0.0625f;\n"
" float v1 = (0.439f * c1.r) - (0.368f * c1.g) - (0.071f * c1.b) + 0.5f;\n"
" float u1 =-(0.148f * c1.r) - (0.291f * c1.g) + (0.439f * c1.b) + 0.5f;\n"
" float v1 = (0.439f * c1.r) - (0.368f * c1.g) - (0.071f * c1.b) + 0.5f;\n"
" ocol0 = float4(y1, u0, y0, v1);\n"
" ocol0 = float4(y1, (u0 + u1) / 2, y0, (v0 + v1) / 2);\n"
"}\n";
if (!PixelShaderCache::CompilePixelShader(s_rgbToYuyvProgram, FProgram)) {
@@ -88,6 +98,39 @@ void CreateYuyvToRgbProgram()
}
}
FRAGMENTSHADER& GetOrCreateEncodingShader(u32 format)
{
if(format > NUM_ENCODING_PROGRAMS)
{
PanicAlert("Unknown texture copy format: 0x%x\n", format);
return s_encodingPrograms[0];
}
// todo - this does not handle the case that an application is using RGB555/4443
// and switches EFB formats between a format that does and does not support alpha
if(s_encodingPrograms[format].glprogid == 0)
{
char* shader = TextureConversionShader::GenerateEncodingShader(format);
#if defined(_DEBUG) || defined(DEBUGFAST)
if (g_Config.iLog & CONF_SAVESHADERS && shader) {
static int counter = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%s/enc_%04i.txt", g_Config.texDumpPath, counter++);
SaveData(szTemp, shader);
}
#endif
if (!PixelShaderCache::CompilePixelShader(s_encodingPrograms[format], shader)) {
const char* error = cgGetLastListing(g_cgcontext);
ERROR_LOG("Failed to create encoding fragment program\n");
}
}
return s_encodingPrograms[format];
}
void Init()
{
glGenFramebuffersEXT( 1, &s_frameBuffer);
@@ -114,16 +157,14 @@ void Shutdown()
glDeleteFramebuffersEXT(1, &s_frameBuffer);
}
void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight)
u8* destAddr, int dstWidth, int dstHeight, bool linearFilter, FRAGMENTSHADER& shader)
{
Renderer::SetRenderMode(Renderer::RM_Normal);
Renderer::ResetGLState();
float dstFormatFactor = 0.5f;
float dstFmtWidth = dstWidth * dstFormatFactor;
// switch to texture converter frame buffer
// attach render buffer as color destination
Renderer::SetFramebuffer(s_frameBuffer);
@@ -134,18 +175,28 @@ void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc,
// set source texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, srcTexture);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
if(linearFilter)
{
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
else
{
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
}
//
TextureMngr::EnableTexRECT(0);
for (int i = 1; i < 8; ++i)
TextureMngr::DisableStage(i);
GL_REPORT_ERRORD();
glViewport(0, 0, (GLsizei)dstFmtWidth, (GLsizei)dstHeight);
glViewport(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, s_rgbToYuyvProgram.glprogid);
glBindProgramARB( GL_FRAGMENT_PROGRAM_ARB, shader.glprogid);
glBegin(GL_QUADS);
glTexCoord2f((float)sourceRc.left, (float)sourceRc.top); glVertex2f(-1,-1);
@@ -155,8 +206,8 @@ void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc,
glEnd();
GL_REPORT_ERRORD();
// TODO: this is real slow. try using a pixel buffer object.
glReadPixels(0, 0, (GLsizei)dstFmtWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr);
// TODO: make this less slow.
glReadPixels(0, 0, (GLsizei)dstWidth, (GLsizei)dstHeight, GL_BGRA, GL_UNSIGNED_BYTE, destAddr);
GL_REPORT_ERRORD();
Renderer::SetFramebuffer(0);
@@ -170,6 +221,74 @@ void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc,
GL_REPORT_ERRORD();
}
void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, bool bScaleByHalf, const TRectangle& source)
{
u32 format = copyfmt;
if(bFromZBuffer)
{
format |= _GX_TF_ZTF;
if(copyfmt == 11)
format = GX_TF_Z16;
else if(format < GX_TF_Z8 || format > GX_TF_Z24X8)
format |= _GX_TF_CTF;
}
else
{
if(copyfmt > GX_TF_RGBA8 || (copyfmt < GX_TF_RGB565 && !bIsIntensityFmt))
format |= _GX_TF_CTF;
}
FRAGMENTSHADER& fs = GetOrCreateEncodingShader(format);
if(fs.glprogid == 0)
return;
u8* ptr = Memory_GetPtr(address);
u32 target = bFromZBuffer?Renderer::GetZBufferTarget():Renderer::GetRenderTarget();
s32 width = source.right - source.left;
s32 height = source.bottom - source.top;
if(bScaleByHalf)
{
width /= 2;
height /= 2;
}
u16 blkW = TextureConversionShader::GetBlockWidthInTexels(format) - 1;
u16 blkH = TextureConversionShader::GetBlockHeightInTexels(format) - 1;
u16 samples = TextureConversionShader::GetEncodedSampleCount(format);
// only copy on cache line boundaries
// extra pixels are copied but not displayed in the resulting texture
s32 expandedWidth = (width + blkW) & (~blkW);
s32 expandedHeight = (height + blkH) & (~blkH);
u32 top = Renderer::GetTargetHeight() - (source.top + expandedHeight);
TextureConversionShader::SetShaderParameters(expandedWidth, expandedHeight, source.left, top, bScaleByHalf?2.0f:1.0f, format);
TRectangle scaledSource;
scaledSource.top = 0;
scaledSource.bottom = expandedHeight;
scaledSource.left = 0;
scaledSource.right = expandedWidth / samples;
EncodeToRam(target, scaledSource, ptr, expandedWidth / samples, expandedHeight, bScaleByHalf, fs);
if (bFromZBuffer )
Renderer::SetZBufferRender(); // notify for future settings
}
void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight)
{
EncodeToRam(srcTexture, sourceRc, destAddr, dstWidth / 2, dstHeight, false, s_rgbToYuyvProgram);
}
void DecodeToTexture(u8* srcAddr, int srcWidth, int srcHeight, GLuint destTexture)
{
Renderer::SetRenderMode(Renderer::RM_Normal);
@@ -190,7 +309,7 @@ void DecodeToTexture(u8* srcAddr, int srcWidth, int srcHeight, GLuint destTextur
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, s_srcTexture);
// TODO: this is slow. try using a pixel buffer object.
// TODO: make this less slow.
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8, (GLsizei)srcFmtWidth, (GLsizei)srcHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, srcAddr);
TextureMngr::EnableTexRECT(0);
@@ -29,6 +29,9 @@ namespace TextureConverter
void Init();
void Shutdown();
void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt,
u32 copyfmt, bool bScaleByHalf, const TRectangle& source);
void EncodeToRam(GLuint srcTexture, const TRectangle& sourceRc,
u8* destAddr, int dstWidth, int dstHeight);
@@ -627,7 +627,7 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
GL_REPORT_ERRORD();
//SaveTexture("frame.tga", GL_TEXTURE_RECTANGLE_ARB, entry.texture, entry.w, entry.h);
//SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, Renderer::GetZBufferTarget(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight());
//SaveTexture("tex.tga", GL_TEXTURE_RECTANGLE_ARB, bFromZBuffer?Renderer::GetZBufferTarget():Renderer::GetRenderTarget(), Renderer::GetTargetWidth(), Renderer::GetTargetHeight());
}
void TextureMngr::EnableTex2D(int stage)
@@ -670,3 +670,10 @@ void TextureMngr::DisableStage(int stage)
glDisable(GL_TEXTURE_RECTANGLE_ARB);
}
}
void TextureMngr::ClearRenderTargets()
{
TexCache::iterator iter = textures.begin();
for (; iter!=textures.end(); iter++)
iter->second.isRenderTarget = false;
}
@@ -79,6 +79,8 @@ public:
static void EnableTex2D(int stage);
static void EnableTexRECT(int stage);
static void DisableStage(int stage); // sets active texture
static void ClearRenderTargets(); // sets render target value of all textures to false
};
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);