2009-02-09 21:15:56 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GSRenderer.h"
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
class GSTextureCache
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-05-14 16:41:52 +00:00
|
|
|
class GSSurface : public GSAlignedClass<16>
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSRenderer* m_renderer;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTexture* m_texture;
|
|
|
|
GSTexture* m_palette;
|
2009-02-09 21:15:56 +00:00
|
|
|
bool m_initpalette;
|
|
|
|
int m_age;
|
|
|
|
GSDirtyRectList m_dirty;
|
|
|
|
GIFRegTEX0 m_TEX0;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
explicit GSSurface(GSRenderer* r);
|
|
|
|
virtual ~GSSurface();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual void Update();
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GSRenderTarget : public GSSurface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool m_used;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
explicit GSRenderTarget(GSRenderer* r);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual bool Create(int w, int h);
|
2009-05-14 16:41:52 +00:00
|
|
|
virtual void Read(const GSVector4i& r) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class GSDepthStencil : public GSSurface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool m_used;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
explicit GSDepthStencil(GSRenderer* renderer);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual bool Create(int w, int h);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
class GSCachedTexture : public GSSurface
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
2009-05-22 01:22:52 +00:00
|
|
|
bool GetDirtyRect(GSVector4i& r);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GIFRegCLAMP m_CLAMP;
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32* m_clut; // *
|
|
|
|
GSVector4i m_valid;
|
2009-02-09 21:15:56 +00:00
|
|
|
int m_bpp;
|
|
|
|
int m_bpp2;
|
|
|
|
bool m_rendered;
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
explicit GSCachedTexture(GSRenderer* renderer);
|
|
|
|
virtual ~GSCachedTexture();
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void Update();
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
virtual bool Create() = 0;
|
|
|
|
virtual bool Create(GSRenderTarget* rt) = 0;
|
|
|
|
virtual bool Create(GSDepthStencil* ds) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSRenderer* m_renderer;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
list<GSRenderTarget*> m_rt;
|
|
|
|
list<GSDepthStencil*> m_ds;
|
2009-05-22 01:22:52 +00:00
|
|
|
list<GSCachedTexture*> m_tex;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
template<class T> void RecycleByAge(list<T*>& l, int maxage = 60)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
for(list<T*>::iterator i = l.begin(); i != l.end(); )
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
list<T*>::iterator j = i++;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
T* t = *j;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(++t->m_age > maxage)
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
l.erase(j);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
delete t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual GSRenderTarget* CreateRenderTarget() = 0;
|
|
|
|
virtual GSDepthStencil* CreateDepthStencil() = 0;
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual GSCachedTexture* CreateTexture() = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSTextureCache(GSRenderer* r);
|
|
|
|
virtual ~GSTextureCache();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void RemoveAll();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
GSRenderTarget* GetRenderTarget(const GIFRegTEX0& TEX0, int w, int h, bool fb = false);
|
|
|
|
GSDepthStencil* GetDepthStencil(const GIFRegTEX0& TEX0, int w, int h);
|
|
|
|
GSCachedTexture* GetTexture();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void InvalidateTextures(const GIFRegFRAME& FRAME, const GIFRegZBUF& ZBUF);
|
|
|
|
void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r);
|
|
|
|
void InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
void IncAge();
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|