2010-04-25 00:31:27 +00:00
|
|
|
/*
|
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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2010-04-25 00:31:27 +00:00
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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};
|
|
|
|
|
2009-09-18 00:16:52 +00:00
|
|
|
enum TextureFormatType
|
|
|
|
{
|
|
|
|
FMT_32,
|
|
|
|
FMT_24,
|
|
|
|
FMT_16,
|
|
|
|
FMT_8H,
|
|
|
|
FMT_4HL,
|
|
|
|
FMT_4HH,
|
|
|
|
FMT_8,
|
|
|
|
};
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
class Surface : public GSAlignedClass<32>
|
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 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-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;
|
2011-02-19 03:36:30 +00:00
|
|
|
uint8* m_temp;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-27 03:32:33 +00:00
|
|
|
public:
|
2011-02-19 03:36:30 +00:00
|
|
|
Source(GSRenderer* r, uint8* temp);
|
2009-06-27 03:32:33 +00:00
|
|
|
virtual ~Source();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
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 void Update();
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
class SourceMap
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
public:
|
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);
|
2011-02-19 03:36:30 +00:00
|
|
|
};
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
protected:
|
|
|
|
GSRenderer* m_renderer;
|
|
|
|
SourceMap m_src;
|
2009-06-27 03:32:33 +00:00
|
|
|
list<Target*> m_dst[2];
|
2011-02-19 03:36:30 +00:00
|
|
|
bool m_paltex;
|
|
|
|
uint8* m_temp;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-31 23:59:06 +00:00
|
|
|
virtual Source* CreateSource(const GIFRegTEX0& TEX0, const GIFRegTEXA& TEXA, Target* t = NULL);
|
|
|
|
virtual Target* CreateTarget(const GIFRegTEX0& TEX0, int w, int h, int type);
|
|
|
|
|
|
|
|
virtual int Get8bitFormat() = 0;
|
|
|
|
|
|
|
|
// TODO: virtual void Write(Source* s, const GSVector4i& r) = 0;
|
|
|
|
// TODO: virtual void Write(Target* t, const GSVector4i& r) = 0;
|
|
|
|
virtual void Read(Target* t, const GSVector4i& r) = 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);
|
2009-07-31 23:59:06 +00:00
|
|
|
Target* LookupTarget(const GIFRegTEX0& TEX0, int w, int h, int type, bool used);
|
|
|
|
Target* LookupTarget(const GIFRegTEX0& TEX0, int w, int h);
|
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();
|
2010-03-14 19:35:10 +00:00
|
|
|
bool UserHacks_HalfPixelOffset;
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|