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-06-27 03:32:33 +00:00
|
|
|
enum {RenderTarget, DepthStencil};
|
|
|
|
|
|
|
|
class Surface : 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;
|
2009-02-09 21:15:56 +00:00
|
|
|
GIFRegTEX0 m_TEX0;
|
2009-06-17 11:24:42 +00:00
|
|
|
GIFRegTEXA m_TEXA;
|
2009-06-27 03:32:33 +00:00
|
|
|
int m_age;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
public:
|
|
|
|
explicit Surface(GSRenderer* r);
|
|
|
|
virtual ~Surface();
|
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
|
|
|
};
|
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
class Target;
|
|
|
|
|
|
|
|
class Source : public Surface
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-28 02:02:14 +00:00
|
|
|
struct {GSVector4i* rect; uint32 count;} m_write;
|
|
|
|
|
|
|
|
void Write(const GSVector4i& r);
|
|
|
|
void Flush(uint32 count);
|
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
protected:
|
|
|
|
virtual int Get8bitFormat() = 0;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
public:
|
2009-06-27 03:32:33 +00:00
|
|
|
GSTexture* m_palette;
|
|
|
|
bool m_initpalette;
|
2009-07-01 21:14:12 +00:00
|
|
|
uint32 m_valid[MAX_PAGES]; // each uint32 bits map to the 32 blocks of that page
|
2009-06-27 03:32:33 +00:00
|
|
|
uint32* m_clut;
|
2009-07-06 16:35:06 +00:00
|
|
|
int m_fmt;
|
2009-06-27 03:32:33 +00:00
|
|
|
bool m_target;
|
2009-07-01 21:14:12 +00:00
|
|
|
bool m_complete;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
public:
|
|
|
|
explicit Source(GSRenderer* renderer);
|
|
|
|
virtual ~Source();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-06 16:35:06 +00:00
|
|
|
virtual bool Create(bool paltex);
|
|
|
|
virtual bool Create(Target* dst);
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual void Update(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GSVector4i& rect);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
class Target : public Surface
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-06-27 03:32:33 +00:00
|
|
|
int m_type;
|
2009-02-09 21:15:56 +00:00
|
|
|
bool m_used;
|
2009-06-27 03:32:33 +00:00
|
|
|
GSDirtyRectList m_dirty;
|
2009-07-12 13:46:05 +00:00
|
|
|
GSVector4i m_valid;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
public:
|
2009-06-27 03:32:33 +00:00
|
|
|
explicit Target(GSRenderer* r);
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual bool Create(int w, int h, int type);
|
|
|
|
virtual void Update();
|
|
|
|
virtual void Read(const GSVector4i& r) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
2009-05-22 01:22:52 +00:00
|
|
|
GSRenderer* m_renderer;
|
2009-07-06 16:35:06 +00:00
|
|
|
bool m_paltex;
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
struct SourceMap
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-07-16 21:36:07 +00:00
|
|
|
hash_set<Source*> m_surfaces;
|
2009-07-12 13:46:05 +00:00
|
|
|
list<Source*> m_map[MAX_PAGES];
|
2009-07-01 21:14:12 +00:00
|
|
|
uint32 m_pages[16];
|
2009-06-27 03:32:33 +00:00
|
|
|
bool m_used;
|
|
|
|
|
2009-07-01 21:14:12 +00:00
|
|
|
SourceMap() : m_used(false) {memset(m_pages, 0, sizeof(m_pages));}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
void Add(Source* s, const GIFRegTEX0& TEX0, const GSOffset* o);
|
2009-06-27 03:32:33 +00:00
|
|
|
void RemoveAll();
|
|
|
|
void RemoveAt(Source* s);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
} m_src;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
list<Target*> m_dst[2];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual Source* CreateSource() = 0;
|
|
|
|
virtual Target* CreateTarget() = 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-06-27 03:32:33 +00:00
|
|
|
Source* LookupSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, const GSVector4i& r);
|
|
|
|
Target* LookupTarget(const GIFRegTEX0& TEX0, int w, int h, int type, bool used, bool fb = false);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
void InvalidateVideoMem(const GSOffset* o, const GSVector4i& r, bool target = true);
|
|
|
|
void InvalidateLocalMem(const GSOffset* o, 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
|
|
|
};
|