summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/windows/drawd3d.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/osd/windows/drawd3d.c')
-rw-r--r--src/osd/windows/drawd3d.c2375
1 files changed, 1220 insertions, 1155 deletions
diff --git a/src/osd/windows/drawd3d.c b/src/osd/windows/drawd3d.c
index 7aa426d4867..1fda54992c7 100644
--- a/src/osd/windows/drawd3d.c
+++ b/src/osd/windows/drawd3d.c
@@ -113,8 +113,6 @@ enum
// GLOBALS
//============================================================
-static d3d_base * d3dintf; // FIX ME
-
static const line_aa_step line_aa_1step[] =
{
{ 0.00f, 0.00f, 1.00f },
@@ -202,80 +200,231 @@ INLINE UINT32 ycc_to_rgb(UINT8 y, UINT8 cb, UINT8 cr)
return MAKE_ARGB(0xff, r, g, b);
}
+//============================================================
+// drawd3d_init
+//============================================================
-INLINE UINT32 texture_compute_hash(const render_texinfo *texture, UINT32 flags)
+static d3d::base * d3dintf; // FIX ME
+
+//============================================================
+// PROTOTYPES
+//============================================================
+
+// core functions
+static void drawd3d_exit(void);
+static int drawd3d_window_init(win_window_info *window);
+static void drawd3d_window_destroy(win_window_info *window);
+static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window);
+static void drawd3d_window_save(win_window_info *window);
+static void drawd3d_window_record(win_window_info *window);
+static void drawd3d_window_toggle_fsfx(win_window_info *window);
+static int drawd3d_window_draw(win_window_info *window, HDC dc, int update);
+
+
+//============================================================
+// drawd3d_window_init
+//============================================================
+
+static int drawd3d_window_init(win_window_info *window)
{
- return (FPTR)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
+ // allocate memory for our structures
+ d3d::renderer *d3d = global_alloc(d3d::renderer(window));
+ window->drawdata = d3d;
+
+ if (!d3d->initialize())
+ {
+ drawd3d_window_destroy(window);
+ mame_printf_error("Unable to initialize Direct3D.\n");
+ return 1;
+ }
+
+ return 0;
}
+//============================================================
+// drawd3d_exit
+//============================================================
+
+static void drawd3d_exit(void)
+{
+ if (d3dintf != NULL)
+ (*d3dintf->d3d.release)(d3dintf);
+}
-INLINE void set_texture(d3d_info *d3d, d3d_texture_info *texture)
+static void drawd3d_window_toggle_fsfx(win_window_info *window)
{
- HRESULT result;
- if (texture != d3d->last_texture)
+ d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
+ d3d->set_restarting(true);
+}
+
+static void drawd3d_window_record(win_window_info *window)
+{
+ d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
+ d3d->get_shaders()->window_record();
+}
+
+static void drawd3d_window_save(win_window_info *window)
+{
+ d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
+ d3d->get_shaders()->window_save();
+}
+
+
+
+//============================================================
+// drawd3d_window_destroy
+//============================================================
+
+static void drawd3d_window_destroy(win_window_info *window)
+{
+ d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
+
+ // skip if nothing
+ if (d3d == NULL)
+ return;
+
+ if (d3d->get_shaders()->recording())
+ d3d->get_shaders()->window_record();
+
+ // free the memory in the window
+ global_free(d3d);
+ window->drawdata = NULL;
+}
+
+
+
+//============================================================
+// drawd3d_window_get_primitives
+//============================================================
+
+static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window)
+{
+ d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
+ RECT client;
+
+ GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen);
+ if (rect_width(&client) > 0 && rect_height(&client) > 0)
{
- d3d->last_texture = texture;
- d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags);
- result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
- d3d->hlsl->set_texture(texture);
+ window->target->set_bounds(rect_width(&client), rect_height(&client), winvideo_monitor_get_aspect(window->monitor));
+ window->target->set_max_update_rate((d3d->get_refresh() == 0) ? d3d->get_origmode().RefreshRate : d3d->get_refresh());
+ }
+ return &window->target->get_primitives();
+}
+
+int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
+{
+ d3dintf = NULL;
+
+ // Use Direct3D9
+ d3dintf = d3d::drawd3d9_init();
+
+ // if we failed, note the error
+ if (d3dintf == NULL)
+ {
+ mame_printf_error("Unable to initialize Direct3D.\n");
+ return 1;
+ }
+
+ // fill in the callbacks
+ callbacks->exit = drawd3d_exit;
+ callbacks->window_init = drawd3d_window_init;
+ callbacks->window_get_primitives = drawd3d_window_get_primitives;
+ callbacks->window_draw = drawd3d_window_draw;
+ callbacks->window_save = drawd3d_window_save;
+ callbacks->window_record = drawd3d_window_record;
+ callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx;
+ callbacks->window_destroy = drawd3d_window_destroy;
+ return 0;
+}
+
+//============================================================
+// drawd3d_window_draw
+//============================================================
+
+static int drawd3d_window_draw(win_window_info *window, HDC dc, int update)
+{
+ d3d::renderer *d3d = (d3d::renderer *)window->drawdata;
+
+ // if we haven't been created, just punt
+ if (d3d == NULL)
+ return 1;
+
+ int check = d3d->pre_window_draw_check();
+ if (check >= 0)
+ return check;
+
+ d3d->begin_frame();
+ d3d->process_primitives();
+ d3d->end_frame();
+
+ return 0;
+}
+
+namespace d3d
+{
+
+void renderer::set_texture(texture_info *texture)
+{
+ if (texture != m_last_texture)
+ {
+ m_last_texture = texture;
+ m_last_texture_flags = (texture == NULL ? 0 : texture->get_flags());
+ HRESULT result = (*d3dintf->device.set_texture)(m_device, 0, (texture == NULL) ? get_default_texture()->get_finaltex() : texture->get_finaltex());
+ m_shaders->set_texture(texture);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
}
}
-INLINE void set_filter(d3d_info *d3d, int filter)
+void renderer::set_filter(int filter)
{
- HRESULT result;
- if (filter != d3d->last_filter)
+ if (filter != m_last_filter)
{
- d3d->last_filter = filter;
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
+ m_last_filter = filter;
+ HRESULT result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MINFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_MAGFILTER, filter ? D3DTEXF_LINEAR : D3DTEXF_POINT);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
}
}
-INLINE void set_wrap(d3d_info *d3d, int wrap)
+void renderer::set_wrap(D3DTEXTUREADDRESS wrap)
{
- HRESULT result;
- if (wrap != d3d->last_wrap)
+ if (wrap != m_last_wrap)
{
- d3d->last_wrap = wrap;
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
+ m_last_wrap = wrap;
+ HRESULT result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSU, wrap);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, (D3DTEXTURESTAGESTATETYPE)D3DTSS_ADDRESSV, wrap);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
}
}
-INLINE void set_modmode(d3d_info *d3d, DWORD modmode)
+void renderer::set_modmode(DWORD modmode)
{
- HRESULT result;
- if (modmode != d3d->last_modmode)
+ if (modmode != m_last_modmode)
{
- d3d->last_modmode = modmode;
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, modmode);
+ m_last_modmode = modmode;
+ HRESULT result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, D3DTSS_COLOROP, modmode);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_COLOROP, modmode);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, D3DTSS_COLOROP, modmode);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture_stage_state call\n", (int)result);
}
}
-INLINE void set_blendmode(d3d_info *d3d, int blendmode)
+void renderer::set_blendmode(int blendmode)
{
- HRESULT result;
int blendenable;
int blendop;
int blendsrc;
@@ -292,437 +441,495 @@ INLINE void set_blendmode(d3d_info *d3d, int blendmode)
}
// adjust the bits that changed
- if (blendenable != d3d->last_blendenable)
+ if (blendenable != m_last_blendenable)
{
- d3d->last_blendenable = blendenable;
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHABLENDENABLE, blendenable);
+ m_last_blendenable = blendenable;
+ HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHABLENDENABLE, blendenable);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result);
}
- if (blendop != d3d->last_blendop)
+ if (blendop != m_last_blendop)
{
- d3d->last_blendop = blendop;
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_BLENDOP, blendop);
+ m_last_blendop = blendop;
+ HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_BLENDOP, blendop);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result);
}
- if (blendsrc != d3d->last_blendsrc)
+ if (blendsrc != m_last_blendsrc)
{
- d3d->last_blendsrc = blendsrc;
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_SRCBLEND, blendsrc);
+ m_last_blendsrc = blendsrc;
+ HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_SRCBLEND, blendsrc);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result);
}
- if (blenddst != d3d->last_blenddst)
+ if (blenddst != m_last_blenddst)
{
- d3d->last_blenddst = blenddst;
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_DESTBLEND, blenddst);
+ m_last_blenddst = blenddst;
+ HRESULT result = (*d3dintf->device.set_render_state)(m_device, D3DRS_DESTBLEND, blenddst);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_state call\n", (int)result);
}
}
-INLINE void reset_render_states(d3d_info *d3d)
+void renderer::reset_render_states()
{
// this ensures subsequent calls to the above setters will force-update the data
- d3d->last_texture = (d3d_texture_info *)~0;
- d3d->last_filter = -1;
- d3d->last_blendenable = -1;
- d3d->last_blendop = -1;
- d3d->last_blendsrc = -1;
- d3d->last_blenddst = -1;
- d3d->last_wrap = -1;
+ m_last_texture = (texture_info *)~0;
+ m_last_filter = -1;
+ m_last_blendenable = -1;
+ m_last_blendop = -1;
+ m_last_blendsrc = -1;
+ m_last_blenddst = -1;
+ m_last_wrap = (D3DTEXTUREADDRESS)-1;
}
-//============================================================
-// PROTOTYPES
-//============================================================
-
-// core functions
-static void drawd3d_exit(void);
-static int drawd3d_window_init(win_window_info *window);
-static void drawd3d_window_destroy(win_window_info *window);
-static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window);
-static void drawd3d_window_save(win_window_info *window);
-static void drawd3d_window_record(win_window_info *window);
-static void drawd3d_window_toggle_fsfx(win_window_info *window);
-static int drawd3d_window_draw(win_window_info *window, HDC dc, int update);
-
-// devices
-static int device_create(win_window_info *window);
-static int device_create_resources(d3d_info *d3d);
-static void device_delete(d3d_info *d3d);
-static void device_delete_resources(d3d_info *d3d);
-static int device_verify_caps(d3d_info *d3d, win_window_info *window);
-static int device_test_cooperative(d3d_info *d3d);
-
-// video modes
-static int config_adapter_mode(win_window_info *window);
-static int get_adapter_for_monitor(d3d_info *d3d, win_monitor_info *monitor);
-static void pick_best_mode(win_window_info *window);
-static int update_window_size(win_window_info *window);
-
-// drawing
-static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_time);
-static void draw_quad(d3d_info *d3d, const render_primitive *prim);
-
-// primitives
-static d3d_vertex *primitive_alloc(d3d_info *d3d, int numverts);
-static void primitive_flush_pending(d3d_info *d3d);
-
-// textures
-static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d_texture_info *texture);
-static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const render_texinfo *texsource, UINT32 flags);
-static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture);
-static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *prim);
-static void texture_update(d3d_info *d3d, const render_primitive *prim);
+texture_manager::texture_manager(renderer *d3d)
+{
+ m_renderer = d3d;
-//============================================================
-// drawd3d_init
-//============================================================
+ m_texlist = NULL;
-int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks)
-{
- int version = downcast<windows_options &>(machine.options()).d3d_version();
- d3dintf = NULL;
+ // check for dynamic texture support
+ DWORD tempcaps;
+ HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_CAPS2, &tempcaps);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
+ m_dynamic_supported = ((tempcaps & D3DCAPS2_DYNAMICTEXTURES) != 0);
+ if (m_dynamic_supported) mame_printf_verbose("Direct3D: Using dynamic textures\n");
- // try Direct3D 9 if requested
- if (version >= 9)
- d3dintf = drawd3d9_init();
+ // check for stretchrect support
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_STRETCH_RECT_FILTER, &tempcaps);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
+ m_stretch_supported = ((tempcaps & D3DPTFILTERCAPS_MAGFPOINT) != 0);
+ if (m_stretch_supported && video_config.prescale > 1) mame_printf_verbose("Direct3D: Using StretchRect for prescaling\n");
-#if DIRECT3D_VERSION < 0x0900
- // if that didn't work, try Direct3D 8
- if (d3dintf == NULL && version >= 8)
- d3dintf = drawd3d8_init();
-#endif
+ // get texture caps
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_TEXTURE_CAPS, &m_texture_caps);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_ASPECT, &m_texture_max_aspect);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_WIDTH, &m_texture_max_width);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_HEIGHT, &m_texture_max_height);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- // if we failed, note the error
- if (d3dintf == NULL)
+ // pick a YUV texture format
+ m_yuv_format = D3DFMT_UYVY;
+ result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, d3d->get_pixel_format(), 0, D3DRTYPE_TEXTURE, D3DFMT_UYVY);
+ if (result != D3D_OK)
{
- mame_printf_error("Unable to initialize Direct3D.\n");
- return 1;
+ m_yuv_format = D3DFMT_YUY2;
+ result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->get_adapter(), D3DDEVTYPE_HAL, d3d->get_pixel_format(), 0, D3DRTYPE_TEXTURE, D3DFMT_YUY2);
+ if (result != D3D_OK)
+ m_yuv_format = D3DFMT_A8R8G8B8;
}
+ mame_printf_verbose("Direct3D: YUV format = %s\n", (m_yuv_format == D3DFMT_YUY2) ? "YUY2" : (m_yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB");
- // fill in the callbacks
- callbacks->exit = drawd3d_exit;
- callbacks->window_init = drawd3d_window_init;
- callbacks->window_get_primitives = drawd3d_window_get_primitives;
- callbacks->window_draw = drawd3d_window_draw;
- callbacks->window_save = drawd3d_window_save;
- callbacks->window_record = drawd3d_window_record;
- callbacks->window_toggle_fsfx = drawd3d_window_toggle_fsfx;
- callbacks->window_destroy = drawd3d_window_destroy;
- return 0;
-}
-
-
-
-//============================================================
-// drawd3d_exit
-//============================================================
-
-static void drawd3d_exit(void)
-{
- if (d3dintf != NULL)
- (*d3dintf->d3d.release)(d3dintf);
+ // set the max texture size
+ d3d->get_window()->target->set_max_texture_size(m_texture_max_width, m_texture_max_height);
+ mame_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)m_texture_max_width, (int)m_texture_max_height);
}
-
-
-//============================================================
-// drawd3d_window_init
-//============================================================
-
-static int drawd3d_window_init(win_window_info *window)
+void texture_manager::create_resources()
{
- d3d_info *d3d;
-
- // allocate memory for our structures
- d3d = global_alloc_clear(d3d_info);
- d3d->restarting = false;
- window->drawdata = d3d;
- d3d->window = window;
- d3d->hlsl = NULL;
-
// experimental: load a PNG to use for vector rendering; it is treated
// as a brightness map
- emu_file file(window->machine().options().art_path(), OPEN_FLAG_READ);
- render_load_png(d3d->vector_bitmap, file, NULL, "vector.png");
- if (d3d->vector_bitmap.valid())
+ emu_file file(m_renderer->get_window()->machine().options().art_path(), OPEN_FLAG_READ);
+ render_load_png(m_vector_bitmap, file, NULL, "vector.png");
+ if (m_vector_bitmap.valid())
{
- d3d->vector_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff));
- render_load_png(d3d->vector_bitmap, file, NULL, "vector.png", true);
+ m_vector_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff));
+ render_load_png(m_vector_bitmap, file, NULL, "vector.png", true);
}
- d3d->default_bitmap.allocate(8, 8);
- d3d->default_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff));
+ m_default_bitmap.allocate(8, 8);
+ m_default_bitmap.fill(MAKE_ARGB(0xff,0xff,0xff,0xff));
- // configure the adapter for the mode we want
- if (config_adapter_mode(window))
- goto error;
+ if (m_default_bitmap.valid())
+ {
+ render_texinfo texture;
- // create the device immediately for the full screen case (defer for window mode)
- if (window->fullscreen && device_create(window))
- goto error;
+ // fake in the basic data so it looks like it came from render.c
+ texture.base = m_default_bitmap.raw_pixptr(0);
+ texture.rowpixels = m_default_bitmap.rowpixels();
+ texture.width = m_default_bitmap.width();
+ texture.height = m_default_bitmap.height();
+ texture.palette = NULL;
+ texture.seqid = 0;
- return 0;
+ // now create it
+ m_default_texture = global_alloc(texture_info(this, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)));
+ }
-error:
- drawd3d_window_destroy(window);
- mame_printf_error("Unable to initialize Direct3D.\n");
- return 1;
-}
+ // experimental: if we have a vector bitmap, create a texture for it
+ if (m_vector_bitmap.valid())
+ {
+ render_texinfo texture;
+ // fake in the basic data so it looks like it came from render.c
+ texture.base = &m_vector_bitmap.pix32(0);
+ texture.rowpixels = m_vector_bitmap.rowpixels();
+ texture.width = m_vector_bitmap.width();
+ texture.height = m_vector_bitmap.height();
+ texture.palette = NULL;
+ texture.seqid = 0;
+ // now create it
+ m_vector_texture = global_alloc(texture_info(this, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32)));
+ }
+}
-static void drawd3d_window_toggle_fsfx(win_window_info *window)
+void texture_manager::delete_resources()
{
- d3d_info *d3d = (d3d_info *)window->drawdata;
+ global_free(m_default_texture);
+ m_default_texture = NULL;
- d3d->restarting = true;
+ // free all textures
+ while (m_texlist != NULL)
+ {
+ texture_info *tex = m_texlist;
+ m_texlist = tex->get_next();
+ global_free(tex);
+ }
}
-static void drawd3d_window_record(win_window_info *window)
+UINT32 texture_manager::texture_compute_hash(const render_texinfo *texture, UINT32 flags)
{
- d3d_info *d3d = (d3d_info *)window->drawdata;
-
- d3d->hlsl->window_record();
+ return (FPTR)texture->base ^ (flags & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK));
}
-static void drawd3d_window_save(win_window_info *window)
+texture_info *texture_manager::find_texinfo(const render_texinfo *texinfo, UINT32 flags)
{
- d3d_info *d3d = (d3d_info *)window->drawdata;
-
- d3d->hlsl->window_save();
-}
+ UINT32 hash = texture_compute_hash(texinfo, flags);
+ texture_info *texture;
+ // find a match
+ for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
+ {
+ UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1;
+ UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1;
+ UINT32 prim_screen = (UINT32)texinfo->osddata >> 1;
+ UINT32 prim_page = (UINT32)texinfo->osddata & 1;
+ if (test_screen != prim_screen || test_page != prim_page)
+ {
+ continue;
+ }
+ if (texture->get_hash() == hash &&
+ texture->get_texinfo().base == texinfo->base &&
+ texture->get_texinfo().width == texinfo->width &&
+ texture->get_texinfo().height == texinfo->height &&
+ ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
+ {
+ // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
+ if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
+ {
+ if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
+ {
+ return texture;
+ }
+ }
+ else
+ {
+ return texture;
+ }
+ }
+ }
-//============================================================
-// drawd3d_window_destroy
-//============================================================
+ // Nothing found
+ /*int checkidx = 0;
+ for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
+ {
+ printf("Checking texture index %d\n", checkidx);
+ UINT32 test_screen = (UINT32)texture->get_texinfo().osddata >> 1;
+ UINT32 test_page = (UINT32)texture->get_texinfo().osddata & 1;
+ UINT32 prim_screen = (UINT32)texinfo->osddata >> 1;
+ UINT32 prim_page = (UINT32)texinfo->osddata & 1;
+ if (test_screen != prim_screen || test_page != prim_page)
+ {
+ printf("No screen/page match: %d vs. %d, %d vs. %d\n", test_screen, prim_screen, test_page, prim_page);
+ continue;
+ }
-static void drawd3d_window_destroy(win_window_info *window)
-{
- d3d_info *d3d = (d3d_info *)window->drawdata;
+ if (texture->get_hash() == hash &&
+ texture->get_texinfo().base == texinfo->base &&
+ texture->get_texinfo().width == texinfo->width &&
+ texture->get_texinfo().height == texinfo->height &&
+ ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
+ {
+ // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
+ if (m_renderer->get_shaders()->enabled() && texinfo->width != 0 && texinfo->height != 0 && (flags & PRIMFLAG_SCREENTEX_MASK) != 0)
+ {
+ if (m_renderer->get_shaders()->find_render_target(texture) != NULL)
+ {
+ return texture;
+ }
+ }
+ else
+ {
+ return texture;
+ }
+ }
- // skip if nothing
- if (d3d == NULL)
- return;
+ if (texture->get_hash() != hash)
+ {
+ printf("No hash match: %d vs. %d\n", texture->get_hash(), hash);
+ }
+ if (texture->get_texinfo().base != texinfo->base)
+ {
+ printf("No base match\n");
+ }
+ if (texture->get_texinfo().width != texinfo->width)
+ {
+ printf("No width match: %d vs. %d\n", texture->get_texinfo().width, texinfo->width);
+ }
+ if (texture->get_texinfo().height != texinfo->height)
+ {
+ printf("No height match: %d vs. %d\n", texture->get_texinfo().height, texinfo->height);
+ }
+ if (((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) != 0)
+ {
+ printf("No flag match: %08x & %08x = %08x\n", texture->get_flags(), flags, ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)));
+ }
+ printf("\n");
+ checkidx++;
+ }
- if (d3d->hlsl->recording())
- d3d->hlsl->window_record();
+ printf("\n\n\n\n");*/
- // delete the device
- device_delete(d3d);
+ // Nothing found, check if we need to unregister something with HLSL
+ if (m_renderer->get_shaders()->enabled())
+ {
+ if (texinfo->width == 0 || texinfo->height == 0)
+ {
+ return NULL;
+ }
- // free the memory in the window
- global_free(d3d);
- window->drawdata = NULL;
-}
+ UINT32 prim_screen = texinfo->osddata >> 1;
+ UINT32 prim_page = texinfo->osddata & 1;
+ for (texture = m_renderer->get_texture_manager()->get_texlist(); texture != NULL; texture = texture->get_next())
+ {
+ UINT32 test_screen = texture->get_texinfo().osddata >> 1;
+ UINT32 test_page = texture->get_texinfo().osddata & 1;
+ if (test_screen != prim_screen || test_page != prim_page)
+ {
+ continue;
+ }
+ // Clear out our old texture reference
+ if (texture->get_hash() == hash &&
+ texture->get_texinfo().base == texinfo->base &&
+ ((texture->get_flags() ^ flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 &&
+ (texture->get_texinfo().width != texinfo->width ||
+ texture->get_texinfo().height != texinfo->height))
+ {
+ m_renderer->get_shaders()->remove_render_target(texture);
+ }
+ }
+ }
-//============================================================
-// drawd3d_window_get_primitives
-//============================================================
+ return NULL;
+}
-static render_primitive_list *drawd3d_window_get_primitives(win_window_info *window)
+renderer::renderer(win_window_info *window)
{
- d3d_info *d3d = (d3d_info *)window->drawdata;
- RECT client;
-
- GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen);
- if (rect_width(&client) > 0 && rect_height(&client) > 0)
- {
- window->target->set_bounds(rect_width(&client), rect_height(&client), winvideo_monitor_get_aspect(window->monitor));
- window->target->set_max_update_rate((d3d->refresh == 0) ? d3d->origmode.RefreshRate : d3d->refresh);
- }
- return &window->target->get_primitives();
+ m_device = NULL;
+ m_restarting = false;
+ m_window = window;
+ m_shaders = NULL;
+ m_numverts = 0;
+ m_numpolys = 0;
}
+int renderer::initialize()
+{
+ // configure the adapter for the mode we want
+ if (config_adapter_mode())
+ return false;
+ // create the device immediately for the full screen case (defer for window mode)
+ if (m_window->fullscreen && device_create())
+ return false;
-//============================================================
-// drawd3d_window_draw
-//============================================================
+ m_texture_manager = global_alloc(texture_manager(this));
-static int drawd3d_window_draw(win_window_info *window, HDC dc, int update)
-{
- d3d_info *d3d = (d3d_info *)window->drawdata;
- render_primitive *prim;
- HRESULT result;
+ return true;
+}
+int renderer::pre_window_draw_check()
+{
// if we're in the middle of resizing, leave things alone
- if (window->resize_state == RESIZE_STATE_RESIZING)
+ if (m_window->resize_state == RESIZE_STATE_RESIZING)
return 0;
// if we're restarting the renderer, leave things alone
- if (d3d->restarting)
+ if (m_restarting)
{
- d3d->hlsl->toggle();
+ m_shaders->toggle();
// free all existing resources and re-create
- device_delete_resources(d3d);
- device_create_resources(d3d);
+ device_delete_resources();
+ device_create_resources();
- d3d->restarting = false;
+ m_restarting = false;
}
- // if we haven't been created, just punt
- if (d3d == NULL)
- return 1;
-
// if we have a device, check the cooperative level
- if (d3d->device != NULL)
+ if (m_device != NULL)
{
- int error = device_test_cooperative(d3d);
- if (error)
+ if (device_test_cooperative())
return 1;
}
// in window mode, we need to track the window size
- if (!window->fullscreen || d3d->device == NULL)
+ if (!m_window->fullscreen || m_device == NULL)
{
// if the size changes, skip this update since the render target will be out of date
- if (update_window_size(window))
+ if (update_window_size())
return 0;
// if we have no device, after updating the size, return an error so GDI can try
- if (d3d->device == NULL)
+ if (m_device == NULL)
return 1;
}
-mtlog_add("drawd3d_window_draw: begin");
- result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
-
- d3d->hlsl->begin_frame();
+ return -1;
+}
- // first update any textures
- window->primlist->acquire_lock();
- for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
+void texture_manager::update_textures()
+{
+ for (render_primitive *prim = m_renderer->get_window()->primlist->first(); prim != NULL; prim = prim->next())
{
if (prim->texture.base != NULL)
{
- texture_update(d3d, prim);
+ texture_info *texture = find_texinfo(&prim->texture, prim->flags);
+ if (texture == NULL)
+ {
+ // if there isn't one, create a new texture
+ global_alloc(texture_info(this, &prim->texture, prim->flags));
+ }
+ else
+ {
+ // if there is one, but with a different seqid, copy the data
+ if (texture->get_texinfo().seqid != prim->texture.seqid)
+ {
+ texture->set_data(&prim->texture, prim->flags);
+ texture->get_texinfo().seqid = prim->texture.seqid;
+ }
+ }
}
- else if(d3d->hlsl->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
+ else if(m_renderer->get_shaders()->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
{
- if (!d3d->hlsl->get_vector_target())
+ if (!m_renderer->get_shaders()->get_vector_target())
{
- d3d->hlsl->create_vector_target(prim);
+ m_renderer->get_shaders()->create_vector_target(prim);
}
}
}
+}
+
+void renderer::begin_frame()
+{
+ HRESULT result = (*d3dintf->device.clear)(m_device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
+ if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result);
+
+ m_shaders->begin_frame();
+
+ m_window->primlist->acquire_lock();
+
+ // first update any textures
+ m_texture_manager->update_textures();
// begin the scene
mtlog_add("drawd3d_window_draw: begin_scene");
- result = (*d3dintf->device.begin_scene)(d3d->device);
+ result = (*d3dintf->device.begin_scene)(m_device);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device begin_scene call\n", (int)result);
- d3d->lockedbuf = NULL;
+ m_lockedbuf = NULL;
- // loop over primitives
- if(d3d->hlsl->enabled())
+ if(m_shaders->enabled())
{
- d3d->hlsl_buf = (void*)primitive_alloc(d3d, 6);
- d3d->hlsl->init_fsfx_quad(d3d->hlsl_buf);
+ m_hlsl_buf = (void*)mesh_alloc(6);
+ m_shaders->init_fsfx_quad(m_hlsl_buf);
}
-mtlog_add("drawd3d_window_draw: count lines");
- int line_count = 0;
- for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
+ m_line_count = 0;
+ // loop over primitives
+ for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next())
if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags))
- line_count++;
+ m_line_count++;
+}
+
+void renderer::process_primitives()
+{
+ if (m_line_count && m_shaders->enabled() && d3dintf->post_fx_available)
+ {
+ batch_vectors();
+ }
-mtlog_add("drawd3d_window_draw: primitive loop begin");
// Rotating index for vector time offsets
- static int start_index = 0;
- int line_index = 0;
- windows_options &options = downcast<windows_options &>(window->machine().options());
- float period = options.screen_vector_time_period();
- for (prim = window->primlist->first(); prim != NULL; prim = prim->next())
+ for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next())
{
switch (prim->type)
{
case render_primitive::LINE:
if (PRIMFLAG_GET_VECTOR(prim->flags))
{
- if (period == 0.0f || line_count == 0)
- {
- draw_line(d3d, prim, 1.0f);
- }
- else
- {
- draw_line(d3d, prim, (float)(start_index + line_index) / ((float)line_count * period));
- line_index++;
- }
+ continue;
}
else
{
- draw_line(d3d, prim, 0.0f);
+ draw_line(prim);
}
break;
case render_primitive::QUAD:
- draw_quad(d3d, prim);
+ draw_quad(prim);
break;
default:
throw emu_fatalerror("Unexpected render_primitive type");
}
}
- start_index += (int)((float)line_index * period);
- if (line_count > 0)
+
+ if (m_line_count && !(m_shaders->enabled() && d3dintf->post_fx_available))
{
- start_index %= line_count;
+ batch_vectors();
}
-mtlog_add("drawd3d_window_draw: primitive loop end");
- window->primlist->release_lock();
+}
+
+void renderer::end_frame()
+{
+ m_window->primlist->release_lock();
// flush any pending polygons
-mtlog_add("drawd3d_window_draw: flush_pending begin");
- primitive_flush_pending(d3d);
-mtlog_add("drawd3d_window_draw: flush_pending end");
+ primitive_flush_pending();
- d3d->hlsl->end_frame();
+ m_shaders->end_frame();
// finish the scene
-mtlog_add("drawd3d_window_draw: end_scene begin");
- result = (*d3dintf->device.end_scene)(d3d->device);
-mtlog_add("drawd3d_window_draw: end_scene end");
+ HRESULT result = (*d3dintf->device.end_scene)(m_device);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device end_scene call\n", (int)result);
// present the current buffers
-mtlog_add("drawd3d_window_draw: present begin");
- result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0);
-mtlog_add("drawd3d_window_draw: present end");
+ result = (*d3dintf->device.present)(m_device, NULL, NULL, NULL, NULL, 0);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device present call\n", (int)result);
-
- return 0;
}
-
-
//============================================================
// device_create
//============================================================
-static int device_create(win_window_info *window)
+int renderer::device_create()
{
- d3d_info *d3d = (d3d_info *)window->drawdata;
- HRESULT result;
- int verify;
-
// if a device exists, free it
- if (d3d->device != NULL)
- device_delete(d3d);
+ if (m_device != NULL)
+ device_delete();
// verify the caps
- verify = device_verify_caps(d3d, window);
+ int verify = device_verify_caps();
if (verify == 2)
{
mame_printf_error("Error: Device does not meet minimum requirements for Direct3D rendering\n");
@@ -732,37 +939,25 @@ static int device_create(win_window_info *window)
mame_printf_warning("Warning: Device may not perform well for Direct3D rendering\n");
// verify texture formats
- result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
+ HRESULT result = (*d3dintf->d3d.check_device_format)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
if (result != D3D_OK)
{
mame_printf_error("Error: A8R8G8B8 format textures not supported\n");
return 1;
}
- // pick a YUV texture format
- d3d->yuv_format = D3DFMT_UYVY;
- result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_UYVY);
- if (result != D3D_OK)
- {
- d3d->yuv_format = D3DFMT_YUY2;
- result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, 0, D3DRTYPE_TEXTURE, D3DFMT_YUY2);
- if (result != D3D_OK)
- d3d->yuv_format = D3DFMT_A8R8G8B8;
- }
- mame_printf_verbose("Direct3D: YUV format = %s\n", (d3d->yuv_format == D3DFMT_YUY2) ? "YUY2" : (d3d->yuv_format == D3DFMT_UYVY) ? "UYVY" : "RGB");
-
try_again:
// try for XRGB first
- d3d->screen_format = D3DFMT_X8R8G8B8;
- result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, d3d->screen_format);
+ m_screen_format = D3DFMT_X8R8G8B8;
+ result = (*d3dintf->d3d.check_device_format)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_texture_manager->is_dynamic_supported() ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, m_screen_format);
if (result != D3D_OK)
{
// if not, try for ARGB
- d3d->screen_format = D3DFMT_A8R8G8B8;
- result = (*d3dintf->d3d.check_device_format)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, d3d->screen_format);
- if (result != D3D_OK && d3d->dynamic_supported)
+ m_screen_format = D3DFMT_A8R8G8B8;
+ result = (*d3dintf->d3d.check_device_format)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_texture_manager->is_dynamic_supported() ? D3DUSAGE_DYNAMIC : 0, D3DRTYPE_TEXTURE, m_screen_format);
+ if (result != D3D_OK && m_texture_manager->is_dynamic_supported())
{
- d3d->dynamic_supported = FALSE;
+ m_texture_manager->set_dynamic_supported(FALSE);
goto try_again;
}
if (result != D3D_OK)
@@ -773,33 +968,34 @@ try_again:
}
// initialize the D3D presentation parameters
- memset(&d3d->presentation, 0, sizeof(d3d->presentation));
- d3d->presentation.BackBufferWidth = d3d->width;
- d3d->presentation.BackBufferHeight = d3d->height;
- d3d->presentation.BackBufferFormat = d3d->pixformat;
- d3d->presentation.BackBufferCount = video_config.triplebuf ? 2 : 1;
- d3d->presentation.MultiSampleType = D3DMULTISAMPLE_NONE;
- d3d->presentation.SwapEffect = D3DSWAPEFFECT_DISCARD;
- d3d->presentation.hDeviceWindow = window->hwnd;
- d3d->presentation.Windowed = !window->fullscreen || win_has_menu(window);
- d3d->presentation.EnableAutoDepthStencil = FALSE;
- d3d->presentation.AutoDepthStencilFormat = D3DFMT_D16;
- d3d->presentation.Flags = 0;
- d3d->presentation.FullScreen_RefreshRateInHz = d3d->refresh;
- d3d->presentation.PresentationInterval = ((video_config.triplebuf && window->fullscreen) || video_config.waitvsync || video_config.syncrefresh) ?
- D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
+ memset(&m_presentation, 0, sizeof(m_presentation));
+ m_presentation.BackBufferWidth = m_width;
+ m_presentation.BackBufferHeight = m_height;
+ m_presentation.BackBufferFormat = m_pixformat;
+ m_presentation.BackBufferCount = video_config.triplebuf ? 2 : 1;
+ m_presentation.MultiSampleType = D3DMULTISAMPLE_NONE;
+ m_presentation.SwapEffect = D3DSWAPEFFECT_DISCARD;
+ m_presentation.hDeviceWindow = m_window->hwnd;
+ m_presentation.Windowed = !m_window->fullscreen || win_has_menu(m_window);
+ m_presentation.EnableAutoDepthStencil = FALSE;
+ m_presentation.AutoDepthStencilFormat = D3DFMT_D16;
+ m_presentation.Flags = 0;
+ m_presentation.FullScreen_RefreshRateInHz = m_refresh;
+ m_presentation.PresentationInterval = ((video_config.triplebuf && m_window->fullscreen) ||
+ video_config.waitvsync || video_config.syncrefresh) ?
+ D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
// create the D3D device
- result = (*d3dintf->d3d.create_device)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, win_window_list->hwnd,
- D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3d->presentation, &d3d->device);
+ result = (*d3dintf->d3d.create_device)(d3dintf, m_adapter, D3DDEVTYPE_HAL, win_window_list->hwnd,
+ D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &m_presentation, &m_device);
if (result != D3D_OK)
{
// if we got a "DEVICELOST" error, it may be transitory; count it and only fail if
// we exceed a threshold
if (result == D3DERR_DEVICELOST)
{
- d3d->create_error_count++;
- if (d3d->create_error_count < 10)
+ m_create_error_count++;
+ if (m_create_error_count < 10)
return 0;
}
@@ -807,44 +1003,42 @@ try_again:
mame_printf_error("Unable to create the Direct3D device (%08X)\n", (UINT32)result);
return 1;
}
- d3d->create_error_count = 0;
- mame_printf_verbose("Direct3D: Device created at %dx%d\n", d3d->width, d3d->height);
-
- // set the max texture size
- window->target->set_max_texture_size(d3d->texture_max_width, d3d->texture_max_height);
- mame_printf_verbose("Direct3D: Max texture size = %dx%d\n", (int)d3d->texture_max_width, (int)d3d->texture_max_height);
+ m_create_error_count = 0;
+ mame_printf_verbose("Direct3D: Device created at %dx%d\n", m_width, m_height);
// set the gamma if we need to
- if (window->fullscreen)
+ if (m_window->fullscreen)
{
// only set the gamma if it's not 1.0f
- windows_options &options = downcast<windows_options &>(window->machine().options());
+ windows_options &options = downcast<windows_options &>(m_window->machine().options());
float brightness = options.full_screen_brightness();
float contrast = options.full_screen_contrast();
float gamma = options.full_screen_gamma();
if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f)
{
// warn if we can't do it
- if (!d3d->gamma_supported)
+ if (!m_gamma_supported)
+ {
mame_printf_warning("Direct3D: Warning - device does not support full screen gamma correction.\n");
+ }
else
{
- D3DGAMMARAMP ramp;
- int i;
-
// create a standard ramp and set it
- for (i = 0; i < 256; i++)
+ D3DGAMMARAMP ramp;
+ for (int i = 0; i < 256; i++)
+ {
ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8;
- (*d3dintf->device.set_gamma_ramp)(d3d->device, 0, &ramp);
+ }
+ (*d3dintf->device.set_gamma_ramp)(m_device, 0, &ramp);
}
}
}
- int ret = d3d->hlsl->create_resources(false);
+ int ret = m_shaders->create_resources(false);
if (ret != 0)
return ret;
- return device_create_resources(d3d);
+ return device_create_resources();
}
@@ -853,15 +1047,14 @@ try_again:
// device_create_resources
//============================================================
-static int device_create_resources(d3d_info *d3d)
+int renderer::device_create_resources()
{
- HRESULT result;
-
// allocate a vertex buffer to use
- result = (*d3dintf->device.create_vertex_buffer)(d3d->device,
- sizeof(d3d_vertex) * VERTEX_BUFFER_SIZE,
+ HRESULT result = (*d3dintf->device.create_vertex_buffer)(m_device,
+ sizeof(vertex) * VERTEX_BUFFER_SIZE,
D3DUSAGE_DYNAMIC | D3DUSAGE_SOFTWAREPROCESSING | D3DUSAGE_WRITEONLY,
- VERTEX_BASE_FORMAT | ((d3d->hlsl->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW), D3DPOOL_DEFAULT, &d3d->vertexbuf);
+ VERTEX_BASE_FORMAT | ((m_shaders->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW),
+ D3DPOOL_DEFAULT, &m_vertexbuf);
if (result != D3D_OK)
{
printf("Error creating vertex buffer (%08X)", (UINT32)result);
@@ -869,7 +1062,8 @@ static int device_create_resources(d3d_info *d3d)
}
// set the vertex format
- result = (*d3dintf->device.set_vertex_format)(d3d->device, (D3DFORMAT)(VERTEX_BASE_FORMAT | ((d3d->hlsl->enabled() && d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW)));
+ result = (*d3dintf->device.set_vertex_format)(m_device, (D3DFORMAT)(VERTEX_BASE_FORMAT | ((m_shaders->enabled() &&
+ d3dintf->post_fx_available) ? D3DFVF_XYZW : D3DFVF_XYZRHW)));
if (result != D3D_OK)
{
mame_printf_error("Error setting vertex format (%08X)", (UINT32)result);
@@ -877,69 +1071,38 @@ static int device_create_resources(d3d_info *d3d)
}
// set the fixed render state
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ZENABLE, D3DZB_FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_FILLMODE, D3DFILL_SOLID);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_SHADEMODE, D3DSHADE_FLAT);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ZWRITEENABLE, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHATESTENABLE, TRUE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_LASTPIXEL, TRUE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_CULLMODE, D3DCULL_NONE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ZFUNC, D3DCMP_LESS);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHAREF, 0);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_ALPHAFUNC, D3DCMP_GREATER);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_DITHERENABLE, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_FOGENABLE, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_SPECULARENABLE, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_STENCILENABLE, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_WRAP0, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_CLIPPING, TRUE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_LIGHTING, FALSE);
- result = (*d3dintf->device.set_render_state)(d3d->device, D3DRS_COLORVERTEX, TRUE);
-
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
- result = (*d3dintf->device.set_texture_stage_state)(d3d->device, 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ZENABLE, D3DZB_FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_FILLMODE, D3DFILL_SOLID);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_SHADEMODE, D3DSHADE_FLAT);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ZWRITEENABLE, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHATESTENABLE, TRUE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_LASTPIXEL, TRUE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_CULLMODE, D3DCULL_NONE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ZFUNC, D3DCMP_LESS);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHAREF, 0);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_ALPHAFUNC, D3DCMP_GREATER);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_DITHERENABLE, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_FOGENABLE, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_SPECULARENABLE, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_STENCILENABLE, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_WRAP0, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_CLIPPING, TRUE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_LIGHTING, FALSE);
+ result = (*d3dintf->device.set_render_state)(m_device, D3DRS_COLORVERTEX, TRUE);
+
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, D3DTSS_COLOROP, D3DTOP_MODULATE);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, D3DTSS_COLOROP, D3DTOP_MODULATE);
+ result = (*d3dintf->device.set_texture_stage_state)(m_device, 1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
// reset the local states to force updates
- reset_render_states(d3d);
+ reset_render_states();
// clear the buffer
- result = (*d3dintf->device.clear)(d3d->device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
- result = (*d3dintf->device.present)(d3d->device, NULL, NULL, NULL, NULL, 0);
-
- if (d3d->default_bitmap.valid())
- {
- render_texinfo texture;
-
- // fake in the basic data so it looks like it came from render.c
- texture.base = d3d->default_bitmap.raw_pixptr(0);
- texture.rowpixels = d3d->default_bitmap.rowpixels();
- texture.width = d3d->default_bitmap.width();
- texture.height = d3d->default_bitmap.height();
- texture.palette = NULL;
- texture.seqid = 0;
-
- // now create it
- d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
- }
-
- // experimental: if we have a vector bitmap, create a texture for it
- if (d3d->vector_bitmap.valid())
- {
- render_texinfo texture;
+ result = (*d3dintf->device.clear)(m_device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0);
+ result = (*d3dintf->device.present)(m_device, NULL, NULL, NULL, NULL, 0);
- // fake in the basic data so it looks like it came from render.c
- texture.base = &d3d->vector_bitmap.pix32(0);
- texture.rowpixels = d3d->vector_bitmap.rowpixels();
- texture.width = d3d->vector_bitmap.width();
- texture.height = d3d->vector_bitmap.height();
- texture.palette = NULL;
- texture.seqid = 0;
-
- // now create it
- d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
- }
+ m_texture_manager->create_resources();
return 0;
}
@@ -950,62 +1113,45 @@ static int device_create_resources(d3d_info *d3d)
// device_delete
//============================================================
-static void device_delete(d3d_info *d3d)
+renderer::~renderer()
+{
+ device_delete();
+}
+
+void renderer::device_delete()
{
// free our effects
- d3d->hlsl->delete_resources(false);
+ m_shaders->delete_resources(false);
// delete the HLSL interface
- global_free(d3d->hlsl);
+ global_free(m_shaders);
// free our base resources
- device_delete_resources(d3d);
+ device_delete_resources();
+
+ if (m_texture_manager != NULL)
+ {
+ global_free(m_texture_manager);
+ }
+ m_texture_manager = NULL;
// free the device itself
- if (d3d->device != NULL)
- (*d3dintf->device.release)(d3d->device);
- d3d->device = NULL;
+ if (m_device != NULL)
+ (*d3dintf->device.release)(m_device);
+ m_device = NULL;
}
-
-
//============================================================
// device_delete_resources
//============================================================
-static void device_delete_resources(d3d_info *d3d)
+void renderer::device_delete_resources()
{
- // free all textures
- while (d3d->texlist != NULL)
- {
- d3d_texture_info *tex = d3d->texlist;
- d3d->texlist = tex->next;
- if (tex->d3dfinaltex != NULL)
- {
- if (tex->d3dtex == tex->d3dfinaltex) tex->d3dtex = NULL;
- (*d3dintf->texture.release)(tex->d3dfinaltex);
- tex->d3dfinaltex = NULL;
- }
- if (tex->d3dtex != NULL)
- {
- (*d3dintf->texture.release)(tex->d3dtex);
- tex->d3dtex = NULL;
- }
- if (tex->d3dsurface != NULL)
- {
- (*d3dintf->surface.release)(tex->d3dsurface);
- tex->d3dsurface = NULL;
- }
- global_free(tex);
- }
-
+ m_texture_manager->delete_resources();
// free the vertex buffer
- if (d3d->vertexbuf != NULL)
- (*d3dintf->vertexbuf.release)(d3d->vertexbuf);
- d3d->vertexbuf = NULL;
-
- global_free(d3d->default_texture);
- d3d->default_texture = NULL;
+ if (m_vertexbuf != NULL)
+ (*d3dintf->vertexbuf.release)(m_vertexbuf);
+ m_vertexbuf = NULL;
}
@@ -1014,26 +1160,15 @@ static void device_delete_resources(d3d_info *d3d)
// device_verify_caps
//============================================================
-static int device_verify_caps(d3d_info *d3d, win_window_info *window)
+int renderer::device_verify_caps()
{
int retval = 0;
- HRESULT result;
- DWORD tempcaps;
-
- // fetch a few core caps
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_CAPS, &d3d->texture_caps);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_ASPECT, &d3d->texture_max_aspect);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_WIDTH, &d3d->texture_max_width);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_TEXTURE_HEIGHT, &d3d->texture_max_height);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- d3d->hlsl = global_alloc_clear(hlsl_info);
- d3d->hlsl->init(d3dintf, window);
+ m_shaders = global_alloc_clear(shaders);
+ m_shaders->init(d3dintf, m_window);
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
+ DWORD tempcaps;
+ HRESULT result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_MAX_PS30_INSN_SLOTS, &tempcaps);
if (result != D3D_OK) mame_printf_verbose("Direct3D Error %08X during get_caps_dword call\n", (int)result);
if(tempcaps < 512)
{
@@ -1042,7 +1177,7 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window)
}
// verify presentation capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_PRESENTATION_INTERVALS, &tempcaps);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
if (!(tempcaps & D3DPRESENT_INTERVAL_IMMEDIATE))
{
@@ -1056,7 +1191,7 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window)
}
// verify device capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_DEV_CAPS, &tempcaps);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_DEV_CAPS, &tempcaps);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
if (!(tempcaps & D3DDEVCAPS_CANRENDERAFTERFLIP))
{
@@ -1069,86 +1204,8 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window)
retval = 1;
}
- // verify source blend capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_SRCBLEND_CAPS, &tempcaps);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- if (!(tempcaps & D3DPBLENDCAPS_SRCALPHA))
- {
- mame_printf_verbose("Direct3D: Error - Device does not support source alpha blending with source alpha\n");
- retval = 2;
- }
- if (!(tempcaps & D3DPBLENDCAPS_DESTCOLOR))
- {
- mame_printf_verbose("Direct3D: Error - Device does not support source alpha blending with destination color\n");
- retval = 2;
- }
-
- // verify destination blend capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_DSTBLEND_CAPS, &tempcaps);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- if (!(tempcaps & D3DPBLENDCAPS_ZERO))
- {
- mame_printf_verbose("Direct3D: Error - Device does not support dest alpha blending with zero\n");
- retval = 2;
- }
- if (!(tempcaps & D3DPBLENDCAPS_ONE))
- {
- mame_printf_verbose("Direct3D: Error - Device does not support dest alpha blending with one\n");
- retval = 2;
- }
- if (!(tempcaps & D3DPBLENDCAPS_INVSRCALPHA))
- {
- mame_printf_verbose("Direct3D: Error - Device does not support dest alpha blending with inverted source alpha\n");
- retval = 2;
- }
-
- // verify texture capabilities
- if (!(d3d->texture_caps & D3DPTEXTURECAPS_ALPHA))
- {
- mame_printf_verbose("Direct3D: Error - Device does not support texture alpha\n");
- retval = 2;
- }
-
- // verify texture filter capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_FILTER_CAPS, &tempcaps);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- if (!(tempcaps & D3DPTFILTERCAPS_MAGFPOINT))
- {
- mame_printf_verbose("Direct3D: Warning - Device does not support point-sample texture filtering for magnification\n");
- retval = 1;
- }
- if (!(tempcaps & D3DPTFILTERCAPS_MAGFLINEAR))
- {
- mame_printf_verbose("Direct3D: Warning - Device does not support bilinear texture filtering for magnification\n");
- retval = 1;
- }
- if (!(tempcaps & D3DPTFILTERCAPS_MINFPOINT))
- {
- mame_printf_verbose("Direct3D: Warning - Device does not support point-sample texture filtering for minification\n");
- retval = 1;
- }
- if (!(tempcaps & D3DPTFILTERCAPS_MINFLINEAR))
- {
- mame_printf_verbose("Direct3D: Warning - Device does not support bilinear texture filtering for minification\n");
- retval = 1;
- }
-
- // verify texture addressing capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_ADDRESS_CAPS, &tempcaps);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- if (!(tempcaps & D3DPTADDRESSCAPS_CLAMP))
- {
- mame_printf_verbose("Direct3D: Warning - Device does not support texture clamping\n");
- retval = 1;
- }
- if (!(tempcaps & D3DPTADDRESSCAPS_WRAP))
- {
- mame_printf_verbose("Direct3D: Warning - Device does not support texture wrapping\n");
- retval = 1;
- }
-
// verify texture operation capabilities
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_OP_CAPS, &tempcaps);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_TEXTURE_OP_CAPS, &tempcaps);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
if (!(tempcaps & D3DTEXOPCAPS_MODULATE))
{
@@ -1157,21 +1214,12 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window)
}
// set a simpler flag to indicate mod2x and mod4x texture modes
- d3d->mod2x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE2X) != 0);
- d3d->mod4x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE4X) != 0);
-
- // set a simpler flag to indicate we can use a gamma ramp
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_CAPS2, &tempcaps);
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- d3d->dynamic_supported = ((tempcaps & D3DCAPS2_DYNAMICTEXTURES) != 0);
- d3d->gamma_supported = ((tempcaps & D3DCAPS2_FULLSCREENGAMMA) != 0);
- if (d3d->dynamic_supported) mame_printf_verbose("Direct3D: Using dynamic textures\n");
+ m_mod2x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE2X) != 0);
+ m_mod4x_supported = ((tempcaps & D3DTEXOPCAPS_MODULATE4X) != 0);
- // set a simpler flag to indicate we can use StretchRect
- result = (*d3dintf->d3d.get_caps_dword)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, CAPS_STRETCH_RECT_FILTER, &tempcaps);
+ result = (*d3dintf->d3d.get_caps_dword)(d3dintf, m_adapter, D3DDEVTYPE_HAL, CAPS_CAPS2, &tempcaps);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during get_caps_dword call\n", (int)result);
- d3d->stretch_supported = ((tempcaps & D3DPTFILTERCAPS_MAGFPOINT) != 0);
- if (d3d->stretch_supported && video_config.prescale > 1) mame_printf_verbose("Direct3D: Using StretchRect for prescaling\n");
+ m_gamma_supported = ((tempcaps & D3DCAPS2_FULLSCREENGAMMA) != 0);
return retval;
}
@@ -1182,12 +1230,10 @@ static int device_verify_caps(d3d_info *d3d, win_window_info *window)
// device_test_cooperative
//============================================================
-static int device_test_cooperative(d3d_info *d3d)
+int renderer::device_test_cooperative()
{
- HRESULT result;
-
// check our current status; if we lost the device, punt to GDI
- result = (*d3dintf->device.test_cooperative_level)(d3d->device);
+ HRESULT result = (*d3dintf->device.test_cooperative_level)(m_device);
if (result == D3DERR_DEVICELOST)
return 1;
@@ -1197,9 +1243,9 @@ static int device_test_cooperative(d3d_info *d3d)
mame_printf_verbose("Direct3D: resetting device\n");
// free all existing resources and call reset on the device
- device_delete_resources(d3d);
- d3d->hlsl->delete_resources(true);
- result = (*d3dintf->device.reset)(d3d->device, &d3d->presentation);
+ device_delete_resources();
+ m_shaders->delete_resources(true);
+ result = (*d3dintf->device.reset)(m_device, &m_presentation);
// if it didn't work, punt to GDI
if (result != D3D_OK)
@@ -1209,17 +1255,17 @@ static int device_test_cooperative(d3d_info *d3d)
}
// try to create the resources again; if that didn't work, delete the whole thing
- if (device_create_resources(d3d))
+ if (device_create_resources())
{
mame_printf_verbose("Direct3D: failed to recreate resources for device; failing permanently\n");
- device_delete(d3d);
+ device_delete();
return 1;
}
- if (d3d->hlsl->create_resources(true))
+ if (m_shaders->create_resources(true))
{
mame_printf_verbose("Direct3D: failed to recreate HLSL resources for device; failing permanently\n");
- device_delete(d3d);
+ device_delete();
return 1;
}
}
@@ -1232,50 +1278,48 @@ static int device_test_cooperative(d3d_info *d3d)
// config_adapter_mode
//============================================================
-static int config_adapter_mode(win_window_info *window)
+int renderer::config_adapter_mode()
{
- d3d_adapter_identifier identifier;
- d3d_info *d3d = (d3d_info *)window->drawdata;
- HRESULT result;
+ adapter_identifier identifier;
// choose the monitor number
- d3d->adapter = get_adapter_for_monitor(d3d, window->monitor);
+ m_adapter = get_adapter_for_monitor();
// get the identifier
- result = (*d3dintf->d3d.get_adapter_identifier)(d3dintf, d3d->adapter, 0, &identifier);
+ HRESULT result = (*d3dintf->d3d.get_adapter_identifier)(d3dintf, m_adapter, 0, &identifier);
if (result != D3D_OK)
{
- mame_printf_error("Error getting identifier for adapter #%d\n", d3d->adapter);
+ mame_printf_error("Error getting identifier for adapter #%d\n", m_adapter);
return 1;
}
- mame_printf_verbose("Direct3D: Configuring adapter #%d = %s\n", d3d->adapter, identifier.Description);
+ mame_printf_verbose("Direct3D: Configuring adapter #%d = %s\n", m_adapter, identifier.Description);
// get the current display mode
- result = (*d3dintf->d3d.get_adapter_display_mode)(d3dintf, d3d->adapter, &d3d->origmode);
+ result = (*d3dintf->d3d.get_adapter_display_mode)(d3dintf, m_adapter, &m_origmode);
if (result != D3D_OK)
{
- mame_printf_error("Error getting mode for adapter #%d\n", d3d->adapter);
+ mame_printf_error("Error getting mode for adapter #%d\n", m_adapter);
return 1;
}
// choose a resolution: window mode case
- if (!window->fullscreen || !video_config.switchres || win_has_menu(window))
+ if (!m_window->fullscreen || !video_config.switchres || win_has_menu(m_window))
{
RECT client;
// bounds are from the window client rect
- GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen);
- d3d->width = client.right - client.left;
- d3d->height = client.bottom - client.top;
+ GetClientRectExceptMenu(m_window->hwnd, &client, m_window->fullscreen);
+ m_width = client.right - client.left;
+ m_height = client.bottom - client.top;
// pix format is from the current mode
- d3d->pixformat = d3d->origmode.Format;
- d3d->refresh = 0;
+ m_pixformat = m_origmode.Format;
+ m_refresh = 0;
// make sure it's a pixel format we can get behind
- if (d3d->pixformat != D3DFMT_X1R5G5B5 && d3d->pixformat != D3DFMT_R5G6B5 && d3d->pixformat != D3DFMT_X8R8G8B8)
+ if (m_pixformat != D3DFMT_X1R5G5B5 && m_pixformat != D3DFMT_R5G6B5 && m_pixformat != D3DFMT_X8R8G8B8)
{
- char *utf8_device = utf8_from_tstring(window->monitor->info.szDevice);
+ char *utf8_device = utf8_from_tstring(m_window->monitor->info.szDevice);
if (utf8_device != NULL)
{
mame_printf_error("Device %s currently in an unsupported mode\n", utf8_device);
@@ -1289,21 +1333,21 @@ static int config_adapter_mode(win_window_info *window)
else
{
// default to the current mode exactly
- d3d->width = d3d->origmode.Width;
- d3d->height = d3d->origmode.Height;
- d3d->pixformat = d3d->origmode.Format;
- d3d->refresh = d3d->origmode.RefreshRate;
+ m_width = m_origmode.Width;
+ m_height = m_origmode.Height;
+ m_pixformat = m_origmode.Format;
+ m_refresh = m_origmode.RefreshRate;
// if we're allowed to switch resolutions, override with something better
if (video_config.switchres)
- pick_best_mode(window);
+ pick_best_mode();
}
// see if we can handle the device type
- result = (*d3dintf->d3d.check_device_type)(d3dintf, d3d->adapter, D3DDEVTYPE_HAL, d3d->pixformat, d3d->pixformat, !window->fullscreen);
+ result = (*d3dintf->d3d.check_device_type)(d3dintf, m_adapter, D3DDEVTYPE_HAL, m_pixformat, m_pixformat, !m_window->fullscreen);
if (result != D3D_OK)
{
- char *utf8_device = utf8_from_tstring(window->monitor->info.szDevice);
+ char *utf8_device = utf8_from_tstring(m_window->monitor->info.szDevice);
if (utf8_device != NULL)
{
mame_printf_error("Proposed video mode not supported on device %s\n", utf8_device);
@@ -1320,22 +1364,21 @@ static int config_adapter_mode(win_window_info *window)
// get_adapter_for_monitor
//============================================================
-static int get_adapter_for_monitor(d3d_info *d3d, win_monitor_info *monitor)
+int renderer::get_adapter_for_monitor()
{
int maxadapter = (*d3dintf->d3d.get_adapter_count)(d3dintf);
- int adapternum;
// iterate over adapters until we error or find a match
- for (adapternum = 0; adapternum < maxadapter; adapternum++)
+ for (int adapternum = 0; adapternum < maxadapter; adapternum++)
{
- HMONITOR curmonitor;
-
// get the monitor for this adapter
- curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum);
+ HMONITOR curmonitor = (*d3dintf->d3d.get_adapter_monitor)(d3dintf, adapternum);
// if we match the proposed monitor, this is it
- if (curmonitor == monitor->handle)
+ if (curmonitor == m_window->monitor->handle)
+ {
return adapternum;
+ }
}
// default to the default
@@ -1348,44 +1391,39 @@ static int get_adapter_for_monitor(d3d_info *d3d, win_monitor_info *monitor)
// pick_best_mode
//============================================================
-static void pick_best_mode(win_window_info *window)
+void renderer::pick_best_mode()
{
double target_refresh = 60.0;
- INT32 target_width, target_height;
- d3d_info *d3d = (d3d_info *)window->drawdata;
INT32 minwidth, minheight;
float best_score = 0.0f;
- int maxmodes;
- int modenum;
// determine the refresh rate of the primary screen
- const screen_device *primary_screen = window->machine().config().first_screen();
+ const screen_device *primary_screen = m_window->machine().config().first_screen();
if (primary_screen != NULL)
+ {
target_refresh = ATTOSECONDS_TO_HZ(primary_screen->refresh_attoseconds());
+ }
// determine the minimum width/height for the selected target
// note: technically we should not be calling this from an alternate window
// thread; however, it is only done during init time, and the init code on
// the main thread is waiting for us to finish, so it is safe to do so here
- window->target->compute_minimum_size(minwidth, minheight);
+ m_window->target->compute_minimum_size(minwidth, minheight);
// use those as the target for now
- target_width = minwidth;
- target_height = minheight;
+ INT32 target_width = minwidth;
+ INT32 target_height = minheight;
// determine the maximum number of modes
- maxmodes = (*d3dintf->d3d.get_adapter_mode_count)(d3dintf, d3d->adapter, D3DFMT_X8R8G8B8);
+ int maxmodes = (*d3dintf->d3d.get_adapter_mode_count)(d3dintf, m_adapter, D3DFMT_X8R8G8B8);
// enumerate all the video modes and find the best match
mame_printf_verbose("Direct3D: Selecting video mode...\n");
- for (modenum = 0; modenum < maxmodes; modenum++)
+ for (int modenum = 0; modenum < maxmodes; modenum++)
{
- float size_score, refresh_score, final_score;
- D3DDISPLAYMODE mode;
- HRESULT result;
-
// check this mode
- result = (*d3dintf->d3d.enum_adapter_modes)(d3dintf, d3d->adapter, D3DFMT_X8R8G8B8, modenum, &mode);
+ D3DDISPLAYMODE mode;
+ HRESULT result = (*d3dintf->d3d.enum_adapter_modes)(d3dintf, m_adapter, D3DFMT_X8R8G8B8, modenum, &mode);
if (result != D3D_OK)
break;
@@ -1394,7 +1432,7 @@ static void pick_best_mode(win_window_info *window)
continue;
// compute initial score based on difference between target and current
- size_score = 1.0f / (1.0f + fabs((float)(mode.Width - target_width)) + fabs((float)(mode.Height - target_height)));
+ float size_score = 1.0f / (1.0f + fabs((float)(mode.Width - target_width)) + fabs((float)(mode.Height - target_height)));
// if the mode is too small, give a big penalty
if (mode.Width < minwidth || mode.Height < minheight)
@@ -1405,35 +1443,35 @@ static void pick_best_mode(win_window_info *window)
size_score *= 0.1f;
// if we're looking for a particular mode, that's a winner
- if (mode.Width == window->maxwidth && mode.Height == window->maxheight)
+ if (mode.Width == m_window->maxwidth && mode.Height == m_window->maxheight)
size_score = 2.0f;
// compute refresh score
- refresh_score = 1.0f / (1.0f + fabs((double)mode.RefreshRate - target_refresh));
+ float refresh_score = 1.0f / (1.0f + fabs((double)mode.RefreshRate - target_refresh));
// if refresh is smaller than we'd like, it only scores up to 0.1
if ((double)mode.RefreshRate < target_refresh)
refresh_score *= 0.1f;
// if we're looking for a particular refresh, make sure it matches
- if (mode.RefreshRate == window->refresh)
+ if (mode.RefreshRate == m_window->refresh)
refresh_score = 2.0f;
// weight size and refresh equally
- final_score = size_score + refresh_score;
+ float final_score = size_score + refresh_score;
// best so far?
mame_printf_verbose(" %4dx%4d@%3dHz -> %f\n", mode.Width, mode.Height, mode.RefreshRate, final_score * 1000.0f);
if (final_score > best_score)
{
best_score = final_score;
- d3d->width = mode.Width;
- d3d->height = mode.Height;
- d3d->pixformat = mode.Format;
- d3d->refresh = mode.RefreshRate;
+ m_width = mode.Width;
+ m_height = mode.Height;
+ m_pixformat = mode.Format;
+ m_refresh = mode.RefreshRate;
}
}
- mame_printf_verbose("Direct3D: Mode selected = %4dx%4d@%3dHz\n", d3d->width, d3d->height, d3d->refresh);
+ mame_printf_verbose("Direct3D: Mode selected = %4dx%4d@%3dHz\n", m_width, m_height, m_refresh);
}
@@ -1442,68 +1480,188 @@ static void pick_best_mode(win_window_info *window)
// update_window_size
//============================================================
-static int update_window_size(win_window_info *window)
+int renderer::update_window_size()
{
- d3d_info *d3d = (d3d_info *)window->drawdata;
- RECT client;
-
// get the current window bounds
- GetClientRectExceptMenu(window->hwnd, &client, window->fullscreen);
+ RECT client;
+ GetClientRectExceptMenu(m_window->hwnd, &client, m_window->fullscreen);
// if we have a device and matching width/height, nothing to do
- if (d3d->device != NULL && rect_width(&client) == d3d->width && rect_height(&client) == d3d->height)
+ if (m_device != NULL && rect_width(&client) == m_width && rect_height(&client) == m_height)
{
// clear out any pending resizing if the area didn't change
- if (window->resize_state == RESIZE_STATE_PENDING)
- window->resize_state = RESIZE_STATE_NORMAL;
+ if (m_window->resize_state == RESIZE_STATE_PENDING)
+ m_window->resize_state = RESIZE_STATE_NORMAL;
return FALSE;
}
// if we're in the middle of resizing, leave it alone as well
- if (window->resize_state == RESIZE_STATE_RESIZING)
+ if (m_window->resize_state == RESIZE_STATE_RESIZING)
return FALSE;
// set the new bounds and create the device again
- d3d->width = rect_width(&client);
- d3d->height = rect_height(&client);
- if (device_create(window))
+ m_width = rect_width(&client);
+ m_height = rect_height(&client);
+ if (device_create())
return FALSE;
// reset the resize state to normal, and indicate we made a change
- window->resize_state = RESIZE_STATE_NORMAL;
+ m_window->resize_state = RESIZE_STATE_NORMAL;
return TRUE;
}
+//============================================================
+// batch_vectors
+//============================================================
+
+void renderer::batch_vectors()
+{
+ windows_options &options = downcast<windows_options &>(m_window->machine().options());
+
+ int vector_size = (options.antialias() ? 24 : 6);
+ m_vectorbatch = mesh_alloc(m_line_count * vector_size);
+ m_batchindex = 0;
+
+ static int start_index = 0;
+ int line_index = 0;
+ float period = options.screen_vector_time_period();
+ UINT32 cached_flags = 0;
+ for (render_primitive *prim = m_window->primlist->first(); prim != NULL; prim = prim->next())
+ {
+ switch (prim->type)
+ {
+ case render_primitive::LINE:
+ if (PRIMFLAG_GET_VECTOR(prim->flags))
+ {
+ if (period == 0.0f || m_line_count == 0)
+ {
+ batch_vector(prim, 1.0f);
+ }
+ else
+ {
+ batch_vector(prim, (float)(start_index + line_index) / ((float)m_line_count * period));
+ line_index++;
+ }
+ cached_flags = prim->flags;
+ }
+ break;
+
+ default:
+ // Skip
+ break;
+ }
+ }
+
+ // now add a polygon entry
+ m_poly[m_numpolys].init(D3DPT_TRIANGLELIST, m_line_count * (options.antialias() ? 8 : 2), vector_size * m_line_count, cached_flags,
+ m_texture_manager->get_vector_texture(), D3DTOP_MODULATE, 0.0f, 1.0f);
+ m_numpolys++;
+
+ start_index += (int)((float)line_index * period);
+ if (m_line_count > 0)
+ {
+ start_index %= m_line_count;
+ }
+}
+
+void renderer::batch_vector(const render_primitive *prim, float line_time)
+{
+ // compute the effective width based on the direction of the line
+ float effwidth = prim->width;
+ if (effwidth < 0.5f)
+ {
+ effwidth = 0.5f;
+ }
+
+ // determine the bounds of a quad to draw this line
+ render_bounds b0, b1;
+ render_line_to_quad(&prim->bounds, effwidth, &b0, &b1);
+
+ // iterate over AA steps
+ for (const line_aa_step *step = PRIMFLAG_GET_ANTIALIAS(prim->flags) ? line_aa_4step : line_aa_1step;
+ step->weight != 0; step++)
+ {
+ // get a pointer to the vertex buffer
+ if (m_vectorbatch == NULL)
+ return;
+
+ m_vectorbatch[m_batchindex + 0].x = b0.x0 + step->xoffs;
+ m_vectorbatch[m_batchindex + 0].y = b0.y0 + step->yoffs;
+ m_vectorbatch[m_batchindex + 1].x = b0.x1 + step->xoffs;
+ m_vectorbatch[m_batchindex + 1].y = b0.y1 + step->yoffs;
+ m_vectorbatch[m_batchindex + 2].x = b1.x0 + step->xoffs;
+ m_vectorbatch[m_batchindex + 2].y = b1.y0 + step->yoffs;
+
+ m_vectorbatch[m_batchindex + 3].x = b0.x1 + step->xoffs;
+ m_vectorbatch[m_batchindex + 3].y = b0.y1 + step->yoffs;
+ m_vectorbatch[m_batchindex + 4].x = b1.x0 + step->xoffs;
+ m_vectorbatch[m_batchindex + 4].y = b1.y0 + step->yoffs;
+ m_vectorbatch[m_batchindex + 5].x = b1.x1 + step->xoffs;
+ m_vectorbatch[m_batchindex + 5].y = b1.y1 + step->yoffs;
+
+ // determine the color of the line
+ INT32 r = (INT32)(prim->color.r * step->weight * 255.0f);
+ INT32 g = (INT32)(prim->color.g * step->weight * 255.0f);
+ INT32 b = (INT32)(prim->color.b * step->weight * 255.0f);
+ INT32 a = (INT32)(prim->color.a * 255.0f);
+ if (r > 255) r = 255;
+ if (g > 255) g = 255;
+ if (b > 255) b = 255;
+ if (a > 255) a = 255;
+ DWORD color = D3DCOLOR_ARGB(a, r, g, b);
+
+ vec2f& start = (get_vector_texture() ? get_vector_texture()->get_uvstart() : get_default_texture()->get_uvstart());
+ vec2f& stop = (get_vector_texture() ? get_vector_texture()->get_uvstop() : get_default_texture()->get_uvstop());
+
+ m_vectorbatch[m_batchindex + 0].u0 = start.c.x;
+ m_vectorbatch[m_batchindex + 0].v0 = start.c.y;
+ m_vectorbatch[m_batchindex + 1].u0 = start.c.x;
+ m_vectorbatch[m_batchindex + 1].v0 = stop.c.y;
+ m_vectorbatch[m_batchindex + 2].u0 = stop.c.x;
+ m_vectorbatch[m_batchindex + 2].v0 = start.c.y;
+
+ m_vectorbatch[m_batchindex + 3].u0 = start.c.x;
+ m_vectorbatch[m_batchindex + 3].v0 = stop.c.y;
+ m_vectorbatch[m_batchindex + 4].u0 = stop.c.x;
+ m_vectorbatch[m_batchindex + 4].v0 = start.c.y;
+ m_vectorbatch[m_batchindex + 5].u0 = stop.c.x;
+ m_vectorbatch[m_batchindex + 5].v0 = stop.c.y;
+
+ // set the color, Z parameters to standard values
+ for (int i = 0; i < 6; i++)
+ {
+ m_vectorbatch[m_batchindex + i].z = 0.0f;
+ m_vectorbatch[m_batchindex + i].rhw = 1.0f;
+ m_vectorbatch[m_batchindex + i].color = color;
+ }
+ m_batchindex += 6;
+ }
+}
//============================================================
// draw_line
//============================================================
-static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_time)
+void renderer::draw_line(const render_primitive *prim)
{
- const line_aa_step *step = line_aa_4step;
- render_bounds b0, b1;
- d3d_vertex *vertex;
- INT32 r, g, b, a;
- d3d_poly_info *poly;
- float effwidth;
- DWORD color;
- int i;
-
// compute the effective width based on the direction of the line
- effwidth = prim->width;
+ float effwidth = prim->width;
if (effwidth < 0.5f)
+ {
effwidth = 0.5f;
+ }
// determine the bounds of a quad to draw this line
+ render_bounds b0, b1;
render_line_to_quad(&prim->bounds, effwidth, &b0, &b1);
// iterate over AA steps
- for (step = PRIMFLAG_GET_ANTIALIAS(prim->flags) ? line_aa_4step : line_aa_1step; step->weight != 0; step++)
+ for (const line_aa_step *step = PRIMFLAG_GET_ANTIALIAS(prim->flags) ? line_aa_4step : line_aa_1step;
+ step->weight != 0; step++)
{
// get a pointer to the vertex buffer
- vertex = primitive_alloc(d3d, 4);
+ vertex *vertex = mesh_alloc(4);
if (vertex == NULL)
return;
@@ -1524,48 +1682,33 @@ static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_ti
vertex[3].y = b1.y1 + step->yoffs;
// determine the color of the line
- r = (INT32)(prim->color.r * step->weight * 255.0f);
- g = (INT32)(prim->color.g * step->weight * 255.0f);
- b = (INT32)(prim->color.b * step->weight * 255.0f);
- a = (INT32)(prim->color.a * 255.0f);
+ INT32 r = (INT32)(prim->color.r * step->weight * 255.0f);
+ INT32 g = (INT32)(prim->color.g * step->weight * 255.0f);
+ INT32 b = (INT32)(prim->color.b * step->weight * 255.0f);
+ INT32 a = (INT32)(prim->color.a * 255.0f);
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
if (a > 255) a = 255;
- color = D3DCOLOR_ARGB(a, r, g, b);
-
- // if we have a texture to use for the vectors, use it here
- if (d3d->vector_texture != NULL)
- {
- vertex[0].u0 = d3d->vector_texture->ustart;
- vertex[0].v0 = d3d->vector_texture->vstart;
-
- vertex[2].u0 = d3d->vector_texture->ustop;
- vertex[2].v0 = d3d->vector_texture->vstart;
+ DWORD color = D3DCOLOR_ARGB(a, r, g, b);
- vertex[1].u0 = d3d->vector_texture->ustart;
- vertex[1].v0 = d3d->vector_texture->vstop;
+ vec2f& start = (get_vector_texture() ? get_vector_texture()->get_uvstart() : get_default_texture()->get_uvstart());
+ vec2f& stop = (get_vector_texture() ? get_vector_texture()->get_uvstop() : get_default_texture()->get_uvstop());
- vertex[3].u0 = d3d->vector_texture->ustop;
- vertex[3].v0 = d3d->vector_texture->vstop;
- }
- else if(d3d->default_texture != NULL)
- {
- vertex[0].u0 = d3d->default_texture->ustart;
- vertex[0].v0 = d3d->default_texture->vstart;
+ vertex[0].u0 = start.c.x;
+ vertex[0].v0 = start.c.y;
- vertex[2].u0 = d3d->default_texture->ustart;
- vertex[2].v0 = d3d->default_texture->vstart;
+ vertex[2].u0 = stop.c.x;
+ vertex[2].v0 = start.c.y;
- vertex[1].u0 = d3d->default_texture->ustart;
- vertex[1].v0 = d3d->default_texture->vstart;
+ vertex[1].u0 = start.c.x;
+ vertex[1].v0 = stop.c.y;
- vertex[3].u0 = d3d->default_texture->ustart;
- vertex[3].v0 = d3d->default_texture->vstart;
- }
+ vertex[3].u0 = stop.c.x;
+ vertex[3].v0 = stop.c.y;
// set the color, Z parameters to standard values
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
vertex[i].z = 0.0f;
vertex[i].rhw = 1.0f;
@@ -1573,29 +1716,9 @@ static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_ti
}
// now add a polygon entry
- poly = &d3d->poly[d3d->numpolys++];
- poly->type = D3DPT_TRIANGLESTRIP;
- poly->count = 2;
- poly->numverts = 4;
- poly->flags = prim->flags;
- poly->modmode = D3DTOP_MODULATE;
- poly->texture = d3d->vector_texture;
- poly->line_time = line_time;
- poly->line_length = 1.0f;
- if (PRIMFLAG_GET_VECTOR(poly->flags))
- {
- float dx = fabs(prim->bounds.x1 - prim->bounds.x0);
- float dy = fabs(prim->bounds.y1 - prim->bounds.y0);
- float length2 = dx * dx + dy * dy;
- if (length2 > 0.0f)
- {
- poly->line_length = sqrt(length2);
- }
- else
- {
- // use default length of 1.0f from above
- }
- }
+ m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim->flags, get_vector_texture(),
+ D3DTOP_MODULATE, 0.0f, 1.0f);
+ m_numpolys++;
}
}
@@ -1605,19 +1728,17 @@ static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_ti
// draw_quad
//============================================================
-static void draw_quad(d3d_info *d3d, const render_primitive *prim)
+void renderer::draw_quad(const render_primitive *prim)
{
- d3d_texture_info *texture = texture_find(d3d, prim);
- DWORD color, modmode;
- d3d_vertex *vertex;
- INT32 r, g, b, a;
- d3d_poly_info *poly;
- int i;
+ texture_info *texture = m_texture_manager->find_texinfo(&prim->texture, prim->flags);
- texture = texture != NULL ? texture : d3d->default_texture;
+ if (texture == NULL)
+ {
+ texture = get_default_texture();
+ }
// get a pointer to the vertex buffer
- vertex = primitive_alloc(d3d, 4);
+ vertex *vertex = mesh_alloc(4);
if (vertex == NULL)
return;
@@ -1634,29 +1755,30 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim)
// set the texture coordinates
if(texture != NULL)
{
- float du = texture->ustop - texture->ustart;
- float dv = texture->vstop - texture->vstart;
- vertex[0].u0 = texture->ustart + du * prim->texcoords.tl.u;
- vertex[0].v0 = texture->vstart + dv * prim->texcoords.tl.v;
- vertex[1].u0 = texture->ustart + du * prim->texcoords.tr.u;
- vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v;
- vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u;
- vertex[2].v0 = texture->vstart + dv * prim->texcoords.bl.v;
- vertex[3].u0 = texture->ustart + du * prim->texcoords.br.u;
- vertex[3].v0 = texture->vstart + dv * prim->texcoords.br.v;
+ vec2f& start = texture->get_uvstart();
+ vec2f& stop = texture->get_uvstop();
+ vec2f delta = stop - start;
+ vertex[0].u0 = start.c.x + delta.c.x * prim->texcoords.tl.u;
+ vertex[0].v0 = start.c.y + delta.c.y * prim->texcoords.tl.v;
+ vertex[1].u0 = start.c.x + delta.c.x * prim->texcoords.tr.u;
+ vertex[1].v0 = start.c.y + delta.c.y * prim->texcoords.tr.v;
+ vertex[2].u0 = start.c.x + delta.c.x * prim->texcoords.bl.u;
+ vertex[2].v0 = start.c.y + delta.c.y * prim->texcoords.bl.v;
+ vertex[3].u0 = start.c.x + delta.c.x * prim->texcoords.br.u;
+ vertex[3].v0 = start.c.y + delta.c.y * prim->texcoords.br.v;
}
// determine the color, allowing for over modulation
- r = (INT32)(prim->color.r * 255.0f);
- g = (INT32)(prim->color.g * 255.0f);
- b = (INT32)(prim->color.b * 255.0f);
- a = (INT32)(prim->color.a * 255.0f);
- modmode = D3DTOP_MODULATE;
+ INT32 r = (INT32)(prim->color.r * 255.0f);
+ INT32 g = (INT32)(prim->color.g * 255.0f);
+ INT32 b = (INT32)(prim->color.b * 255.0f);
+ INT32 a = (INT32)(prim->color.a * 255.0f);
+ DWORD modmode = D3DTOP_MODULATE;
if (texture != NULL)
{
- if (d3d->mod2x_supported && (r > 255 || g > 255 || b > 255))
+ if (m_mod2x_supported && (r > 255 || g > 255 || b > 255))
{
- if (d3d->mod4x_supported && (r > 2*255 || g > 2*255 || b > 2*255))
+ if (m_mod4x_supported && (r > 2*255 || g > 2*255 || b > 2*255))
{
r >>= 2; g >>= 2; b >>= 2;
modmode = D3DTOP_MODULATE4X;
@@ -1672,10 +1794,10 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim)
if (g > 255) g = 255;
if (b > 255) b = 255;
if (a > 255) a = 255;
- color = D3DCOLOR_ARGB(a, r, g, b);
+ DWORD color = D3DCOLOR_ARGB(a, r, g, b);
// set the color, Z parameters to standard values
- for (i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
vertex[i].z = 0.0f;
vertex[i].rhw = 1.0f;
@@ -1683,51 +1805,64 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim)
}
// now add a polygon entry
- poly = &d3d->poly[d3d->numpolys++];
- poly->type = D3DPT_TRIANGLESTRIP;
- poly->count = 2;
- poly->numverts = 4;
- poly->flags = prim->flags;
- poly->modmode = modmode;
- poly->texture = texture;
- //poly->
+ m_poly[m_numpolys].init(D3DPT_TRIANGLESTRIP, 2, 4, prim->flags, texture, modmode);
+ m_numpolys++;
+}
+
+void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
+ UINT32 flags, texture_info *texture, UINT32 modmode,
+ float line_time, float line_length)
+{
+ init(type, count, numverts, flags, texture, modmode);
+ m_line_time = line_time;
+ m_line_length = line_length;
}
+void poly_info::init(D3DPRIMITIVETYPE type, UINT32 count, UINT32 numverts,
+ UINT32 flags, texture_info *texture, UINT32 modmode)
+{
+ m_type = type;
+ m_count = count;
+ m_numverts = numverts;
+ m_flags = flags;
+ m_texture = texture;
+ m_modmode = modmode;
+}
//============================================================
// primitive_alloc
//============================================================
-static d3d_vertex *primitive_alloc(d3d_info *d3d, int numverts)
+vertex *renderer::mesh_alloc(int numverts)
{
HRESULT result;
// if we're going to overflow, flush
- if (d3d->lockedbuf != NULL && d3d->numverts + numverts >= VERTEX_BUFFER_SIZE)
+ if (m_lockedbuf != NULL && m_numverts + numverts >= VERTEX_BUFFER_SIZE)
{
- primitive_flush_pending(d3d);
+ primitive_flush_pending();
- if(d3d->hlsl->enabled())
+ if(m_shaders->enabled())
{
- d3d->hlsl_buf = (void*)primitive_alloc(d3d, 6);
- d3d->hlsl->init_fsfx_quad(d3d->hlsl_buf);
+ m_hlsl_buf = (void*)mesh_alloc(6);
+ m_shaders->init_fsfx_quad(m_hlsl_buf);
}
}
// if we don't have a lock, grab it now
- if (d3d->lockedbuf == NULL)
+ if (m_lockedbuf == NULL)
{
- result = (*d3dintf->vertexbuf.lock)(d3d->vertexbuf, 0, 0, (VOID **)&d3d->lockedbuf, D3DLOCK_DISCARD);
+ result = (*d3dintf->vertexbuf.lock)(m_vertexbuf, 0, 0, (VOID **)&m_lockedbuf, D3DLOCK_DISCARD);
if (result != D3D_OK)
return NULL;
}
// if we already have the lock and enough room, just return a pointer
- if (d3d->lockedbuf != NULL && d3d->numverts + numverts < VERTEX_BUFFER_SIZE)
+ if (m_lockedbuf != NULL && m_numverts + numverts < VERTEX_BUFFER_SIZE)
{
- int oldverts = d3d->numverts;
- d3d->numverts += numverts;
- return &d3d->lockedbuf[oldverts];
+ int oldverts = m_numverts;
+ m_numverts += numverts;
+ return &m_lockedbuf[oldverts];
}
return NULL;
}
@@ -1738,170 +1873,206 @@ static d3d_vertex *primitive_alloc(d3d_info *d3d, int numverts)
// primitive_flush_pending
//============================================================
-static void primitive_flush_pending(d3d_info *d3d)
+void renderer::primitive_flush_pending()
{
- HRESULT result;
- int polynum;
- int vertnum;
-
// ignore if we're not locked
- if (d3d->lockedbuf == NULL)
+ if (m_lockedbuf == NULL)
+ {
return;
+ }
// unlock the buffer
- result = (*d3dintf->vertexbuf.unlock)(d3d->vertexbuf);
+ HRESULT result = (*d3dintf->vertexbuf.unlock)(m_vertexbuf);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer unlock call\n", (int)result);
- d3d->lockedbuf = NULL;
+ m_lockedbuf = NULL;
// set the stream
- result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex));
+ result = (*d3dintf->device.set_stream_source)(m_device, 0, m_vertexbuf, sizeof(vertex));
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result);
- d3d->hlsl->begin_draw();
+ m_shaders->begin_draw();
- if (d3d->hlsl->enabled())
+ int vertnum = 0;
+ if (m_shaders->enabled())
{
vertnum = 6;
}
- else
- {
- vertnum = 0;
- }
// now do the polys
- for (polynum = 0; polynum < d3d->numpolys; polynum++)
+ for (int polynum = 0; polynum < m_numpolys; polynum++)
{
- d3d_poly_info *poly = &d3d->poly[polynum];
+ UINT32 flags = m_poly[polynum].get_flags();
+ texture_info *texture = m_poly[polynum].get_texture();
int newfilter;
// set the texture if different
- set_texture(d3d, poly->texture);
+ set_texture(texture);
// set filtering if different
- if (poly->texture != NULL)
+ if (texture != NULL)
{
newfilter = FALSE;
- if (PRIMFLAG_GET_SCREENTEX(poly->flags))
+ if (PRIMFLAG_GET_SCREENTEX(flags))
newfilter = video_config.filter;
- set_filter(d3d, newfilter);
- set_wrap(d3d, PRIMFLAG_GET_TEXWRAP(poly->flags));
- set_modmode(d3d, poly->modmode);
+ set_filter(newfilter);
+ set_wrap(PRIMFLAG_GET_TEXWRAP(flags) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
+ set_modmode(m_poly[polynum].get_modmode());
- d3d->hlsl->init_effect_info(poly);
+ m_shaders->init_effect_info(&m_poly[polynum]);
}
// set the blendmode if different
- set_blendmode(d3d, PRIMFLAG_GET_BLENDMODE(poly->flags));
+ set_blendmode(PRIMFLAG_GET_BLENDMODE(flags));
- if(d3d->hlsl->enabled() && d3dintf->post_fx_available)
- {
- assert(vertnum + poly->numverts <= d3d->numverts);
+ assert(vertnum + m_poly[polynum].get_vertcount() <= m_numverts);
- d3d->hlsl->render_quad(poly, vertnum);
+ if(m_shaders->enabled() && d3dintf->post_fx_available)
+ {
+ m_shaders->render_quad(&m_poly[polynum], vertnum);
}
else
{
- assert(vertnum + poly->numverts <= d3d->numverts);
-
// add the primitives
- result = (*d3dintf->device.draw_primitive)(d3d->device, poly->type, vertnum, poly->count);
+ result = (*d3dintf->device.draw_primitive)(m_device, m_poly[polynum].get_type(), vertnum,
+ m_poly[polynum].get_count());
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
}
- vertnum += poly->numverts;
+ vertnum += m_poly[polynum].get_vertcount();
}
- d3d->hlsl->end_draw();
+ m_shaders->end_draw();
// reset the vertex count
- d3d->numverts = 0;
- d3d->numpolys = 0;
+ m_numverts = 0;
+ m_numpolys = 0;
}
+//============================================================
+// texture_info destructor
+//============================================================
-void texture_destroy(d3d_info *d3d, d3d_texture_info *info)
+texture_info::~texture_info()
{
+ if (m_d3dfinaltex != NULL)
+ {
+ if (m_d3dtex == m_d3dfinaltex)
+ {
+ m_d3dtex = NULL;
+ }
+ (*d3dintf->texture.release)(m_d3dfinaltex);
+ m_d3dfinaltex = NULL;
+ }
+ if (m_d3dtex != NULL)
+ {
+ (*d3dintf->texture.release)(m_d3dtex);
+ m_d3dtex = NULL;
+ }
+ if (m_d3dsurface != NULL)
+ {
+ (*d3dintf->surface.release)(m_d3dsurface);
+ m_d3dsurface = NULL;
+ }
}
//============================================================
-// texture_create
+// texture_info constructor
//============================================================
-d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource, UINT32 flags)
+texture_info::texture_info(texture_manager *manager, const render_texinfo* texsource, UINT32 flags)
{
- d3d_texture_info *texture;
HRESULT result;
- // allocate a new texture
- texture = global_alloc_clear(d3d_texture_info);
-
// fill in the core data
- texture->hash = texture_compute_hash(texsource, flags);
- texture->flags = flags;
- texture->texinfo = *texsource;
- texture->xprescale = video_config.prescale;
- texture->yprescale = video_config.prescale;
+ m_texture_manager = manager;
+ m_renderer = m_texture_manager->get_d3d();
+ m_hash = m_texture_manager->texture_compute_hash(texsource, flags);
+ m_flags = flags;
+ m_texinfo = *texsource;
+ m_xprescale = video_config.prescale;
+ m_yprescale = video_config.prescale;
+
+ m_d3dtex = NULL;
+ m_d3dsurface = NULL;
+ m_d3dfinaltex = NULL;
// compute the size
- texture_compute_size(d3d, texsource->width, texsource->height, texture);
+ compute_size(texsource->width, texsource->height);
// non-screen textures are easy
if (!PRIMFLAG_GET_SCREENTEX(flags))
{
assert(PRIMFLAG_TEXFORMAT(flags) != TEXFORMAT_YUY16);
- result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture->d3dtex);
+ result = (*d3dintf->device.create_texture)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_d3dtex);
if (result != D3D_OK)
goto error;
- texture->d3dfinaltex = texture->d3dtex;
- texture->type = TEXTURE_TYPE_PLAIN;
+ m_d3dfinaltex = m_d3dtex;
+ m_type = TEXTURE_TYPE_PLAIN;
}
// screen textures are allocated differently
else
{
D3DFORMAT format;
- DWORD usage = d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0;
- D3DPOOL pool = d3d->dynamic_supported ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
- int maxdim = MAX(d3d->presentation.BackBufferWidth, d3d->presentation.BackBufferHeight);
- int attempt;
+ DWORD usage = m_texture_manager->is_dynamic_supported() ? D3DUSAGE_DYNAMIC : 0;
+ D3DPOOL pool = m_texture_manager->is_dynamic_supported() ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
+ int maxdim = MAX(m_renderer->get_presentation()->BackBufferWidth, m_renderer->get_presentation()->BackBufferHeight);
// pick the format
if (PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_YUY16)
- format = d3d->yuv_format;
+ {
+ format = m_texture_manager->get_yuv_format();
+ }
else if (PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_ARGB32 || PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_PALETTEA16)
+ {
format = D3DFMT_A8R8G8B8;
+ }
else
- format = d3d->screen_format;
+ {
+ format = m_renderer->get_screen_format();
+ }
// don't prescale above screen size
- while (texture->xprescale > 1 && texture->rawwidth * texture->xprescale >= 2 * maxdim)
- texture->xprescale--;
- while (texture->xprescale > 1 && texture->rawwidth * texture->xprescale > d3d->texture_max_width)
- texture->xprescale--;
- while (texture->yprescale > 1 && texture->rawheight * texture->yprescale >= 2 * maxdim)
- texture->yprescale--;
- while (texture->yprescale > 1 && texture->rawheight * texture->yprescale > d3d->texture_max_height)
- texture->yprescale--;
- if (texture->xprescale != video_config.prescale || texture->yprescale != video_config.prescale)
- mame_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, texture->xprescale, texture->yprescale);
+ while (m_xprescale > 1 && m_rawdims.c.x * m_xprescale >= 2 * maxdim)
+ {
+ m_xprescale--;
+ }
+ while (m_xprescale > 1 && m_rawdims.c.x * m_xprescale > manager->get_max_texture_width())
+ {
+ m_xprescale--;
+ }
+ while (m_yprescale > 1 && m_rawdims.c.y * m_yprescale >= 2 * maxdim)
+ {
+ m_yprescale--;
+ }
+ while (m_yprescale > 1 && m_rawdims.c.y * m_yprescale > manager->get_max_texture_height())
+ {
+ m_yprescale--;
+ }
+ if (m_xprescale != video_config.prescale || m_yprescale != video_config.prescale)
+ {
+ mame_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, m_xprescale, m_yprescale);
+ }
// loop until we allocate something or error
- for (attempt = 0; attempt < 2; attempt++)
+ for (int attempt = 0; attempt < 2; attempt++)
{
// second attempt is always 1:1
if (attempt == 1)
- texture->xprescale = texture->yprescale = 1;
+ {
+ m_xprescale = m_yprescale = 1;
+ }
// screen textures with no prescaling are pretty easy
- if (texture->xprescale == 1 && texture->yprescale == 1)
+ if (m_xprescale == 1 && m_yprescale == 1)
{
- result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, usage, format, pool, &texture->d3dtex);
+ result = (*d3dintf->device.create_texture)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, usage, format, pool, &m_d3dtex);
if (result == D3D_OK)
{
- texture->d3dfinaltex = texture->d3dtex;
- texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
+ m_d3dfinaltex = m_d3dtex;
+ m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
- if (d3d->hlsl->enabled() && !d3d->hlsl->register_texture(texture))
+ if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_texture(this))
{
goto error;
}
@@ -1913,98 +2084,98 @@ d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource,
// screen textures with prescaling require two allocations
else
{
- int scwidth, scheight;
- D3DFORMAT finalfmt;
-
// use an offscreen plain surface for stretching if supported
// (won't work for YUY textures)
- if (d3d->stretch_supported && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16)
+ if (m_texture_manager->is_stretch_supported() && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16)
{
- result = (*d3dintf->device.create_offscreen_plain_surface)(d3d->device, texture->rawwidth, texture->rawheight, format, D3DPOOL_DEFAULT, &texture->d3dsurface);
+ result = (*d3dintf->device.create_offscreen_plain_surface)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, format, D3DPOOL_DEFAULT, &m_d3dsurface);
if (result != D3D_OK)
+ {
continue;
- texture->type = TEXTURE_TYPE_SURFACE;
+ }
+ m_type = TEXTURE_TYPE_SURFACE;
}
// otherwise, we allocate a dynamic texture for the source
else
{
- result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, usage, format, pool, &texture->d3dtex);
+ result = (*d3dintf->device.create_texture)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, usage, format, pool, &m_d3dtex);
if (result != D3D_OK)
+ {
continue;
- texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
+ }
+ m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
}
// for the target surface, we allocate a render target texture
- scwidth = texture->rawwidth * texture->xprescale;
- scheight = texture->rawheight * texture->yprescale;
+ int scwidth = m_rawdims.c.x * m_xprescale;
+ int scheight = m_rawdims.c.y * m_yprescale;
// target surfaces typically cannot be YCbCr, so we always pick RGB in that case
- finalfmt = (format != d3d->yuv_format) ? format : D3DFMT_A8R8G8B8;
- result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &texture->d3dfinaltex);
+ D3DFORMAT finalfmt = (format != m_texture_manager->get_yuv_format()) ? format : D3DFMT_A8R8G8B8;
+ result = (*d3dintf->device.create_texture)(m_renderer->get_device(), scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &m_d3dfinaltex);
if (result == D3D_OK)
{
- if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(texture))
+ if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_prescaled_texture(this))
{
goto error;
}
break;
}
- (*d3dintf->texture.release)(texture->d3dtex);
- texture->d3dtex = NULL;
+ (*d3dintf->texture.release)(m_d3dtex);
+ m_d3dtex = NULL;
}
}
}
// copy the data to the texture
- texture_set_data(d3d, texture, texsource, flags);
+ set_data(texsource, flags);
+ //texsource->osdhandle = (void*)this;
// add us to the texture list
- if(d3d->texlist != NULL)
- d3d->texlist->prev = texture;
- texture->prev = NULL;
- texture->next = d3d->texlist;
- d3d->texlist = texture;
- return texture;
+ if(m_texture_manager->get_texlist() != NULL)
+ m_texture_manager->get_texlist()->m_prev = this;
+ m_prev = NULL;
+ m_next = m_texture_manager->get_texlist();
+ m_texture_manager->set_texlist(this);
+ return;
error:
d3dintf->post_fx_available = false;
printf("Direct3D: Critical warning: A texture failed to allocate. Expect things to get bad quickly.\n");
- if (texture->d3dsurface != NULL)
- (*d3dintf->surface.release)(texture->d3dsurface);
- if (texture->d3dtex != NULL)
- (*d3dintf->texture.release)(texture->d3dtex);
- global_free(texture);
- return NULL;
+ if (m_d3dsurface != NULL)
+ (*d3dintf->surface.release)(m_d3dsurface);
+ if (m_d3dtex != NULL)
+ (*d3dintf->texture.release)(m_d3dtex);
}
//============================================================
-// texture_compute_size
+// texture_info::compute_size
//============================================================
-static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d_texture_info *texture)
+void texture_info::compute_size(int texwidth, int texheight)
{
int finalheight = texheight;
int finalwidth = texwidth;
// if we're not wrapping, add a 1-2 pixel border on all sides
- texture->xborderpix = 0;
- texture->yborderpix = 0;
- if (ENABLE_BORDER_PIX && !(texture->flags & PRIMFLAG_TEXWRAP_MASK))
+ m_xborderpix = 0;
+ m_yborderpix = 0;
+ if (ENABLE_BORDER_PIX && !(m_flags & PRIMFLAG_TEXWRAP_MASK))
{
// note we need 2 pixels in X for YUY textures
- texture->xborderpix = (PRIMFLAG_GET_TEXFORMAT(texture->flags) == TEXFORMAT_YUY16) ? 2 : 1;
- texture->yborderpix = 1;
+ m_xborderpix = (PRIMFLAG_GET_TEXFORMAT(m_flags) == TEXFORMAT_YUY16) ? 2 : 1;
+ m_yborderpix = 1;
}
// compute final texture size
- finalwidth += 2 * texture->xborderpix;
- finalheight += 2 * texture->yborderpix;
+ finalwidth += 2 * m_xborderpix;
+ finalheight += 2 * m_yborderpix;
// round width/height up to nearest power of 2 if we need to
- if (!(d3d->texture_caps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
+ if (!(m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
{
// first the width
if (finalwidth & (finalwidth - 1))
@@ -2028,7 +2199,7 @@ static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d
}
// round up to square if we need to
- if (d3d->texture_caps & D3DPTEXTURECAPS_SQUAREONLY)
+ if (m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY)
{
if (finalwidth < finalheight)
finalwidth = finalheight;
@@ -2037,38 +2208,42 @@ static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d
}
// adjust the aspect ratio if we need to
- while (finalwidth < finalheight && finalheight / finalwidth > d3d->texture_max_aspect)
+ while (finalwidth < finalheight && finalheight / finalwidth > m_texture_manager->get_max_texture_aspect())
+ {
finalwidth *= 2;
- while (finalheight < finalwidth && finalwidth / finalheight > d3d->texture_max_aspect)
+ }
+ while (finalheight < finalwidth && finalwidth / finalheight > m_texture_manager->get_max_texture_aspect())
+ {
finalheight *= 2;
+ }
// if we added pixels for the border, and that just barely pushed us over, take it back
- if ((finalwidth > d3d->texture_max_width && finalwidth - 2 * texture->xborderpix <= d3d->texture_max_width) ||
- (finalheight > d3d->texture_max_height && finalheight - 2 * texture->yborderpix <= d3d->texture_max_height))
+ if ((finalwidth > m_texture_manager->get_max_texture_width() && finalwidth - 2 * m_xborderpix <= m_texture_manager->get_max_texture_width()) ||
+ (finalheight > m_texture_manager->get_max_texture_height() && finalheight - 2 * m_yborderpix <= m_texture_manager->get_max_texture_height()))
{
- finalwidth -= 2 * texture->xborderpix;
- finalheight -= 2 * texture->yborderpix;
- texture->xborderpix = 0;
- texture->yborderpix = 0;
+ finalwidth -= 2 * m_xborderpix;
+ finalheight -= 2 * m_yborderpix;
+ m_xborderpix = 0;
+ m_yborderpix = 0;
}
// if we're above the max width/height, do what?
- if (finalwidth > d3d->texture_max_width || finalheight > d3d->texture_max_height)
+ if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height())
{
static int printed = FALSE;
- if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth, finalheight, (int)d3d->texture_max_width, (int)d3d->texture_max_height);
+ if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth, finalheight, (int)m_texture_manager->get_max_texture_width(), (int)m_texture_manager->get_max_texture_height());
printed = TRUE;
}
// compute the U/V scale factors
- texture->ustart = (float)texture->xborderpix / (float)finalwidth;
- texture->ustop = (float)(texwidth + texture->xborderpix) / (float)finalwidth;
- texture->vstart = (float)texture->yborderpix / (float)finalheight;
- texture->vstop = (float)(texheight + texture->yborderpix) / (float)finalheight;
+ m_start.c.x = (float)m_xborderpix / (float)finalwidth;
+ m_start.c.y = (float)m_yborderpix / (float)finalheight;
+ m_stop.c.x = (float)(texwidth + m_xborderpix) / (float)finalwidth;
+ m_stop.c.y = (float)(texheight + m_yborderpix) / (float)finalheight;
// set the final values
- texture->rawwidth = finalwidth;
- texture->rawheight = finalheight;
+ m_rawdims.c.x = finalwidth;
+ m_rawdims.c.y = finalheight;
}
@@ -2411,58 +2586,58 @@ INLINE void copyline_yuy16_to_argb(UINT32 *dst, const UINT16 *src, int width, co
// texture_set_data
//============================================================
-static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const render_texinfo *texsource, UINT32 flags)
+void texture_info::set_data(const render_texinfo *texsource, UINT32 flags)
{
D3DLOCKED_RECT rect;
HRESULT result;
- int miny, maxy;
- int dsty;
// lock the texture
- switch (texture->type)
+ switch (m_type)
{
default:
- case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.lock_rect)(texture->d3dtex, 0, &rect, NULL, 0); break;
- case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.lock_rect)(texture->d3dtex, 0, &rect, NULL, D3DLOCK_DISCARD); break;
- case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.lock_rect)(texture->d3dsurface, &rect, NULL, D3DLOCK_DISCARD); break;
+ case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.lock_rect)(m_d3dtex, 0, &rect, NULL, 0); break;
+ case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.lock_rect)(m_d3dtex, 0, &rect, NULL, D3DLOCK_DISCARD); break;
+ case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.lock_rect)(m_d3dsurface, &rect, NULL, D3DLOCK_DISCARD); break;
}
if (result != D3D_OK)
+ {
return;
+ }
// loop over Y
- miny = 0 - texture->yborderpix;
- maxy = texsource->height + texture->yborderpix;
- for (dsty = miny; dsty < maxy; dsty++)
+ int miny = 0 - m_yborderpix;
+ int maxy = texsource->height + m_yborderpix;
+ for (int dsty = miny; dsty < maxy; dsty++)
{
int srcy = (dsty < 0) ? 0 : (dsty >= texsource->height) ? texsource->height - 1 : dsty;
- void *dst = (BYTE *)rect.pBits + (dsty + texture->yborderpix) * rect.Pitch;
+ void *dst = (BYTE *)rect.pBits + (dsty + m_yborderpix) * rect.Pitch;
// switch off of the format and
switch (PRIMFLAG_GET_TEXFORMAT(flags))
{
case TEXFORMAT_PALETTE16:
- copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
+ copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_PALETTEA16:
- copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
+ copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_RGB32:
- copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
+ copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_ARGB32:
- copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
+ copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_YUY16:
- if (d3d->yuv_format == D3DFMT_YUY2)
- copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
- else if (d3d->yuv_format == D3DFMT_UYVY)
- copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
+ if (m_texture_manager->get_yuv_format() == D3DFMT_YUY2)
+ copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
+ else if (m_texture_manager->get_yuv_format() == D3DFMT_UYVY)
+ copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
else
- copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
+ copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
default:
@@ -2472,251 +2647,153 @@ static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const ren
}
// unlock
- switch (texture->type)
+ switch (m_type)
{
default:
- case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.unlock_rect)(texture->d3dtex, 0); break;
- case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.unlock_rect)(texture->d3dtex, 0); break;
- case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.unlock_rect)(texture->d3dsurface); break;
+ case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.unlock_rect)(m_d3dtex, 0); break;
+ case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.unlock_rect)(m_d3dtex, 0); break;
+ case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.unlock_rect)(m_d3dsurface); break;
+ }
+ if (result != D3D_OK)
+ {
+ mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result);
}
- if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result);
// prescale
- texture_prescale(d3d, texture);
+ prescale();
}
//============================================================
-// texture_prescale
+// texture_info::prescale
//============================================================
-static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture)
+void texture_info::prescale()
{
- d3d_surface *surface;
+ surface *scale_surface;
HRESULT result;
int i;
// if we don't need to, just skip it
- if (texture->d3dtex == texture->d3dfinaltex)
+ if (m_d3dtex == m_d3dfinaltex)
return;
// for all cases, we need to get the surface of the render target
- result = (*d3dintf->texture.get_surface_level)(texture->d3dfinaltex, 0, &surface);
+ result = (*d3dintf->texture.get_surface_level)(m_d3dfinaltex, 0, &scale_surface);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture get_surface_level call\n", (int)result);
// if we have an offscreen plain surface, we can just StretchRect to it
- if (texture->type == TEXTURE_TYPE_SURFACE)
+ if (m_type == TEXTURE_TYPE_SURFACE)
{
- RECT source, dest;
-
- assert(texture->d3dsurface != NULL);
+ assert(m_d3dsurface != NULL);
// set the source bounds
+ RECT source;
source.left = source.top = 0;
- source.right = texture->texinfo.width + 2 * texture->xborderpix;
- source.bottom = texture->texinfo.height + 2 * texture->yborderpix;
+ source.right = m_texinfo.width + 2 * m_xborderpix;
+ source.bottom = m_texinfo.height + 2 * m_yborderpix;
// set the target bounds
+ RECT dest;
dest = source;
- dest.right *= texture->xprescale;
- dest.bottom *= texture->yprescale;
+ dest.right *= m_xprescale;
+ dest.bottom *= m_yprescale;
// do the stretchrect
- result = (*d3dintf->device.stretch_rect)(d3d->device, texture->d3dsurface, &source, surface, &dest, D3DTEXF_POINT);
+ result = (*d3dintf->device.stretch_rect)(m_renderer->get_device(), m_d3dsurface, &source, scale_surface, &dest, D3DTEXF_POINT);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device stretct_rect call\n", (int)result);
}
// if we are using a texture render target, we need to do more preparations
else
{
- d3d_surface *backbuffer;
+ surface *backbuffer;
- assert(texture->d3dtex != NULL);
+ assert(m_d3dtex != NULL);
// first remember the original render target and set the new one
- result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer);
+ result = (*d3dintf->device.get_render_target)(m_renderer->get_device(), 0, &backbuffer);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
- result = (*d3dintf->device.set_render_target)(d3d->device, 0, surface);
+ result = (*d3dintf->device.set_render_target)(m_renderer->get_device(), 0, scale_surface);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 1\n", (int)result);
- reset_render_states(d3d);
+ m_renderer->reset_render_states();
// start the scene
- result = (*d3dintf->device.begin_scene)(d3d->device);
+ result = (*d3dintf->device.begin_scene)(m_renderer->get_device());
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device begin_scene call\n", (int)result);
// configure the rendering pipeline
- set_filter(d3d, FALSE);
- set_blendmode(d3d, BLENDMODE_NONE);
- result = (*d3dintf->device.set_texture)(d3d->device, 0, texture->d3dtex);
+ m_renderer->set_filter(FALSE);
+ m_renderer->set_blendmode(BLENDMODE_NONE);
+ result = (*d3dintf->device.set_texture)(m_renderer->get_device(), 0, m_d3dtex);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
// lock the vertex buffer
- result = (*d3dintf->vertexbuf.lock)(d3d->vertexbuf, 0, 0, (VOID **)&d3d->lockedbuf, D3DLOCK_DISCARD);
+ result = (*d3dintf->vertexbuf.lock)(m_renderer->get_vertex_buffer(), 0, 0, m_renderer->get_locked_buffer_ptr(), D3DLOCK_DISCARD);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer lock call\n", (int)result);
// configure the X/Y coordinates on the target surface
- d3d->lockedbuf[0].x = -0.5f;
- d3d->lockedbuf[0].y = -0.5f;
- d3d->lockedbuf[1].x = (float)((texture->texinfo.width + 2 * texture->xborderpix) * texture->xprescale) - 0.5f;
- d3d->lockedbuf[1].y = -0.5f;
- d3d->lockedbuf[2].x = -0.5f;
- d3d->lockedbuf[2].y = (float)((texture->texinfo.height + 2 * texture->yborderpix) * texture->yprescale) - 0.5f;
- d3d->lockedbuf[3].x = (float)((texture->texinfo.width + 2 * texture->xborderpix) * texture->xprescale) - 0.5f;
- d3d->lockedbuf[3].y = (float)((texture->texinfo.height + 2 * texture->yborderpix) * texture->yprescale) - 0.5f;
+ vertex *lockedbuf = m_renderer->get_locked_buffer();
+ lockedbuf[0].x = -0.5f;
+ lockedbuf[0].y = -0.5f;
+ lockedbuf[1].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f;
+ lockedbuf[1].y = -0.5f;
+ lockedbuf[2].x = -0.5f;
+ lockedbuf[2].y = (float)((m_texinfo.height + 2 * m_yborderpix) * m_yprescale) - 0.5f;
+ lockedbuf[3].x = (float)((m_texinfo.width + 2 * m_xborderpix) * m_xprescale) - 0.5f;
+ lockedbuf[3].y = (float)((m_texinfo.height + 2 * m_yborderpix) * m_yprescale) - 0.5f;
// configure the U/V coordintes on the source texture
- d3d->lockedbuf[0].u0 = 0.0f;
- d3d->lockedbuf[0].v0 = 0.0f;
- d3d->lockedbuf[1].u0 = (float)(texture->texinfo.width + 2 * texture->xborderpix) / (float)texture->rawwidth;
- d3d->lockedbuf[1].v0 = 0.0f;
- d3d->lockedbuf[2].u0 = 0.0f;
- d3d->lockedbuf[2].v0 = (float)(texture->texinfo.height + 2 * texture->yborderpix) / (float)texture->rawheight;
- d3d->lockedbuf[3].u0 = (float)(texture->texinfo.width + 2 * texture->xborderpix) / (float)texture->rawwidth;
- d3d->lockedbuf[3].v0 = (float)(texture->texinfo.height + 2 * texture->yborderpix) / (float)texture->rawheight;
+ lockedbuf[0].u0 = 0.0f;
+ lockedbuf[0].v0 = 0.0f;
+ lockedbuf[1].u0 = (float)(m_texinfo.width + 2 * m_xborderpix) / (float)m_rawdims.c.x;
+ lockedbuf[1].v0 = 0.0f;
+ lockedbuf[2].u0 = 0.0f;
+ lockedbuf[2].v0 = (float)(m_texinfo.height + 2 * m_yborderpix) / (float)m_rawdims.c.y;
+ lockedbuf[3].u0 = (float)(m_texinfo.width + 2 * m_xborderpix) / (float)m_rawdims.c.x;
+ lockedbuf[3].v0 = (float)(m_texinfo.height + 2 * m_yborderpix) / (float)m_rawdims.c.y;
// reset the remaining vertex parameters
for (i = 0; i < 4; i++)
{
- d3d->lockedbuf[i].z = 0.0f;
- d3d->lockedbuf[i].rhw = 1.0f;
- d3d->lockedbuf[i].color = D3DCOLOR_ARGB(0xff,0xff,0xff,0xff);
+ lockedbuf[i].z = 0.0f;
+ lockedbuf[i].rhw = 1.0f;
+ lockedbuf[i].color = D3DCOLOR_ARGB(0xff,0xff,0xff,0xff);
}
// unlock the vertex buffer
- result = (*d3dintf->vertexbuf.unlock)(d3d->vertexbuf);
+ result = (*d3dintf->vertexbuf.unlock)(m_renderer->get_vertex_buffer());
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer unlock call\n", (int)result);
- d3d->lockedbuf = NULL;
+ m_renderer->set_locked_buffer(NULL);
// set the stream and draw the triangle strip
- result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex));
+ result = (*d3dintf->device.set_stream_source)(m_renderer->get_device(), 0, m_renderer->get_vertex_buffer(), sizeof(vertex));
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result);
- result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLESTRIP, 0, 2);
+ result = (*d3dintf->device.draw_primitive)(m_renderer->get_device(), D3DPT_TRIANGLESTRIP, 0, 2);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
// end the scene
- result = (*d3dintf->device.end_scene)(d3d->device);
+ result = (*d3dintf->device.end_scene)(m_renderer->get_device());
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device end_scene call\n", (int)result);
// reset the render target and release our reference to the backbuffer
- result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer);
+ result = (*d3dintf->device.set_render_target)(m_renderer->get_device(), 0, backbuffer);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 2\n", (int)result);
(*d3dintf->surface.release)(backbuffer);
- reset_render_states(d3d);
+ m_renderer->reset_render_states();
}
// release our reference to the target surface
- (*d3dintf->surface.release)(surface);
-}
-
-
-
-//============================================================
-// texture_find
-//============================================================
-
-static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *prim)
-{
- UINT32 texhash = texture_compute_hash(&prim->texture, prim->flags);
- d3d_texture_info *texture;
-
- // find a match
- for (texture = d3d->texlist; texture != NULL; texture = texture->next)
- {
- UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1;
- UINT32 test_page = (UINT32)texture->texinfo.osddata & 1;
- UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1;
- UINT32 prim_page = (UINT32)prim->texture.osddata & 1;
- if (test_screen != prim_screen || test_page != prim_page)
- {
- continue;
- }
-
- if (texture->hash == texhash &&
- texture->texinfo.base == prim->texture.base &&
- texture->texinfo.width == prim->texture.width &&
- texture->texinfo.height == prim->texture.height &&
- ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
- {
- // Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
- if (d3d->hlsl->enabled() && prim->texture.width != 0 && prim->texture.height != 0 && (prim->flags & PRIMFLAG_SCREENTEX_MASK) != 0)
- {
- if (d3d->hlsl->find_render_target(texture) != NULL)
- {
- return texture;
- }
- }
- else
- {
- return texture;
- }
- }
- }
-
- // nothing found, check if we need to unregister something with hlsl
- if (d3d->hlsl->enabled())
- {
- if (prim->texture.width == 0 || prim->texture.height == 0)
- {
- return NULL;
- }
-
- UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1;
- UINT32 prim_page = (UINT32)prim->texture.osddata & 1;
-
- for (texture = d3d->texlist; texture != NULL; texture = texture->next)
- {
- UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1;
- UINT32 test_page = (UINT32)texture->texinfo.osddata & 1;
- if (test_screen != prim_screen || test_page != prim_page)
- {
- continue;
- }
-
- // Clear our old texture reference
- if (texture->hash == texhash &&
- texture->texinfo.base == prim->texture.base &&
- ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 &&
- (texture->texinfo.width != prim->texture.width ||
- texture->texinfo.height != prim->texture.height))
- {
- d3d->hlsl->remove_render_target(texture);
- break;
- }
- }
- }
- return NULL;
-}
-
-
-//============================================================
-// texture_update
-//============================================================
-
-static void texture_update(d3d_info *d3d, const render_primitive *prim)
-{
- d3d_texture_info *texture = texture_find(d3d, prim);
-
- // if we didn't find one, create a new texture
- if (texture == NULL)
- {
- texture = texture_create(d3d, &prim->texture, prim->flags);
- }
-
- // if we found it, but with a different seqid, copy the data
- if (texture->texinfo.seqid != prim->texture.seqid)
- {
- texture_set_data(d3d, texture, &prim->texture, prim->flags);
- texture->texinfo.seqid = prim->texture.seqid;
- }
+ (*d3dintf->surface.release)(scale_surface);
}
//============================================================
-// d3d_cache_target::~d3d_cache_target
+// cache_target::~cache_target
//============================================================
-d3d_cache_target::~d3d_cache_target()
+cache_target::~cache_target()
{
for (int index = 0; index < 11; index++)
{
@@ -2746,32 +2823,29 @@ d3d_cache_target::~d3d_cache_target()
//============================================================
-// d3d_cache_target::init - initializes a target cache
+// cache_target::init - initializes a target cache
//============================================================
-bool d3d_cache_target::init(d3d_info *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y, bool bloom)
+bool cache_target::init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y)
{
- if (bloom)
- {
- int bloom_size = (width * prescale_x < height * prescale_y) ? width * prescale_x : height * prescale_y;
- int bloom_index = 0;
- int bloom_width = width * prescale_x;
- int bloom_height = height * prescale_y;
- for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1)
+ int bloom_size = (width * prescale_x < height * prescale_y) ? width * prescale_x : height * prescale_y;
+ int bloom_index = 0;
+ int bloom_width = width * prescale_x;
+ int bloom_height = height * prescale_y;
+ for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1)
+ {
+ bloom_width >>= 1;
+ bloom_height >>= 1;
+ HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]);
+ if (result != D3D_OK)
{
- bloom_width >>= 1;
- bloom_height >>= 1;
- HRESULT result = (*d3dintf->device.create_texture)(d3d->device, bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]);
- if (result != D3D_OK)
- {
- return false;
- }
- (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]);
- bloom_index++;
+ return false;
}
+ (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]);
+ bloom_index++;
}
- HRESULT result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture);
+ HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture);
if (result != D3D_OK)
return false;
(*d3dintf->texture.get_surface_level)(last_texture, 0, &last_target);
@@ -2783,10 +2857,10 @@ bool d3d_cache_target::init(d3d_info *d3d, d3d_base *d3dintf, int width, int hei
}
//============================================================
-// d3d_render_target::~d3d_render_target
+// render_target::~render_target
//============================================================
-d3d_render_target::~d3d_render_target()
+render_target::~render_target()
{
for (int index = 0; index < 11; index++)
{
@@ -2804,10 +2878,10 @@ d3d_render_target::~d3d_render_target()
for (int index = 0; index < 5; index++)
{
- if (texture[index] != NULL)
+ if (render_texture[index] != NULL)
{
- (*d3dintf->texture.release)(texture[index]);
- texture[index] = NULL;
+ (*d3dintf->texture.release)(render_texture[index]);
+ render_texture[index] = NULL;
}
if (target[index] != NULL)
{
@@ -2841,72 +2915,61 @@ d3d_render_target::~d3d_render_target()
//============================================================
-// d3d_render_target::init - initializes a render target
+// render_target::init - initializes a render target
//============================================================
-bool d3d_render_target::init(d3d_info *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y, bool bloom)
+bool render_target::init(renderer *d3d, base *d3dintf, int width, int height, int prescale_x, int prescale_y)
{
- D3DFORMAT format = bloom ? D3DFMT_A16B16G16R16F : D3DFMT_A8R8G8B8;
+ D3DFORMAT format = D3DFMT_A8R8G8B8;
- HRESULT result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture[0]);
+ HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &render_texture[0]);
if (result != D3D_OK)
return false;
- (*d3dintf->texture.get_surface_level)(texture[0], 0, &target[0]);
+ (*d3dintf->texture.get_surface_level)(render_texture[0], 0, &target[0]);
- result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture[1]);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &render_texture[1]);
if (result != D3D_OK)
return false;
- (*d3dintf->texture.get_surface_level)(texture[1], 0, &target[1]);
+ (*d3dintf->texture.get_surface_level)(render_texture[1], 0, &target[1]);
- result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &texture[2]);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, format, D3DPOOL_DEFAULT, &render_texture[2]);
if (result != D3D_OK)
return false;
- (*d3dintf->texture.get_surface_level)(texture[2], 0, &target[2]);
+ (*d3dintf->texture.get_surface_level)(render_texture[2], 0, &target[2]);
- if (!bloom)
- {
- result = (*d3dintf->device.create_texture)(d3d->device, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture[3]);
- if (result != D3D_OK)
- return false;
- (*d3dintf->texture.get_surface_level)(texture[3], 0, &target[3]);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &render_texture[3]);
+ if (result != D3D_OK)
+ return false;
+ (*d3dintf->texture.get_surface_level)(render_texture[3], 0, &target[3]);
- result = (*d3dintf->device.create_texture)(d3d->device, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture[4]);
- if (result != D3D_OK)
- return false;
- (*d3dintf->texture.get_surface_level)(texture[4], 0, &target[4]);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &render_texture[4]);
+ if (result != D3D_OK)
+ return false;
+ (*d3dintf->texture.get_surface_level)(render_texture[4], 0, &target[4]);
- result = (*d3dintf->device.create_texture)(d3d->device, width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &smalltexture);
- if (result != D3D_OK)
- return false;
- (*d3dintf->texture.get_surface_level)(smalltexture, 0, &smalltarget);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &smalltexture);
+ if (result != D3D_OK)
+ return false;
+ (*d3dintf->texture.get_surface_level)(smalltexture, 0, &smalltarget);
- result = (*d3dintf->device.create_texture)(d3d->device, width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &prescaletexture);
- if (result != D3D_OK)
- return false;
- (*d3dintf->texture.get_surface_level)(prescaletexture, 0, &prescaletarget);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &prescaletexture);
+ if (result != D3D_OK)
+ return false;
+ (*d3dintf->texture.get_surface_level)(prescaletexture, 0, &prescaletarget);
- for (int index = 0; index < 11; index++)
- {
- bloom_texture[index] = NULL;
- bloom_target[index] = NULL;
- }
- }
- else
+ int bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height();
+ int bloom_index = 0;
+ int bloom_width = d3d->get_width();
+ int bloom_height = d3d->get_height();
+ for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1)
{
- int bloom_size = (width < height) ? width : height;
- int bloom_index = 0;
- int bloom_width = width;
- int bloom_height = height;
- for (; bloom_size >= 2 && bloom_index < 11; bloom_size >>= 1)
- {
- bloom_width >>= 1;
- bloom_height >>= 1;
- result = (*d3dintf->device.create_texture)(d3d->device, bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]);
- if (result != D3D_OK)
- return false;
- (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]);
- bloom_index++;
- }
+ bloom_width >>= 1;
+ bloom_height >>= 1;
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), bloom_width, bloom_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bloom_texture[bloom_index]);
+ if (result != D3D_OK)
+ return false;
+ (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_target[bloom_index]);
+ bloom_index++;
}
target_width = width * prescale_x;
@@ -2914,3 +2977,5 @@ bool d3d_render_target::init(d3d_info *d3d, d3d_base *d3dintf, int width, int he
return true;
}
+
+}; \ No newline at end of file