gsdx-sourceforge/gsdx/GSDevice.h

245 lines
5.2 KiB
C
Raw Permalink Normal View History

2007-12-17 05:17:14 +00:00
/*
2008-12-05 09:47:18 +00:00
* Copyright (C) 2007-2009 Gabest
2007-12-17 05:17:14 +00:00
* 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"
2007-12-23 18:42:10 +00:00
#include "GSVertex.h"
2007-12-17 05:17:14 +00:00
2007-12-28 02:16:03 +00:00
#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)
2007-12-17 05:17:14 +00:00
template<class Texture> class GSDevice
{
CAtlList<Texture> m_pool;
2007-12-20 07:14:22 +00:00
protected:
2007-12-23 14:23:10 +00:00
HWND m_hWnd;
2008-07-21 06:55:57 +00:00
bool m_vsync;
2007-12-23 14:23:10 +00:00
Texture m_backbuffer;
2007-12-20 07:14:22 +00:00
Texture m_merge;
2007-12-18 22:04:48 +00:00
Texture m_weavebob;
Texture m_blend;
2007-12-20 07:14:22 +00:00
Texture m_1x1;
Texture m_current;
2007-12-18 22:04:48 +00:00
bool Fetch(int type, Texture& t, int w, int h, int format)
2007-12-17 05:17:14 +00:00
{
Recycle(t);
for(POSITION pos = m_pool.GetHeadPosition(); pos; m_pool.GetNext(pos))
{
const Texture& t2 = m_pool.GetAt(pos);
if(t2.GetType() == type && t2.GetWidth() == w && t2.GetHeight() == h && t2.GetFormat() == format)
{
t = t2;
m_pool.RemoveAt(pos);
return true;
}
}
return Create(type, t, w, h, format);
}
2007-12-18 22:04:48 +00:00
virtual bool Create(int type, Texture& t, int w, int h, int format) = 0;
2007-12-28 02:16:03 +00:00
virtual void DoMerge(Texture* st, GSVector4* sr, GSVector4* dr, Texture& dt, bool slbg, bool mmod, GSVector4& c) = 0;
2007-12-20 07:14:22 +00:00
virtual void DoInterlace(Texture& st, Texture& dt, int shader, bool linear, float yoffset) = 0;
2007-12-17 05:17:14 +00:00
public:
2007-12-23 14:23:10 +00:00
GSDevice() : m_hWnd(NULL)
2007-12-17 05:17:14 +00:00
{
}
virtual ~GSDevice()
{
}
2008-07-21 06:55:57 +00:00
virtual bool Create(HWND hWnd, bool vsync)
2007-12-17 05:17:14 +00:00
{
2007-12-23 14:23:10 +00:00
m_hWnd = hWnd;
2008-07-21 06:55:57 +00:00
m_vsync = vsync;
2007-12-23 14:23:10 +00:00
2007-12-17 05:17:14 +00:00
return true;
}
2007-12-18 22:04:48 +00:00
virtual bool Reset(int w, int h, bool fs)
2007-12-17 05:17:14 +00:00
{
m_pool.RemoveAll();
2007-12-23 14:23:10 +00:00
m_backbuffer = Texture();
2007-12-20 07:14:22 +00:00
m_merge = Texture();
2007-12-18 22:04:48 +00:00
m_weavebob = Texture();
m_blend = Texture();
2007-12-20 07:14:22 +00:00
m_1x1 = Texture();
m_current = Texture();
2007-12-17 05:17:14 +00:00
return true;
}
2007-12-18 22:04:48 +00:00
virtual bool IsLost() = 0;
2008-06-24 02:04:36 +00:00
virtual void Present(const CRect& r) = 0;
2007-12-18 22:04:48 +00:00
virtual void BeginScene() = 0;
virtual void EndScene() = 0;
2007-12-26 20:47:55 +00:00
virtual void Draw(LPCTSTR str) = 0;
2008-06-24 02:04:36 +00:00
virtual bool CopyOffscreen(Texture& src, const GSVector4& sr, Texture& dst, int w, int h, int format = 0) = 0;
2007-12-28 02:16:03 +00:00
virtual void ClearRenderTarget(Texture& t, const GSVector4& c) = 0;
2007-12-26 20:47:55 +00:00
virtual void ClearRenderTarget(Texture& t, DWORD c) = 0;
virtual void ClearDepth(Texture& t, float c) = 0;
virtual void ClearStencil(Texture& t, BYTE c) = 0;
2007-12-18 22:04:48 +00:00
virtual bool CreateRenderTarget(Texture& t, int w, int h, int format = 0)
2007-12-17 05:17:14 +00:00
{
return Fetch(GSTexture::RenderTarget, t, w, h, format);
}
2007-12-18 22:04:48 +00:00
virtual bool CreateDepthStencil(Texture& t, int w, int h, int format = 0)
2007-12-17 05:17:14 +00:00
{
return Fetch(GSTexture::DepthStencil, t, w, h, format);
}
2007-12-18 22:04:48 +00:00
virtual bool CreateTexture(Texture& t, int w, int h, int format = 0)
2007-12-17 05:17:14 +00:00
{
return Fetch(GSTexture::Texture, t, w, h, format);
}
2007-12-18 22:04:48 +00:00
virtual bool CreateOffscreen(Texture& t, int w, int h, int format = 0)
2007-12-17 05:17:14 +00:00
{
return Fetch(GSTexture::Offscreen, t, w, h, format);
}
void Recycle(Texture& t)
{
if(t)
{
m_pool.AddHead(t);
while(m_pool.GetCount() > 200)
{
m_pool.RemoveTail();
}
t = Texture();
}
}
2007-12-18 22:04:48 +00:00
2007-12-20 07:14:22 +00:00
bool SaveCurrent(LPCTSTR fn)
{
return m_current.Save(fn);
}
2008-06-24 02:04:36 +00:00
void GetCurrent(Texture& t)
{
t = m_current;
}
2007-12-28 02:16:03 +00:00
void Merge(Texture* st, GSVector4* sr, GSVector4* dr, CSize fs, bool slbg, bool mmod, GSVector4& c)
2007-12-18 22:04:48 +00:00
{
2007-12-20 07:14:22 +00:00
if(!m_merge || m_merge.GetWidth() != fs.cx || m_merge.GetHeight() != fs.cy)
{
CreateRenderTarget(m_merge, fs.cx, fs.cy);
}
// TODO: m_1x1
2007-12-28 02:16:03 +00:00
DoMerge(st, sr, dr, m_merge, slbg, mmod, c);
2007-12-18 22:04:48 +00:00
2007-12-20 07:14:22 +00:00
m_current = m_merge;
}
bool Interlace(CSize ds, int field, int mode, float yoffset)
{
2007-12-18 22:04:48 +00:00
if(!m_weavebob || m_weavebob.GetWidth() != ds.cx || m_weavebob.GetHeight() != ds.cy)
{
CreateRenderTarget(m_weavebob, ds.cx, ds.cy);
}
if(mode == 0 || mode == 2) // weave or blend
{
// weave first
2007-12-20 07:14:22 +00:00
DoInterlace(m_merge, m_weavebob, field, false, 0);
2007-12-18 22:04:48 +00:00
if(mode == 2)
{
// blend
if(!m_blend || m_blend.GetWidth() != ds.cx || m_blend.GetHeight() != ds.cy)
{
CreateRenderTarget(m_blend, ds.cx, ds.cy);
}
2007-12-20 07:14:22 +00:00
DoInterlace(m_weavebob, m_blend, 2, false, 0);
2007-12-18 22:04:48 +00:00
2007-12-20 07:14:22 +00:00
m_current = m_blend;
2007-12-18 22:04:48 +00:00
}
else
{
2007-12-20 07:14:22 +00:00
m_current = m_weavebob;
2007-12-18 22:04:48 +00:00
}
}
else if(mode == 1) // bob
{
2007-12-20 07:14:22 +00:00
DoInterlace(m_merge, m_weavebob, 3, true, yoffset * field);
2007-12-18 22:04:48 +00:00
2007-12-20 07:14:22 +00:00
m_current = m_weavebob;
}
else
{
m_current = m_merge;
2007-12-18 22:04:48 +00:00
}
return true;
}
2008-06-30 14:32:36 +00:00
virtual bool IsCurrentRGBA()
{
return true;
}
2007-12-17 05:17:14 +00:00
};