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 "GPUState.h"
|
|
|
|
#include "GSVertexList.h"
|
2009-05-22 01:22:52 +00:00
|
|
|
#include "GSDevice.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 23:23:38 +00:00
|
|
|
class GPURenderer : public GPUState
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
bool Merge();
|
|
|
|
|
2009-05-22 23:23:38 +00:00
|
|
|
protected:
|
2009-06-03 12:09:04 +00:00
|
|
|
GSDevice* m_dev;
|
2009-02-09 21:15:56 +00:00
|
|
|
int m_filter;
|
|
|
|
int m_dither;
|
|
|
|
int m_aspectratio;
|
|
|
|
bool m_vsync;
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector2i m_scale;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
virtual void ResetDevice() {}
|
|
|
|
virtual GSTexture* GetOutput() = 0;
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
HWND m_hWnd;
|
|
|
|
WNDPROC m_wndproc;
|
2009-05-22 01:22:52 +00:00
|
|
|
static map<HWND, GPURenderer*> m_wnd2gpu;
|
2009-06-03 12:09:04 +00:00
|
|
|
GSWnd m_wnd;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 23:23:38 +00:00
|
|
|
public:
|
|
|
|
GPURenderer(GSDevice* dev);
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual ~GPURenderer();
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
virtual bool Create(HWND hWnd);
|
2009-06-03 12:09:04 +00:00
|
|
|
virtual void VSync();
|
|
|
|
virtual bool MakeSnapshot(const string& path);
|
2009-02-09 21:15:56 +00:00
|
|
|
};
|
|
|
|
|
2009-05-22 01:22:52 +00:00
|
|
|
template<class Vertex>
|
|
|
|
class GPURendererT : public GPURenderer
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
Vertex* m_vertices;
|
|
|
|
int m_count;
|
|
|
|
int m_maxcount;
|
|
|
|
GSVertexList<Vertex> m_vl;
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
m_count = 0;
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
|
|
|
|
__super::Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetPrim()
|
|
|
|
{
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlushPrim()
|
|
|
|
{
|
|
|
|
if(m_count > 0)
|
|
|
|
{
|
|
|
|
/*
|
2009-05-11 08:18:00 +00:00
|
|
|
Dump("db");
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(m_env.PRIM.TME)
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i r;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
r.left = m_env.STATUS.TX << 6;
|
|
|
|
r.top = m_env.STATUS.TY << 8;
|
|
|
|
r.right = r.left + 256;
|
|
|
|
r.bottom = r.top + 256;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
Dump(format("da_%d_%d_%d_%d_%d", m_env.STATUS.TP, r).c_str(), m_env.STATUS.TP, r, false);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
m_count = 0;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
//Dump("dc", false);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
void GrowVertexBuffer()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
m_maxcount = max(10000, m_maxcount * 3/2);
|
|
|
|
m_vertices = (Vertex*)_aligned_realloc(m_vertices, sizeof(Vertex) * m_maxcount, 16);
|
2009-02-09 21:15:56 +00:00
|
|
|
m_maxcount -= 100;
|
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
__forceinline Vertex* DrawingKick(int& count)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
count = (int)m_env.PRIM.VTX;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
if(m_vl.GetCount() < count)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
return NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
if(m_count >= m_maxcount)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
GrowVertexBuffer();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
Vertex* v = &m_vertices[m_count];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
switch(m_env.PRIM.TYPE)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-03 12:09:04 +00:00
|
|
|
case GPU_POLYGON:
|
|
|
|
m_vl.GetAt(0, v[0]);
|
|
|
|
m_vl.GetAt(1, v[1]);
|
|
|
|
m_vl.GetAt(2, v[2]);
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
break;
|
|
|
|
case GPU_LINE:
|
|
|
|
m_vl.GetAt(0, v[0]);
|
|
|
|
m_vl.GetAt(1, v[1]);
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
break;
|
|
|
|
case GPU_SPRITE:
|
|
|
|
m_vl.GetAt(0, v[0]);
|
|
|
|
m_vl.GetAt(1, v[1]);
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ASSERT(0);
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
return NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
return v;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
virtual void VertexKick() = 0;
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
virtual void Draw() = 0;
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
public:
|
|
|
|
GPURendererT(GSDevice* dev)
|
|
|
|
: GPURenderer(dev)
|
|
|
|
, m_count(0)
|
|
|
|
, m_maxcount(0)
|
|
|
|
, m_vertices(NULL)
|
|
|
|
{
|
|
|
|
}
|
2009-05-22 01:22:52 +00:00
|
|
|
|
2009-06-03 12:09:04 +00:00
|
|
|
virtual ~GPURendererT()
|
|
|
|
{
|
|
|
|
if(m_vertices) _aligned_free(m_vertices);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
};
|