2011-02-19 10:57:28 +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
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2011-02-19 10:57:28 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "GPUState.h"
|
2018-11-16 18:41:37 +00:00
|
|
|
#include "Renderers/Common/GSVertexList.h"
|
|
|
|
#include "Renderers/Common/GSDevice.h"
|
2016-01-27 15:33:10 +00:00
|
|
|
#ifdef _WIN32
|
2018-11-16 18:41:37 +00:00
|
|
|
#include "Window/GSWndDX.h"
|
2013-01-04 11:41:51 +00:00
|
|
|
#endif
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
class GPURenderer : public GPUState
|
|
|
|
{
|
|
|
|
bool Merge();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
GSDevice* m_dev;
|
|
|
|
int m_filter;
|
|
|
|
int m_dither;
|
|
|
|
int m_aspectratio;
|
2017-05-21 20:14:34 +00:00
|
|
|
int m_vsync;
|
2014-01-17 10:17:24 +00:00
|
|
|
bool m_shaderfx;
|
2011-07-25 11:16:01 +00:00
|
|
|
bool m_fxaa;
|
2012-02-29 00:29:29 +00:00
|
|
|
bool m_shadeboost;
|
2011-02-19 10:57:28 +00:00
|
|
|
GSVector2i m_scale;
|
|
|
|
|
|
|
|
virtual void ResetDevice() {}
|
|
|
|
virtual GSTexture* GetOutput() = 0;
|
|
|
|
|
2016-01-27 15:33:10 +00:00
|
|
|
#ifdef _WIN32
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
HWND m_hWnd;
|
|
|
|
WNDPROC m_wndproc;
|
2017-05-26 16:17:01 +00:00
|
|
|
static std::map<HWND, GPURenderer*> m_wnd2gpu;
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-02-22 21:02:34 +00:00
|
|
|
std::shared_ptr<GSWnd> m_wnd;
|
2011-02-19 10:57:28 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
GPURenderer(GSDevice* dev);
|
|
|
|
virtual ~GPURenderer();
|
|
|
|
|
|
|
|
virtual bool Create(void* hWnd);
|
|
|
|
virtual void VSync();
|
2017-05-26 15:26:46 +00:00
|
|
|
virtual bool MakeSnapshot(const std::string& path);
|
2011-02-19 10:57:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class Vertex>
|
|
|
|
class GPURendererT : public GPURenderer
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
Vertex* m_vertices;
|
|
|
|
int m_count;
|
|
|
|
int m_maxcount;
|
|
|
|
GSVertexList<Vertex> m_vl;
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
m_count = 0;
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
|
|
|
|
GPURenderer::Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetPrim()
|
|
|
|
{
|
|
|
|
m_vl.RemoveAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlushPrim()
|
|
|
|
{
|
|
|
|
if(m_count > 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Dump("db");
|
|
|
|
|
|
|
|
if(m_env.PRIM.TME)
|
|
|
|
{
|
|
|
|
GSVector4i r;
|
|
|
|
|
|
|
|
r.left = m_env.STATUS.TX << 6;
|
|
|
|
r.top = m_env.STATUS.TY << 8;
|
|
|
|
r.right = r.left + 256;
|
|
|
|
r.bottom = r.top + 256;
|
|
|
|
|
2011-03-27 03:12:12 +00:00
|
|
|
Dump(format("da_%d_%d_%d_%d_%d", m_env.STATUS.TP, r.left, r.top, r.right, r.bottom).c_str(), m_env.STATUS.TP, r, false);
|
2011-02-19 10:57:28 +00:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
Draw();
|
|
|
|
|
|
|
|
m_count = 0;
|
|
|
|
|
|
|
|
//Dump("dc", false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GrowVertexBuffer()
|
|
|
|
{
|
2011-04-30 00:31:35 +00:00
|
|
|
int maxcount = std::max<int>(m_maxcount * 3 / 2, 10000);
|
2013-06-17 04:11:10 +00:00
|
|
|
Vertex* vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * maxcount, 32);
|
2011-02-19 10:57:28 +00:00
|
|
|
|
2014-09-15 13:49:16 +00:00
|
|
|
if(vertices == NULL)
|
2014-01-25 19:14:28 +00:00
|
|
|
{
|
2016-01-22 08:58:10 +00:00
|
|
|
printf("GSdx: failed to allocate %d bytes for verticles.\n", (int)sizeof(Vertex) * maxcount);
|
2014-01-25 19:14:28 +00:00
|
|
|
throw GSDXError();
|
|
|
|
}
|
|
|
|
|
2014-09-15 13:49:16 +00:00
|
|
|
if(m_vertices != NULL)
|
2011-04-30 00:31:35 +00:00
|
|
|
{
|
|
|
|
memcpy(vertices, m_vertices, sizeof(Vertex) * m_maxcount);
|
|
|
|
_aligned_free(m_vertices);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_vertices = vertices;
|
|
|
|
m_maxcount = maxcount - 100;
|
2011-02-19 10:57:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline Vertex* DrawingKick(int& count)
|
|
|
|
{
|
|
|
|
count = (int)m_env.PRIM.VTX;
|
|
|
|
|
|
|
|
if(m_vl.GetCount() < count)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_count >= m_maxcount)
|
|
|
|
{
|
|
|
|
GrowVertexBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vertex* v = &m_vertices[m_count];
|
|
|
|
|
|
|
|
switch(m_env.PRIM.TYPE)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void VertexKick() = 0;
|
|
|
|
|
|
|
|
virtual void Draw() = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GPURendererT(GSDevice* dev)
|
|
|
|
: GPURenderer(dev)
|
2013-06-28 17:32:37 +00:00
|
|
|
, m_vertices(NULL)
|
2011-02-19 10:57:28 +00:00
|
|
|
, m_count(0)
|
|
|
|
, m_maxcount(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~GPURendererT()
|
|
|
|
{
|
|
|
|
if(m_vertices) _aligned_free(m_vertices);
|
|
|
|
}
|
|
|
|
};
|