-
Notifications
You must be signed in to change notification settings - Fork 5
/
GPURenderer.h
203 lines (166 loc) · 3.79 KB
/
GPURenderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
* 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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#pragma once
#include "GPUState.h"
#include "GSVertexList.h"
#include "GSDevice.h"
#ifdef _WINDOWS
#include "GSWndDX.h"
#endif
class GPURenderer : public GPUState
{
bool Merge();
protected:
GSDevice* m_dev;
int m_filter;
int m_dither;
int m_aspectratio;
bool m_vsync;
bool m_shaderfx;
bool m_customshader;
bool m_fxaa;
bool m_shadeboost;
GSVector2i m_scale;
virtual void ResetDevice() {}
virtual GSTexture* GetOutput() = 0;
#ifdef _WINDOWS
HWND m_hWnd;
WNDPROC m_wndproc;
static map<HWND, GPURenderer*> m_wnd2gpu;
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
#endif
GSWnd* m_wnd;
public:
GPURenderer(GSDevice* dev);
virtual ~GPURenderer();
virtual bool Create(void* hWnd);
virtual void VSync();
virtual bool MakeSnapshot(const string& path);
};
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;
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);
}
*/
Draw();
m_count = 0;
//Dump("dc", false);
}
}
void GrowVertexBuffer()
{
int maxcount = std::max<int>(m_maxcount * 3 / 2, 10000);
Vertex* vertices = (Vertex*)_aligned_malloc(sizeof(Vertex) * maxcount, 32);
if(vertices == NULL)
{
printf("GSdx: failed to allocate %d bytes for verticles.\n", sizeof(Vertex) * maxcount);
throw GSDXError();
}
if(m_vertices != NULL)
{
memcpy(vertices, m_vertices, sizeof(Vertex) * m_maxcount);
_aligned_free(m_vertices);
}
m_vertices = vertices;
m_maxcount = maxcount - 100;
}
__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)
, m_vertices(NULL)
, m_count(0)
, m_maxcount(0)
{
}
virtual ~GPURendererT()
{
if(m_vertices) _aligned_free(m_vertices);
}
};