Convert d3d_texture_info to a class, nw

This commit is contained in:
Ryan Holtz 2013-04-07 23:14:22 +00:00
parent 478bfd6391
commit a6ac25b796
6 changed files with 424 additions and 474 deletions

View File

@ -249,6 +249,7 @@ struct render_texinfo
const rgb_t * palette; // palette for PALETTE16 textures, LUTs for RGB15/RGB32
UINT32 seqid; // sequence ID
UINT64 osddata; // aux data to pass to osd
void * osdhandle; // handle to OSD-side representation;
};

View File

@ -42,40 +42,68 @@
#ifndef __WIN_D3DCOMM__
#define __WIN_D3DCOMM__
struct d3d_info;
//============================================================
// CONSTANTS
//============================================================
namespace d3d
{
//============================================================
// FORWARD DECLARATIONS
//============================================================
class texture_info;
//============================================================
// TYPE DEFINITIONS
//============================================================
/* d3d_texture_info holds information about a texture */
struct d3d_texture_info
/* d3d::texture_info holds information about a texture */
class texture_info
{
d3d_texture_info * next; // next texture in the list
d3d_texture_info * prev; // prev texture in the list
UINT32 hash; // hash value for the texture
UINT32 flags; // rendering flags
render_texinfo texinfo; // copy of the texture info
float ustart, ustop; // beginning/ending U coordinates
float vstart, vstop; // beginning/ending V coordinates
int rawwidth, rawheight; // raw width/height of the texture
int type; // what type of texture are we?
int xborderpix; // number of border pixels in X
int yborderpix; // number of border pixels in Y
int xprescale; // what is our X prescale factor?
int yprescale; // what is our Y prescale factor?
int cur_frame; // what is our current frame?
int prev_frame; // what was our last frame? (used to determine pause state)
d3d_texture * d3dtex; // Direct3D texture pointer
d3d_surface * d3dsurface; // Direct3D offscreen plain surface pointer
d3d_texture * d3dfinaltex; // Direct3D final (post-scaled) texture
int target_index; // Direct3D target index
public:
texture_info(d3d_info *d3d, render_texinfo *texsource, UINT32 flags);
~texture_info();
render_texinfo * get_texinfo() { return m_texinfo; }
int get_width() { return m_rawwidth; }
int get_height() { return m_rawheight; }
int get_xscale() { return m_xprescale; }
int get_yscale() { return m_yprescale; }
void set_data(const render_texinfo *texsource, UINT32 flags);
public:
void prescale();
void compute_size(int texwidth, int texheight);
d3d_info * m_d3d; // d3d info pointer
texture_info * m_next; // next texture in the list
texture_info * m_prev; // prev texture in the list
UINT32 m_hash; // hash value for the texture
UINT32 m_flags; // rendering flags
render_texinfo * m_texinfo; // copy of the texture info
float m_ustart, m_ustop; // beginning/ending U coordinates
float m_vstart, m_vstop; // beginning/ending V coordinates
int m_rawwidth, m_rawheight; // raw width/height of the texture
int m_type; // what type of texture are we?
int m_xborderpix, m_yborderpix; // number of border pixels on X/Y
int m_xprescale, m_yprescale; // X/Y prescale factor
int m_cur_frame; // what is our current frame?
int m_prev_frame; // what was our last frame? (used to determine pause state)
d3d_texture * m_d3dtex; // Direct3D texture pointer
d3d_surface * m_d3dsurface; // Direct3D offscreen plain surface pointer
d3d_texture * m_d3dfinaltex; // Direct3D final (post-scaled) texture
int m_target_index; // Direct3D target index
};
}; // d3d
/* d3d_poly_info holds information about a single polygon/d3d primitive */
struct d3d_poly_info
@ -85,7 +113,7 @@ struct d3d_poly_info
UINT32 numverts; // total number of vertices
UINT32 flags; // rendering flags
DWORD modmode; // texture modulation mode
d3d_texture_info * texture; // pointer to texture info
d3d::texture_info * texture; // pointer to texture info
float line_time; // used by vectors
float line_length; // used by vectors
};
@ -108,5 +136,4 @@ struct line_aa_step
float weight; // weight contribution
};
#endif

View File

@ -621,7 +621,7 @@ void hlsl_info::remove_cache_target(d3d_cache_target *cache)
// remove_render_target - remove an active target
//============================================================
void hlsl_info::remove_render_target(d3d_texture_info *texture)
void hlsl_info::remove_render_target(d3d::texture_info *texture)
{
remove_render_target(find_render_target(texture));
}
@ -677,7 +677,7 @@ void hlsl_info::remove_render_target(d3d_render_target *rt)
// hlsl_info::set_texture
//============================================================
void hlsl_info::set_texture(d3d_texture_info *texture)
void hlsl_info::set_texture(d3d::texture_info *texture)
{
if (!master_enable || !d3dintf->post_fx_available)
return;
@ -686,7 +686,7 @@ void hlsl_info::set_texture(d3d_texture_info *texture)
if(texture != NULL)
{
if(texture->prev_frame == texture->cur_frame)
if(texture->m_prev_frame == texture->m_cur_frame)
{
paused = true;
}
@ -695,15 +695,15 @@ void hlsl_info::set_texture(d3d_texture_info *texture)
paused = false;
}
texture->prev_frame = texture->cur_frame;
texture->m_prev_frame = texture->m_cur_frame;
}
(*d3dintf->effect.set_texture)(effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
(*d3dintf->effect.set_texture)(effect, "Diffuse", (texture == NULL) ? d3d->default_texture->m_d3dfinaltex : texture->m_d3dfinaltex);
if (options->yiq_enable)
(*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
(*d3dintf->effect.set_texture)(yiq_encode_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->m_d3dfinaltex : texture->m_d3dfinaltex);
else
(*d3dintf->effect.set_texture)(color_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
(*d3dintf->effect.set_texture)(pincushion_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
(*d3dintf->effect.set_texture)(color_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->m_d3dfinaltex : texture->m_d3dfinaltex);
(*d3dintf->effect.set_texture)(pincushion_effect, "Diffuse", (texture == NULL) ? d3d->default_texture->m_d3dfinaltex : texture->m_d3dfinaltex);
}
@ -1115,7 +1115,7 @@ int hlsl_info::create_resources(bool reset)
texture.seqid = 0;
// now create it
shadow_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
shadow_texture = new d3d::texture_info(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
}
const char *fx_dir = downcast<windows_options &>(window->machine().options()).screen_post_fx_dir();
@ -1526,14 +1526,14 @@ void hlsl_info::init_effect_info(d3d_poly_info *poly)
// just post-processing.
curr_effect = post_effect;
(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture->cur_frame == 0) ? 0.0f : options->scanline_offset);
(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture->m_cur_frame == 0) ? 0.0f : options->scanline_offset);
if(options->params_dirty)
{
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", d3d->height);
(*d3dintf->effect.set_vector)(curr_effect, "Floor", 3, options->floor);
@ -1542,20 +1542,20 @@ void hlsl_info::init_effect_info(d3d_poly_info *poly)
(*d3dintf->effect.set_float)(curr_effect, "PincushionAmount", options->pincushion);
(*d3dintf->effect.set_float)(curr_effect, "CurvatureAmount", options->curvature);
(*d3dintf->effect.set_float)(curr_effect, "UseShadow", shadow_texture == NULL ? 0.0f : 1.0f);
(*d3dintf->effect.set_texture)(curr_effect, "Shadow", shadow_texture == NULL ? NULL : shadow_texture->d3dfinaltex);
(*d3dintf->effect.set_texture)(curr_effect, "Shadow", shadow_texture == NULL ? NULL : shadow_texture->m_d3dfinaltex);
(*d3dintf->effect.set_float)(curr_effect, "ShadowBrightness", options->shadow_mask_alpha);
(*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeX", (float)options->shadow_mask_count_x);
(*d3dintf->effect.set_float)(curr_effect, "ShadowMaskSizeY", (float)options->shadow_mask_count_y);
(*d3dintf->effect.set_float)(curr_effect, "ShadowU", options->shadow_mask_u_size);
(*d3dintf->effect.set_float)(curr_effect, "ShadowV", options->shadow_mask_v_size);
(*d3dintf->effect.set_float)(curr_effect, "ShadowWidth", shadow_texture == NULL ? 1.0f : (float)shadow_texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "ShadowHeight", shadow_texture == NULL ? 1.0f : (float)shadow_texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "ShadowWidth", shadow_texture == NULL ? 1.0f : (float)shadow_texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "ShadowHeight", shadow_texture == NULL ? 1.0f : (float)shadow_texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "ScanlineAmount", options->scanline_alpha);
(*d3dintf->effect.set_float)(curr_effect, "ScanlineScale", options->scanline_scale);
(*d3dintf->effect.set_float)(curr_effect, "ScanlineHeight", options->scanline_height);
(*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightScale", options->scanline_bright_scale);
(*d3dintf->effect.set_float)(curr_effect, "ScanlineBrightOffset", options->scanline_bright_offset);
//(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture->cur_frame == 0) ? 0.0f : options->scanline_offset);
//(*d3dintf->effect.set_float)(curr_effect, "ScanlineOffset", (poly->texture->m_cur_frame == 0) ? 0.0f : options->scanline_offset);
(*d3dintf->effect.set_vector)(curr_effect, "Power", 3, options->power);
}
}
@ -1572,15 +1572,15 @@ void hlsl_info::init_effect_info(d3d_poly_info *poly)
// hlsl_info::find_render_target
//============================================================
d3d_render_target* hlsl_info::find_render_target(d3d_texture_info *info)
d3d_render_target* hlsl_info::find_render_target(d3d::texture_info *info)
{
d3d_render_target *curr = targethead;
UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
render_texinfo *texinfo = info->get_texinfo();
UINT32 screen_index_data = (UINT32)texinfo->osddata;
UINT32 screen_index = screen_index_data >> 1;
UINT32 page_index = screen_index_data & 1;
while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index || curr->width != info->texinfo.width || curr->height != info->texinfo.height))
while (curr != NULL && (curr->screen_index != screen_index || curr->page_index != page_index || curr->width != texinfo->width || curr->height != texinfo->height))
{
curr = curr->next;
}
@ -1642,7 +1642,7 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
{
return;
}
d3d_cache_target *ct = find_cache_target(rt->screen_index, poly->texture->texinfo.width, poly->texture->texinfo.height);
d3d_cache_target *ct = find_cache_target(rt->screen_index, poly->texture->get_texinfo()->width, poly->texture->get_texinfo()->height);
if(options->yiq_enable)
{
@ -1651,15 +1651,15 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
if(options->params_dirty)
{
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc);
(*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a);
(*d3dintf->effect.set_float)(curr_effect, "BValue", (poly->texture->cur_frame == 2) ? 0.0f : ((float)poly->texture->cur_frame * options->yiq_b));
(*d3dintf->effect.set_float)(curr_effect, "BValue", (poly->texture->m_cur_frame == 2) ? 0.0f : ((float)poly->texture->m_cur_frame * options->yiq_b));
(*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p);
(*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n);
(*d3dintf->effect.set_float)(curr_effect, "YFreqResponse", options->yiq_y);
@ -1691,18 +1691,18 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
curr_effect = yiq_decode_effect;
(*d3dintf->effect.set_texture)(curr_effect, "Composite", rt->texture[4]);
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->d3dfinaltex);
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", poly->texture->m_d3dfinaltex);
if(options->params_dirty)
{
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "CCValue", options->yiq_cc);
(*d3dintf->effect.set_float)(curr_effect, "AValue", options->yiq_a);
(*d3dintf->effect.set_float)(curr_effect, "BValue", (poly->texture->cur_frame == 2) ? 0.0f : ((float)poly->texture->cur_frame * options->yiq_b));
(*d3dintf->effect.set_float)(curr_effect, "BValue", (poly->texture->m_cur_frame == 2) ? 0.0f : ((float)poly->texture->m_cur_frame * options->yiq_b));
(*d3dintf->effect.set_float)(curr_effect, "OValue", options->yiq_o);
(*d3dintf->effect.set_float)(curr_effect, "PValue", options->yiq_p);
(*d3dintf->effect.set_float)(curr_effect, "NotchHalfWidth", options->yiq_n);
@ -1741,10 +1741,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
/* Render the initial color-convolution pass */
if(options->params_dirty)
{
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", options->yiq_enable ? 1.0f : (1.0f / (poly->texture->ustop - poly->texture->ustart)));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", options->yiq_enable ? 1.0f : (1.0f / (poly->texture->vstop - poly->texture->vstart)));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", options->yiq_enable ? 1.0f : (1.0f / (poly->texture->m_ustop - poly->texture->m_ustart)));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", options->yiq_enable ? 1.0f : (1.0f / (poly->texture->m_vstop - poly->texture->m_vstart)));
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "YIQEnable", options->yiq_enable ? 1.0f : 0.0f);
@ -1783,10 +1783,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
{
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
}
(*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
@ -1815,10 +1815,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
{
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
(*d3dintf->effect.set_vector)(curr_effect, "ConvergeX", 3, options->converge_x);
(*d3dintf->effect.set_vector)(curr_effect, "ConvergeY", 3, options->converge_y);
(*d3dintf->effect.set_vector)(curr_effect, "RadialConvergeX", 3, options->radial_converge_x);
@ -1855,10 +1855,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->m_ustop - poly->texture->m_ustart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->m_vstop - poly->texture->m_vstart)) : 0.0f);
(*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[0]);
(*d3dintf->effect.begin)(curr_effect, &num_passes, 0);
@ -1885,8 +1885,8 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f);
(*d3dintf->effect.set_vector)(curr_effect, "Defocus", 2, &options->defocus[1]);
@ -1917,10 +1917,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
{
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
(*d3dintf->effect.set_vector)(curr_effect, "Phosphor", 3, options->phosphor);
}
(*d3dintf->effect.set_float)(curr_effect, "TextureWidth", (float)rt->target_width);
@ -2151,10 +2151,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
(*d3dintf->effect.set_texture)(curr_effect, "Diffuse", rt->texture[2]);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->m_rawwidth : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->m_rawheight : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->m_ustop - poly->texture->m_ustart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->m_vstop - poly->texture->m_vstart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f);
@ -2174,8 +2174,8 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
(*d3dintf->effect.end)(curr_effect);
#endif
poly->texture->cur_frame++;
poly->texture->cur_frame %= options->yiq_phase_count;
poly->texture->m_cur_frame++;
poly->texture->m_cur_frame %= options->yiq_phase_count;
options->params_dirty = false;
}
@ -2379,10 +2379,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->ustop - poly->texture->ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->vstop - poly->texture->vstart));
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", (float)poly->texture->m_rawwidth);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", (float)poly->texture->m_rawheight);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", 1.0f / (poly->texture->m_ustop - poly->texture->m_ustart));
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", 1.0f / (poly->texture->m_vstop - poly->texture->m_vstart));
result = (*d3dintf->device.set_render_target)(d3d->device, 0, rt->target[1]);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call\n", (int)result);
@ -2407,10 +2407,10 @@ void hlsl_info::render_quad(d3d_poly_info *poly, int vertnum)
#endif
else
{
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->rawwidth : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->rawheight : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->ustop - poly->texture->ustart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->vstop - poly->texture->vstart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawWidth", poly->texture != NULL ? (float)poly->texture->m_rawwidth : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "RawHeight", poly->texture != NULL ? (float)poly->texture->m_rawheight : 8.0f);
(*d3dintf->effect.set_float)(curr_effect, "WidthRatio", poly->texture != NULL ? (1.0f / (poly->texture->m_ustop - poly->texture->m_ustart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "HeightRatio", poly->texture != NULL ? (1.0f / (poly->texture->m_vstop - poly->texture->m_vstart)) : 0.0f);
(*d3dintf->effect.set_float)(curr_effect, "TargetWidth", (float)d3d->width);
(*d3dintf->effect.set_float)(curr_effect, "TargetHeight", (float)d3d->height);
(*d3dintf->effect.set_float)(curr_effect, "PostPass", 0.0f);
@ -2450,16 +2450,16 @@ void hlsl_info::end_draw()
// hlsl_info::register_prescaled_texture
//============================================================
bool hlsl_info::register_prescaled_texture(d3d_texture_info *texture)
bool hlsl_info::register_prescaled_texture(d3d::texture_info *texture)
{
return register_texture(texture, texture->rawwidth, texture->rawheight, texture->xprescale, texture->yprescale);
return register_texture(texture);
}
//============================================================
// hlsl_info::add_cache_target - register a cache target
//============================================================
bool hlsl_info::add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
bool hlsl_info::add_cache_target(d3d_info* d3d, d3d::texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index)
{
d3d_cache_target* target = (d3d_cache_target*)global_alloc_clear(d3d_cache_target);
@ -2471,8 +2471,8 @@ bool hlsl_info::add_cache_target(d3d_info* d3d, d3d_texture_info* info, int widt
if (info != NULL)
{
target->width = info->texinfo.width;
target->height = info->texinfo.height;
target->width = info->get_texinfo()->width;
target->height = info->get_texinfo()->height;
}
else
{
@ -2524,7 +2524,7 @@ void hlsl_info::create_vector_target(render_primitive *prim)
// hlsl_info::add_render_target - register a render target
//============================================================
bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, bool bloom)
bool hlsl_info::add_render_target(d3d_info* d3d, d3d::texture_info* info, int width, int height, int xprescale, int yprescale, bool bloom)
{
UINT32 screen_index = 0;
UINT32 page_index = 0;
@ -2536,7 +2536,7 @@ bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int wid
remove_render_target(existing_target);
}
UINT32 screen_index_data = (UINT32)info->texinfo.osddata;
UINT32 screen_index_data = (UINT32)info->get_texinfo()->osddata;
screen_index = screen_index_data >> 1;
page_index = screen_index_data & 1;
}
@ -2559,8 +2559,8 @@ bool hlsl_info::add_render_target(d3d_info* d3d, d3d_texture_info* info, int wid
if (info != NULL)
{
target->width = info->texinfo.width;
target->height = info->texinfo.height;
target->width = info->get_texinfo()->width;
target->height = info->get_texinfo()->height;
}
else
{
@ -2611,23 +2611,20 @@ void hlsl_info::enumerate_screens()
//============================================================
// hlsl_info::register_texture
// hlsl_info::register_texture(d3d_texture::info)
//============================================================
bool hlsl_info::register_texture(d3d_texture_info *texture)
bool hlsl_info::register_texture(d3d::texture_info *texture)
{
return register_texture(texture, texture->rawwidth, texture->rawheight, 1, 1);
}
int width = texture->get_width();
int height = texture->get_height();
int xscale = texture->get_xscale();
int yscale = texture->get_yscale();
//============================================================
// hlsl_info::register_texture(d3d_texture_info, int, int, int, int)
//============================================================
bool hlsl_info::register_texture(d3d_texture_info *texture, int width, int height, int xscale, int yscale)
{
if (!master_enable || !d3dintf->post_fx_available)
return 0;
{
return false;
}
enumerate_screens();

View File

@ -138,10 +138,10 @@ public:
void init_effect_info(d3d_poly_info *poly);
void render_quad(d3d_poly_info *poly, int vertnum);
bool register_texture(d3d_texture_info *texture);
bool register_prescaled_texture(d3d_texture_info *texture);
bool add_render_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, bool bloom = false);
bool add_cache_target(d3d_info* d3d, d3d_texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index);
bool register_texture(d3d::texture_info *texture);
bool register_prescaled_texture(d3d::texture_info *texture);
bool add_render_target(d3d_info* d3d, d3d::texture_info* info, int width, int height, int xprescale, int yprescale, bool bloom = false);
bool add_cache_target(d3d_info* d3d, d3d::texture_info* info, int width, int height, int xprescale, int yprescale, int screen_index);
void window_save();
void window_record();
@ -152,9 +152,9 @@ public:
void record_texture();
void init_fsfx_quad(void *vertbuf);
void set_texture(d3d_texture_info *texture);
d3d_render_target * find_render_target(d3d_texture_info *info);
void remove_render_target(d3d_texture_info *texture);
void set_texture(d3d::texture_info *texture);
d3d_render_target * find_render_target(d3d::texture_info *info);
void remove_render_target(d3d::texture_info *texture);
void remove_render_target(int width, int height, UINT32 screen_index, UINT32 page_index);
void remove_render_target(d3d_render_target *rt);
@ -175,7 +175,7 @@ private:
void end_avi_recording();
void begin_avi_recording(const char *name);
bool register_texture(d3d_texture_info *texture, int width, int height, int xscale, int yscale);
bool register_texture(d3d::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);
d3d_cache_target * find_cache_target(UINT32 screen_index, int width, int height);
@ -199,7 +199,7 @@ private:
int prescale_size_y; // prescale size y
int preset; // preset, if relevant
bitmap_argb32 shadow_bitmap; // shadow mask bitmap for post-processing shader
d3d_texture_info * shadow_texture; // shadow mask texture for post-processing shader
d3d::texture_info * shadow_texture; // shadow mask texture for post-processing shader
hlsl_options * options; // current uniform state
D3DPRIMITIVETYPE vecbuf_type;
UINT32 vecbuf_index;

View File

@ -209,14 +209,14 @@ INLINE UINT32 texture_compute_hash(const render_texinfo *texture, UINT32 flags)
}
INLINE void set_texture(d3d_info *d3d, d3d_texture_info *texture)
INLINE void set_texture(d3d_info *d3d, d3d::texture_info *texture)
{
HRESULT result;
if (texture != d3d->last_texture)
{
d3d->last_texture = texture;
d3d->last_texture_flags = (texture == NULL ? 0 : texture->flags);
result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? d3d->default_texture->d3dfinaltex : texture->d3dfinaltex);
d3d->last_texture_flags = (texture == NULL ? 0 : texture->m_flags);
result = (*d3dintf->device.set_texture)(d3d->device, 0, (texture == NULL) ? d3d->default_texture->m_d3dfinaltex : texture->m_d3dfinaltex);
d3d->hlsl->set_texture(texture);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
}
@ -325,7 +325,7 @@ INLINE void set_blendmode(d3d_info *d3d, int blendmode)
INLINE void reset_render_states(d3d_info *d3d)
{
// this ensures subsequent calls to the above setters will force-update the data
d3d->last_texture = (d3d_texture_info *)~0;
d3d->last_texture = (d3d::texture_info *)~0;
d3d->last_filter = -1;
d3d->last_blendenable = -1;
d3d->last_blendop = -1;
@ -372,13 +372,6 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim);
static d3d_vertex *primitive_alloc(d3d_info *d3d, int numverts);
static void primitive_flush_pending(d3d_info *d3d);
// textures
static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d_texture_info *texture);
static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const render_texinfo *texsource, UINT32 flags);
static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture);
static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *prim);
static void texture_update(d3d_info *d3d, const render_primitive *prim);
//============================================================
// drawd3d_init
//============================================================
@ -607,7 +600,21 @@ mtlog_add("drawd3d_window_draw: begin");
{
if (prim->texture.base != NULL)
{
texture_update(d3d, prim);
if (prim->texture.osdhandle == NULL)
{
// if there isn't one, create a new texture
prim->texture.osdhandle = (void*)(new d3d::texture_info(d3d, &prim->texture, prim->flags));
}
else
{
// if there is one, but with a different seqid, copy the data
d3d::texture_info *texture = (d3d::texture_info *)prim->texture.osdhandle;
if (texture->get_texinfo()->seqid != prim->texture.seqid)
{
texture->set_data(&prim->texture, prim->flags);
texture->get_texinfo()->seqid = prim->texture.seqid;
}
}
}
else if(d3d->hlsl->vector_enabled() && PRIMFLAG_GET_VECTORBUF(prim->flags))
{
@ -921,7 +928,7 @@ static int device_create_resources(d3d_info *d3d)
texture.seqid = 0;
// now create it
d3d->default_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
d3d->default_texture = new d3d::texture_info(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
}
// experimental: if we have a vector bitmap, create a texture for it
@ -938,7 +945,7 @@ static int device_create_resources(d3d_info *d3d)
texture.seqid = 0;
// now create it
d3d->vector_texture = texture_create(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
d3d->vector_texture = new d3d::texture_info(d3d, &texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA) | PRIMFLAG_TEXFORMAT(TEXFORMAT_ARGB32));
}
return 0;
@ -978,25 +985,9 @@ static void device_delete_resources(d3d_info *d3d)
// free all textures
while (d3d->texlist != NULL)
{
d3d_texture_info *tex = d3d->texlist;
d3d->texlist = tex->next;
if (tex->d3dfinaltex != NULL)
{
if (tex->d3dtex == tex->d3dfinaltex) tex->d3dtex = NULL;
(*d3dintf->texture.release)(tex->d3dfinaltex);
tex->d3dfinaltex = NULL;
}
if (tex->d3dtex != NULL)
{
(*d3dintf->texture.release)(tex->d3dtex);
tex->d3dtex = NULL;
}
if (tex->d3dsurface != NULL)
{
(*d3dintf->surface.release)(tex->d3dsurface);
tex->d3dsurface = NULL;
}
global_free(tex);
d3d::texture_info *tex = d3d->texlist;
d3d->texlist = tex->m_next;
delete tex;
}
// free the vertex buffer
@ -1537,31 +1528,31 @@ static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_ti
// if we have a texture to use for the vectors, use it here
if (d3d->vector_texture != NULL)
{
vertex[0].u0 = d3d->vector_texture->ustart;
vertex[0].v0 = d3d->vector_texture->vstart;
vertex[0].u0 = d3d->vector_texture->m_ustart;
vertex[0].v0 = d3d->vector_texture->m_vstart;
vertex[2].u0 = d3d->vector_texture->ustop;
vertex[2].v0 = d3d->vector_texture->vstart;
vertex[2].u0 = d3d->vector_texture->m_ustop;
vertex[2].v0 = d3d->vector_texture->m_vstart;
vertex[1].u0 = d3d->vector_texture->ustart;
vertex[1].v0 = d3d->vector_texture->vstop;
vertex[1].u0 = d3d->vector_texture->m_ustart;
vertex[1].v0 = d3d->vector_texture->m_vstop;
vertex[3].u0 = d3d->vector_texture->ustop;
vertex[3].v0 = d3d->vector_texture->vstop;
vertex[3].u0 = d3d->vector_texture->m_ustop;
vertex[3].v0 = d3d->vector_texture->m_vstop;
}
else if(d3d->default_texture != NULL)
{
vertex[0].u0 = d3d->default_texture->ustart;
vertex[0].v0 = d3d->default_texture->vstart;
vertex[0].u0 = d3d->default_texture->m_ustart;
vertex[0].v0 = d3d->default_texture->m_vstart;
vertex[2].u0 = d3d->default_texture->ustart;
vertex[2].v0 = d3d->default_texture->vstart;
vertex[2].u0 = d3d->default_texture->m_ustart;
vertex[2].v0 = d3d->default_texture->m_vstart;
vertex[1].u0 = d3d->default_texture->ustart;
vertex[1].v0 = d3d->default_texture->vstart;
vertex[1].u0 = d3d->default_texture->m_ustart;
vertex[1].v0 = d3d->default_texture->m_vstart;
vertex[3].u0 = d3d->default_texture->ustart;
vertex[3].v0 = d3d->default_texture->vstart;
vertex[3].u0 = d3d->default_texture->m_ustart;
vertex[3].v0 = d3d->default_texture->m_vstart;
}
// set the color, Z parameters to standard values
@ -1607,17 +1598,15 @@ static void draw_line(d3d_info *d3d, const render_primitive *prim, float line_ti
static void draw_quad(d3d_info *d3d, const render_primitive *prim)
{
d3d_texture_info *texture = texture_find(d3d, prim);
DWORD color, modmode;
d3d_vertex *vertex;
INT32 r, g, b, a;
d3d_poly_info *poly;
int i;
d3d::texture_info *texture = (d3d::texture_info *)prim->texture.osdhandle;
texture = texture != NULL ? texture : d3d->default_texture;
if (texture == NULL)
{
texture = d3d->default_texture;
}
// get a pointer to the vertex buffer
vertex = primitive_alloc(d3d, 4);
d3d_vertex *vertex = primitive_alloc(d3d, 4);
if (vertex == NULL)
return;
@ -1634,24 +1623,24 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim)
// set the texture coordinates
if(texture != NULL)
{
float du = texture->ustop - texture->ustart;
float dv = texture->vstop - texture->vstart;
vertex[0].u0 = texture->ustart + du * prim->texcoords.tl.u;
vertex[0].v0 = texture->vstart + dv * prim->texcoords.tl.v;
vertex[1].u0 = texture->ustart + du * prim->texcoords.tr.u;
vertex[1].v0 = texture->vstart + dv * prim->texcoords.tr.v;
vertex[2].u0 = texture->ustart + du * prim->texcoords.bl.u;
vertex[2].v0 = texture->vstart + dv * prim->texcoords.bl.v;
vertex[3].u0 = texture->ustart + du * prim->texcoords.br.u;
vertex[3].v0 = texture->vstart + dv * prim->texcoords.br.v;
float du = texture->m_ustop - texture->m_ustart;
float dv = texture->m_vstop - texture->m_vstart;
vertex[0].u0 = texture->m_ustart + du * prim->texcoords.tl.u;
vertex[0].v0 = texture->m_vstart + dv * prim->texcoords.tl.v;
vertex[1].u0 = texture->m_ustart + du * prim->texcoords.tr.u;
vertex[1].v0 = texture->m_vstart + dv * prim->texcoords.tr.v;
vertex[2].u0 = texture->m_ustart + du * prim->texcoords.bl.u;
vertex[2].v0 = texture->m_vstart + dv * prim->texcoords.bl.v;
vertex[3].u0 = texture->m_ustart + du * prim->texcoords.br.u;
vertex[3].v0 = texture->m_vstart + dv * prim->texcoords.br.v;
}
// determine the color, allowing for over modulation
r = (INT32)(prim->color.r * 255.0f);
g = (INT32)(prim->color.g * 255.0f);
b = (INT32)(prim->color.b * 255.0f);
a = (INT32)(prim->color.a * 255.0f);
modmode = D3DTOP_MODULATE;
INT32 r = (INT32)(prim->color.r * 255.0f);
INT32 g = (INT32)(prim->color.g * 255.0f);
INT32 b = (INT32)(prim->color.b * 255.0f);
INT32 a = (INT32)(prim->color.a * 255.0f);
DWORD modmode = D3DTOP_MODULATE;
if (texture != NULL)
{
if (d3d->mod2x_supported && (r > 255 || g > 255 || b > 255))
@ -1672,10 +1661,10 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim)
if (g > 255) g = 255;
if (b > 255) b = 255;
if (a > 255) a = 255;
color = D3DCOLOR_ARGB(a, r, g, b);
DWORD color = D3DCOLOR_ARGB(a, r, g, b);
// set the color, Z parameters to standard values
for (i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
{
vertex[i].z = 0.0f;
vertex[i].rhw = 1.0f;
@ -1683,7 +1672,7 @@ static void draw_quad(d3d_info *d3d, const render_primitive *prim)
}
// now add a polygon entry
poly = &d3d->poly[d3d->numpolys++];
d3d_poly_info *poly = &d3d->poly[d3d->numpolys++];
poly->type = D3DPT_TRIANGLESTRIP;
poly->count = 2;
poly->numverts = 4;
@ -1818,42 +1807,65 @@ static void primitive_flush_pending(d3d_info *d3d)
d3d->numpolys = 0;
}
//============================================================
// texture_info destructor
//============================================================
void texture_destroy(d3d_info *d3d, d3d_texture_info *info)
d3d::texture_info::~texture_info()
{
if (m_d3dfinaltex != NULL)
{
if (m_d3dtex == m_d3dfinaltex)
{
m_d3dtex = NULL;
}
(*d3dintf->texture.release)(m_d3dfinaltex);
m_d3dfinaltex = NULL;
}
if (m_d3dtex != NULL)
{
(*d3dintf->texture.release)(m_d3dtex);
m_d3dtex = NULL;
}
if (m_d3dsurface != NULL)
{
(*d3dintf->surface.release)(m_d3dsurface);
m_d3dsurface = NULL;
}
}
//============================================================
// texture_create
// texture_info constructor
//============================================================
d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource, UINT32 flags)
d3d::texture_info::texture_info(d3d_info *d3d, render_texinfo* texsource, UINT32 flags)
{
d3d_texture_info *texture;
HRESULT result;
// allocate a new texture
texture = global_alloc_clear(d3d_texture_info);
// fill in the core data
texture->hash = texture_compute_hash(texsource, flags);
texture->flags = flags;
texture->texinfo = *texsource;
texture->xprescale = video_config.prescale;
texture->yprescale = video_config.prescale;
m_d3d = d3d;
m_hash = texture_compute_hash(texsource, flags);
m_flags = flags;
m_texinfo = texsource;
m_xprescale = video_config.prescale;
m_yprescale = video_config.prescale;
m_d3dtex = NULL;
m_d3dsurface = NULL;
m_d3dfinaltex = NULL;
// compute the size
texture_compute_size(d3d, texsource->width, texsource->height, texture);
compute_size(texsource->width, texsource->height);
// non-screen textures are easy
if (!PRIMFLAG_GET_SCREENTEX(flags))
{
assert(PRIMFLAG_TEXFORMAT(flags) != TEXFORMAT_YUY16);
result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture->d3dtex);
result = (*d3dintf->device.create_texture)(d3d->device, m_rawwidth, m_rawheight, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &m_d3dtex);
if (result != D3D_OK)
goto error;
texture->d3dfinaltex = texture->d3dtex;
texture->type = TEXTURE_TYPE_PLAIN;
m_d3dfinaltex = m_d3dtex;
m_type = TEXTURE_TYPE_PLAIN;
}
// screen textures are allocated differently
@ -1863,45 +1875,62 @@ d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource,
DWORD usage = d3d->dynamic_supported ? D3DUSAGE_DYNAMIC : 0;
D3DPOOL pool = d3d->dynamic_supported ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
int maxdim = MAX(d3d->presentation.BackBufferWidth, d3d->presentation.BackBufferHeight);
int attempt;
// pick the format
if (PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_YUY16)
{
format = d3d->yuv_format;
}
else if (PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_ARGB32 || PRIMFLAG_GET_TEXFORMAT(flags) == TEXFORMAT_PALETTEA16)
{
format = D3DFMT_A8R8G8B8;
}
else
{
format = d3d->screen_format;
}
// don't prescale above screen size
while (texture->xprescale > 1 && texture->rawwidth * texture->xprescale >= 2 * maxdim)
texture->xprescale--;
while (texture->xprescale > 1 && texture->rawwidth * texture->xprescale > d3d->texture_max_width)
texture->xprescale--;
while (texture->yprescale > 1 && texture->rawheight * texture->yprescale >= 2 * maxdim)
texture->yprescale--;
while (texture->yprescale > 1 && texture->rawheight * texture->yprescale > d3d->texture_max_height)
texture->yprescale--;
if (texture->xprescale != video_config.prescale || texture->yprescale != video_config.prescale)
mame_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, texture->xprescale, texture->yprescale);
while (m_xprescale > 1 && m_rawwidth * m_xprescale >= 2 * maxdim)
{
m_xprescale--;
}
while (m_xprescale > 1 && m_rawwidth * m_xprescale > d3d->texture_max_width)
{
m_xprescale--;
}
while (m_yprescale > 1 && m_rawheight * m_yprescale >= 2 * maxdim)
{
m_yprescale--;
}
while (m_yprescale > 1 && m_rawheight * m_yprescale > d3d->texture_max_height)
{
m_yprescale--;
}
if (m_xprescale != video_config.prescale || m_yprescale != video_config.prescale)
{
mame_printf_verbose("Direct3D: adjusting prescale from %dx%d to %dx%d\n", video_config.prescale, video_config.prescale, m_xprescale, m_yprescale);
}
// loop until we allocate something or error
for (attempt = 0; attempt < 2; attempt++)
for (int attempt = 0; attempt < 2; attempt++)
{
// second attempt is always 1:1
if (attempt == 1)
texture->xprescale = texture->yprescale = 1;
{
m_xprescale = m_yprescale = 1;
}
// screen textures with no prescaling are pretty easy
if (texture->xprescale == 1 && texture->yprescale == 1)
if (m_xprescale == 1 && m_yprescale == 1)
{
result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, usage, format, pool, &texture->d3dtex);
result = (*d3dintf->device.create_texture)(d3d->device, m_rawwidth, m_rawheight, 1, usage, format, pool, &m_d3dtex);
if (result == D3D_OK)
{
texture->d3dfinaltex = texture->d3dtex;
texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
m_d3dfinaltex = m_d3dtex;
m_type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
if (d3d->hlsl->enabled() && !d3d->hlsl->register_texture(texture))
if (d3d->hlsl->enabled() && !d3d->hlsl->register_texture(this))
{
goto error;
}
@ -1913,98 +1942,98 @@ d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource,
// screen textures with prescaling require two allocations
else
{
int scwidth, scheight;
D3DFORMAT finalfmt;
// use an offscreen plain surface for stretching if supported
// (won't work for YUY textures)
if (d3d->stretch_supported && PRIMFLAG_GET_TEXFORMAT(flags) != TEXFORMAT_YUY16)
{
result = (*d3dintf->device.create_offscreen_plain_surface)(d3d->device, texture->rawwidth, texture->rawheight, format, D3DPOOL_DEFAULT, &texture->d3dsurface);
result = (*d3dintf->device.create_offscreen_plain_surface)(d3d->device, m_rawwidth, m_rawheight, format, D3DPOOL_DEFAULT, &m_d3dsurface);
if (result != D3D_OK)
{
continue;
texture->type = TEXTURE_TYPE_SURFACE;
}
m_type = TEXTURE_TYPE_SURFACE;
}
// otherwise, we allocate a dynamic texture for the source
else
{
result = (*d3dintf->device.create_texture)(d3d->device, texture->rawwidth, texture->rawheight, 1, usage, format, pool, &texture->d3dtex);
result = (*d3dintf->device.create_texture)(d3d->device, m_rawwidth, m_rawheight, 1, usage, format, pool, &m_d3dtex);
if (result != D3D_OK)
{
continue;
texture->type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
}
m_type = d3d->dynamic_supported ? TEXTURE_TYPE_DYNAMIC : TEXTURE_TYPE_PLAIN;
}
// for the target surface, we allocate a render target texture
scwidth = texture->rawwidth * texture->xprescale;
scheight = texture->rawheight * texture->yprescale;
int scwidth = m_rawwidth * m_xprescale;
int scheight = m_rawheight * m_yprescale;
// target surfaces typically cannot be YCbCr, so we always pick RGB in that case
finalfmt = (format != d3d->yuv_format) ? format : D3DFMT_A8R8G8B8;
result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &texture->d3dfinaltex);
D3DFORMAT finalfmt = (format != d3d->yuv_format) ? format : D3DFMT_A8R8G8B8;
result = (*d3dintf->device.create_texture)(d3d->device, scwidth, scheight, 1, D3DUSAGE_RENDERTARGET, finalfmt, D3DPOOL_DEFAULT, &m_d3dfinaltex);
if (result == D3D_OK)
{
if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(texture))
if (d3d->hlsl->enabled() && !d3d->hlsl->register_prescaled_texture(this))
{
goto error;
}
break;
}
(*d3dintf->texture.release)(texture->d3dtex);
texture->d3dtex = NULL;
(*d3dintf->texture.release)(m_d3dtex);
m_d3dtex = NULL;
}
}
}
// copy the data to the texture
texture_set_data(d3d, texture, texsource, flags);
set_data(texsource, flags);
texsource->osdhandle = (void*)this;
// add us to the texture list
if(d3d->texlist != NULL)
d3d->texlist->prev = texture;
texture->prev = NULL;
texture->next = d3d->texlist;
d3d->texlist = texture;
return texture;
d3d->texlist->m_prev = this;
m_prev = NULL;
m_next = d3d->texlist;
d3d->texlist = this;
return;
error:
d3dintf->post_fx_available = false;
printf("Direct3D: Critical warning: A texture failed to allocate. Expect things to get bad quickly.\n");
if (texture->d3dsurface != NULL)
(*d3dintf->surface.release)(texture->d3dsurface);
if (texture->d3dtex != NULL)
(*d3dintf->texture.release)(texture->d3dtex);
global_free(texture);
return NULL;
if (m_d3dsurface != NULL)
(*d3dintf->surface.release)(m_d3dsurface);
if (m_d3dtex != NULL)
(*d3dintf->texture.release)(m_d3dtex);
}
//============================================================
// texture_compute_size
// texture_info::compute_size
//============================================================
static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d_texture_info *texture)
void d3d::texture_info::compute_size(int texwidth, int texheight)
{
int finalheight = texheight;
int finalwidth = texwidth;
// if we're not wrapping, add a 1-2 pixel border on all sides
texture->xborderpix = 0;
texture->yborderpix = 0;
if (ENABLE_BORDER_PIX && !(texture->flags & PRIMFLAG_TEXWRAP_MASK))
m_xborderpix = 0;
m_yborderpix = 0;
if (ENABLE_BORDER_PIX && !(m_flags & PRIMFLAG_TEXWRAP_MASK))
{
// note we need 2 pixels in X for YUY textures
texture->xborderpix = (PRIMFLAG_GET_TEXFORMAT(texture->flags) == TEXFORMAT_YUY16) ? 2 : 1;
texture->yborderpix = 1;
m_xborderpix = (PRIMFLAG_GET_TEXFORMAT(m_flags) == TEXFORMAT_YUY16) ? 2 : 1;
m_yborderpix = 1;
}
// compute final texture size
finalwidth += 2 * texture->xborderpix;
finalheight += 2 * texture->yborderpix;
finalwidth += 2 * m_xborderpix;
finalheight += 2 * m_yborderpix;
// round width/height up to nearest power of 2 if we need to
if (!(d3d->texture_caps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
if (!(m_d3d->texture_caps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL))
{
// first the width
if (finalwidth & (finalwidth - 1))
@ -2028,7 +2057,7 @@ static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d
}
// round up to square if we need to
if (d3d->texture_caps & D3DPTEXTURECAPS_SQUAREONLY)
if (m_d3d->texture_caps & D3DPTEXTURECAPS_SQUAREONLY)
{
if (finalwidth < finalheight)
finalwidth = finalheight;
@ -2037,38 +2066,42 @@ static void texture_compute_size(d3d_info *d3d, int texwidth, int texheight, d3d
}
// adjust the aspect ratio if we need to
while (finalwidth < finalheight && finalheight / finalwidth > d3d->texture_max_aspect)
while (finalwidth < finalheight && finalheight / finalwidth > m_d3d->texture_max_aspect)
{
finalwidth *= 2;
while (finalheight < finalwidth && finalwidth / finalheight > d3d->texture_max_aspect)
}
while (finalheight < finalwidth && finalwidth / finalheight > m_d3d->texture_max_aspect)
{
finalheight *= 2;
}
// if we added pixels for the border, and that just barely pushed us over, take it back
if ((finalwidth > d3d->texture_max_width && finalwidth - 2 * texture->xborderpix <= d3d->texture_max_width) ||
(finalheight > d3d->texture_max_height && finalheight - 2 * texture->yborderpix <= d3d->texture_max_height))
if ((finalwidth > m_d3d->texture_max_width && finalwidth - 2 * m_xborderpix <= m_d3d->texture_max_width) ||
(finalheight > m_d3d->texture_max_height && finalheight - 2 * m_yborderpix <= m_d3d->texture_max_height))
{
finalwidth -= 2 * texture->xborderpix;
finalheight -= 2 * texture->yborderpix;
texture->xborderpix = 0;
texture->yborderpix = 0;
finalwidth -= 2 * m_xborderpix;
finalheight -= 2 * m_yborderpix;
m_xborderpix = 0;
m_yborderpix = 0;
}
// if we're above the max width/height, do what?
if (finalwidth > d3d->texture_max_width || finalheight > d3d->texture_max_height)
if (finalwidth > m_d3d->texture_max_width || finalheight > m_d3d->texture_max_height)
{
static int printed = FALSE;
if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth, finalheight, (int)d3d->texture_max_width, (int)d3d->texture_max_height);
if (!printed) mame_printf_warning("Texture too big! (wanted: %dx%d, max is %dx%d)\n", finalwidth, finalheight, (int)m_d3d->texture_max_width, (int)m_d3d->texture_max_height);
printed = TRUE;
}
// compute the U/V scale factors
texture->ustart = (float)texture->xborderpix / (float)finalwidth;
texture->ustop = (float)(texwidth + texture->xborderpix) / (float)finalwidth;
texture->vstart = (float)texture->yborderpix / (float)finalheight;
texture->vstop = (float)(texheight + texture->yborderpix) / (float)finalheight;
m_ustart = (float)m_xborderpix / (float)finalwidth;
m_ustop = (float)(texwidth + m_xborderpix) / (float)finalwidth;
m_vstart = (float)m_yborderpix / (float)finalheight;
m_vstop = (float)(texheight + m_yborderpix) / (float)finalheight;
// set the final values
texture->rawwidth = finalwidth;
texture->rawheight = finalheight;
m_rawwidth = finalwidth;
m_rawheight = finalheight;
}
@ -2411,58 +2444,58 @@ INLINE void copyline_yuy16_to_argb(UINT32 *dst, const UINT16 *src, int width, co
// texture_set_data
//============================================================
static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const render_texinfo *texsource, UINT32 flags)
void d3d::texture_info::set_data(const render_texinfo *texsource, UINT32 flags)
{
D3DLOCKED_RECT rect;
HRESULT result;
int miny, maxy;
int dsty;
// lock the texture
switch (texture->type)
switch (m_type)
{
default:
case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.lock_rect)(texture->d3dtex, 0, &rect, NULL, 0); break;
case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.lock_rect)(texture->d3dtex, 0, &rect, NULL, D3DLOCK_DISCARD); break;
case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.lock_rect)(texture->d3dsurface, &rect, NULL, D3DLOCK_DISCARD); break;
case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.lock_rect)(m_d3dtex, 0, &rect, NULL, 0); break;
case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.lock_rect)(m_d3dtex, 0, &rect, NULL, D3DLOCK_DISCARD); break;
case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.lock_rect)(m_d3dsurface, &rect, NULL, D3DLOCK_DISCARD); break;
}
if (result != D3D_OK)
{
return;
}
// loop over Y
miny = 0 - texture->yborderpix;
maxy = texsource->height + texture->yborderpix;
for (dsty = miny; dsty < maxy; dsty++)
int miny = 0 - m_yborderpix;
int maxy = texsource->height + m_yborderpix;
for (int dsty = miny; dsty < maxy; dsty++)
{
int srcy = (dsty < 0) ? 0 : (dsty >= texsource->height) ? texsource->height - 1 : dsty;
void *dst = (BYTE *)rect.pBits + (dsty + texture->yborderpix) * rect.Pitch;
void *dst = (BYTE *)rect.pBits + (dsty + m_yborderpix) * rect.Pitch;
// switch off of the format and
switch (PRIMFLAG_GET_TEXFORMAT(flags))
{
case TEXFORMAT_PALETTE16:
copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
copyline_palette16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_PALETTEA16:
copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
copyline_palettea16((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_RGB32:
copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
copyline_rgb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_ARGB32:
copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
copyline_argb32((UINT32 *)dst, (UINT32 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
case TEXFORMAT_YUY16:
if (d3d->yuv_format == D3DFMT_YUY2)
copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
else if (d3d->yuv_format == D3DFMT_UYVY)
copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
if (m_d3d->yuv_format == D3DFMT_YUY2)
copyline_yuy16_to_yuy2((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
else if (m_d3d->yuv_format == D3DFMT_UYVY)
copyline_yuy16_to_uyvy((UINT16 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
else
copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, texture->xborderpix);
copyline_yuy16_to_argb((UINT32 *)dst, (UINT16 *)texsource->base + srcy * texsource->rowpixels, texsource->width, texsource->palette, m_xborderpix);
break;
default:
@ -2472,58 +2505,61 @@ static void texture_set_data(d3d_info *d3d, d3d_texture_info *texture, const ren
}
// unlock
switch (texture->type)
switch (m_type)
{
default:
case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.unlock_rect)(texture->d3dtex, 0); break;
case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.unlock_rect)(texture->d3dtex, 0); break;
case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.unlock_rect)(texture->d3dsurface); break;
case TEXTURE_TYPE_PLAIN: result = (*d3dintf->texture.unlock_rect)(m_d3dtex, 0); break;
case TEXTURE_TYPE_DYNAMIC: result = (*d3dintf->texture.unlock_rect)(m_d3dtex, 0); break;
case TEXTURE_TYPE_SURFACE: result = (*d3dintf->surface.unlock_rect)(m_d3dsurface); break;
}
if (result != D3D_OK)
{
mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result);
}
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture unlock_rect call\n", (int)result);
// prescale
texture_prescale(d3d, texture);
prescale();
}
//============================================================
// texture_prescale
// texture_info::prescale
//============================================================
static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture)
void d3d::texture_info::prescale()
{
d3d_surface *surface;
HRESULT result;
int i;
// if we don't need to, just skip it
if (texture->d3dtex == texture->d3dfinaltex)
if (m_d3dtex == m_d3dfinaltex)
return;
// for all cases, we need to get the surface of the render target
result = (*d3dintf->texture.get_surface_level)(texture->d3dfinaltex, 0, &surface);
result = (*d3dintf->texture.get_surface_level)(m_d3dfinaltex, 0, &surface);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during texture get_surface_level call\n", (int)result);
// if we have an offscreen plain surface, we can just StretchRect to it
if (texture->type == TEXTURE_TYPE_SURFACE)
if (m_type == TEXTURE_TYPE_SURFACE)
{
RECT source, dest;
assert(texture->d3dsurface != NULL);
assert(m_d3dsurface != NULL);
// set the source bounds
RECT source;
source.left = source.top = 0;
source.right = texture->texinfo.width + 2 * texture->xborderpix;
source.bottom = texture->texinfo.height + 2 * texture->yborderpix;
source.right = m_texinfo->width + 2 * m_xborderpix;
source.bottom = m_texinfo->height + 2 * m_yborderpix;
// set the target bounds
RECT dest;
dest = source;
dest.right *= texture->xprescale;
dest.bottom *= texture->yprescale;
dest.right *= m_xprescale;
dest.bottom *= m_yprescale;
// do the stretchrect
result = (*d3dintf->device.stretch_rect)(d3d->device, texture->d3dsurface, &source, surface, &dest, D3DTEXF_POINT);
result = (*d3dintf->device.stretch_rect)(m_d3d->device, m_d3dsurface, &source, surface, &dest, D3DTEXF_POINT);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device stretct_rect call\n", (int)result);
}
@ -2532,77 +2568,77 @@ static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture)
{
d3d_surface *backbuffer;
assert(texture->d3dtex != NULL);
assert(m_d3dtex != NULL);
// first remember the original render target and set the new one
result = (*d3dintf->device.get_render_target)(d3d->device, 0, &backbuffer);
result = (*d3dintf->device.get_render_target)(m_d3d->device, 0, &backbuffer);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device get_render_target call\n", (int)result);
result = (*d3dintf->device.set_render_target)(d3d->device, 0, surface);
result = (*d3dintf->device.set_render_target)(m_d3d->device, 0, surface);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 1\n", (int)result);
reset_render_states(d3d);
reset_render_states(m_d3d);
// start the scene
result = (*d3dintf->device.begin_scene)(d3d->device);
result = (*d3dintf->device.begin_scene)(m_d3d->device);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device begin_scene call\n", (int)result);
// configure the rendering pipeline
set_filter(d3d, FALSE);
set_blendmode(d3d, BLENDMODE_NONE);
result = (*d3dintf->device.set_texture)(d3d->device, 0, texture->d3dtex);
set_filter(m_d3d, FALSE);
set_blendmode(m_d3d, BLENDMODE_NONE);
result = (*d3dintf->device.set_texture)(m_d3d->device, 0, m_d3dtex);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_texture call\n", (int)result);
// lock the vertex buffer
result = (*d3dintf->vertexbuf.lock)(d3d->vertexbuf, 0, 0, (VOID **)&d3d->lockedbuf, D3DLOCK_DISCARD);
result = (*d3dintf->vertexbuf.lock)(m_d3d->vertexbuf, 0, 0, (VOID **)&m_d3d->lockedbuf, D3DLOCK_DISCARD);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer lock call\n", (int)result);
// configure the X/Y coordinates on the target surface
d3d->lockedbuf[0].x = -0.5f;
d3d->lockedbuf[0].y = -0.5f;
d3d->lockedbuf[1].x = (float)((texture->texinfo.width + 2 * texture->xborderpix) * texture->xprescale) - 0.5f;
d3d->lockedbuf[1].y = -0.5f;
d3d->lockedbuf[2].x = -0.5f;
d3d->lockedbuf[2].y = (float)((texture->texinfo.height + 2 * texture->yborderpix) * texture->yprescale) - 0.5f;
d3d->lockedbuf[3].x = (float)((texture->texinfo.width + 2 * texture->xborderpix) * texture->xprescale) - 0.5f;
d3d->lockedbuf[3].y = (float)((texture->texinfo.height + 2 * texture->yborderpix) * texture->yprescale) - 0.5f;
m_d3d->lockedbuf[0].x = -0.5f;
m_d3d->lockedbuf[0].y = -0.5f;
m_d3d->lockedbuf[1].x = (float)((m_texinfo->width + 2 * m_xborderpix) * m_xprescale) - 0.5f;
m_d3d->lockedbuf[1].y = -0.5f;
m_d3d->lockedbuf[2].x = -0.5f;
m_d3d->lockedbuf[2].y = (float)((m_texinfo->height + 2 * m_yborderpix) * m_yprescale) - 0.5f;
m_d3d->lockedbuf[3].x = (float)((m_texinfo->width + 2 * m_xborderpix) * m_xprescale) - 0.5f;
m_d3d->lockedbuf[3].y = (float)((m_texinfo->height + 2 * m_yborderpix) * m_yprescale) - 0.5f;
// configure the U/V coordintes on the source texture
d3d->lockedbuf[0].u0 = 0.0f;
d3d->lockedbuf[0].v0 = 0.0f;
d3d->lockedbuf[1].u0 = (float)(texture->texinfo.width + 2 * texture->xborderpix) / (float)texture->rawwidth;
d3d->lockedbuf[1].v0 = 0.0f;
d3d->lockedbuf[2].u0 = 0.0f;
d3d->lockedbuf[2].v0 = (float)(texture->texinfo.height + 2 * texture->yborderpix) / (float)texture->rawheight;
d3d->lockedbuf[3].u0 = (float)(texture->texinfo.width + 2 * texture->xborderpix) / (float)texture->rawwidth;
d3d->lockedbuf[3].v0 = (float)(texture->texinfo.height + 2 * texture->yborderpix) / (float)texture->rawheight;
m_d3d->lockedbuf[0].u0 = 0.0f;
m_d3d->lockedbuf[0].v0 = 0.0f;
m_d3d->lockedbuf[1].u0 = (float)(m_texinfo->width + 2 * m_xborderpix) / (float)m_rawwidth;
m_d3d->lockedbuf[1].v0 = 0.0f;
m_d3d->lockedbuf[2].u0 = 0.0f;
m_d3d->lockedbuf[2].v0 = (float)(m_texinfo->height + 2 * m_yborderpix) / (float)m_rawheight;
m_d3d->lockedbuf[3].u0 = (float)(m_texinfo->width + 2 * m_xborderpix) / (float)m_rawwidth;
m_d3d->lockedbuf[3].v0 = (float)(m_texinfo->height + 2 * m_yborderpix) / (float)m_rawheight;
// reset the remaining vertex parameters
for (i = 0; i < 4; i++)
{
d3d->lockedbuf[i].z = 0.0f;
d3d->lockedbuf[i].rhw = 1.0f;
d3d->lockedbuf[i].color = D3DCOLOR_ARGB(0xff,0xff,0xff,0xff);
m_d3d->lockedbuf[i].z = 0.0f;
m_d3d->lockedbuf[i].rhw = 1.0f;
m_d3d->lockedbuf[i].color = D3DCOLOR_ARGB(0xff,0xff,0xff,0xff);
}
// unlock the vertex buffer
result = (*d3dintf->vertexbuf.unlock)(d3d->vertexbuf);
result = (*d3dintf->vertexbuf.unlock)(m_d3d->vertexbuf);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during vertex buffer unlock call\n", (int)result);
d3d->lockedbuf = NULL;
m_d3d->lockedbuf = NULL;
// set the stream and draw the triangle strip
result = (*d3dintf->device.set_stream_source)(d3d->device, 0, d3d->vertexbuf, sizeof(d3d_vertex));
result = (*d3dintf->device.set_stream_source)(m_d3d->device, 0, m_d3d->vertexbuf, sizeof(d3d_vertex));
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_stream_source call\n", (int)result);
result = (*d3dintf->device.draw_primitive)(d3d->device, D3DPT_TRIANGLESTRIP, 0, 2);
result = (*d3dintf->device.draw_primitive)(m_d3d->device, D3DPT_TRIANGLESTRIP, 0, 2);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device draw_primitive call\n", (int)result);
// end the scene
result = (*d3dintf->device.end_scene)(d3d->device);
result = (*d3dintf->device.end_scene)(m_d3d->device);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device end_scene call\n", (int)result);
// reset the render target and release our reference to the backbuffer
result = (*d3dintf->device.set_render_target)(d3d->device, 0, backbuffer);
result = (*d3dintf->device.set_render_target)(m_d3d->device, 0, backbuffer);
if (result != D3D_OK) mame_printf_verbose("Direct3D: Error %08X during device set_render_target call 2\n", (int)result);
(*d3dintf->surface.release)(backbuffer);
reset_render_states(d3d);
reset_render_states(m_d3d);
}
// release our reference to the target surface
@ -2610,108 +2646,6 @@ static void texture_prescale(d3d_info *d3d, d3d_texture_info *texture)
}
//============================================================
// texture_find
//============================================================
static d3d_texture_info *texture_find(d3d_info *d3d, const render_primitive *prim)
{
UINT32 texhash = texture_compute_hash(&prim->texture, prim->flags);
d3d_texture_info *texture;
// find a match
for (texture = d3d->texlist; texture != NULL; texture = texture->next)
{
UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1;
UINT32 test_page = (UINT32)texture->texinfo.osddata & 1;
UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1;
UINT32 prim_page = (UINT32)prim->texture.osddata & 1;
if (test_screen != prim_screen || test_page != prim_page)
{
continue;
}
if (texture->hash == texhash &&
texture->texinfo.base == prim->texture.base &&
texture->texinfo.width == prim->texture.width &&
texture->texinfo.height == prim->texture.height &&
((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0)
{
// Reject a texture if it belongs to an out-of-date render target, so as to cause the HLSL system to re-cache
if (d3d->hlsl->enabled() && prim->texture.width != 0 && prim->texture.height != 0 && (prim->flags & PRIMFLAG_SCREENTEX_MASK) != 0)
{
if (d3d->hlsl->find_render_target(texture) != NULL)
{
return texture;
}
}
else
{
return texture;
}
}
}
// nothing found, check if we need to unregister something with hlsl
if (d3d->hlsl->enabled())
{
if (prim->texture.width == 0 || prim->texture.height == 0)
{
return NULL;
}
UINT32 prim_screen = (UINT32)prim->texture.osddata >> 1;
UINT32 prim_page = (UINT32)prim->texture.osddata & 1;
for (texture = d3d->texlist; texture != NULL; texture = texture->next)
{
UINT32 test_screen = (UINT32)texture->texinfo.osddata >> 1;
UINT32 test_page = (UINT32)texture->texinfo.osddata & 1;
if (test_screen != prim_screen || test_page != prim_page)
{
continue;
}
// Clear our old texture reference
if (texture->hash == texhash &&
texture->texinfo.base == prim->texture.base &&
((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0 &&
(texture->texinfo.width != prim->texture.width ||
texture->texinfo.height != prim->texture.height))
{
d3d->hlsl->remove_render_target(texture);
break;
}
}
}
return NULL;
}
//============================================================
// texture_update
//============================================================
static void texture_update(d3d_info *d3d, const render_primitive *prim)
{
d3d_texture_info *texture = texture_find(d3d, prim);
// if we didn't find one, create a new texture
if (texture == NULL)
{
texture = texture_create(d3d, &prim->texture, prim->flags);
}
// if we found it, but with a different seqid, copy the data
if (texture->texinfo.seqid != prim->texture.seqid)
{
texture_set_data(d3d, texture, &prim->texture, prim->flags);
texture->texinfo.seqid = prim->texture.seqid;
}
}
//============================================================
// d3d_cache_target::~d3d_cache_target
//============================================================

View File

@ -145,7 +145,7 @@ struct d3d_info
bool restarting; // if we're restarting
d3d_texture_info * texlist; // list of active textures
d3d::texture_info * texlist; // list of active textures
int dynamic_supported; // are dynamic textures supported?
int stretch_supported; // is StretchRect with point filtering supported?
int mod2x_supported; // is D3DTOP_MODULATE2X supported?
@ -158,7 +158,7 @@ struct d3d_info
DWORD texture_max_width; // texture maximum width
DWORD texture_max_height; // texture maximum height
d3d_texture_info * last_texture; // previous texture
d3d::texture_info * last_texture; // previous texture
UINT32 last_texture_flags; // previous texture flags
int last_blendenable; // previous blendmode
int last_blendop; // previous blendmode
@ -169,22 +169,13 @@ struct d3d_info
DWORD last_modmode; // previous texture modulation
bitmap_argb32 vector_bitmap; // experimental: bitmap for vectors
d3d_texture_info * vector_texture; // experimental: texture for vectors
d3d::texture_info * vector_texture; // experimental: texture for vectors
bitmap_rgb32 default_bitmap; // experimental: default bitmap
d3d_texture_info * default_texture; // experimental: default texture
d3d::texture_info * default_texture; // experimental: default texture
void * hlsl_buf; // HLSL vertex data
hlsl_info * hlsl; // HLSL interface
};
//============================================================
// PROTOTYPES
//============================================================
d3d_texture_info *texture_create(d3d_info *d3d, const render_texinfo *texsource, UINT32 flags);
void texture_destroy(d3d_info *d3d, d3d_texture_info *info);
#endif