diff options
Diffstat (limited to 'src/osd/modules/render')
-rw-r--r-- | src/osd/modules/render/d3d/d3dcomm.h | 26 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.cpp | 274 | ||||
-rw-r--r-- | src/osd/modules/render/d3d/d3dhlsl.h | 19 | ||||
-rw-r--r-- | src/osd/modules/render/drawd3d.cpp | 315 |
4 files changed, 315 insertions, 319 deletions
diff --git a/src/osd/modules/render/d3d/d3dcomm.h b/src/osd/modules/render/d3d/d3dcomm.h index 4894cd7f491..6240deb3011 100644 --- a/src/osd/modules/render/d3d/d3dcomm.h +++ b/src/osd/modules/render/d3d/d3dcomm.h @@ -77,6 +77,8 @@ public: DWORD get_max_texture_width() { return m_texture_max_width; } DWORD get_max_texture_height() { return m_texture_max_height; } + void compute_texture_size(int texwidth, int texheight, int* p_width, int* p_height); + texture_info * get_default_texture() { return m_default_texture; } texture_info * get_vector_texture() { return m_vector_texture; } @@ -148,7 +150,6 @@ public: private: void prescale(); void compute_size(int texwidth, int texheight); - void compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height); d3d_texture_manager * m_texture_manager; // texture manager pointer @@ -244,7 +245,7 @@ public: cache_target() { } ~cache_target(); - bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y); + bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height); surface *last_target; texture *last_texture; @@ -269,31 +270,34 @@ public: d3d_render_target() { } ~d3d_render_target(); - bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y); + bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int target_width, int target_height); int next_index(int index) { return ++index > 1 ? 0 : index; } + // real target dimension int target_width; int target_height; - int prescale_x; - int prescale_y; - + // only used to identify/find the render target int width; int height; int screen_index; int page_index; - surface *prescale_target[2]; - texture *prescale_texture[2]; - surface *native_target[2]; - texture *native_texture[2]; + surface *target_surface[2]; + texture *target_texture[2]; + surface *source_surface[2]; + texture *source_texture[2]; d3d_render_target *next; d3d_render_target *prev; - surface *bloom_target[11]; + surface *bloom_surface[11]; texture *bloom_texture[11]; + + float bloom_dims[11][2]; + + int bloom_count; }; #endif diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp index 17b2f411336..c55c679be54 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.cpp +++ b/src/osd/modules/render/d3d/d3dhlsl.cpp @@ -60,7 +60,7 @@ static direct3dx9_loadeffect_ptr g_load_effect = nullptr; //============================================================ shaders::shaders() : - d3dintf(nullptr), machine(nullptr), d3d(nullptr), num_screens(0), curr_screen(0), curr_frame(0), write_ini(false), read_ini(false), hlsl_prescale_x(0), hlsl_prescale_y(0), bloom_count(0), + d3dintf(nullptr), machine(nullptr), d3d(nullptr), num_screens(0), curr_screen(0), curr_frame(0), vecbuf_type(), vecbuf_index(0), vecbuf_count(0), avi_output_file(nullptr), avi_frame(0), avi_copy_surface(nullptr), avi_copy_texture(nullptr), avi_final_target(nullptr), avi_final_texture(nullptr), black_surface(nullptr), black_texture(nullptr), render_snap(false), snap_rendered(false), snap_copy_target(nullptr), snap_copy_texture(nullptr), snap_target(nullptr), snap_texture(nullptr), snap_width(0), snap_height(0), lines_pending(false), backbuffer(nullptr), curr_effect(nullptr), default_effect(nullptr), prescale_effect(nullptr), post_effect(nullptr), distortion_effect(nullptr), @@ -69,11 +69,8 @@ shaders::shaders() : { master_enable = false; vector_enable = true; - hlsl_prescale_x = 1; - hlsl_prescale_x = 1; - preset = -1; - shadow_texture = nullptr; - options = nullptr; + shadow_texture = NULL; + options = NULL; paused = true; lastidx = -1; targethead = nullptr; @@ -668,8 +665,6 @@ void shaders::init(d3d_base *d3dintf, running_machine *machine, renderer_d3d9 *r windows_options &winoptions = downcast<windows_options &>(machine->options()); master_enable = winoptions.d3d_hlsl_enable(); - hlsl_prescale_x = winoptions.d3d_hlsl_prescale_x(); - hlsl_prescale_y = winoptions.d3d_hlsl_prescale_y(); snap_width = winoptions.d3d_snap_width(); snap_height = winoptions.d3d_snap_height(); @@ -957,6 +952,7 @@ int shaders::create_resources(bool reset) effects[i]->add_uniform("ScreenDims", uniform::UT_VEC2, uniform::CU_SCREEN_DIMS); effects[i]->add_uniform("QuadDims", uniform::UT_VEC2, uniform::CU_QUAD_DIMS); effects[i]->add_uniform("SwapXY", uniform::UT_BOOL, uniform::CU_SWAP_XY); + effects[i]->add_uniform("VectorScreen", uniform::UT_BOOL, uniform::CU_VECTOR_SCREEN); } ntsc_effect->add_uniform("CCValue", uniform::UT_FLOAT, uniform::CU_NTSC_CCFREQ); @@ -986,18 +982,11 @@ int shaders::create_resources(bool reset) phosphor_effect->add_uniform("Phosphor", uniform::UT_VEC3, uniform::CU_PHOSPHOR_LIFE); - post_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING); // backward compatibility - post_effect->add_uniform("CurvatureAmount", uniform::UT_FLOAT, uniform::CU_POST_CURVATURE); // backward compatibility - post_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER); // backward compatibility - post_effect->add_uniform("SmoothBorderAmount", uniform::UT_FLOAT, uniform::CU_POST_SMOOTH_BORDER); // backward compatibility - post_effect->add_uniform("ReflectionAmount", uniform::UT_FLOAT, uniform::CU_POST_REFLECTION); // backward compatibility - post_effect->add_uniform("ShadowAlpha", uniform::UT_FLOAT, uniform::CU_POST_SHADOW_ALPHA); post_effect->add_uniform("ShadowCount", uniform::UT_VEC2, uniform::CU_POST_SHADOW_COUNT); post_effect->add_uniform("ShadowUV", uniform::UT_VEC2, uniform::CU_POST_SHADOW_UV); post_effect->add_uniform("ShadowUVOffset", uniform::UT_VEC2, uniform::CU_POST_SHADOW_UV_OFFSET); post_effect->add_uniform("ShadowDims", uniform::UT_VEC2, uniform::CU_POST_SHADOW_DIMS); - post_effect->add_uniform("ScanlineAlpha", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_ALPHA); post_effect->add_uniform("ScanlineScale", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_SCALE); post_effect->add_uniform("ScanlineHeight", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_HEIGHT); @@ -1005,7 +994,6 @@ int shaders::create_resources(bool reset) post_effect->add_uniform("ScanlineBrightOffset", uniform::UT_FLOAT, uniform::CU_POST_SCANLINE_BRIGHT_OFFSET); post_effect->add_uniform("Power", uniform::UT_VEC3, uniform::CU_POST_POWER); post_effect->add_uniform("Floor", uniform::UT_VEC3, uniform::CU_POST_FLOOR); - post_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE); distortion_effect->add_uniform("VignettingAmount", uniform::UT_FLOAT, uniform::CU_POST_VIGNETTING); @@ -1013,7 +1001,6 @@ int shaders::create_resources(bool reset) distortion_effect->add_uniform("RoundCornerAmount", uniform::UT_FLOAT, uniform::CU_POST_ROUND_CORNER); distortion_effect->add_uniform("SmoothBorderAmount", uniform::UT_FLOAT, uniform::CU_POST_SMOOTH_BORDER); distortion_effect->add_uniform("ReflectionAmount", uniform::UT_FLOAT, uniform::CU_POST_REFLECTION); - distortion_effect->add_uniform("RotationType", uniform::UT_INT, uniform::CU_ROTATION_TYPE); initialized = true; @@ -1035,7 +1022,7 @@ void shaders::begin_draw() curr_effect = default_effect; - default_effect->set_technique("DefaultTechnique"); + default_effect->set_technique("ScreenTechnique"); post_effect->set_technique("DefaultTechnique"); distortion_effect->set_technique("DefaultTechnique"); prescale_effect->set_technique("DefaultTechnique"); @@ -1236,9 +1223,9 @@ int shaders::ntsc_pass(d3d_render_target *rt, int source_index, poly_info *poly, curr_effect->set_float("SignalOffset", signal_offset); next_index = rt->next_index(next_index); - blit(rt->native_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->source_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); - color_effect->set_texture("Diffuse", rt->native_texture[next_index]); + color_effect->set_texture("Diffuse", rt->source_texture[next_index]); return next_index; } @@ -1293,7 +1280,7 @@ int shaders::color_convolution_pass(d3d_render_target *rt, int source_index, pol // initial "Diffuse" texture is set in shaders::set_texture() or the result of shaders::ntsc_pass() next_index = rt->next_index(next_index); - blit(rt->native_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->source_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); return next_index; } @@ -1304,10 +1291,11 @@ int shaders::prescale_pass(d3d_render_target *rt, int source_index, poly_info *p curr_effect = prescale_effect; curr_effect->update_uniforms(); - curr_effect->set_texture("Diffuse", rt->native_texture[next_index]); + curr_effect->set_texture("Diffuse", rt->source_texture[next_index]); next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1327,10 +1315,11 @@ int shaders::deconverge_pass(d3d_render_target *rt, int source_index, poly_info curr_effect = deconverge_effect; curr_effect->update_uniforms(); - curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1347,10 +1336,11 @@ int shaders::defocus_pass(d3d_render_target *rt, int source_index, poly_info *po curr_effect = focus_effect; curr_effect->update_uniforms(); - curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1367,21 +1357,23 @@ int shaders::phosphor_pass(d3d_render_target *rt, cache_target *ct, int source_i curr_effect = phosphor_effect; curr_effect->update_uniforms(); - curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); curr_effect->set_texture("LastPass", ct->last_texture); curr_effect->set_bool("Passthrough", false); next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); // Pass along our phosphor'd screen curr_effect->update_uniforms(); - curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); - curr_effect->set_texture("LastPass", rt->prescale_texture[next_index]); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); + curr_effect->set_texture("LastPass", rt->target_texture[next_index]); curr_effect->set_bool("Passthrough", true); // Avoid changing targets due to page flipping - blit(ct->last_target, true, D3DPT_TRIANGLELIST, 0, 2); + // blit(ct->last_target, true, D3DPT_TRIANGLELIST, 0, 2); + blit(ct->last_target, true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1390,9 +1382,6 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, { int next_index = source_index; - bool prepare_vector = - machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR; - screen_device_iterator screen_iterator(machine->root_device()); screen_device *screen = screen_iterator.first(); for (int i = 0; i < curr_screen; i++) @@ -1409,15 +1398,20 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, float screen_scale[2] = { xscale, yscale }; float screen_offset[2] = { xoffset, yoffset }; - rgb_t back_color_rgb = !machine->first_screen()->has_palette() ? rgb_t(0, 0, 0) : machine->first_screen()->palette().palette()->entry_color(0); + rgb_t back_color_rgb = !machine->first_screen()->has_palette() + ? rgb_t(0, 0, 0) + : machine->first_screen()->palette().palette()->entry_color(0); back_color_rgb = apply_color_convolution(back_color_rgb); - float back_color[3] = { static_cast<float>(back_color_rgb.r()) / 255.0f, static_cast<float>(back_color_rgb.g()) / 255.0f, static_cast<float>(back_color_rgb.b()) / 255.0f }; + float back_color[3] = { + static_cast<float>(back_color_rgb.r()) / 255.0f, + static_cast<float>(back_color_rgb.g()) / 255.0f, + static_cast<float>(back_color_rgb.b()) / 255.0f }; curr_effect = post_effect; curr_effect->update_uniforms(); curr_effect->set_texture("ShadowTexture", shadow_texture == nullptr ? nullptr : shadow_texture->get_finaltex()); curr_effect->set_int("ShadowTileMode", options->shadow_mask_tile_mode); - curr_effect->set_texture("DiffuseTexture", rt->prescale_texture[next_index]); + curr_effect->set_texture("DiffuseTexture", rt->target_texture[next_index]); curr_effect->set_vector("BackColor", 3, back_color); curr_effect->set_vector("ScreenScale", 2, screen_scale); curr_effect->set_vector("ScreenOffset", 2, screen_offset); @@ -1425,10 +1419,10 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly, curr_effect->set_float("TimeMilliseconds", (float)machine->time().as_double() * 1000.0f); curr_effect->set_float("HumBarAlpha", options->hum_bar_alpha); curr_effect->set_bool("PrepareBloom", prepare_bloom); - curr_effect->set_bool("PrepareVector", prepare_vector); next_index = rt->next_index(next_index); - blit(prepare_bloom ? rt->native_target[next_index] : rt->prescale_target[next_index], true, poly->get_type(), vertnum, poly->get_count()); + // blit(prepare_bloom ? rt->source_surface[next_index] : rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(prepare_bloom ? rt->source_surface[next_index] : rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1443,38 +1437,22 @@ int shaders::downsample_pass(d3d_render_target *rt, int source_index, poly_info return next_index; } - bool prepare_vector = - machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR; - curr_effect = downsample_effect; curr_effect->update_uniforms(); - curr_effect->set_bool("PrepareVector", prepare_vector); - int bloom_index = 0; - float bloom_width = prepare_vector ? rt->target_width : rt->target_width / hlsl_prescale_x; - float bloom_height = prepare_vector ? rt->target_height : rt->target_height / hlsl_prescale_y; - float bloom_size = (bloom_width < bloom_height) ? bloom_width : bloom_height; - for (; bloom_size >= 2.0f && bloom_index < 11; bloom_size *= 0.5f) + for (int bloom_index = 0; bloom_index < rt->bloom_count; bloom_index++) { - bloom_dims[bloom_index][0] = (float)(int)bloom_width; - bloom_dims[bloom_index][1] = (float)(int)bloom_height; - - curr_effect->set_vector("TargetDims", 2, bloom_dims[bloom_index]); + curr_effect->set_vector("TargetDims", 2, rt->bloom_dims[bloom_index]); + curr_effect->set_int("BloomLevel", bloom_index + 1); curr_effect->set_texture("DiffuseTexture", bloom_index == 0 - ? rt->native_texture[next_index] + ? rt->source_texture[next_index] : rt->bloom_texture[bloom_index - 1]); - blit(rt->bloom_target[bloom_index], true, poly->get_type(), vertnum, poly->get_count()); - - bloom_width *= 0.5f; - bloom_height *= 0.5f; - - bloom_index++; + // blit(rt->bloom_surface[bloom_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->bloom_surface[bloom_index], true, poly->get_type(), vertnum, poly->get_count()); } - bloom_count = bloom_index; - return next_index; } @@ -1519,33 +1497,34 @@ int shaders::bloom_pass(d3d_render_target *rt, int source_index, poly_info *poly curr_effect->set_vector("Level78Weight", 2, weight78); curr_effect->set_vector("Level9AWeight", 2, weight9A); - curr_effect->set_vector("Level0Size", 2, bloom_dims[0]); - curr_effect->set_vector("Level12Size", 4, bloom_dims[1]); - curr_effect->set_vector("Level34Size", 4, bloom_dims[3]); - curr_effect->set_vector("Level56Size", 4, bloom_dims[5]); - curr_effect->set_vector("Level78Size", 4, bloom_dims[7]); - curr_effect->set_vector("Level9ASize", 4, bloom_dims[9]); + curr_effect->set_vector("Level0Size", 2, rt->bloom_dims[0]); + curr_effect->set_vector("Level12Size", 4, rt->bloom_dims[1]); + curr_effect->set_vector("Level34Size", 4, rt->bloom_dims[3]); + curr_effect->set_vector("Level56Size", 4, rt->bloom_dims[5]); + curr_effect->set_vector("Level78Size", 4, rt->bloom_dims[7]); + curr_effect->set_vector("Level9ASize", 4, rt->bloom_dims[9]); curr_effect->set_int("BloomBlendMode", options->bloom_blend_mode); curr_effect->set_float("BloomScale", options->bloom_scale); curr_effect->set_vector("BloomOverdrive", 3, options->bloom_overdrive); - curr_effect->set_texture("DiffuseA", rt->prescale_texture[next_index]); + curr_effect->set_texture("DiffuseA", rt->target_texture[next_index]); char name[9] = "Diffuse*"; - for (int index = 1; index < bloom_count; index++) + for (int index = 1; index < rt->bloom_count; index++) { name[7] = 'A' + index; curr_effect->set_texture(name, rt->bloom_texture[index - 1]); } - for (int index = bloom_count; index < 11; index++) + for (int index = rt->bloom_count; index < 11; index++) { name[7] = 'A' + index; curr_effect->set_texture(name, black_texture); } next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, poly->get_type(), vertnum, poly->get_count()); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1566,7 +1545,7 @@ int shaders::distortion_pass(d3d_render_target *rt, int source_index, poly_info int screen_count = d3d->window().target()->current_view()->screens().count(); - // only one screen is supported + // todo: only one screen is supported if (screen_count > 1) { return next_index; @@ -1574,22 +1553,26 @@ int shaders::distortion_pass(d3d_render_target *rt, int source_index, poly_info render_bounds bounds = d3d->window().target()->current_view()->bounds(); render_bounds screen_bounds = d3d->window().target()->current_view()->screen_bounds(); - - // artworks are not supported - if (bounds.x0 != screen_bounds.x0 || + bool screen_bounds_zoomed = d3d->window().target()->zoom_to_screen(); + bool screen_bounds_differ = + bounds.x0 != screen_bounds.x0 || bounds.y0 != screen_bounds.y0 || bounds.x1 != screen_bounds.x1 || - bounds.y1 != screen_bounds.y1) + bounds.y1 != screen_bounds.y1; + + // todo: full artworks are not supported + if (screen_bounds_differ && !screen_bounds_zoomed) { return next_index; } curr_effect = distortion_effect; curr_effect->update_uniforms(); - curr_effect->set_texture("DiffuseTexture", rt->prescale_texture[next_index]); + curr_effect->set_texture("DiffuseTexture", rt->target_texture[next_index]); next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, poly->get_type(), vertnum, poly->get_count()); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1606,7 +1589,8 @@ int shaders::vector_pass(d3d_render_target *rt, int source_index, poly_info *pol curr_effect->set_vector("TimeParams", 2, time_params); curr_effect->set_vector("LengthParams", 3, length_params); - blit(rt->prescale_target[next_index], true, poly->get_type(), vertnum, poly->get_count()); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1617,13 +1601,13 @@ int shaders::vector_buffer_pass(d3d_render_target *rt, int source_index, poly_in curr_effect = default_effect; curr_effect->update_uniforms(); + curr_effect->set_technique("VectorBufferTechnique"); - curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); - curr_effect->set_bool("PostPass", true); - curr_effect->set_float("Brighten", 1.0f); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); next_index = rt->next_index(next_index); - blit(rt->prescale_target[next_index], true, poly->get_type(), vertnum, poly->get_count()); + // blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2); + blit(rt->target_surface[next_index], true, poly->get_type(), vertnum, poly->get_count()); return next_index; } @@ -1632,17 +1616,13 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol { int next_index = source_index; - bool prepare_vector = - machine->first_screen()->screen_type() == SCREEN_TYPE_VECTOR; - curr_effect = default_effect; curr_effect->update_uniforms(); + curr_effect->set_technique("ScreenTechnique"); - curr_effect->set_texture("Diffuse", rt->prescale_texture[next_index]); - curr_effect->set_bool("PostPass", true); - curr_effect->set_float("Brighten", prepare_vector ? 1.0f : 0.0f); + curr_effect->set_texture("Diffuse", rt->target_texture[next_index]); - // we do not clear the backbuffe here because multiple screens might rendered into + // we do not clear the backbuffe here because multiple screens might be rendered into blit(backbuffer, false, poly->get_type(), vertnum, poly->get_count()); if (avi_output_file != nullptr) @@ -1660,12 +1640,11 @@ int shaders::screen_pass(d3d_render_target *rt, int source_index, poly_info *pol return next_index; } -void shaders::menu_pass(poly_info *poly, int vertnum) +void shaders::ui_pass(poly_info *poly, int vertnum) { curr_effect = default_effect; curr_effect->update_uniforms(); - curr_effect->set_bool("PostPass", false); - curr_effect->set_float("Brighten", 0.0f); + curr_effect->set_technique("UiTechnique"); blit(nullptr, false, poly->get_type(), vertnum, poly->get_count()); } @@ -1694,6 +1673,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) d3d_render_target *rt = curr_render_target; if (rt == nullptr) { + osd_printf_verbose("Direct3D: No raster render target\n"); return; } @@ -1740,6 +1720,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) d3d_render_target *rt = curr_render_target; if (rt == nullptr) { + osd_printf_verbose("Direct3D: No vector render target\n"); return; } @@ -1762,6 +1743,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) d3d_render_target *rt = curr_render_target; if (rt == nullptr) { + osd_printf_verbose("Direct3D: No vector buffer render target\n"); return; } @@ -1800,7 +1782,7 @@ void shaders::render_quad(poly_info *poly, int vertnum) } else { - menu_pass(poly, vertnum); + ui_pass(poly, vertnum); } curr_render_target = nullptr; @@ -1825,23 +1807,13 @@ void shaders::end_draw() //============================================================ -// shaders::register_prescaled_texture -//============================================================ - -bool shaders::register_prescaled_texture(texture_info *texture) -{ - return register_texture(texture); -} - - -//============================================================ // shaders::add_cache_target - register a cache target //============================================================ -bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index) +bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int screen_index) { cache_target* target = (cache_target*)global_alloc_clear<cache_target>(); - if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) + if (!target->init(d3d, d3dintf, width, height)) { global_free(target); return false; @@ -1884,7 +1856,10 @@ d3d_render_target* shaders::get_vector_target() void shaders::create_vector_target(render_primitive *prim) { - if (!add_render_target(d3d, nullptr, d3d->get_width(), d3d->get_height(), 1, 1)) + int width = d3d->get_width(); + int height = d3d->get_height(); + + if (!add_render_target(d3d, nullptr, width, height, width, height)) { vector_enable = false; } @@ -1895,7 +1870,7 @@ void shaders::create_vector_target(render_primitive *prim) // shaders::add_render_target - register a render target //============================================================ -bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int xprescale, int yprescale) +bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int target_width, int target_height) { UINT32 screen_index = 0; UINT32 page_index = 0; @@ -1922,7 +1897,7 @@ bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int widt d3d_render_target* target = (d3d_render_target*)global_alloc_clear<d3d_render_target>(); - if (!target->init(d3d, d3dintf, width, height, xprescale, yprescale)) + if (!target->init(d3d, d3dintf, width, height, target_width, target_height)) { global_free(target); return false; @@ -1939,7 +1914,7 @@ bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int widt target->height = d3d->get_height(); } - HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, target->prescale_target[0]); + HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, target->target_surface[0]); if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result); result = (*d3dintf->device.clear)(d3d->get_device(), 0, nullptr, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0,0,0,0), 0, 0); if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device clear call\n", (int)result); @@ -1952,7 +1927,7 @@ bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int widt cache_target* cache = find_cache_target(target->screen_index, target->width, target->height); if (cache == nullptr) { - if (!add_cache_target(d3d, info, width, height, xprescale, yprescale, target->screen_index)) + if (!add_cache_target(d3d, info, target_width, target_height, target->screen_index)) { global_free(target); return false; @@ -1986,13 +1961,8 @@ void shaders::enumerate_screens() // shaders::register_texture(texture::info) //============================================================ -bool shaders::register_texture(texture_info *texture) +bool shaders::register_texture(render_primitive *prim, texture_info *texture) { - int width = texture->get_width(); - int height = texture->get_height(); - int xscale = texture->get_xscale(); - int yscale = texture->get_yscale(); - if (!master_enable || !d3dintf->post_fx_available) { return false; @@ -2000,31 +1970,7 @@ bool shaders::register_texture(texture_info *texture) enumerate_screens(); - // Find the nearest prescale factor that is over our screen size - if (hlsl_prescale_x == 0) - { - hlsl_prescale_x = 1; - while (width * xscale * hlsl_prescale_x <= d3d->get_width()) - { - hlsl_prescale_x++; - } - hlsl_prescale_x--; - } - - if (hlsl_prescale_y == 0) - { - hlsl_prescale_y = 1; - while (height * yscale * hlsl_prescale_y <= d3d->get_height()) - { - hlsl_prescale_y++; - } - hlsl_prescale_y--; - } - - hlsl_prescale_x = ((hlsl_prescale_x == 0) ? 1 : hlsl_prescale_x); - hlsl_prescale_y = ((hlsl_prescale_y == 0) ? 1 : hlsl_prescale_y); - - if (!add_render_target(d3d, texture, width, height, xscale * hlsl_prescale_x, yscale * hlsl_prescale_y)) + if (!add_render_target(d3d, texture, texture->get_width(), texture->get_height(), d3d->get_width(), d3d->get_height())) { return false; } @@ -2400,10 +2346,10 @@ slider_desc shaders::s_sliders[] = { "Screen Reflection", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_ANY, SLIDER_REFLECTION, 0.01f, "%1.2f", {} }, { "Image Vignetting", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_ANY, SLIDER_VIGNETTING, 0.01f, "%1.2f", {} }, { "Scanline Darkness", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_ALPHA, 0.01f, "%1.2f", {} }, - { "Scanline Screen Height", 1, 20, 80, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_SCALE, 0.05f, "%1.2f", {} }, - { "Scanline Indiv. Height", 1, 20, 80, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_HEIGHT, 0.05f, "%1.2f", {} }, - { "Scanline Brightness", 0, 20, 40, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_BRIGHT_SCALE, 0.05f, "%1.2f", {} }, - { "Scanline Brightness Overdrive", 0, 0, 20, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_BRIGHT_OFFSET, 0.05f, "%1.2f", {} }, + { "Scanline Screen Scale", 0, 100, 400, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_SCALE, 0.01f, "%1.2f", {} }, + { "Scanline Height", 0, 100, 400, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_HEIGHT, 0.01f, "%1.2f", {} }, + { "Scanline Brightness", 0, 100, 400, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_BRIGHT_SCALE, 0.01f, "%1.2f", {} }, + { "Scanline Brightness Overdrive", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_BRIGHT_OFFSET, 0.01f, "%1.2f", {} }, { "Scanline Jitter", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_SCANLINE_JITTER, 0.01f, "%1.2f", {} }, { "Hum Bar Darkness", 0, 0, 100, 1, SLIDER_FLOAT, SLIDER_SCREEN_TYPE_LCD_OR_RASTER, SLIDER_HUM_BAR_ALPHA, 0.01f, "%2.2f", {} }, { "Defocus", 0, 0, 100, 1, SLIDER_VEC2, SLIDER_SCREEN_TYPE_ANY, SLIDER_DEFOCUS, 0.1f, "%2.1f", {} }, @@ -2661,28 +2607,25 @@ void uniform::update() vec2f sourcedims = shadersys->curr_texture->get_rawdims(); m_shader->set_vector("SourceDims", 2, &sourcedims.c.x); } - + else + { + vec2f sourcedims = d3d->get_dims(); + m_shader->set_vector("SourceDims", 2, &sourcedims.c.x); + } break; } case CU_SOURCE_RECT: { - bool prepare_vector = - d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; - - if (prepare_vector) - { - float delta[2] = { 1.0f, 1.0f }; - m_shader->set_vector("SourceRect", 2, delta); - break; - } - if (shadersys->curr_texture != nullptr) { vec2f delta = shadersys->curr_texture->get_uvstop() - shadersys->curr_texture->get_uvstart(); m_shader->set_vector("SourceRect", 2, &delta.c.x); - break; } - + else + { + float delta[2] = { 1.0f, 1.0f }; + m_shader->set_vector("SourceRect", 2, delta); + } break; } case CU_TARGET_DIMS: @@ -2716,12 +2659,14 @@ void uniform::update() (d3d->window().target()->orientation() & ROT90) == ROT90 || (d3d->window().target()->orientation() & ROT270) == ROT270; m_shader->set_bool("SwapXY", orientation_swap_xy ^ rotation_swap_xy); + break; } case CU_ORIENTATION_SWAP: { bool orientation_swap_xy = (d3d->window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY; m_shader->set_bool("OrientationSwapXY", orientation_swap_xy); + break; } case CU_ROTATION_SWAP: @@ -2730,6 +2675,7 @@ void uniform::update() (d3d->window().target()->orientation() & ROT90) == ROT90 || (d3d->window().target()->orientation() & ROT270) == ROT270; m_shader->set_bool("RotationSwapXY", rotation_swap_xy); + break; } case CU_ROTATION_TYPE: { @@ -2742,6 +2688,14 @@ void uniform::update() ? 3 : 0; m_shader->set_int("RotationType", rotation_type); + break; + } + case CU_VECTOR_SCREEN: + { + bool vector_screen = + d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + m_shader->set_bool("VectorScreen", vector_screen); + break; } case CU_NTSC_CCFREQ: diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h index 4ff8b1ac88c..0c3bc095d4c 100644 --- a/src/osd/modules/render/d3d/d3dhlsl.h +++ b/src/osd/modules/render/d3d/d3dhlsl.h @@ -53,6 +53,7 @@ public: CU_ORIENTATION_SWAP, CU_ROTATION_SWAP, CU_ROTATION_TYPE, + CU_VECTOR_SCREEN, CU_NTSC_CCFREQ, CU_NTSC_A, @@ -318,10 +319,9 @@ public: void init_effect_info(poly_info *poly); void render_quad(poly_info *poly, int vertnum); - bool register_texture(texture_info *texture); - bool register_prescaled_texture(texture_info *texture); - bool add_render_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int xprescale, int yprescale); - bool add_cache_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index); + bool register_texture(render_primitive *prim, texture_info *texture); + bool add_render_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int target_width, int target_height); + bool add_cache_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int screen_index); void window_save(); void window_record(); @@ -352,8 +352,6 @@ private: void end_avi_recording(); void begin_avi_recording(const char *name); - bool register_texture(texture_info *texture, int width, int height, int xscale, int yscale); - d3d_render_target* find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index); cache_target * find_cache_target(UINT32 screen_index, int width, int height); void remove_cache_target(cache_target *cache); @@ -374,7 +372,7 @@ private: int vector_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int vector_buffer_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); int screen_pass(d3d_render_target *rt, int source_index, poly_info *poly, int vertnum); - void menu_pass(poly_info *poly, int vertnum); + void ui_pass(poly_info *poly, int vertnum); d3d_base * d3dintf; // D3D interface @@ -388,13 +386,6 @@ private: int curr_screen; // current screen for render target operations int curr_frame; // current frame (0/1) of a screen for render target operations int lastidx; // index of the last-encountered target - bool write_ini; // enable external ini saving - bool read_ini; // enable external ini loading - int hlsl_prescale_x; // hlsl prescale x - int hlsl_prescale_y; // hlsl prescale y - float bloom_dims[11][2]; // bloom texture dimensions - int bloom_count; // count of used bloom textures - int preset; // preset, if relevant bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader texture_info * shadow_texture; // shadow mask texture for post-processing shader hlsl_options * options; // current options diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp index 0f50cae8d55..4037c9c0bbe 100644 --- a/src/osd/modules/render/drawd3d.cpp +++ b/src/osd/modules/render/drawd3d.cpp @@ -209,6 +209,7 @@ render_primitive_list *renderer_d3d9::get_primitives() } if (m_shaders != nullptr) { + // do not transform primitives (scale, offset) if shaders are enabled, the shaders will handle the transformation window().target()->set_transform_primitives(!m_shaders->enabled()); } return &window().target()->get_primitives(); @@ -419,6 +420,63 @@ d3d_texture_manager::~d3d_texture_manager() { } + +//============================================================ +// d3d_texture_manager::compute_texture_size +//============================================================ + +void d3d_texture_manager::compute_texture_size(int texwidth, int texheight, int* p_width, int* p_height) +{ + int finalheight = texheight; + int finalwidth = texwidth; + + // round width/height up to nearest power of 2 if we need to + if (!(get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) + { + // first the width + if (finalwidth & (finalwidth - 1)) + { + finalwidth |= finalwidth >> 1; + finalwidth |= finalwidth >> 2; + finalwidth |= finalwidth >> 4; + finalwidth |= finalwidth >> 8; + finalwidth++; + } + + // then the height + if (finalheight & (finalheight - 1)) + { + finalheight |= finalheight >> 1; + finalheight |= finalheight >> 2; + finalheight |= finalheight >> 4; + finalheight |= finalheight >> 8; + finalheight++; + } + } + + // round up to square if we need to + if (get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY) + { + if (finalwidth < finalheight) + finalwidth = finalheight; + else + finalheight = finalwidth; + } + + // adjust the aspect ratio if we need to + while (finalwidth < finalheight && finalheight / finalwidth > get_max_texture_aspect()) + { + finalwidth *= 2; + } + while (finalheight < finalwidth && finalwidth / finalheight > get_max_texture_aspect()) + { + finalheight *= 2; + } + + *p_width = finalwidth; + *p_height = finalheight; +} + void d3d_texture_manager::create_resources() { // experimental: load a PNG to use for vector rendering; it is treated @@ -636,8 +694,20 @@ void d3d_texture_manager::update_textures() texture_info *texture = find_texinfo(&prim->texture, prim->flags); if (texture == nullptr) { - // if there isn't one, create a new texture - global_alloc(texture_info(this, &prim->texture, m_renderer->window().prescale(), prim->flags)); + if (m_renderer->get_shaders()->enabled()) + { + // create a new texture without prescale, shaders will handle the prescale + texture = global_alloc(texture_info(this, &prim->texture, 1, prim->flags)); + if (texture != nullptr) + { + m_renderer->get_shaders()->register_texture(prim, texture); + } + } + else + { + // create a new texture + texture = global_alloc(texture_info(this, &prim->texture, m_renderer->window().prescale(), prim->flags)); + } } else { @@ -1631,11 +1701,12 @@ void renderer_d3d9::draw_quad(const render_primitive *prim) float height = prim->bounds.y1 - prim->bounds.y0; // set the texture coordinates - if(texture != nullptr) + if (texture != nullptr) { 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; @@ -1888,18 +1959,20 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t m_d3dsurface = nullptr; m_d3dfinaltex = nullptr; - // compute the size - compute_size(texsource->width, texsource->height); - // non-screen textures are easy if (!PRIMFLAG_GET_SCREENTEX(flags)) { + // required to compute the size + m_type = TEXTURE_TYPE_PLAIN; + + // compute the size + compute_size(texsource->width, texsource->height); + assert(PRIMFLAG_TEXFORMAT(flags) != TEXFORMAT_YUY16); 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; m_d3dfinaltex = m_d3dtex; - m_type = TEXTURE_TYPE_PLAIN; } // screen textures are allocated differently @@ -1957,23 +2030,22 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t m_xprescale = m_yprescale = 1; } - // screen textures with no prescaling are pretty easy + // screen textures with no prescaling are pretty easy and shaders handle prescale itself if (m_xprescale == 1 && m_yprescale == 1) { + // required to compute the size + m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; + + // compute the size + compute_size(texsource->width, texsource->height); + 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) { m_d3dfinaltex = m_d3dtex; - m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; - if (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_texture(this)) - { - goto error; - } - break; } } - // screen textures with prescaling require two allocations else { @@ -1981,23 +2053,32 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t // (won't work for YUY textures) if (m_texture_manager->is_stretch_supported() && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16) { + // required to compute the size + m_type = TEXTURE_TYPE_SURFACE; + + // compute the size + compute_size(texsource->width, texsource->height); + 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; } - m_type = TEXTURE_TYPE_SURFACE; } - // otherwise, we allocate a dynamic texture for the source else { + // required to compute the size + m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; + + // compute the size + compute_size(texsource->width, texsource->height); + 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; } - m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN; } // for the target surface, we allocate a render target texture @@ -2006,15 +2087,13 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t // target surfaces typically cannot be YCbCr, so we always pick RGB in that case 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 (m_renderer->get_shaders()->enabled() && !m_renderer->get_shaders()->register_prescaled_texture(this)) - { - goto error; - } break; } + (*d3dintf->texture.release)(m_d3dtex); m_d3dtex = nullptr; } @@ -2024,7 +2103,6 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t // copy the data to the texture set_data(texsource, flags); - //texsource->osdhandle = (void*)this; // add us to the texture list if(m_texture_manager->get_texlist() != nullptr) m_texture_manager->get_texlist()->m_prev = this; @@ -2044,63 +2122,6 @@ error: //============================================================ -// texture_info::compute_size_subroutine -//============================================================ - -void texture_info::compute_size_subroutine(int texwidth, int texheight, int* p_width, int* p_height) -{ - int finalheight = texheight; - int finalwidth = texwidth; - - // round width/height up to nearest power of 2 if we need to - if (!(m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)) - { - // first the width - if (finalwidth & (finalwidth - 1)) - { - finalwidth |= finalwidth >> 1; - finalwidth |= finalwidth >> 2; - finalwidth |= finalwidth >> 4; - finalwidth |= finalwidth >> 8; - finalwidth++; - } - - // then the height - if (finalheight & (finalheight - 1)) - { - finalheight |= finalheight >> 1; - finalheight |= finalheight >> 2; - finalheight |= finalheight >> 4; - finalheight |= finalheight >> 8; - finalheight++; - } - } - - // round up to square if we need to - if (m_texture_manager->get_texture_caps() & D3DPTEXTURECAPS_SQUAREONLY) - { - if (finalwidth < finalheight) - finalwidth = finalheight; - else - finalheight = finalwidth; - } - - // adjust the aspect ratio if we need to - while (finalwidth < finalheight && finalheight / finalwidth > m_texture_manager->get_max_texture_aspect()) - { - finalwidth *= 2; - } - while (finalheight < finalwidth && finalwidth / finalheight > m_texture_manager->get_max_texture_aspect()) - { - finalheight *= 2; - } - - *p_width = finalwidth; - *p_height = finalheight; -} - - -//============================================================ // texture_info::compute_size //============================================================ @@ -2112,30 +2133,42 @@ void texture_info::compute_size(int texwidth, int texheight) m_xborderpix = 0; m_yborderpix = 0; - // if we're not wrapping, add a 1-2 pixel border on all sides - if (ENABLE_BORDER_PIX && !(m_flags & PRIMFLAG_TEXWRAP_MASK)) + bool shaders_enabled = m_renderer->get_shaders()->enabled(); + bool wrap_texture = (m_flags & PRIMFLAG_TEXWRAP_MASK) == PRIMFLAG_TEXWRAP_MASK; + bool border_texture = ENABLE_BORDER_PIX && !wrap_texture; + bool surface_texture = m_type == TEXTURE_TYPE_SURFACE; + + // skip border when shaders are enabled and we're not creating a surface (UI) texture + if (!shaders_enabled || surface_texture) { - // note we need 2 pixels in X for YUY textures - m_xborderpix = (PRIMFLAG_GET_TEXFORMAT(m_flags) == TEXFORMAT_YUY16) ? 2 : 1; - m_yborderpix = 1; + // if we're not wrapping, add a 1-2 pixel border on all sides + if (border_texture) + { + // note we need 2 pixels in X for YUY textures + m_xborderpix = (PRIMFLAG_GET_TEXFORMAT(m_flags) == TEXFORMAT_YUY16) ? 2 : 1; + m_yborderpix = 1; + } } - // compute final texture size finalwidth += 2 * m_xborderpix; finalheight += 2 * m_yborderpix; - compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight); - - // if we added pixels for the border, and that just barely pushed us over, take it back - if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height()) + // take texture size as given when shaders are enabled and we're not creating a surface (UI) texture, still update wrapped textures + if (!shaders_enabled || surface_texture || wrap_texture) { - finalheight = texheight; - finalwidth = texwidth; + m_texture_manager->compute_texture_size(finalwidth, finalheight, &finalwidth, &finalheight); - m_xborderpix = 0; - m_yborderpix = 0; + // if we added pixels for the border, and that just barely pushed us over, take it back + if (finalwidth > m_texture_manager->get_max_texture_width() || finalheight > m_texture_manager->get_max_texture_height()) + { + finalheight = texheight; + finalwidth = texwidth; + + m_xborderpix = 0; + m_yborderpix = 0; - compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight); + m_texture_manager->compute_texture_size(finalwidth, finalheight, &finalwidth, &finalheight); + } } // if we're above the max width/height, do what? @@ -2714,18 +2747,20 @@ cache_target::~cache_target() // cache_target::init - initializes a target cache //============================================================ -bool cache_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y) +bool cache_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int target_width, int target_height) { - HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &last_texture); + // d3d->get_texture_manager()->compute_texture_size(target_width, target_height, &target_width, &target_height); + + this->target_width = target_width; + this->target_height = target_height; + + HRESULT result = (*d3dintf->device.create_texture)(d3d->get_device(), target_width, target_height, 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); - target_width = width * prescale_x; - target_height = height * prescale_y; - return true; } @@ -2743,34 +2778,34 @@ d3d_render_target::~d3d_render_target() (*d3dintf->texture.release)(bloom_texture[index]); bloom_texture[index] = nullptr; } - if (bloom_target[index] != nullptr) + if (bloom_surface[index] != nullptr) { - (*d3dintf->surface.release)(bloom_target[index]); - bloom_target[index] = nullptr; + (*d3dintf->surface.release)(bloom_surface[index]); + bloom_surface[index] = nullptr; } } for (int index = 0; index < 2; index++) { - if (native_texture[index] != nullptr) + if (source_texture[index] != nullptr) { - (*d3dintf->texture.release)(native_texture[index]); - native_texture[index] = nullptr; + (*d3dintf->texture.release)(source_texture[index]); + source_texture[index] = nullptr; } - if (native_target[index] != nullptr) + if (source_surface[index] != nullptr) { - (*d3dintf->surface.release)(native_target[index]); - native_target[index] = nullptr; + (*d3dintf->surface.release)(source_surface[index]); + source_surface[index] = nullptr; } - if (prescale_texture[index] != nullptr) + if (target_texture[index] != nullptr) { - (*d3dintf->texture.release)(prescale_texture[index]); - prescale_texture[index] = nullptr; + (*d3dintf->texture.release)(target_texture[index]); + target_texture[index] = nullptr; } - if (prescale_target[index] != nullptr) + if (target_surface[index] != nullptr) { - (*d3dintf->surface.release)(prescale_target[index]); - prescale_target[index] = nullptr; + (*d3dintf->surface.release)(target_surface[index]); + target_surface[index] = nullptr; } } } @@ -2780,51 +2815,63 @@ d3d_render_target::~d3d_render_target() // d3d_render_target::init - initializes a render target //============================================================ -bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int prescale_x, int prescale_y) +bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int target_width, int target_height) { HRESULT result; + // d3d->get_texture_manager()->compute_texture_size(target_width, target_height, &target_width, &target_height); + + this->width = width; + this->height = height; + + this->target_width = target_width; + this->target_height = target_height; + for (int index = 0; index < 2; index++) { - result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &native_texture[index]); + result = (*d3dintf->device.create_texture)(d3d->get_device(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &source_texture[index]); if (result != D3D_OK) { return false; } - (*d3dintf->texture.get_surface_level)(native_texture[index], 0, &native_target[index]); + (*d3dintf->texture.get_surface_level)(source_texture[index], 0, &source_surface[index]); - result = (*d3dintf->device.create_texture)(d3d->get_device(), width * prescale_x, height * prescale_y, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &prescale_texture[index]); + result = (*d3dintf->device.create_texture)(d3d->get_device(), target_width, target_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &target_texture[index]); if (result != D3D_OK) { return false; } - (*d3dintf->texture.get_surface_level)(prescale_texture[index], 0, &prescale_target[index]); + (*d3dintf->texture.get_surface_level)(target_texture[index], 0, &target_surface[index]); } - int bloom_index = 0; - float bloom_size = (d3d->get_width() < d3d->get_height()) ? d3d->get_width() : d3d->get_height(); - float bloom_width = d3d->get_width(); - float bloom_height = d3d->get_height(); - for (; bloom_size >= 2.0f && bloom_index < 11; bloom_size *= 0.5f) + bool vector_screen = + d3d->window().machine().first_screen()->screen_type() == SCREEN_TYPE_VECTOR; + + // larger blur width for vector screens than raster screens + float scale_factor = vector_screen ? 0.5f : 0.75f; + + float bloom_width = (float)width; + float bloom_height = (float)height; + float bloom_size = bloom_width < bloom_height ? bloom_width : bloom_height; + for (int bloom_index = 0; bloom_index < 11 && bloom_size >= 2.0f; bloom_size *= scale_factor) { - bloom_width *= 0.5f; - bloom_height *= 0.5f; + this->bloom_dims[bloom_index][0] = (int)bloom_width; + this->bloom_dims[bloom_index][1] = (int)bloom_height; result = (*d3dintf->device.create_texture)(d3d->get_device(), (int)bloom_width, (int)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]); + (*d3dintf->texture.get_surface_level)(bloom_texture[bloom_index], 0, &bloom_surface[bloom_index]); - bloom_index++; - } + bloom_width *= scale_factor; + bloom_height *= scale_factor; - this->width = width; - this->height = height; + bloom_index++; - target_width = width * prescale_x; - target_height = height * prescale_y; + this->bloom_count = bloom_index; + } return true; } |