d3d: a little speedup in efb to ram please test and let me know the result
opengl: a little code cleanup and possible speedup in texture recreation. d3d and opengl :plugins corrected the efb alignment when efb to ram is used. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4637 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
afdfd29fcd
commit
a99a1451f9
|
@ -258,10 +258,10 @@ void dumpMatrix(D3DXMATRIX &mtx)
|
||||||
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
TargetRectangle Renderer::ConvertEFBRectangle(const EFBRectangle& rc)
|
||||||
{
|
{
|
||||||
TargetRectangle result;
|
TargetRectangle result;
|
||||||
result.left = (int)ceilf((((float)rc.left * s_target_width) / (float)EFB_WIDTH)-0.5f) ;
|
result.left = (int)((rc.left) * xScale) ;
|
||||||
result.top = (int)ceilf((((float)rc.top * s_target_height) / (float)EFB_HEIGHT)-0.5f);
|
result.top = (int)((rc.top) * yScale);
|
||||||
result.right = (int)floorf((((float)rc.right * s_target_width) / (float)EFB_WIDTH)+0.5f) ;
|
result.right = (int)((rc.right) * xScale) ;
|
||||||
result.bottom = (int)floorf((((float)rc.bottom * s_target_height) / (float)EFB_HEIGHT)+0.5f);
|
result.bottom = (int)((rc.bottom) * yScale);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,14 +637,10 @@ u32 Renderer::AccessEFB(EFBAccessType type, int x, int y)
|
||||||
LPDIRECT3DTEXTURE9 read_texture = FBManager::GetEFBDepthTexture(source_rect);
|
LPDIRECT3DTEXTURE9 read_texture = FBManager::GetEFBDepthTexture(source_rect);
|
||||||
|
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
|
|
||||||
|
|
||||||
D3D::drawShadedTexQuad(read_texture,&RectToLock, Renderer::GetTargetWidth() , Renderer::GetTargetHeight(),&PixelRect,(BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram():PixelShaderCache::GetDepthMatrixProgram(),VertexShaderCache::GetSimpleVertexShader());
|
D3D::drawShadedTexQuad(read_texture,&RectToLock, Renderer::GetTargetWidth() , Renderer::GetTargetHeight(),&PixelRect,(BufferFormat == FOURCC_RAWZ)?PixelShaderCache::GetColorMatrixProgram():PixelShaderCache::GetDepthMatrixProgram(),VertexShaderCache::GetSimpleVertexShader());
|
||||||
|
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER);
|
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MIPFILTER);
|
|
||||||
|
|
||||||
hr = D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
hr = D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
||||||
hr = D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
hr = D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
||||||
|
@ -785,9 +781,9 @@ void UpdateViewport()
|
||||||
vp.Width = Width;
|
vp.Width = Width;
|
||||||
vp.Height = Height;
|
vp.Height = Height;
|
||||||
//some games set invalids values for z min and z max so fix them to the max an min alowed and let the shaders do this work
|
//some games set invalids values for z min and z max so fix them to the max an min alowed and let the shaders do this work
|
||||||
vp.MinZ = (xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
|
vp.MinZ = 0.0f;//(xfregs.rawViewport[5] - xfregs.rawViewport[2]) / 16777216.0f;
|
||||||
vp.MaxZ = xfregs.rawViewport[5] / 16777216.0f;
|
vp.MaxZ =1.0f;// xfregs.rawViewport[5] / 16777216.0f;
|
||||||
if(vp.MinZ < 0.0f)
|
/*if(vp.MinZ < 0.0f)
|
||||||
vp.MinZ = 0.0f;
|
vp.MinZ = 0.0f;
|
||||||
if(vp.MinZ > 1.0f)
|
if(vp.MinZ > 1.0f)
|
||||||
vp.MinZ = 1.0f;
|
vp.MinZ = 1.0f;
|
||||||
|
@ -800,7 +796,7 @@ void UpdateViewport()
|
||||||
float temp = vp.MinZ;
|
float temp = vp.MinZ;
|
||||||
vp.MinZ = vp.MaxZ;
|
vp.MinZ = vp.MaxZ;
|
||||||
vp.MaxZ = temp;
|
vp.MaxZ = temp;
|
||||||
}
|
}*/
|
||||||
D3D::dev->SetViewport(&vp);
|
D3D::dev->SetViewport(&vp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -295,7 +295,6 @@ void TextureCache::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, boo
|
||||||
|
|
||||||
int tex_w = (abs(source_rect.GetWidth()) >> bScaleByHalf);
|
int tex_w = (abs(source_rect.GetWidth()) >> bScaleByHalf);
|
||||||
int tex_h = (abs(source_rect.GetHeight()) >> bScaleByHalf);
|
int tex_h = (abs(source_rect.GetHeight()) >> bScaleByHalf);
|
||||||
|
|
||||||
TexCache::iterator iter;
|
TexCache::iterator iter;
|
||||||
LPDIRECT3DTEXTURE9 tex;
|
LPDIRECT3DTEXTURE9 tex;
|
||||||
iter = textures.find(address);
|
iter = textures.find(address);
|
||||||
|
@ -476,14 +475,22 @@ have_texture:
|
||||||
sourcerect.top = targetSource.top;
|
sourcerect.top = targetSource.top;
|
||||||
|
|
||||||
if(bScaleByHalf)
|
if(bScaleByHalf)
|
||||||
|
{
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||||
|
D3D::dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
||||||
|
D3D::dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
D3DFORMAT bformat = FBManager::GetEFBDepthRTSurfaceFormat();
|
D3DFORMAT bformat = FBManager::GetEFBDepthRTSurfaceFormat();
|
||||||
D3D::drawShadedTexQuad(read_texture,&sourcerect, Renderer::GetTargetWidth() , Renderer::GetTargetHeight(),&destrect,((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer)? PixelShaderCache::GetDepthMatrixProgram(): PixelShaderCache::GetColorMatrixProgram(),VertexShaderCache::GetSimpleVertexShader());
|
D3D::drawShadedTexQuad(read_texture,&sourcerect, Renderer::GetTargetWidth() , Renderer::GetTargetHeight(),&destrect,((bformat != FOURCC_RAWZ && bformat != D3DFMT_D24X8) && bFromZBuffer)? PixelShaderCache::GetDepthMatrixProgram(): PixelShaderCache::GetColorMatrixProgram(),VertexShaderCache::GetSimpleVertexShader());
|
||||||
|
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
||||||
|
D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER);
|
||||||
|
|
||||||
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
D3D::dev->SetRenderTarget(0, FBManager::GetEFBColorRTSurface());
|
||||||
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
||||||
|
|
|
@ -33,18 +33,21 @@
|
||||||
#include "D3DUtil.h"
|
#include "D3DUtil.h"
|
||||||
#include "D3DShader.h"
|
#include "D3DShader.h"
|
||||||
#include "TextureCache.h"
|
#include "TextureCache.h"
|
||||||
|
#include "Math.h"
|
||||||
|
|
||||||
namespace TextureConverter
|
namespace TextureConverter
|
||||||
{
|
{
|
||||||
|
struct TransformBuffer
|
||||||
/*static LPDIRECT3DTEXTURE9 s_texConvFrameBuffer = 0;
|
{
|
||||||
static LPDIRECT3DTEXTURE9 s_srcTexture = 0; // for decoding from RAM
|
LPDIRECT3DTEXTURE9 FBTexture;
|
||||||
static u32 s_srcTextureWidth = 0;
|
LPDIRECT3DSURFACE9 RenderSurface;
|
||||||
static u32 s_srcTextureHeight = 0;
|
LPDIRECT3DSURFACE9 ReadSurface;
|
||||||
static LPDIRECT3DSURFACE9 s_texConvReadSurface = 0;
|
int Width;
|
||||||
|
int Height;
|
||||||
const int renderBufferWidth = 1024;
|
};
|
||||||
const int renderBufferHeight = 1024;*/
|
const u32 NUM_TRANSFORM_BUFFERS = 16;
|
||||||
|
static TransformBuffer TrnBuffers[NUM_TRANSFORM_BUFFERS];
|
||||||
|
static u32 WorkingBuffers = 0;
|
||||||
|
|
||||||
static LPDIRECT3DPIXELSHADER9 s_rgbToYuyvProgram = NULL;
|
static LPDIRECT3DPIXELSHADER9 s_rgbToYuyvProgram = NULL;
|
||||||
static LPDIRECT3DPIXELSHADER9 s_yuyvToRgbProgram = NULL;
|
static LPDIRECT3DPIXELSHADER9 s_yuyvToRgbProgram = NULL;
|
||||||
|
@ -136,17 +139,21 @@ LPDIRECT3DPIXELSHADER9 GetOrCreateEncodingShader(u32 format)
|
||||||
|
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
/*HRESULT hr = D3D::dev->CreateTexture(renderBufferWidth, renderBufferHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
|
|
||||||
D3DPOOL_DEFAULT, &s_texConvFrameBuffer, NULL);
|
|
||||||
hr = D3D::dev->CreateTexture(renderBufferWidth, renderBufferHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
|
|
||||||
D3DPOOL_DEFAULT, &s_srcTexture, NULL);
|
|
||||||
hr = D3D::dev->CreateOffscreenPlainSurface(renderBufferWidth, renderBufferWidth, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &s_texConvReadSurface, NULL );*/
|
|
||||||
for (unsigned int i = 0; i < NUM_ENCODING_PROGRAMS; i++)
|
for (unsigned int i = 0; i < NUM_ENCODING_PROGRAMS; i++)
|
||||||
{
|
{
|
||||||
s_encodingPrograms[i] = NULL;
|
s_encodingPrograms[i] = NULL;
|
||||||
}
|
}
|
||||||
|
for (unsigned int i = 0; i < NUM_TRANSFORM_BUFFERS; i++)
|
||||||
|
{
|
||||||
|
TrnBuffers[i].FBTexture = NULL;
|
||||||
|
TrnBuffers[i].RenderSurface = NULL;
|
||||||
|
TrnBuffers[i].ReadSurface = NULL;
|
||||||
|
TrnBuffers[i].Width = 0;
|
||||||
|
TrnBuffers[i].Height = 0;
|
||||||
|
}
|
||||||
CreateRgbToYuyvProgram();
|
CreateRgbToYuyvProgram();
|
||||||
CreateYuyvToRgbProgram();
|
CreateYuyvToRgbProgram();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown()
|
void Shutdown()
|
||||||
|
@ -158,22 +165,30 @@ void Shutdown()
|
||||||
s_yuyvToRgbProgram->Release();
|
s_yuyvToRgbProgram->Release();
|
||||||
s_yuyvToRgbProgram=NULL;
|
s_yuyvToRgbProgram=NULL;
|
||||||
|
|
||||||
/*if(s_texConvReadSurface)
|
|
||||||
s_texConvReadSurface->Release();
|
|
||||||
s_texConvReadSurface=NULL;*/
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < NUM_ENCODING_PROGRAMS; i++)
|
for (unsigned int i = 0; i < NUM_ENCODING_PROGRAMS; i++)
|
||||||
{
|
{
|
||||||
if(s_encodingPrograms[i])
|
if(s_encodingPrograms[i])
|
||||||
s_encodingPrograms[i]->Release();
|
s_encodingPrograms[i]->Release();
|
||||||
s_encodingPrograms[i] = NULL;
|
s_encodingPrograms[i] = NULL;
|
||||||
}
|
}
|
||||||
/*if(s_srcTexture)
|
for (unsigned int i = 0; i < NUM_TRANSFORM_BUFFERS; i++)
|
||||||
s_srcTexture->Release();
|
{
|
||||||
s_srcTexture=NULL;
|
if(TrnBuffers[i].RenderSurface != NULL)
|
||||||
if(s_texConvFrameBuffer)
|
TrnBuffers[i].RenderSurface->Release();
|
||||||
s_texConvFrameBuffer->Release();
|
TrnBuffers[i].RenderSurface = NULL;
|
||||||
s_texConvFrameBuffer = NULL;*/
|
|
||||||
|
if(TrnBuffers[i].ReadSurface != NULL)
|
||||||
|
TrnBuffers[i].ReadSurface->Release();
|
||||||
|
TrnBuffers[i].ReadSurface = NULL;
|
||||||
|
|
||||||
|
if(TrnBuffers[i].FBTexture != NULL)
|
||||||
|
TrnBuffers[i].FBTexture->Release();
|
||||||
|
TrnBuffers[i].FBTexture = NULL;
|
||||||
|
|
||||||
|
TrnBuffers[i].Width = 0;
|
||||||
|
TrnBuffers[i].Height = 0;
|
||||||
|
}
|
||||||
|
WorkingBuffers = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 srcTexture, const TargetRectangle& sourceRc,
|
void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 srcTexture, const TargetRectangle& sourceRc,
|
||||||
|
@ -181,31 +196,57 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
Renderer::ResetAPIState();
|
Renderer::ResetAPIState();
|
||||||
// switch to texture converter frame buffer
|
u32 index =0;
|
||||||
LPDIRECT3DTEXTURE9 tempTexture = 0;
|
while(index < WorkingBuffers && (TrnBuffers[index].Width != dstWidth || TrnBuffers[index].Height != dstHeight))
|
||||||
hr = D3D::dev->CreateTexture(dstWidth, dstHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
|
index++;
|
||||||
D3DPOOL_DEFAULT, &tempTexture, NULL);
|
|
||||||
|
LPDIRECT3DSURFACE9 s_texConvReadSurface = NULL;
|
||||||
LPDIRECT3DSURFACE9 Rendersurf = NULL;
|
LPDIRECT3DSURFACE9 Rendersurf = NULL;
|
||||||
|
|
||||||
tempTexture->GetSurfaceLevel(0,&Rendersurf);
|
if(index >= WorkingBuffers)
|
||||||
|
{
|
||||||
|
if(WorkingBuffers < NUM_TRANSFORM_BUFFERS)
|
||||||
|
WorkingBuffers++;
|
||||||
|
if(index >= WorkingBuffers)
|
||||||
|
index--;
|
||||||
|
if(TrnBuffers[index].RenderSurface != NULL)
|
||||||
|
{
|
||||||
|
TrnBuffers[index].RenderSurface->Release();
|
||||||
|
TrnBuffers[index].RenderSurface = NULL;
|
||||||
|
}
|
||||||
|
if(TrnBuffers[index].ReadSurface != NULL)
|
||||||
|
{
|
||||||
|
TrnBuffers[index].ReadSurface->Release();
|
||||||
|
TrnBuffers[index].ReadSurface = NULL;
|
||||||
|
}
|
||||||
|
if(TrnBuffers[index].FBTexture != NULL)
|
||||||
|
{
|
||||||
|
TrnBuffers[index].FBTexture->Release();
|
||||||
|
TrnBuffers[index].FBTexture = NULL;
|
||||||
|
}
|
||||||
|
TrnBuffers[index].Width = dstWidth;
|
||||||
|
TrnBuffers[index].Height = dstHeight;
|
||||||
|
D3D::dev->CreateTexture(dstWidth, dstHeight, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
|
||||||
|
D3DPOOL_DEFAULT, &TrnBuffers[index].FBTexture, NULL);
|
||||||
|
TrnBuffers[index].FBTexture->GetSurfaceLevel(0,&TrnBuffers[index].RenderSurface);
|
||||||
|
D3D::dev->CreateOffscreenPlainSurface(dstWidth, dstHeight, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &TrnBuffers[index].ReadSurface, NULL );
|
||||||
|
}
|
||||||
|
|
||||||
|
s_texConvReadSurface = TrnBuffers[index].ReadSurface;
|
||||||
|
Rendersurf = TrnBuffers[index].RenderSurface;
|
||||||
|
|
||||||
hr = D3D::dev->SetDepthStencilSurface(NULL);
|
hr = D3D::dev->SetDepthStencilSurface(NULL);
|
||||||
hr = D3D::dev->SetRenderTarget(0, Rendersurf);
|
hr = D3D::dev->SetRenderTarget(0, Rendersurf);
|
||||||
|
|
||||||
|
|
||||||
if (linearFilter)
|
if (linearFilter)
|
||||||
{
|
{
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
D3D::dev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
|
|
||||||
D3D::dev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
D3DVIEWPORT9 vp;
|
D3DVIEWPORT9 vp;
|
||||||
vp.X = 0;
|
vp.X = 0;
|
||||||
vp.Y = 0;
|
vp.Y = 0;
|
||||||
|
@ -232,18 +273,14 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
|
||||||
hr = D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
hr = D3D::dev->SetDepthStencilSurface(FBManager::GetEFBDepthRTSurface());
|
||||||
Renderer::RestoreAPIState();
|
Renderer::RestoreAPIState();
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
D3D::RefreshSamplerState(0, D3DSAMP_MINFILTER);
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MAGFILTER);
|
|
||||||
D3D::RefreshSamplerState(0, D3DSAMP_MIPFILTER);
|
|
||||||
|
|
||||||
// .. and then readback the results.
|
// .. and then readback the results.
|
||||||
// TODO: make this less slow.
|
// TODO: make this less slow.
|
||||||
|
|
||||||
D3DLOCKED_RECT drect;
|
D3DLOCKED_RECT drect;
|
||||||
|
|
||||||
LPDIRECT3DSURFACE9 s_tempConvReadSurface = 0;
|
|
||||||
hr = D3D::dev->CreateOffscreenPlainSurface(dstWidth, dstHeight, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &s_tempConvReadSurface, NULL );
|
hr = D3D::dev->GetRenderTargetData(Rendersurf,s_texConvReadSurface);
|
||||||
hr = D3D::dev->GetRenderTargetData(Rendersurf,s_tempConvReadSurface);
|
if((hr = s_texConvReadSurface->LockRect(&drect, &DstRect, D3DLOCK_READONLY)) != D3D_OK)
|
||||||
if((hr = s_tempConvReadSurface->LockRect(&drect, &DstRect, D3DLOCK_READONLY)) != D3D_OK)
|
|
||||||
{
|
{
|
||||||
PanicAlert("ERROR: %s", hr == D3DERR_WASSTILLDRAWING ? "Still drawing" :
|
PanicAlert("ERROR: %s", hr == D3DERR_WASSTILLDRAWING ? "Still drawing" :
|
||||||
hr == D3DERR_INVALIDCALL ? "Invalid call" : "w00t");
|
hr == D3DERR_INVALIDCALL ? "Invalid call" : "w00t");
|
||||||
|
@ -273,11 +310,8 @@ void EncodeToRamUsingShader(LPDIRECT3DPIXELSHADER9 shader, LPDIRECT3DTEXTURE9 sr
|
||||||
else
|
else
|
||||||
memcpy(destAddr,drect.pBits,dstWidth*dstHeight*4);// 4 bytes per pixel
|
memcpy(destAddr,drect.pBits,dstWidth*dstHeight*4);// 4 bytes per pixel
|
||||||
|
|
||||||
hr = s_tempConvReadSurface->UnlockRect();
|
hr = s_texConvReadSurface->UnlockRect();
|
||||||
}
|
}
|
||||||
s_tempConvReadSurface->Release();
|
|
||||||
Rendersurf->Release();
|
|
||||||
tempTexture->Release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
|
void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyfmt, int bScaleByHalf, const EFBRectangle& source)
|
||||||
|
@ -324,14 +358,13 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf
|
||||||
float MValueX = Renderer::GetTargetScaleX();
|
float MValueX = Renderer::GetTargetScaleX();
|
||||||
float MValueY = Renderer::GetTargetScaleY();
|
float MValueY = Renderer::GetTargetScaleY();
|
||||||
|
|
||||||
float top = source.top * MValueY;
|
|
||||||
float sampleStride = bScaleByHalf?2.0f:1.0f;
|
float sampleStride = bScaleByHalf?2.0f:1.0f;
|
||||||
|
|
||||||
TextureConversionShader::SetShaderParameters(
|
TextureConversionShader::SetShaderParameters(
|
||||||
(float)expandedWidth,
|
(float)expandedWidth,
|
||||||
expandedHeight * MValueY,
|
expandedHeight * MValueY,
|
||||||
source.left * MValueX + 0.5f,
|
ceilf(source.left * MValueX + 1.0f),
|
||||||
top + 0.5f,
|
ceilf(source.top * MValueY + 1.0f),
|
||||||
sampleStride * MValueX,
|
sampleStride * MValueX,
|
||||||
sampleStride * MValueY,
|
sampleStride * MValueY,
|
||||||
(float)Renderer::GetTargetWidth(),
|
(float)Renderer::GetTargetWidth(),
|
||||||
|
|
|
@ -292,11 +292,16 @@ void EncodeToRam(u32 address, bool bFromZBuffer, bool bIsIntensityFmt, u32 copyf
|
||||||
float MValueX = Renderer::GetTargetScaleX();
|
float MValueX = Renderer::GetTargetScaleX();
|
||||||
float MValueY = Renderer::GetTargetScaleY();
|
float MValueY = Renderer::GetTargetScaleY();
|
||||||
|
|
||||||
float top = Renderer::GetTargetHeight() - (source.top + expandedHeight) * MValueY;
|
float top = Renderer::GetTargetHeight() - floorf((source.top + expandedHeight) * MValueY - 0.5f);
|
||||||
|
|
||||||
float sampleStride = bScaleByHalf?2.0f:1.0f;
|
float sampleStride = bScaleByHalf?2.0f:1.0f;
|
||||||
|
|
||||||
TextureConversionShader::SetShaderParameters((float)expandedWidth, expandedHeight * MValueY, source.left * MValueX, top, sampleStride * MValueX, sampleStride * MValueY);
|
TextureConversionShader::SetShaderParameters((float)expandedWidth,
|
||||||
|
expandedHeight * MValueY,
|
||||||
|
ceilf(source.left * MValueX + 0.5f),
|
||||||
|
top,
|
||||||
|
sampleStride * MValueX,
|
||||||
|
sampleStride * MValueY);
|
||||||
|
|
||||||
TargetRectangle scaledSource;
|
TargetRectangle scaledSource;
|
||||||
scaledSource.top = 0;
|
scaledSource.top = 0;
|
||||||
|
|
|
@ -424,26 +424,41 @@ TextureMngr::TCacheEntry* TextureMngr::Load(int texstage, u32 address, int width
|
||||||
gl_type = GL_UNSIGNED_SHORT_5_6_5;
|
gl_type = GL_UNSIGNED_SHORT_5_6_5;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
bool GenerateMipmaps = !entry.isRectangle && ((tm0.min_filter & 3) == 1 || (tm0.min_filter & 3) == 2);
|
||||||
if (!entry.isRectangle && ((tm0.min_filter & 3) == 1 || (tm0.min_filter & 3) == 2))
|
if (GenerateMipmaps)
|
||||||
{
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
glTexParameteri(target, GL_GENERATE_MIPMAP, GL_TRUE);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
}
|
||||||
|
if(skip_texture_create)
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
|
{
|
||||||
entry.bHaveMipMaps = true;
|
glTexSubImage2D(target, 0,0,0,width, height, gl_format, gl_type, temp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
glTexImage2D(target, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
glTexImage2D(target, 0, gl_iformat, width, height, 0, gl_format, gl_type, temp);
|
||||||
|
}
|
||||||
|
if (GenerateMipmaps)
|
||||||
|
{
|
||||||
|
glTexParameteri(target, GL_GENERATE_MIPMAP, GL_FALSE);
|
||||||
|
entry.bHaveMipMaps = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (expandedWidth != width) // reset
|
if (expandedWidth != width) // reset
|
||||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(skip_texture_create)
|
||||||
|
{
|
||||||
|
glCompressedTexSubImage2D(target, 0,0,0,expandedWidth, expandedHeight,
|
||||||
|
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,expandedWidth*expandedHeight/2, temp);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
glCompressedTexImage2D(target, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
|
glCompressedTexImage2D(target, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
|
||||||
expandedWidth, expandedHeight, 0, expandedWidth*expandedHeight/2, temp);
|
expandedWidth, expandedHeight, 0, expandedWidth*expandedHeight/2, temp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
entry.frameCount = frameCount;
|
entry.frameCount = frameCount;
|
||||||
entry.w = width;
|
entry.w = width;
|
||||||
|
@ -496,9 +511,9 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
|
||||||
// IA4,RA4 - IA4
|
// IA4,RA4 - IA4
|
||||||
// Z8M,G8,I8,A8,Z8,R8,B8,Z8L - I8
|
// Z8M,G8,I8,A8,Z8,R8,B8,Z8L - I8
|
||||||
// Z16,GB8,RG8,Z16L,IA8,RA8 - IA8
|
// Z16,GB8,RG8,Z16L,IA8,RA8 - IA8
|
||||||
int gl_format;
|
GLenum gl_format = GL_RGBA;
|
||||||
int gl_iformat;
|
GLenum gl_iformat = 4;
|
||||||
int gl_type;
|
GLenum gl_type = GL_UNSIGNED_BYTE;
|
||||||
float colmat[16];
|
float colmat[16];
|
||||||
float fConstAdd[4] = {0};
|
float fConstAdd[4] = {0};
|
||||||
memset(colmat, 0, sizeof(colmat));
|
memset(colmat, 0, sizeof(colmat));
|
||||||
|
@ -508,58 +523,29 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
|
||||||
switch(copyfmt)
|
switch(copyfmt)
|
||||||
{
|
{
|
||||||
case 0: // Z4
|
case 0: // Z4
|
||||||
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
|
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
break;
|
|
||||||
case 1: // Z8
|
case 1: // Z8
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
|
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
|
||||||
break;
|
break;
|
||||||
case 3: // Z16 //?
|
case 3: // Z16 //?
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE8_ALPHA8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1;
|
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1;
|
||||||
break;
|
break;
|
||||||
case 11: // Z16 (reverse order)
|
case 11: // Z16 (reverse order)
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE8_ALPHA8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[2] = colmat[6] = colmat[10] = colmat[13] = 1;
|
colmat[2] = colmat[6] = colmat[10] = colmat[13] = 1;
|
||||||
break;
|
break;
|
||||||
case 6: // Z24X8
|
case 6: // Z24X8
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[2] = colmat[5] = colmat[8] = colmat[15] = 1;
|
colmat[2] = colmat[5] = colmat[8] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
case 9: // Z8M
|
case 9: // Z8M
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1;
|
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1;
|
||||||
break;
|
break;
|
||||||
case 10: // Z8L
|
case 10: // Z8L
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
|
||||||
break;
|
break;
|
||||||
case 12: // Z16L
|
case 12: // Z16L
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE8_ALPHA8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERROR_LOG(VIDEO, "Unknown copy zbuf format: 0x%x", copyfmt);
|
ERROR_LOG(VIDEO, "Unknown copy zbuf format: 0x%x", copyfmt);
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -578,32 +564,6 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
|
||||||
}
|
}
|
||||||
else// alpha
|
else// alpha
|
||||||
colmat[15] = 1;
|
colmat[15] = 1;
|
||||||
switch (copyfmt)
|
|
||||||
{
|
|
||||||
case 0: // I4
|
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
break;
|
|
||||||
case 1: // I8
|
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
break;
|
|
||||||
case 2: // IA4
|
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE4_ALPHA4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
break;
|
|
||||||
case 3: // IA8
|
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE8_ALPHA8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ERROR_LOG(VIDEO, "Unknown copy intensity format: 0x%x", copyfmt);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -611,82 +571,43 @@ void TextureMngr::CopyRenderTargetToTexture(u32 address, bool bFromZBuffer, bool
|
||||||
{
|
{
|
||||||
case 0: // R4
|
case 0: // R4
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
break;
|
break;
|
||||||
case 8: // R8
|
case 8: // R8
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[12] = 1;
|
||||||
break;
|
break;
|
||||||
case 2: // RA4
|
case 2: // RA4
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE4_ALPHA4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
case 3: // RA8
|
case 3: // RA8
|
||||||
gl_format = GL_LUMINANCE_ALPHA;
|
|
||||||
gl_iformat = GL_LUMINANCE8_ALPHA8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
case 7: // A8
|
case 7: // A8
|
||||||
gl_format = GL_ALPHA;
|
|
||||||
gl_iformat = GL_ALPHA8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[3] = colmat[7] = colmat[11] = colmat[15] = 1;
|
colmat[3] = colmat[7] = colmat[11] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
case 9: // G8
|
case 9: // G8
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1;
|
colmat[1] = colmat[5] = colmat[9] = colmat[13] = 1;
|
||||||
break;
|
break;
|
||||||
case 10: // B8
|
case 10: // B8
|
||||||
gl_format = GL_LUMINANCE;
|
|
||||||
gl_iformat = GL_INTENSITY8;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
|
colmat[2] = colmat[6] = colmat[10] = colmat[14] = 1;
|
||||||
break;
|
break;
|
||||||
case 11: // RG8
|
case 11: // RG8
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1;
|
colmat[0] = colmat[4] = colmat[8] = colmat[13] = 1;
|
||||||
break;
|
break;
|
||||||
case 12: // GB8
|
case 12: // GB8
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1;
|
colmat[1] = colmat[5] = colmat[9] = colmat[14] = 1;
|
||||||
break;
|
break;
|
||||||
case 4: // RGB565
|
case 4: // RGB565
|
||||||
gl_format = GL_RGB;
|
|
||||||
gl_iformat = GL_RGB;
|
|
||||||
gl_type = GL_UNSIGNED_SHORT_5_6_5;
|
|
||||||
colmat[0] = colmat[5] = colmat[10] = 1;
|
colmat[0] = colmat[5] = colmat[10] = 1;
|
||||||
fConstAdd[3] = 1; // set alpha to 1
|
fConstAdd[3] = 1; // set alpha to 1
|
||||||
break;
|
break;
|
||||||
case 5: // RGB5A3
|
case 5: // RGB5A3
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
case 6: // RGBA8
|
case 6: // RGBA8
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ERROR_LOG(VIDEO, "Unknown copy color format: 0x%x", copyfmt);
|
ERROR_LOG(VIDEO, "Unknown copy color format: 0x%x", copyfmt);
|
||||||
gl_format = GL_RGBA;
|
|
||||||
gl_iformat = 4;
|
|
||||||
gl_type = GL_UNSIGNED_BYTE;
|
|
||||||
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
colmat[0] = colmat[5] = colmat[10] = colmat[15] = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue