Create common set vertices function

This commit is contained in:
twinaphex 2018-05-17 21:07:44 +02:00
parent 2011453340
commit d946cf1ee5
3 changed files with 98 additions and 159 deletions

View File

@ -874,89 +874,17 @@ static void d3d9_cg_renderchain_set_vertices(
unsigned vp_width, unsigned vp_height,
unsigned rotation)
{
const struct LinkInfo *info = (const struct LinkInfo*)&pass->info;
if (pass->last_width != width || pass->last_height != height)
{
struct D3D9Vertex vert[4];
unsigned i;
void *verts = NULL;
float _u = (float)(width) / info->tex_w;
float _v = (float)(height) / info->tex_h;
pass->last_width = width;
pass->last_height = height;
vert[0].x = 0.0f;
vert[0].y = out_height;
vert[0].z = 0.5f;
vert[0].u = 0.0f;
vert[0].v = 0.0f;
vert[0].lut_u = 0.0f;
vert[0].lut_v = 0.0f;
vert[0].r = 1.0f;
vert[0].g = 1.0f;
vert[0].b = 1.0f;
vert[0].a = 1.0f;
vert[1].x = out_width;
vert[1].y = out_height;
vert[1].z = 0.5f;
vert[1].u = _u;
vert[1].v = 0.0f;
vert[1].lut_u = 1.0f;
vert[1].lut_v = 0.0f;
vert[1].r = 1.0f;
vert[1].g = 1.0f;
vert[1].b = 1.0f;
vert[1].a = 1.0f;
vert[2].x = 0.0f;
vert[2].y = 0.0f;
vert[2].z = 0.5f;
vert[2].u = 0.0f;
vert[2].v = _v;
vert[2].lut_u = 0.0f;
vert[2].lut_v = 1.0f;
vert[2].r = 1.0f;
vert[2].g = 1.0f;
vert[2].b = 1.0f;
vert[2].a = 1.0f;
vert[3].x = out_width;
vert[3].y = 0.0f;
vert[3].z = 0.5f;
vert[3].u = _u;
vert[3].v = _v;
vert[3].lut_u = 1.0f;
vert[3].lut_v = 1.0f;
vert[3].r = 1.0f;
vert[3].g = 1.0f;
vert[3].b = 1.0f;
vert[3].a = 1.0f;
/* Align texels and vertices.
*
* Fixes infamous 'half-texel offset' issue of D3D9
* http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx.
*/
for (i = 0; i < 4; i++)
{
vert[i].x -= 0.5f;
vert[i].y += 0.5f;
}
verts = d3d9_vertex_buffer_lock(pass->vertex_buf);
memcpy(verts, vert, sizeof(vert));
d3d9_vertex_buffer_unlock(pass->vertex_buf);
}
d3d9_renderchain_set_vertices_on_change(chain,
pass, width, height, out_width, out_height,
vp_width, vp_height, rotation);
d3d9_cg_renderchain_calc_and_set_shader_mvp(
pass->vprg, vp_width, vp_height, rotation);
d3d9_cg_renderchain_set_shader_params(chain, chain->dev,
pass,
width, height,
info->tex_w, info->tex_h,
pass->info.tex_w, pass->info.tex_h,
vp_width, vp_height);
}

View File

@ -567,93 +567,20 @@ static void hlsl_d3d9_renderchain_set_vertices(
uint64_t frame_count,
unsigned rotation)
{
const struct LinkInfo *info = (const struct LinkInfo*)&pass->info;
if (pass->last_width != width || pass->last_height != height)
{
unsigned i;
struct D3D9Vertex vert[4];
void *verts = NULL;
float _u = (float)(width) / info->tex_w;
float _v = (float)(height) / info->tex_h;
pass->last_width = width;
pass->last_height = height;
vert[0].x = 0.0f;
vert[0].y = out_height;
vert[0].z = 0.5f;
vert[0].u = 0.0f;
vert[0].v = 0.0f;
vert[0].lut_u = 0.0f;
vert[0].lut_v = 0.0f;
vert[0].r = 1.0f;
vert[0].g = 1.0f;
vert[0].b = 1.0f;
vert[0].a = 1.0f;
vert[1].x = out_width;
vert[1].y = out_height;
vert[1].z = 0.5f;
vert[1].u = _u;
vert[1].v = 0.0f;
vert[1].lut_u = 1.0f;
vert[1].lut_v = 0.0f;
vert[1].r = 1.0f;
vert[1].g = 1.0f;
vert[1].b = 1.0f;
vert[1].a = 1.0f;
vert[2].x = 0.0f;
vert[2].y = 0.0f;
vert[2].z = 0.5f;
vert[2].u = 0.0f;
vert[2].v = _v;
vert[2].lut_u = 0.0f;
vert[2].lut_v = 1.0f;
vert[2].r = 1.0f;
vert[2].g = 1.0f;
vert[2].b = 1.0f;
vert[2].a = 1.0f;
vert[3].x = out_width;
vert[3].y = 0.0f;
vert[3].z = 0.5f;
vert[3].u = _u;
vert[3].v = _v;
vert[3].lut_u = 1.0f;
vert[3].lut_v = 1.0f;
vert[3].r = 1.0f;
vert[3].g = 1.0f;
vert[3].b = 1.0f;
vert[3].a = 1.0f;
#if 0
/* Align texels and vertices. */
for (i = 0; i < 4; i++)
{
vert[i].x -= 0.5f;
vert[i].y += 0.5f;
}
#endif
verts = d3d9_vertex_buffer_lock(pass->vertex_buf);
memcpy(verts, vert, sizeof(vert));
d3d9_vertex_buffer_unlock(pass->vertex_buf);
}
if (chain->shader_pipeline)
hlsl_use(chain->shader_pipeline, chain->chain.dev, pass_count, true);
d3d9_renderchain_set_vertices_on_change(&chain->chain,
pass, width, height, out_width, out_height,
vp_width, vp_height, rotation);
hlsl_use(chain->shader_pipeline, chain->chain.dev, pass_count, true);
d3d9_hlsl_renderchain_calc_and_set_shader_mvp(chain, d3d,
/*pass->vPrg, */vp_width, vp_height, rotation);
if (chain->shader_pipeline)
hlsl_d3d9_renderchain_set_shader_params(&chain->chain,
chain->shader_pipeline, chain->chain.dev,
pass,
width, height,
info->tex_w, info->tex_h,
vp_width, vp_height);
hlsl_d3d9_renderchain_set_shader_params(&chain->chain,
chain->shader_pipeline, chain->chain.dev,
pass,
width, height,
pass->info.tex_w, pass->info.tex_h,
vp_width, vp_height);
}
static void d3d9_hlsl_deinit_progs(hlsl_d3d9_renderchain_t *chain)

View File

@ -100,6 +100,90 @@ typedef struct d3d9_renderchain
struct lut_info_vector_list *luts;
} d3d9_renderchain_t;
static INLINE void d3d9_renderchain_set_vertices_on_change(
d3d9_renderchain_t *chain,
struct shader_pass *pass,
unsigned width, unsigned height,
unsigned out_width, unsigned out_height,
unsigned vp_width, unsigned vp_height,
unsigned rotation
)
{
struct D3D9Vertex vert[4];
unsigned i;
void *verts = NULL;
const struct
LinkInfo *info = (const struct LinkInfo*)&pass->info;
float _u = (float)(width) / info->tex_w;
float _v = (float)(height) / info->tex_h;
pass->last_width = width;
pass->last_height = height;
vert[0].x = 0.0f;
vert[0].y = out_height;
vert[0].z = 0.5f;
vert[0].u = 0.0f;
vert[0].v = 0.0f;
vert[0].lut_u = 0.0f;
vert[0].lut_v = 0.0f;
vert[0].r = 1.0f;
vert[0].g = 1.0f;
vert[0].b = 1.0f;
vert[0].a = 1.0f;
vert[1].x = out_width;
vert[1].y = out_height;
vert[1].z = 0.5f;
vert[1].u = _u;
vert[1].v = 0.0f;
vert[1].lut_u = 1.0f;
vert[1].lut_v = 0.0f;
vert[1].r = 1.0f;
vert[1].g = 1.0f;
vert[1].b = 1.0f;
vert[1].a = 1.0f;
vert[2].x = 0.0f;
vert[2].y = 0.0f;
vert[2].z = 0.5f;
vert[2].u = 0.0f;
vert[2].v = _v;
vert[2].lut_u = 0.0f;
vert[2].lut_v = 1.0f;
vert[2].r = 1.0f;
vert[2].g = 1.0f;
vert[2].b = 1.0f;
vert[2].a = 1.0f;
vert[3].x = out_width;
vert[3].y = 0.0f;
vert[3].z = 0.5f;
vert[3].u = _u;
vert[3].v = _v;
vert[3].lut_u = 1.0f;
vert[3].lut_v = 1.0f;
vert[3].r = 1.0f;
vert[3].g = 1.0f;
vert[3].b = 1.0f;
vert[3].a = 1.0f;
/* Align texels and vertices.
*
* Fixes infamous 'half-texel offset' issue of D3D9
* http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx.
*/
for (i = 0; i < 4; i++)
{
vert[i].x -= 0.5f;
vert[i].y += 0.5f;
}
verts = d3d9_vertex_buffer_lock(pass->vertex_buf);
memcpy(verts, vert, sizeof(vert));
d3d9_vertex_buffer_unlock(pass->vertex_buf);
}
static INLINE bool d3d9_renderchain_add_pass(d3d9_renderchain_t *chain,
struct shader_pass *pass,
const struct LinkInfo *info)