2011-11-16 22:17:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011-2011 Gregory hainaut
|
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* 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; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* 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 for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2011-11-16 22:17:37 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "GSTextureCacheOGL.h"
|
|
|
|
|
|
|
|
GSTextureCacheOGL::GSTextureCacheOGL(GSRenderer* r)
|
|
|
|
: GSTextureCache(r)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void GSTextureCacheOGL::Read(Target* t, const GSVector4i& r)
|
|
|
|
{
|
2015-05-19 11:03:07 +00:00
|
|
|
if(!t->m_dirty.empty())
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-19 11:03:07 +00:00
|
|
|
const GIFRegTEX0& TEX0 = t->m_TEX0;
|
|
|
|
|
|
|
|
GLuint fmt;
|
|
|
|
int ps_shader;
|
|
|
|
switch (TEX0.PSM)
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
2015-05-19 11:03:07 +00:00
|
|
|
case PSM_PSMCT32:
|
|
|
|
case PSM_PSMCT24:
|
|
|
|
fmt = GL_RGBA8;
|
|
|
|
ps_shader = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_PSMCT16:
|
|
|
|
case PSM_PSMCT16S:
|
|
|
|
fmt = GL_R16UI;
|
|
|
|
ps_shader = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PSM_PSMZ32:
|
|
|
|
fmt = GL_R32UI;
|
|
|
|
ps_shader = 10;
|
2015-05-20 06:07:40 +00:00
|
|
|
break;
|
2015-05-19 11:03:07 +00:00
|
|
|
|
|
|
|
case PSM_PSMZ24:
|
|
|
|
fmt = GL_R32UI;
|
2015-05-19 16:56:32 +00:00
|
|
|
ps_shader = 10;
|
2015-05-20 06:07:40 +00:00
|
|
|
break;
|
2015-05-19 11:03:07 +00:00
|
|
|
|
|
|
|
case PSM_PSMZ16:
|
2015-05-20 06:07:40 +00:00
|
|
|
case PSM_PSMZ16S:
|
2015-05-19 11:03:07 +00:00
|
|
|
fmt = GL_R16UI;
|
2015-05-19 16:56:32 +00:00
|
|
|
ps_shader = 10;
|
2015-05-20 06:07:40 +00:00
|
|
|
break;
|
2015-05-19 11:03:07 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-05-16 15:32:24 +00:00
|
|
|
|
2015-05-19 11:03:07 +00:00
|
|
|
// Yes lots of logging, but I'm not confident with this code
|
|
|
|
GL_PUSH("Texture Cache Read. Format(0x%x)", TEX0.PSM);
|
2015-05-17 10:19:38 +00:00
|
|
|
|
2015-05-19 11:03:07 +00:00
|
|
|
GL_CACHE("TC: Read Back Target: %d (0x%x)[fmt: 0x%x]",
|
|
|
|
t->m_texture->GetID(), TEX0.TBP0, TEX0.PSM);
|
2015-05-06 16:52:51 +00:00
|
|
|
|
2015-05-19 11:03:07 +00:00
|
|
|
GL_PERF("Read texture from GPU. Format(0x%x)", TEX0.PSM);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
GSVector4 src = GSVector4(r) * GSVector4(t->m_texture->GetScale()).xyxy() / GSVector4(t->m_texture->GetSize()).xyxy();
|
|
|
|
|
2015-05-19 11:03:07 +00:00
|
|
|
if(GSTexture* offscreen = m_renderer->m_dev->CopyOffscreen(t->m_texture, src, r.width(), r.height(), fmt, ps_shader))
|
2011-11-16 22:17:37 +00:00
|
|
|
{
|
|
|
|
GSTexture::GSMap m;
|
|
|
|
|
|
|
|
if(offscreen->Map(m))
|
|
|
|
{
|
|
|
|
// TODO: block level write
|
|
|
|
|
2015-05-15 18:40:09 +00:00
|
|
|
GSOffset* off = m_renderer->m_mem.GetOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM);
|
2011-11-16 22:17:37 +00:00
|
|
|
|
|
|
|
switch(TEX0.PSM)
|
|
|
|
{
|
2015-05-19 11:03:07 +00:00
|
|
|
case PSM_PSMCT32:
|
|
|
|
m_renderer->m_mem.WritePixel32(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
case PSM_PSMCT24:
|
|
|
|
m_renderer->m_mem.WritePixel24(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
case PSM_PSMCT16:
|
|
|
|
case PSM_PSMCT16S:
|
|
|
|
m_renderer->m_mem.WritePixel16(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
2015-05-20 06:07:40 +00:00
|
|
|
|
|
|
|
case PSM_PSMZ32:
|
|
|
|
m_renderer->m_mem.WritePixel32(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
case PSM_PSMZ24:
|
|
|
|
m_renderer->m_mem.WritePixel24(m.bits, m.pitch, off, r);
|
|
|
|
break;
|
|
|
|
case PSM_PSMZ16:
|
|
|
|
case PSM_PSMZ16S:
|
|
|
|
m_renderer->m_mem.WritePixel16(m.bits, m.pitch, off, r);
|
|
|
|
|
2015-05-19 11:03:07 +00:00
|
|
|
default:
|
|
|
|
ASSERT(0);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offscreen->Unmap();
|
|
|
|
}
|
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
// FIXME invalidate data
|
2012-03-05 20:16:26 +00:00
|
|
|
m_renderer->m_dev->Recycle(offscreen);
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
2015-05-06 16:52:51 +00:00
|
|
|
|
|
|
|
GL_POP();
|
2011-11-16 22:17:37 +00:00
|
|
|
}
|
|
|
|
|