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 "GSTexture.h"
|
|
|
|
#include "GSVertex.h"
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
|
|
|
|
struct MergeConstantBuffer
|
|
|
|
{
|
|
|
|
GSVector4 BGColor;
|
|
|
|
|
|
|
|
struct MergeConstantBuffer() {memset(this, 0, sizeof(*this));}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InterlaceConstantBuffer
|
|
|
|
{
|
|
|
|
GSVector2 ZrH;
|
|
|
|
float hH;
|
|
|
|
float _pad[1];
|
|
|
|
|
|
|
|
struct InterlaceConstantBuffer() {memset(this, 0, sizeof(*this));}
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
template<class Texture> class GSDevice
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
list<Texture> m_pool;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
HWND m_hWnd;
|
|
|
|
bool m_vsync;
|
|
|
|
Texture m_backbuffer;
|
|
|
|
Texture m_merge;
|
|
|
|
Texture m_weavebob;
|
|
|
|
Texture m_blend;
|
|
|
|
Texture m_1x1;
|
|
|
|
Texture m_current;
|
|
|
|
|
|
|
|
bool Fetch(int type, Texture& t, int w, int h, int format)
|
|
|
|
{
|
|
|
|
Recycle(t);
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
for(list<Texture>::iterator i = m_pool.begin(); i != m_pool.end(); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
const Texture& t2 = *i;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(t2.GetType() == type && t2.GetWidth() == w && t2.GetHeight() == h && t2.GetFormat() == format)
|
|
|
|
{
|
|
|
|
t = t2;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
m_pool.erase(i);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Create(type, t, w, h, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Create(int type, Texture& t, int w, int h, int format) = 0;
|
|
|
|
virtual void DoMerge(Texture* st, GSVector4* sr, GSVector4* dr, Texture& dt, bool slbg, bool mmod, GSVector4& c) = 0;
|
|
|
|
virtual void DoInterlace(Texture& st, Texture& dt, int shader, bool linear, float yoffset) = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GSDevice() : m_hWnd(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GSDevice()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Create(HWND hWnd, bool vsync)
|
|
|
|
{
|
|
|
|
m_hWnd = hWnd;
|
|
|
|
m_vsync = vsync;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool Reset(int w, int h, bool fs)
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
m_pool.clear();
|
2009-02-09 21:15:56 +00:00
|
|
|
m_backbuffer = Texture();
|
|
|
|
m_merge = Texture();
|
|
|
|
m_weavebob = Texture();
|
|
|
|
m_blend = Texture();
|
|
|
|
m_1x1 = Texture();
|
|
|
|
m_current = Texture();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsLost() = 0;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
virtual void Present(const GSVector4i& r) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
virtual void BeginScene() = 0;
|
|
|
|
|
|
|
|
virtual void EndScene() = 0;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
virtual void Draw(const string& s) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
virtual bool CopyOffscreen(Texture& src, const GSVector4& sr, Texture& dst, int w, int h, int format = 0) = 0;
|
|
|
|
|
|
|
|
virtual void ClearRenderTarget(Texture& t, const GSVector4& c) = 0;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
virtual void ClearRenderTarget(Texture& t, uint32 c) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
virtual void ClearDepth(Texture& t, float c) = 0;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
virtual void ClearStencil(Texture& t, uint8 c) = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
virtual bool CreateRenderTarget(Texture& t, int w, int h, int format = 0)
|
|
|
|
{
|
|
|
|
return Fetch(GSTexture::RenderTarget, t, w, h, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CreateDepthStencil(Texture& t, int w, int h, int format = 0)
|
|
|
|
{
|
|
|
|
return Fetch(GSTexture::DepthStencil, t, w, h, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CreateTexture(Texture& t, int w, int h, int format = 0)
|
|
|
|
{
|
|
|
|
return Fetch(GSTexture::Texture, t, w, h, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CreateOffscreen(Texture& t, int w, int h, int format = 0)
|
|
|
|
{
|
|
|
|
return Fetch(GSTexture::Offscreen, t, w, h, format);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Recycle(Texture& t)
|
|
|
|
{
|
|
|
|
if(t)
|
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
m_pool.push_front(t);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
while(m_pool.size() > 200)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
m_pool.pop_back();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t = Texture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
bool SaveCurrent(const string& fn)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return m_current.Save(fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetCurrent(Texture& t)
|
|
|
|
{
|
|
|
|
t = m_current;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
void Merge(Texture* st, GSVector4* sr, GSVector4* dr, const GSVector2i& fs, bool slbg, bool mmod, GSVector4& c)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
if(!m_merge || m_merge.GetWidth() != fs.x || m_merge.GetHeight() != fs.y)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
CreateRenderTarget(m_merge, fs.x, fs.y);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: m_1x1
|
|
|
|
|
|
|
|
DoMerge(st, sr, dr, m_merge, slbg, mmod, c);
|
|
|
|
|
|
|
|
m_current = m_merge;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
bool Interlace(const GSVector2i& ds, int field, int mode, float yoffset)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
if(!m_weavebob || m_weavebob.GetWidth() != ds.x || m_weavebob.GetHeight() != ds.y)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
CreateRenderTarget(m_weavebob, ds.x, ds.y);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mode == 0 || mode == 2) // weave or blend
|
|
|
|
{
|
|
|
|
// weave first
|
|
|
|
|
|
|
|
DoInterlace(m_merge, m_weavebob, field, false, 0);
|
|
|
|
|
|
|
|
if(mode == 2)
|
|
|
|
{
|
|
|
|
// blend
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(!m_blend || m_blend.GetWidth() != ds.x || m_blend.GetHeight() != ds.y)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
CreateRenderTarget(m_blend, ds.x, ds.y);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DoInterlace(m_weavebob, m_blend, 2, false, 0);
|
|
|
|
|
|
|
|
m_current = m_blend;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_current = m_weavebob;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(mode == 1) // bob
|
|
|
|
{
|
|
|
|
DoInterlace(m_merge, m_weavebob, 3, true, yoffset * field);
|
|
|
|
|
|
|
|
m_current = m_weavebob;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_current = m_merge;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsCurrentRGBA()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|