summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/emu/render.cpp52
-rw-r--r--src/emu/render.h2
-rw-r--r--src/osd/modules/render/d3d/d3dcomm.h7
-rw-r--r--src/osd/modules/render/d3d/d3dhlsl.cpp202
-rw-r--r--src/osd/modules/render/d3d/d3dhlsl.h15
-rw-r--r--src/osd/modules/render/drawd3d.cpp230
-rw-r--r--src/osd/modules/render/drawd3d.h13
7 files changed, 289 insertions, 232 deletions
diff --git a/src/emu/render.cpp b/src/emu/render.cpp
index 3de791eab52..0a7fc00c151 100644
--- a/src/emu/render.cpp
+++ b/src/emu/render.cpp
@@ -102,7 +102,7 @@ struct object_transform
// GLOBAL VARIABLES
//**************************************************************************
-// precomputed UV coordinates for various orientations
+// precomputed UV coordinates for raster primitive with various orientations
static const render_quad_texuv oriented_texcoords[8] =
{
{ { 0,0 }, { 1,0 }, { 0,1 }, { 1,1 } }, // 0
@@ -115,6 +115,12 @@ static const render_quad_texuv oriented_texcoords[8] =
{ { 1,1 }, { 1,0 }, { 0,1 }, { 0,0 } } // ORIENTATION_SWAP_XY | ORIENTATION_FLIP_X | ORIENTATION_FLIP_Y
};
+// precomputed UV coordinates for vector primitive
+static const render_quad_texuv oriented_vector_texcoords[1] =
+{
+ { { 0,0 }, { 1,0 }, { 0,1 }, { 1,1 } }
+};
+
// layer orders
static const int layer_order_standard[] = { ITEM_LAYER_SCREEN, ITEM_LAYER_OVERLAY, ITEM_LAYER_BACKDROP, ITEM_LAYER_BEZEL, ITEM_LAYER_CPANEL, ITEM_LAYER_MARQUEE };
static const int layer_order_alternate[] = { ITEM_LAYER_BACKDROP, ITEM_LAYER_SCREEN, ITEM_LAYER_OVERLAY, ITEM_LAYER_BEZEL, ITEM_LAYER_CPANEL, ITEM_LAYER_MARQUEE };
@@ -1756,18 +1762,39 @@ void render_target::add_container_primitives(render_primitive_list &list, const
// set the palette
prim->texture.palette = curitem->texture()->get_adjusted_palette(container);
- // determine UV coordinates and apply clipping
+ // determine UV coordinates
prim->texcoords = oriented_texcoords[finalorient];
+
+ // apply clipping
clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords);
// apply the final orientation from the quad flags and then build up the final flags
- prim->flags = (curitem->flags() & ~(PRIMFLAG_TEXORIENT_MASK | PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) |
- PRIMFLAG_TEXORIENT(finalorient) |
- PRIMFLAG_TEXFORMAT(curitem->texture()->format());
- if (blendmode != -1)
- prim->flags |= PRIMFLAG_BLENDMODE(blendmode);
- else
- prim->flags |= PRIMFLAG_BLENDMODE(PRIMFLAG_GET_BLENDMODE(curitem->flags()));
+ prim->flags = (curitem->flags() & ~(PRIMFLAG_TEXORIENT_MASK | PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK))
+ | PRIMFLAG_TEXORIENT(finalorient)
+ | PRIMFLAG_TEXFORMAT(curitem->texture()->format());
+ prim->flags |= blendmode != -1
+ ? PRIMFLAG_BLENDMODE(blendmode)
+ : PRIMFLAG_BLENDMODE(PRIMFLAG_GET_BLENDMODE(curitem->flags()));
+ }
+ else if (curitem->flags() & PRIMFLAG_VECTORBUF_MASK)
+ {
+ // adjust the color for brightness/contrast/gamma
+ prim->color.r = container.apply_brightness_contrast_gamma_fp(prim->color.r);
+ prim->color.g = container.apply_brightness_contrast_gamma_fp(prim->color.g);
+ prim->color.b = container.apply_brightness_contrast_gamma_fp(prim->color.b);
+
+ // determine UV coordinates
+ prim->texcoords = oriented_vector_texcoords[0];
+
+ // apply clipping
+ clipped = render_clip_quad(&prim->bounds, &cliprect, &prim->texcoords);
+
+ // no texture
+ prim->texture.base = nullptr;
+
+ // set the basic flags
+ prim->flags = (curitem->flags() & ~PRIMFLAG_BLENDMODE_MASK)
+ | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA);
}
else
{
@@ -1776,9 +1803,12 @@ void render_target::add_container_primitives(render_primitive_list &list, const
prim->color.g = container.apply_brightness_contrast_gamma_fp(prim->color.g);
prim->color.b = container.apply_brightness_contrast_gamma_fp(prim->color.b);
- // no texture -- set the basic flags
+ // no texture
prim->texture.base = nullptr;
- prim->flags = (curitem->flags() &~ PRIMFLAG_BLENDMODE_MASK) | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA);
+
+ // set the basic flags
+ prim->flags = (curitem->flags() & ~PRIMFLAG_BLENDMODE_MASK)
+ | PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA);
// apply clipping
clipped = render_clip_quad(&prim->bounds, &cliprect, nullptr);
diff --git a/src/emu/render.h b/src/emu/render.h
index 6d55c75ada9..09fe68282ef 100644
--- a/src/emu/render.h
+++ b/src/emu/render.h
@@ -329,6 +329,8 @@ public:
// getters
render_primitive *next() const { return m_next; }
bool packable(const INT32 pack_size) const { return (flags & PRIMFLAG_PACKABLE) && texture.base != nullptr && texture.width <= pack_size && texture.height <= pack_size; }
+ float get_quad_width() const { return bounds.x1 - bounds.x0; }
+ float get_quad_height() const { return bounds.y1 - bounds.y0; }
// reset to prepare for re-use
void reset();
diff --git a/src/osd/modules/render/d3d/d3dcomm.h b/src/osd/modules/render/d3d/d3dcomm.h
index 6240deb3011..3419619df57 100644
--- a/src/osd/modules/render/d3d/d3dcomm.h
+++ b/src/osd/modules/render/d3d/d3dcomm.h
@@ -77,8 +77,6 @@ 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; }
@@ -150,6 +148,7 @@ 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
@@ -245,7 +244,7 @@ public:
cache_target() { }
~cache_target();
- bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height);
+ bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height);
surface *last_target;
texture *last_texture;
@@ -270,7 +269,7 @@ public:
d3d_render_target() { }
~d3d_render_target();
- bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, int height, int target_width, int target_height);
+ bool init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height);
int next_index(int index) { return ++index > 1 ? 0 : index; }
// real target dimension
diff --git a/src/osd/modules/render/d3d/d3dhlsl.cpp b/src/osd/modules/render/d3d/d3dhlsl.cpp
index c55c679be54..cea0825092b 100644
--- a/src/osd/modules/render/d3d/d3dhlsl.cpp
+++ b/src/osd/modules/render/d3d/d3dhlsl.cpp
@@ -69,8 +69,8 @@ shaders::shaders() :
{
master_enable = false;
vector_enable = true;
- shadow_texture = NULL;
- options = NULL;
+ shadow_texture = nullptr;
+ options = nullptr;
paused = true;
lastidx = -1;
targethead = nullptr;
@@ -553,9 +553,9 @@ void shaders::remove_render_target(texture_info *texture)
remove_render_target(find_render_target(texture));
}
-void shaders::remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
+void shaders::remove_render_target(int source_width, int source_height, UINT32 screen_index, UINT32 page_index)
{
- d3d_render_target *target = find_render_target(width, height, screen_index, page_index);
+ d3d_render_target *target = find_render_target(source_width, source_height, screen_index, page_index);
if (target != nullptr)
{
remove_render_target(target);
@@ -1145,9 +1145,9 @@ void shaders::init_effect_info(poly_info *poly)
// shaders::find_render_target
//============================================================
-d3d_render_target* shaders::find_render_target(texture_info *info)
+d3d_render_target* shaders::find_render_target(texture_info *texture)
{
- UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata;
+ UINT32 screen_index_data = (UINT32)texture->get_texinfo().osddata;
UINT32 screen_index = screen_index_data >> 1;
UINT32 page_index = screen_index_data & 1;
@@ -1155,8 +1155,8 @@ d3d_render_target* shaders::find_render_target(texture_info *info)
while (curr != nullptr && (
curr->screen_index != screen_index ||
curr->page_index != page_index ||
- curr->width != info->get_texinfo().width ||
- curr->height != info->get_texinfo().height))
+ curr->width != texture->get_width() ||
+ curr->height != texture->get_height()))
{
curr = curr->next;
}
@@ -1169,12 +1169,12 @@ d3d_render_target* shaders::find_render_target(texture_info *info)
// shaders::find_render_target
//============================================================
-d3d_render_target* shaders::find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index)
+d3d_render_target* shaders::find_render_target(int source_width, int source_height, UINT32 screen_index, UINT32 page_index)
{
d3d_render_target *curr = targethead;
while (curr != nullptr && (
- curr->width != width ||
- curr->height != height ||
+ curr->width != source_width ||
+ curr->height != source_height ||
curr->screen_index != screen_index ||
curr->page_index != page_index))
{
@@ -1294,8 +1294,7 @@ int shaders::prescale_pass(d3d_render_target *rt, int source_index, poly_info *p
curr_effect->set_texture("Diffuse", rt->source_texture[next_index]);
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1318,8 +1317,7 @@ int shaders::deconverge_pass(d3d_render_target *rt, int source_index, poly_info
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1339,8 +1337,7 @@ int shaders::defocus_pass(d3d_render_target *rt, int source_index, poly_info *po
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1362,8 +1359,7 @@ int shaders::phosphor_pass(d3d_render_target *rt, cache_target *ct, int source_i
curr_effect->set_bool("Passthrough", false);
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
// Pass along our phosphor'd screen
curr_effect->update_uniforms();
@@ -1372,8 +1368,7 @@ int shaders::phosphor_pass(d3d_render_target *rt, cache_target *ct, int source_i
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, poly->get_type(), vertnum, poly->get_count());
+ blit(ct->last_target, true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1421,8 +1416,7 @@ int shaders::post_pass(d3d_render_target *rt, int source_index, poly_info *poly,
curr_effect->set_bool("PrepareBloom", prepare_bloom);
next_index = rt->next_index(next_index);
- // 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());
+ blit(prepare_bloom ? rt->source_surface[next_index] : rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1449,8 +1443,7 @@ int shaders::downsample_pass(d3d_render_target *rt, int source_index, poly_info
? rt->source_texture[next_index]
: rt->bloom_texture[bloom_index - 1]);
- // 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());
+ blit(rt->bloom_surface[bloom_index], true, D3DPT_TRIANGLELIST, 0, 2);
}
return next_index;
@@ -1523,8 +1516,7 @@ int shaders::bloom_pass(d3d_render_target *rt, int source_index, poly_info *poly
}
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1543,36 +1535,12 @@ int shaders::distortion_pass(d3d_render_target *rt, int source_index, poly_info
return next_index;
}
- int screen_count = d3d->window().target()->current_view()->screens().count();
-
- // todo: only one screen is supported
- if (screen_count > 1)
- {
- return next_index;
- }
-
- render_bounds bounds = d3d->window().target()->current_view()->bounds();
- render_bounds screen_bounds = d3d->window().target()->current_view()->screen_bounds();
- 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;
-
- // 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->target_texture[next_index]);
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1589,7 +1557,6 @@ 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->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,8 +1573,7 @@ int shaders::vector_buffer_pass(d3d_render_target *rt, int source_index, poly_in
curr_effect->set_texture("Diffuse", rt->target_texture[next_index]);
next_index = rt->next_index(next_index);
- // 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());
+ blit(rt->target_surface[next_index], true, D3DPT_TRIANGLELIST, 0, 2);
return next_index;
}
@@ -1677,7 +1643,7 @@ void shaders::render_quad(poly_info *poly, int vertnum)
return;
}
- cache_target *ct = find_cache_target(rt->screen_index, curr_texture->get_texinfo().width, curr_texture->get_texinfo().height);
+ cache_target *ct = find_cache_target(rt->screen_index, curr_texture->get_width(), curr_texture->get_height());
int next_index = 0;
@@ -1770,7 +1736,9 @@ void shaders::render_quad(poly_info *poly, int vertnum)
next_index = distortion_pass(rt, next_index, poly, vertnum);
// render on screen
+ d3d->set_wrap(D3DTADDRESS_MIRROR);
next_index = screen_pass(rt, next_index, poly, vertnum);
+ d3d->set_wrap(PRIMFLAG_GET_TEXWRAP(curr_texture->get_flags()) ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
HRESULT result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
if (result != D3D_OK)
@@ -1809,27 +1777,16 @@ void shaders::end_draw()
//============================================================
// shaders::add_cache_target - register a cache target
//============================================================
-bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* info, int width, int height, int screen_index)
+bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* texture, int source_width, int source_height, int target_width, int target_height, int screen_index)
{
cache_target* target = (cache_target*)global_alloc_clear<cache_target>();
- if (!target->init(d3d, d3dintf, width, height))
+ if (!target->init(d3d, d3dintf, source_width, source_height, target_width, target_height))
{
global_free(target);
return false;
}
- if (info != nullptr)
- {
- target->width = info->get_texinfo().width;
- target->height = info->get_texinfo().height;
- }
- else
- {
- target->width = d3d->get_width();
- target->height = d3d->get_height();
- }
-
target->next = cachehead;
target->prev = nullptr;
@@ -1844,22 +1801,65 @@ bool shaders::add_cache_target(renderer_d3d9* d3d, texture_info* info, int width
return true;
}
-d3d_render_target* shaders::get_vector_target()
+//============================================================
+// shaders::get_texture_target(render_primitive::prim, texture_info::texture)
+//============================================================
+d3d_render_target* shaders::get_texture_target(render_primitive *prim, texture_info *texture)
+{
+ if (!vector_enable)
+ {
+ return nullptr;
+ }
+
+ bool swap_xy = d3d->swap_xy();
+ int target_width = swap_xy
+ ? static_cast<int>(prim->get_quad_height() + 0.5f)
+ : static_cast<int>(prim->get_quad_width() + 0.5f);
+ int target_height = swap_xy
+ ? static_cast<int>(prim->get_quad_width() + 0.5f)
+ : static_cast<int>(prim->get_quad_height() + 0.5f);
+
+ // find render target and check if the size of the target quad has changed
+ d3d_render_target *target = find_render_target(texture);
+ if (target != nullptr && target->target_width == target_width && target->target_height == target_height)
+ {
+ return target;
+ }
+
+ osd_printf_verbose("get_texture_target() - invalid size\n");
+
+ return nullptr;
+}
+
+d3d_render_target* shaders::get_vector_target(render_primitive *prim)
{
if (!vector_enable)
{
return nullptr;
}
- return find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
+ int target_width = static_cast<int>(prim->get_quad_width() + 0.5f);
+ int target_height = static_cast<int>(prim->get_quad_height() + 0.5f);
+
+ // find render target and check of the size of the target quad has changed
+ d3d_render_target *target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
+ if (target != nullptr && target->target_width == target_width && target->target_height == target_height)
+ {
+ return target;
+ }
+
+ osd_printf_verbose("get_vector_target() - invalid size\n");
+
+ return nullptr;
}
void shaders::create_vector_target(render_primitive *prim)
{
- int width = d3d->get_width();
- int height = d3d->get_height();
+ int target_width = static_cast<int>(prim->get_quad_width() + 0.5f);
+ int target_height = static_cast<int>(prim->get_quad_height() + 0.5f);
- if (!add_render_target(d3d, nullptr, width, height, width, height))
+ osd_printf_verbose("create_vector_target() - %f, %f; %d, %d\n", prim->get_quad_width(), prim->get_quad_height(), (int)(prim->get_quad_width() + 0.5f), (int)(prim->get_quad_height() + 0.5f));
+ if (!add_render_target(d3d, nullptr, d3d->get_width(), d3d->get_height(), target_width, target_height))
{
vector_enable = false;
}
@@ -1870,25 +1870,25 @@ 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 target_width, int target_height)
+bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* texture, int source_width, int source_height, int target_width, int target_height)
{
UINT32 screen_index = 0;
UINT32 page_index = 0;
- if (info != nullptr)
+ if (texture != nullptr)
{
- d3d_render_target *existing_target = find_render_target(info);
+ d3d_render_target *existing_target = find_render_target(texture);
if (existing_target != nullptr)
{
remove_render_target(existing_target);
}
- UINT32 screen_index_data = (UINT32)info->get_texinfo().osddata;
+ UINT32 screen_index_data = (UINT32)texture->get_texinfo().osddata;
screen_index = screen_index_data >> 1;
page_index = screen_index_data & 1;
}
else
{
- d3d_render_target *existing_target = find_render_target(d3d->get_width(), d3d->get_height(), 0, 0);
+ d3d_render_target *existing_target = find_render_target(source_width, source_height, 0, 0);
if (existing_target != nullptr)
{
remove_render_target(existing_target);
@@ -1897,22 +1897,14 @@ 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, target_width, target_height))
+ if (!target->init(d3d, d3dintf, source_width, source_height, target_width, target_height))
{
global_free(target);
return false;
}
- if (info != nullptr)
- {
- target->width = info->get_texinfo().width;
- target->height = info->get_texinfo().height;
- }
- else
- {
- target->width = d3d->get_width();
- target->height = d3d->get_height();
- }
+ target->screen_index = screen_index;
+ target->page_index = page_index;
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);
@@ -1921,13 +1913,10 @@ bool shaders::add_render_target(renderer_d3d9* d3d, texture_info* info, int widt
result = (*d3dintf->device.set_render_target)(d3d->get_device(), 0, backbuffer);
if (result != D3D_OK) osd_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
- target->screen_index = screen_index;
- target->page_index = page_index;
-
- cache_target* cache = find_cache_target(target->screen_index, target->width, target->height);
+ cache_target* cache = find_cache_target(target->screen_index, source_width, source_height);
if (cache == nullptr)
{
- if (!add_cache_target(d3d, info, target_width, target_height, target->screen_index))
+ if (!add_cache_target(d3d, texture, source_width, source_height, target_width, target_height, target->screen_index))
{
global_free(target);
return false;
@@ -1970,7 +1959,16 @@ bool shaders::register_texture(render_primitive *prim, texture_info *texture)
enumerate_screens();
- if (!add_render_target(d3d, texture, texture->get_width(), texture->get_height(), d3d->get_width(), d3d->get_height()))
+ bool swap_xy = d3d->swap_xy();
+ int target_width = swap_xy
+ ? static_cast<int>(prim->get_quad_height() + 0.5f)
+ : static_cast<int>(prim->get_quad_width() + 0.5f);
+ int target_height = swap_xy
+ ? static_cast<int>(prim->get_quad_width() + 0.5f)
+ : static_cast<int>(prim->get_quad_height() + 0.5f);
+
+ osd_printf_verbose("register_texture() - %f, %f; %d, %d\n", prim->get_quad_width(), prim->get_quad_height(), (int)(prim->get_quad_width() + 0.5f), (int)(prim->get_quad_height() + 0.5f));
+ if (!add_render_target(d3d, texture, texture->get_width(), texture->get_height(), target_width, target_height))
{
return false;
}
@@ -2644,8 +2642,9 @@ void uniform::update()
if (shadersys->curr_poly != nullptr)
{
float quaddims[2] = {
- shadersys->curr_poly->get_prim_width(),
- shadersys->curr_poly->get_prim_height() };
+ // round
+ static_cast<float>(static_cast<int>(shadersys->curr_poly->get_prim_width() + 0.5f)),
+ static_cast<float>(static_cast<int>(shadersys->curr_poly->get_prim_height() + 0.5f)) };
m_shader->set_vector("QuadDims", 2, quaddims);
}
break;
@@ -2653,12 +2652,7 @@ void uniform::update()
case CU_SWAP_XY:
{
- bool orientation_swap_xy =
- (d3d->window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
- bool rotation_swap_xy =
- (d3d->window().target()->orientation() & ROT90) == ROT90 ||
- (d3d->window().target()->orientation() & ROT270) == ROT270;
- m_shader->set_bool("SwapXY", orientation_swap_xy ^ rotation_swap_xy);
+ m_shader->set_bool("SwapXY", d3d->swap_xy());
break;
}
case CU_ORIENTATION_SWAP:
diff --git a/src/osd/modules/render/d3d/d3dhlsl.h b/src/osd/modules/render/d3d/d3dhlsl.h
index 0c3bc095d4c..2ad564c31b1 100644
--- a/src/osd/modules/render/d3d/d3dhlsl.h
+++ b/src/osd/modules/render/d3d/d3dhlsl.h
@@ -307,7 +307,7 @@ public:
void toggle();
bool vector_enabled() { return master_enable && vector_enable; }
- d3d_render_target* get_vector_target();
+ d3d_render_target* get_vector_target(render_primitive *prim);
void create_vector_target(render_primitive *prim);
void begin_frame();
@@ -320,8 +320,9 @@ public:
void render_quad(poly_info *poly, int vertnum);
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);
+ d3d_render_target* get_texture_target(render_primitive *prim, texture_info *texture);
+ bool add_render_target(renderer_d3d9* d3d, texture_info* texture, int source_width, int source_height, int target_width, int target_height);
+ bool add_cache_target(renderer_d3d9* d3d, texture_info* texture, int source_width, int source_height, int target_width, int target_height, int screen_index);
void window_save();
void window_record();
@@ -332,10 +333,10 @@ public:
void record_texture();
void init_fsfx_quad(void *vertbuf);
- void set_texture(texture_info *texture);
- d3d_render_target * find_render_target(texture_info *info);
+ void set_texture(texture_info *info);
+ d3d_render_target * find_render_target(texture_info *texture);
void remove_render_target(texture_info *texture);
- void remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
+ void remove_render_target(int source_width, int source_height, UINT32 screen_index, UINT32 page_index);
void remove_render_target(d3d_render_target *rt);
int create_resources(bool reset);
@@ -352,7 +353,7 @@ private:
void end_avi_recording();
void begin_avi_recording(const char *name);
- d3d_render_target* find_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
+ d3d_render_target* find_render_target(int source_width, int source_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);
diff --git a/src/osd/modules/render/drawd3d.cpp b/src/osd/modules/render/drawd3d.cpp
index 4037c9c0bbe..e927c36458f 100644
--- a/src/osd/modules/render/drawd3d.cpp
+++ b/src/osd/modules/render/drawd3d.cpp
@@ -420,63 +420,6 @@ 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
@@ -696,16 +639,12 @@ void d3d_texture_manager::update_textures()
{
if (m_renderer->get_shaders()->enabled())
{
- // create a new texture without prescale, shaders will handle the prescale
+ // if there isn't one, create a new texture without 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
+ // if there isn't one, create a new texture
texture = global_alloc(texture_info(this, &prim->texture, m_renderer->window().prescale(), prim->flags));
}
}
@@ -718,10 +657,21 @@ void d3d_texture_manager::update_textures()
texture->get_texinfo().seqid = prim->texture.seqid;
}
}
+
+ if (m_renderer->get_shaders()->enabled())
+ {
+ if (!m_renderer->get_shaders()->get_texture_target(prim, texture))
+ {
+ if (!m_renderer->get_shaders()->register_texture(prim, texture))
+ {
+ d3dintf->post_fx_available = false;
+ }
+ }
+ }
}
else if(m_renderer->get_shaders()->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
{
- if (!m_renderer->get_shaders()->get_vector_target())
+ if (!m_renderer->get_shaders()->get_vector_target(prim))
{
m_renderer->get_shaders()->create_vector_target(prim);
}
@@ -754,12 +704,15 @@ void renderer_d3d9::begin_frame()
m_shaders->init_fsfx_quad(m_hlsl_buf);
}
+ // loop over line primitives
m_line_count = 0;
-
- // loop over primitives
for (render_primitive *prim = window().m_primlist->first(); prim != nullptr; prim = prim->next())
+ {
if (prim->type == render_primitive::LINE && PRIMFLAG_GET_VECTOR(prim->flags))
+ {
m_line_count++;
+ }
+ }
}
void renderer_d3d9::process_primitives()
@@ -1444,6 +1397,9 @@ void renderer_d3d9::batch_vectors()
m_vectorbatch = mesh_alloc(m_line_count * vector_size);
m_batchindex = 0;
+ float width = 0.0f;
+ float height = 0.0f;
+
static int start_index = 0;
int line_index = 0;
float period = options.screen_vector_time_period();
@@ -1468,6 +1424,14 @@ void renderer_d3d9::batch_vectors()
}
break;
+ case render_primitive::QUAD:
+ if (PRIMFLAG_GET_VECTORBUF(prim->flags))
+ {
+ width = prim->bounds.x1 - prim->bounds.x0;
+ height = prim->bounds.y1 - prim->bounds.y0;
+ }
+ break;
+
default:
// Skip
break;
@@ -1476,7 +1440,7 @@ void renderer_d3d9::batch_vectors()
// 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, 0.0f, 0.0f);
+ m_texture_manager->get_vector_texture(), D3DTOP_MODULATE, 0.0f, 1.0f, width, height);
m_numpolys++;
start_index += (int)((float)line_index * period);
@@ -1959,15 +1923,36 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t
m_d3dsurface = nullptr;
m_d3dfinaltex = nullptr;
- // non-screen textures are easy
+ // determine texture type, required to compute texture size
if (!PRIMFLAG_GET_SCREENTEX(flags))
{
- // required to compute the size
- m_type = TEXTURE_TYPE_PLAIN;
+ m_type = TEXTURE_TYPE_PLAIN;
+ }
+ else
+ {
+ if ((m_xprescale == 1 && m_yprescale == 1) || m_renderer->get_shaders()->enabled())
+ {
+ m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
+ }
+ else
+ {
+ if (m_texture_manager->is_stretch_supported() && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16)
+ {
+ m_type = TEXTURE_TYPE_SURFACE;
+ }
+ else
+ {
+ m_type = m_texture_manager->is_dynamic_supported() ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
+ }
+ }
+ }
- // compute the size
- compute_size(texsource->width, texsource->height);
+ // compute the size
+ 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)(m_renderer->get_device(), m_rawdims.c.x, m_rawdims.c.y, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_d3dtex);
if (result != D3D_OK)
@@ -2030,15 +2015,9 @@ 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 and shaders handle prescale itself
+ // screen textures with no prescaling are pretty easy
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)
{
@@ -2053,12 +2032,6 @@ 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)
{
@@ -2068,12 +2041,6 @@ texture_info::texture_info(d3d_texture_manager *manager, const render_texinfo* t
// 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)
{
@@ -2122,6 +2089,63 @@ 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
//============================================================
@@ -2156,7 +2180,7 @@ void texture_info::compute_size(int texwidth, int texheight)
// 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)
{
- m_texture_manager->compute_texture_size(finalwidth, finalheight, &finalwidth, &finalheight);
+ 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())
@@ -2167,7 +2191,7 @@ void texture_info::compute_size(int texwidth, int texheight)
m_xborderpix = 0;
m_yborderpix = 0;
- m_texture_manager->compute_texture_size(finalwidth, finalheight, &finalwidth, &finalheight);
+ compute_size_subroutine(finalwidth, finalheight, &finalwidth, &finalheight);
}
}
@@ -2747,10 +2771,10 @@ cache_target::~cache_target()
// cache_target::init - initializes a target cache
//============================================================
-bool cache_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int target_width, int target_height)
+bool cache_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_height, int target_width, int target_height)
{
- // d3d->get_texture_manager()->compute_texture_size(target_width, target_height, &target_width, &target_height);
-
+ this->width = source_width;
+ this->height = source_height;
this->target_width = target_width;
this->target_height = target_height;
@@ -2815,21 +2839,19 @@ 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 target_width, int target_height)
+bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int source_width, int source_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->width = source_width;
+ this->height = source_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, &source_texture[index]);
+ result = (*d3dintf->device.create_texture)(d3d->get_device(), source_width, source_height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &source_texture[index]);
if (result != D3D_OK)
{
return false;
@@ -2850,8 +2872,8 @@ bool d3d_render_target::init(renderer_d3d9 *d3d, d3d_base *d3dintf, int width, i
// 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_width = (float)source_width;
+ float bloom_height = (float)source_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)
{
diff --git a/src/osd/modules/render/drawd3d.h b/src/osd/modules/render/drawd3d.h
index 474f9ef8487..de8506ebfbd 100644
--- a/src/osd/modules/render/drawd3d.h
+++ b/src/osd/modules/render/drawd3d.h
@@ -54,6 +54,17 @@ public:
virtual void record() override;
virtual void toggle_fsfx() override;
+ bool swap_xy()
+ {
+ // todo: move to osd_window
+ bool orientation_swap_xy =
+ (window().machine().system().flags & ORIENTATION_SWAP_XY) == ORIENTATION_SWAP_XY;
+ bool rotation_swap_xy =
+ (window().target()->orientation() & ROT90) == ROT90 ||
+ (window().target()->orientation() & ROT270) == ROT270;
+ return orientation_swap_xy ^ rotation_swap_xy;
+ };
+
int initialize();
int device_create(HWND device_HWND);
@@ -81,8 +92,6 @@ public:
vertex * mesh_alloc(int numverts);
- void update_textures();
-
void process_primitives();
void primitive_flush_pending();