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 "GPURenderer.h"
|
|
|
|
#include "GPUDrawScanline.h"
|
|
|
|
|
|
|
|
template <class Device>
|
|
|
|
class GPURendererSW : public GPURenderer<Device, GSVertexSW>
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
GSRasterizerList m_rl;
|
|
|
|
Texture m_texture;
|
|
|
|
|
|
|
|
void ResetDevice()
|
|
|
|
{
|
|
|
|
m_texture = Texture();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetOutput(Texture& t)
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i r = m_env.GetDisplayRect();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
r.left <<= m_scale.x;
|
|
|
|
r.top <<= m_scale.y;
|
|
|
|
r.right <<= m_scale.x;
|
|
|
|
r.bottom <<= m_scale.y;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
// TODO
|
2009-05-14 16:41:52 +00:00
|
|
|
static uint32* buff = (uint32*)_aligned_malloc(m_mem.GetWidth() * m_mem.GetHeight() * sizeof(uint32), 16);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
m_mem.ReadFrame32(r, buff, !!m_env.STATUS.ISRGB24);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
int w = r.width();
|
|
|
|
int h = r.height();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(m_texture.GetWidth() != w || m_texture.GetHeight() != h)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
m_texture = Texture();
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
if(!m_texture && !m_dev.CreateTexture(m_texture, w, h))
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
m_texture.Update(GSVector4i(0, 0, w, h), buff, m_mem.GetWidth() * sizeof(uint32));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
t = m_texture;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VertexKick()
|
|
|
|
{
|
|
|
|
GSVertexSW& v = m_vl.AddTail();
|
|
|
|
|
|
|
|
// TODO: x/y + off.x/y should wrap around at +/-1024
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
int x = (int)(m_v.XY.X + m_env.DROFF.X) << m_scale.x;
|
|
|
|
int y = (int)(m_v.XY.Y + m_env.DROFF.Y) << m_scale.y;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
int s = m_v.UV.X;
|
|
|
|
int t = m_v.UV.Y;
|
|
|
|
|
|
|
|
GSVector4 pt(x, y, s, t);
|
|
|
|
|
|
|
|
v.p = pt.xyxy(GSVector4::zero());
|
|
|
|
v.t = (pt.zwzw(GSVector4::zero()) + GSVector4(0.125f)) * 256.0f;
|
2009-05-14 16:41:52 +00:00
|
|
|
v.c = GSVector4(m_v.RGB.u32) * 128.0f;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
__super::VertexKick();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawingKickTriangle(GSVertexSW* v, int& count)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawingKickLine(GSVertexSW* v, int& count)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawingKickSprite(GSVertexSW* v, int& count)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
GSVector4i GetScissor()
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i r;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
r.left = (int)m_env.DRAREATL.X << m_scale.x;
|
|
|
|
r.top = (int)m_env.DRAREATL.Y << m_scale.y;
|
|
|
|
r.right = min((int)(m_env.DRAREABR.X + 1) << m_scale.x, m_mem.GetWidth());
|
|
|
|
r.bottom = min((int)(m_env.DRAREABR.Y + 1) << m_scale.y, m_mem.GetHeight());
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
return r;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Draw()
|
|
|
|
{
|
|
|
|
const GPUDrawingEnvironment& env = m_env;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
GPUScanlineParam p;
|
|
|
|
|
2009-02-11 07:05:44 +00:00
|
|
|
p.sel.key = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
p.sel.iip = env.PRIM.IIP;
|
|
|
|
p.sel.me = env.STATUS.ME;
|
2009-02-19 13:13:20 +00:00
|
|
|
|
|
|
|
if(env.PRIM.ABE)
|
|
|
|
{
|
|
|
|
p.sel.abe = env.PRIM.ABE;
|
|
|
|
p.sel.abr = env.STATUS.ABR;
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
p.sel.tge = env.PRIM.TGE;
|
|
|
|
|
|
|
|
if(env.PRIM.TME)
|
|
|
|
{
|
2009-02-19 13:13:20 +00:00
|
|
|
p.sel.tme = env.PRIM.TME;
|
|
|
|
p.sel.tlu = env.STATUS.TP < 2;
|
2009-05-14 16:41:52 +00:00
|
|
|
p.sel.twin = (env.TWIN.u32 & 0xfffff) != 0;
|
2009-02-19 13:13:20 +00:00
|
|
|
p.sel.ltf = m_filter == 1 && env.PRIM.TYPE == GPU_POLYGON || m_filter == 2 ? 1 : 0;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
const void* t = m_mem.GetTexture(env.STATUS.TP, env.STATUS.TX, env.STATUS.TY);
|
|
|
|
|
|
|
|
if(!t) {ASSERT(0); return;}
|
|
|
|
|
|
|
|
p.tex = t;
|
|
|
|
p.clut = m_mem.GetCLUT(env.STATUS.TP, env.CLUT.X, env.CLUT.Y);
|
|
|
|
}
|
|
|
|
|
2009-02-19 13:13:20 +00:00
|
|
|
p.sel.dtd = m_dither ? env.STATUS.DTD : 0;
|
|
|
|
p.sel.md = env.STATUS.MD;
|
|
|
|
p.sel.sprite = env.PRIM.TYPE == GPU_SPRITE;
|
2009-05-14 16:41:52 +00:00
|
|
|
p.sel.scalex = m_mem.GetScale().x;
|
2009-02-19 13:13:20 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
GSRasterizerData data;
|
|
|
|
|
|
|
|
data.scissor = GetScissor();
|
|
|
|
data.vertices = m_vertices;
|
|
|
|
data.count = m_count;
|
|
|
|
data.param = &p;
|
|
|
|
|
|
|
|
switch(env.PRIM.TYPE)
|
|
|
|
{
|
|
|
|
case GPU_POLYGON: data.primclass = GS_TRIANGLE_CLASS; break;
|
|
|
|
case GPU_LINE: data.primclass = GS_LINE_CLASS; break;
|
|
|
|
case GPU_SPRITE: data.primclass = GS_SPRITE_CLASS; break;
|
|
|
|
default: __assume(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_rl.Draw(&data);
|
|
|
|
|
|
|
|
GSRasterizerStats stats;
|
|
|
|
|
|
|
|
m_rl.GetStats(stats);
|
|
|
|
|
|
|
|
m_perfmon.Put(GSPerfMon::Draw, 1);
|
|
|
|
m_perfmon.Put(GSPerfMon::Prim, stats.prims);
|
|
|
|
m_perfmon.Put(GSPerfMon::Fillrate, stats.pixels);
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
{
|
|
|
|
GSVector4 tl(+1e10f);
|
|
|
|
GSVector4 br(-1e10f);
|
|
|
|
|
|
|
|
for(int i = 0, j = m_count; i < j; i++)
|
|
|
|
{
|
|
|
|
GSVector4 p = m_vertices[i].p;
|
|
|
|
|
|
|
|
tl = tl.minv(p);
|
|
|
|
br = br.maxv(p);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i r = GSVector4i(tl.xyxy(br)).rintersect(data.scissor);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
r.left >>= m_scale.x;
|
|
|
|
r.top >>= m_scale.y;
|
|
|
|
r.right >>= m_scale.x;
|
|
|
|
r.bottom >>= m_scale.y;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
Invalidate(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
GPURendererSW(const GPURendererSettings& rs, int threads)
|
|
|
|
: GPURenderer(rs)
|
|
|
|
{
|
|
|
|
m_rl.Create<GPUDrawScanline>(this, threads);
|
|
|
|
|
|
|
|
m_fpDrawingKickHandlers[GPU_POLYGON] = (DrawingKickHandler)&GPURendererSW::DrawingKickTriangle;
|
|
|
|
m_fpDrawingKickHandlers[GPU_LINE] = (DrawingKickHandler)&GPURendererSW::DrawingKickLine;
|
|
|
|
m_fpDrawingKickHandlers[GPU_SPRITE] = (DrawingKickHandler)&GPURendererSW::DrawingKickSprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GPURendererSW()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|