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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
//============================================================
//
// d3dcomm.h - Common Win32 Direct3D structures
//
//============================================================
#ifndef __WIN_D3DCOMM__
#define __WIN_D3DCOMM__
//============================================================
// FORWARD DECLARATIONS
//============================================================
class texture_info;
class renderer_d3d9;
struct d3d_base;
//============================================================
// TYPE DEFINITIONS
//============================================================
class vec2f
{
public:
vec2f()
{
memset(&c, 0, sizeof(float) * 2);
}
vec2f(float x, float y)
{
c.x = x;
c.y = y;
}
vec2f operator+(const vec2f& a)
{
return vec2f(c.x + a.c.x, c.y + a.c.y);
}
vec2f operator-(const vec2f& a)
{
return vec2f(c.x - a.c.x, c.y - a.c.y);
}
struct
{
float x, y;
} c;
};
class d3d_texture_manager
{
public:
d3d_texture_manager() { }
d3d_texture_manager(renderer_d3d9 *d3d);
~d3d_texture_manager();
void update_textures();
void create_resources();
void delete_resources();
texture_info * find_texinfo(const render_texinfo *texture, UINT32 flags);
UINT32 texture_compute_hash(const render_texinfo *texture, UINT32 flags);
texture_info * get_texlist() { return m_texlist; }
void set_texlist(texture_info *texlist) { m_texlist = texlist; }
bool is_dynamic_supported() { return (bool)m_dynamic_supported; }
void set_dynamic_supported(bool dynamic_supported) { m_dynamic_supported = dynamic_supported; }
bool is_stretch_supported() { return (bool)m_stretch_supported; }
D3DFORMAT get_yuv_format() { return m_yuv_format; }
DWORD get_texture_caps() { return m_texture_caps; }
DWORD get_max_texture_aspect() { return m_texture_max_aspect; }
DWORD get_max_texture_width() { return m_texture_max_width; }
DWORD get_max_texture_height() { return m_texture_max_height; }
void compute_texture_size(int texwidth, int texheight, int* p_width, int* p_height);
texture_info * get_default_texture() { return m_default_texture; }
texture_info * get_vector_texture() { return m_vector_texture; }
renderer_d3d9 * get_d3d() { return m_renderer; }
private:
renderer_d3d9 * m_renderer;
texture_info * m_texlist; // list of active textures
int m_dynamic_supported; // are dynamic textures supported?
int m_stretch_supported; // is StretchRect with point filtering supported?
D3DFORMAT m_yuv_format; // format to use for YUV textures
DWORD m_texture_caps; // textureCaps field
DWORD m_texture_max_aspect; // texture maximum aspect ratio
DWORD m_texture_max_width; // texture maximum width
DWORD m_texture_max_height; // texture maximum height
bitmap_argb32 m_vector_bitmap; // experimental: bitmap for vectors
texture_info * m_vector_texture; // experimental: texture for vectors
bitmap_rgb32 m_default_bitmap; // experimental: default bitmap
texture_info * m_default_texture; // experimental: default texture
};
/* texture_info holds information about a texture */
class texture_info
{
public:
texture_info(d3d_texture_manager *manager, const render_texinfo *texsource, int prescale, UINT32 flags);
~texture_info();
render_texinfo & get_texinfo() { return m_texinfo; }
int get_width() { return m_rawdims.c.x; }
int get_height() { return m_rawdims.c.y; }
int get_xscale() { return m_xprescale; }
int get_yscale() { return m_yprescale; }
UINT32 get_flags() { return m_flags; }
void set_data(const render_texinfo *texsource, UINT32 flags);
texture_info * get_next() { return m_next; }
texture_info * get_prev() { return m_prev; }
UINT32 get_hash() { return m_hash; }
void set_next(texture_info *next) { m_next = next; }
void set_prev(texture_info *prev) { m_prev = prev; }
bool paused() { return m_cur_frame == m_prev_frame; }
void advance_frame() { m_prev_frame = m_cur_frame; }
void increment_frame_count() { m_cur_frame++; }
void mask_frame_count(int mask) { m_cur_frame %= mask; }
int get_cur_frame() { return m_cur_frame; }
int get_prev_frame() { return m_prev_frame; }
texture * get_tex() { return m_d3dtex; }
surface * get_surface() { return m_d3dsurface; }
texture * get_finaltex() { return m_d3dfinaltex; }
vec2f & get_uvstart() { return m_start; }
vec2f & get_uvstop() { return m_stop; }
vec2f & get_rawdims() { return m_rawdims; }
private:
void prescale();
void compute_size(int texwidth, int texheight);
d3d_texture_manager * m_texture_manager; // texture manager pointer
renderer_d3d9 * m_renderer; // renderer pointer
texture_info * m_next; // next texture in the list
texture_info * m_prev; // prev texture in the list
UINT32 m_hash; // hash value for the texture
UINT32 m_flags; // rendering flags
render_texinfo m_texinfo; // copy of the texture info
vec2f m_start; // beggining UV coordinates
vec2f m_stop; // ending UV coordinates
vec2f m_rawdims; // raw dims of the texture
int m_type; // what type of texture are we?
int m_xborderpix, m_yborderpix; // number of border pixels on X/Y
int m_xprescale, m_yprescale; // X/Y prescale factor
int m_cur_frame; // what is our current frame?
int m_prev_frame; // what was our last frame? (used to determine pause state)
texture * m_d3dtex; // Direct3D texture pointer
surface * m_d3dsurface; // Direct3D offscreen plain surface pointer
texture * m_d3dfinaltex; // Direct3D final (post-scaled) texture
};
/* poly_info holds information about a single polygon/d3d primitive */
class poly_info
{
public:
poly_info() { }
void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, texture_info *texture, UINT32 modmode,
float prim_width, float prim_height);
void init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
UINT32 flags, texture_info *texture, UINT32 modmode,
float line_time, float line_length,
float prim_width, float prim_height);
D3DPRIMITIVETYPE get_type() { return m_type; }
UINT32 get_count() { return m_count; }
UINT32 get_vertcount() { return m_numverts; }
UINT32 get_flags() { return m_flags; }
texture_info * get_texture() { return m_texture; }
DWORD get_modmode() { return m_modmode; }
float get_line_time() { return m_line_time; }
float get_line_length() { return m_line_length; }
float get_prim_width() { return m_prim_width; }
float get_prim_height() { return m_prim_height; }
private:
D3DPRIMITIVETYPE m_type; // type of primitive
UINT32 m_count; // total number of primitives
UINT32 m_numverts; // total number of vertices
UINT32 m_flags; // rendering flags
texture_info * m_texture; // pointer to texture info
DWORD m_modmode; // texture modulation mode
float m_line_time; // used by vectors
float m_line_length; // used by vectors
float m_prim_width; // used by quads
float m_prim_height; // used by quads
};
/* vertex describes a single vertex */
struct vertex
{
float x, y, z; // X,Y,Z coordinates
float rhw; // RHW when no HLSL, padding when HLSL
D3DCOLOR color; // diffuse color
float u0, v0; // texture stage 0 coordinates
float u1, v1; // additional info for vector data
};
/* line_aa_step is used for drawing antialiased lines */
struct line_aa_step
{
float xoffs, yoffs; // X/Y deltas
float weight; // weight contribution
};
/* cache_target is a simple linked list containing only a rednerable target and texture, used for phosphor effects */
class cache_target
{
public:
// construction/destruction
cache_target() { }
~cache_target();
bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height);
surface *last_target;
texture *last_texture;
int target_width;
int target_height;
int width;
int height;
int screen_index;
cache_target *next;
cache_target *prev;
};
/* render_target is the information about a Direct3D render target chain */
class d3d_render_target
{
public:
// construction/destruction
d3d_render_target() { }
~d3d_render_target();
bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int target_width, int target_height);
int next_index(int index) { return ++index > 1 ? 0 : index; }
// real target dimension
int target_width;
int target_height;
// only used to identify/find the render target
int width;
int height;
int screen_index;
int page_index;
surface *target_surface[2];
texture *target_texture[2];
surface *source_surface[2];
texture *source_texture[2];
d3d_render_target *next;
d3d_render_target *prev;
surface *bloom_surface[11];
texture *bloom_texture[11];
float bloom_dims[11][2];
int bloom_count;
};
#endif
|