summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/windows/drawd3d.h
blob: 6ab48555f21b826bf3c3108220e6274724b4a54d (plain) (blame)
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
//============================================================
//
//  drawd3d.h - Win32 Direct3D header
//
//============================================================
//
//  Copyright Aaron Giles
//  All rights reserved.
//
//  Redistribution and use in source and binary forms, with or
//  without modification, are permitted provided that the
//  following conditions are met:
//
//    * Redistributions of source code must retain the above
//      copyright notice, this list of conditions and the
//      following disclaimer.
//    * Redistributions in binary form must reproduce the
//      above copyright notice, this list of conditions and
//      the following disclaimer in the documentation and/or
//      other materials provided with the distribution.
//    * Neither the name 'MAME' nor the names of its
//      contributors may be used to endorse or promote
//      products derived from this software without specific
//      prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND
//  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
//  EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
//  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
//  DAMAGE (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
//  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
//  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
//  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
//  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//============================================================

#ifndef __WIN_DRAWD3D__
#define __WIN_DRAWD3D__


#include "d3dhlsl.h"


//============================================================
//  CONSTANTS
//============================================================

#define VERTEX_BASE_FORMAT  (D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEX2)
#define VERTEX_BUFFER_SIZE  (40960*4+4)

//============================================================
//  TYPE DEFINITIONS
//============================================================

namespace d3d
{
class cache_target;
class render_target;
class renderer;

/* 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 *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y);

	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;

	surface *bloom_target[11];
	texture *bloom_texture[11];
};

/* render_target is the information about a Direct3D render target chain */
class render_target
{
public:
	// construction/destruction
	render_target() { }
	~render_target();

	bool init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y);

	int target_width;
	int target_height;

	int prescale_x;
	int prescale_y;

	int width;
	int height;

	int screen_index;
	int page_index;

	surface *prescaletarget;
	texture *prescaletexture;
	surface *smalltarget;
	texture *smalltexture;
	surface *target[5];
	texture *render_texture[5];

	render_target *next;
	render_target *prev;

	surface *bloom_target[11];
	texture *bloom_texture[11];
};

/* renderer is the information about Direct3D for the current screen */
class renderer
{
public:
	renderer() { }
	renderer(win_window_info *window);
	~renderer();

	int                     initialize();

	int                     device_create();
	int                     device_create_resources();
	void                    device_delete();
	void                    device_delete_resources();

	int                     device_verify_caps();
	int                     device_test_cooperative();

	int                     config_adapter_mode();
	void                    pick_best_mode();
	int                     get_adapter_for_monitor();

	int                     update_window_size();

	int                     pre_window_draw_check();
	void                    begin_frame();
	void                    end_frame();

	void                    draw_line(const render_primitive *prim);
	void                    draw_quad(const render_primitive *prim);
	void                    batch_vector(const render_primitive *prim, float line_time);
	void                    batch_vectors();

	vertex *                mesh_alloc(int numverts);

	void                    update_textures();

	void                    process_primitives();
	void                    primitive_flush_pending();

	void                    set_texture(texture_info *texture);
	void                    set_filter(int filter);
	void                    set_wrap(D3DTEXTUREADDRESS wrap);
	void                    set_modmode(DWORD modmode);
	void                    set_blendmode(int blendmode);
	void                    reset_render_states();

	// Setters / getters
	int                     get_adapter() { return m_adapter; }
	int                     get_width() { return m_width; }
	int                     get_height() { return m_height; }
	int                     get_refresh() { return m_refresh; }

	win_window_info *       get_window() { return m_window; }

	device *                get_device() { return m_device; }
	present_parameters *    get_presentation() { return &m_presentation; }

	vertex_buffer *         get_vertex_buffer() { return m_vertexbuf; }
	vertex *                get_locked_buffer() { return m_lockedbuf; }
	VOID **                 get_locked_buffer_ptr() { return (VOID **)&m_lockedbuf; }
	void                    set_locked_buffer(vertex *lockedbuf) { m_lockedbuf = lockedbuf; }

	void                    set_restarting(bool restarting) { m_restarting = restarting; }
	bool                    is_mod2x_supported() { return (bool)m_mod2x_supported; }
	bool                    is_mod4x_supported() { return (bool)m_mod4x_supported; }

	D3DFORMAT               get_screen_format() { return m_screen_format; }
	D3DFORMAT               get_pixel_format() { return m_pixformat; }
	D3DDISPLAYMODE          get_origmode() { return m_origmode; }

	UINT32                  get_last_texture_flags() { return m_last_texture_flags; }

	texture_manager *       get_texture_manager() { return m_texture_manager; }
	texture_info *          get_default_texture() { return m_texture_manager->get_default_texture(); }
	texture_info *          get_vector_texture() { return m_texture_manager->get_vector_texture(); }

	shaders *               get_shaders() { return m_shaders; }

private:
	int                     m_adapter;                  // ordinal adapter number
	int                     m_width;                    // current width
	int                     m_height;                   // current height
	int                     m_refresh;                  // current refresh rate
	int                     m_create_error_count;       // number of consecutive create errors

	win_window_info *       m_window;                     // current window info

	device *                m_device;                   // pointer to the Direct3DDevice object
	int                     m_gamma_supported;          // is full screen gamma supported?
	present_parameters      m_presentation;             // set of presentation parameters
	D3DDISPLAYMODE          m_origmode;                 // original display mode for the adapter
	D3DFORMAT               m_pixformat;                // pixel format we are using

	vertex_buffer *         m_vertexbuf;                // pointer to the vertex buffer object
	vertex *                m_lockedbuf;                // pointer to the locked vertex buffer
	int                     m_numverts;                 // number of accumulated vertices

	vertex *                m_vectorbatch;              // pointer to the vector batch buffer
	int                     m_batchindex;               // current index into the vector batch

	poly_info               m_poly[VERTEX_BUFFER_SIZE/3];// array to hold polygons as they are created
	int                     m_numpolys;                 // number of accumulated polygons

	bool                    m_restarting;               // if we're restarting

	int                     m_mod2x_supported;          // is D3DTOP_MODULATE2X supported?
	int                     m_mod4x_supported;          // is D3DTOP_MODULATE4X supported?
	D3DFORMAT               m_screen_format;            // format to use for screen textures

	texture_info *          m_last_texture;             // previous texture
	UINT32                  m_last_texture_flags;       // previous texture flags
	int                     m_last_blendenable;         // previous blendmode
	int                     m_last_blendop;             // previous blendmode
	int                     m_last_blendsrc;            // previous blendmode
	int                     m_last_blenddst;            // previous blendmode
	int                     m_last_filter;              // previous texture filter
	D3DTEXTUREADDRESS       m_last_wrap;                // previous wrap state
	DWORD                   m_last_modmode;             // previous texture modulation

	void *                  m_hlsl_buf;                 // HLSL vertex data
	shaders *               m_shaders;                  // HLSL interface

	texture_manager *       m_texture_manager;          // texture manager

	int                     m_line_count;
};

};

#endif