From 684374eec898bf8049063740d30893e624959ee4 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 25 Jan 2018 10:03:34 +0100 Subject: [PATCH] Remove D3DVIEWPORT dependency --- gfx/common/d3d_common.c | 4 +- gfx/common/d3d_common.h | 2 +- gfx/drivers/d3d.h | 12 ++++- gfx/drivers/d3d8.c | 35 +++++++-------- gfx/drivers/d3d9.c | 20 ++++----- gfx/drivers_renderchain/d3d9_cg_renderchain.c | 44 +++++++++---------- 6 files changed, 62 insertions(+), 55 deletions(-) diff --git a/gfx/common/d3d_common.c b/gfx/common/d3d_common.c index bfae08d679..f2ff2fa659 100644 --- a/gfx/common/d3d_common.c +++ b/gfx/common/d3d_common.c @@ -1767,7 +1767,7 @@ void d3d_lock_rectangle_clear(void *tex, d3d_unlock_rectangle(tex); } -void d3d_set_viewports(void *_dev, D3DVIEWPORT *vp) +void d3d_set_viewports(void *_dev, void *_vp) { switch (d3d_common_api) { @@ -1775,6 +1775,7 @@ void d3d_set_viewports(void *_dev, D3DVIEWPORT *vp) { #ifdef HAVE_D3D9 LPDIRECT3DDEVICE9 dev = (LPDIRECT3DDEVICE9)_dev; + D3DVIEWPORT9 *vp = (D3DVIEWPORT9*)_vp; if (!dev) return; #ifdef __cplusplus @@ -1789,6 +1790,7 @@ void d3d_set_viewports(void *_dev, D3DVIEWPORT *vp) { #ifdef HAVE_D3D8 LPDIRECT3DDEVICE8 dev = (LPDIRECT3DDEVICE8)_dev; + D3DVIEWPORT8 *vp = (D3DVIEWPORT8*)_vp; if (!dev) return; #ifdef __cplusplus diff --git a/gfx/common/d3d_common.h b/gfx/common/d3d_common.h index 27c478661d..c9ae413557 100644 --- a/gfx/common/d3d_common.h +++ b/gfx/common/d3d_common.h @@ -130,7 +130,7 @@ bool d3d_vertex_declaration_new(void *dev, void d3d_vertex_declaration_free(void *data); -void d3d_set_viewports(void *dev, D3DVIEWPORT *vp); +void d3d_set_viewports(void *dev, void *vp); void d3d_enable_blend_func(void *data); diff --git a/gfx/drivers/d3d.h b/gfx/drivers/d3d.h index eb529a95ab..ed3f84222e 100644 --- a/gfx/drivers/d3d.h +++ b/gfx/drivers/d3d.h @@ -63,6 +63,16 @@ typedef struct Vertex float u, v; } Vertex; +typedef struct d3d_video_viewport +{ + DWORD x; + DWORD y; + DWORD width; + DWORD height; + float min_z; + float max_z; +} d3d_video_viewport_t; + typedef struct d3d_video { bool keep_aspect; @@ -93,7 +103,7 @@ typedef struct d3d_video video_info_t video_info; WNDCLASSEX windowClass; void *dev; - D3DVIEWPORT final_viewport; + d3d_video_viewport_t final_viewport; char *shader_path; diff --git a/gfx/drivers/d3d8.c b/gfx/drivers/d3d8.c index 6e38dc3d78..38ea181231 100644 --- a/gfx/drivers/d3d8.c +++ b/gfx/drivers/d3d8.c @@ -246,10 +246,10 @@ static void d3d8_renderchain_viewport_info(void *data, video_driver_get_size(&width, &height); - vp->x = d3d->final_viewport.X; - vp->y = d3d->final_viewport.Y; - vp->width = d3d->final_viewport.Width; - vp->height = d3d->final_viewport.Height; + vp->x = d3d->final_viewport.x; + vp->y = d3d->final_viewport.y; + vp->width = d3d->final_viewport.width; + vp->height = d3d->final_viewport.height; vp->full_width = width; vp->full_height = height; @@ -261,6 +261,7 @@ static void d3d8_renderchain_render_pass( unsigned pass_index, unsigned rotation) { + D3DVIEWPORT8 vp; settings_t *settings = config_get_ptr(); d3d_set_texture(d3dr, 0, chain->tex); @@ -269,7 +270,7 @@ static void d3d8_renderchain_render_pass( d3d_set_sampler_minfilter(d3dr, pass_index, settings->bools.video_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - d3d_set_viewports(chain->dev, &d3d->final_viewport); + d3d_set_viewports(chain->dev, (D3DVIEWPORT8*)&d3d->final_viewport); d3d_set_vertex_shader(d3dr, D3DFVF_CUSTOMVERTEX, NULL); d3d_set_stream_source(d3dr, 0, chain->vertex_buf, 0, sizeof(Vertex)); d3d8_renderchain_set_mvp(d3d, chain, NULL, &d3d->mvp_rotate); @@ -297,7 +298,6 @@ static bool d3d8_renderchain_render(void *data, const void *frame, static bool d3d8_renderchain_init(void *data, const void *_video_info, void *dev_data, - const void *final_viewport_data, const void *info_data, bool rgb32 ) @@ -310,7 +310,6 @@ static bool d3d8_renderchain_init(void *data, d3d8_renderchain_t *chain = (d3d8_renderchain_t*)d3d->renderchain_data; unsigned fmt = (rgb32) ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565; struct video_viewport *custom_vp = video_viewport_get_custom(); - (void)final_viewport_data; video_driver_get_size(&width, &height); @@ -365,7 +364,7 @@ static bool d3d8_init_chain(d3d_video_t *d3d, const video_info_t *video_info) !d3d8_renderchain_init( d3d, &d3d->video_info, - d3d->dev, &d3d->final_viewport, &link_info, + d3d->dev, &link_info, d3d->video_info.rgb32) ) { @@ -425,6 +424,7 @@ static void d3d8_overlay_render(d3d_video_t *d3d, video_frame_info_t *video_info, overlay_t *overlay) { + D3DVIEWPORT8 vp_full; struct video_viewport vp; void *verts; unsigned i; @@ -483,7 +483,6 @@ static void d3d8_overlay_render(d3d_video_t *d3d, if (overlay->fullscreen) { - D3DVIEWPORT vp_full; vp_full.X = 0; vp_full.Y = 0; @@ -504,6 +503,7 @@ static void d3d8_overlay_render(d3d_video_t *d3d, /* Restore previous state. */ d3d_disable_blend_func(d3d->dev); + d3d_set_viewports(d3d->dev, &d3d->final_viewport); } @@ -799,7 +799,6 @@ static void d3d8_set_viewport(void *data, bool allow_rotate) { D3DMATRIX proj, ortho, rot, matrix; - D3DVIEWPORT viewport; int x = 0; int y = 0; d3d_video_t *d3d = (d3d_video_t*)data; @@ -813,14 +812,12 @@ static void d3d8_set_viewport(void *data, if (y < 0) y = 0; - viewport.X = x; - viewport.Y = y; - viewport.Width = width; - viewport.Height = height; - viewport.MinZ = 0.0f; - viewport.MaxZ = 1.0f; - - d3d->final_viewport = viewport; + d3d->final_viewport.x = x; + d3d->final_viewport.y = y; + d3d->final_viewport.width = width; + d3d->final_viewport.height= height; + d3d->final_viewport.min_z = 0.0f; + d3d->final_viewport.max_z = 0.0f; d3d_matrix_ortho_off_center_lh(&ortho, 0, 1, 0, 1, 0.0f, 1.0f); d3d_matrix_identity(&rot); @@ -1426,7 +1423,7 @@ static bool d3d8_frame(void *data, const void *frame, uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info) { - D3DVIEWPORT screen_vp; + D3DVIEWPORT8 screen_vp; unsigned i = 0; d3d_video_t *d3d = (d3d_video_t*)data; unsigned width = video_info->width; diff --git a/gfx/drivers/d3d9.c b/gfx/drivers/d3d9.c index 21a80203d4..7c59a52580 100644 --- a/gfx/drivers/d3d9.c +++ b/gfx/drivers/d3d9.c @@ -411,7 +411,7 @@ static void d3d9_overlay_render(d3d_video_t *d3d, if (overlay->fullscreen) { - D3DVIEWPORT vp_full; + D3DVIEWPORT9 vp_full; vp_full.X = 0; vp_full.Y = 0; @@ -722,7 +722,7 @@ static void d3d9_set_viewport(void *data, bool force_full, bool allow_rotate) { - D3DVIEWPORT viewport; + D3DVIEWPORT9 viewport; int x = 0; int y = 0; d3d_video_t *d3d = (d3d_video_t*)data; @@ -736,14 +736,12 @@ static void d3d9_set_viewport(void *data, if (y < 0) y = 0; - viewport.X = x; - viewport.Y = y; - viewport.Width = width; - viewport.Height = height; - viewport.MinZ = 0.0f; - viewport.MaxZ = 1.0f; - - d3d->final_viewport = viewport; + d3d->final_viewport.x = x; + d3d->final_viewport.y = y; + d3d->final_viewport.width = width; + d3d->final_viewport.height = height; + d3d->final_viewport.min_z = 0.0f; + d3d->final_viewport.max_z = 1.0f; if (d3d->renderchain_driver && d3d->renderchain_driver->set_font_rect) d3d->renderchain_driver->set_font_rect(d3d, NULL); @@ -1384,7 +1382,7 @@ static bool d3d9_frame(void *data, const void *frame, uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info) { - D3DVIEWPORT screen_vp; + D3DVIEWPORT9 screen_vp; unsigned i = 0; d3d_video_t *d3d = (d3d_video_t*)data; unsigned width = video_info->width; diff --git a/gfx/drivers_renderchain/d3d9_cg_renderchain.c b/gfx/drivers_renderchain/d3d9_cg_renderchain.c index fc2be9f33f..0c5785cae6 100644 --- a/gfx/drivers_renderchain/d3d9_cg_renderchain.c +++ b/gfx/drivers_renderchain/d3d9_cg_renderchain.c @@ -112,7 +112,7 @@ typedef struct cg_renderchain void *dev; const video_info_t *video_info; state_tracker_t *state_tracker; - D3DVIEWPORT *final_viewport; + D3DVIEWPORT9 *final_viewport; CGcontext cgCtx; struct pass_vector_list *passes; struct lut_info_vector_list *luts; @@ -913,7 +913,7 @@ static bool d3d9_cg_renderchain_init(void *data, chain->dev = (void*)dev_; chain->video_info = video_info; chain->state_tracker = NULL; - chain->final_viewport = (D3DVIEWPORT*)final_viewport_; + chain->final_viewport = (D3DVIEWPORT9*)final_viewport_; chain->frame_count = 0; chain->pixel_size = (fmt == RETRO_PIXEL_FORMAT_RGB565) ? 2 : 4; @@ -971,9 +971,9 @@ static void d3d9_cg_renderchain_convert_geometry( unsigned height, void *final_viewport_data) { - const struct LinkInfo *info = (const struct LinkInfo*)info_data; - cg_renderchain_t *chain = (cg_renderchain_t*)data; - D3DVIEWPORT *final_viewport = (D3DVIEWPORT*)final_viewport_data; + const struct LinkInfo *info = (const struct LinkInfo*)info_data; + cg_renderchain_t *chain = (cg_renderchain_t*)data; + D3DVIEWPORT9 *final_viewport = (D3DVIEWPORT9*)final_viewport_data; if (!chain || !info) return; @@ -1059,12 +1059,12 @@ static void d3d9_cg_renderchain_set_final_viewport( void *renderchain_data, const void *viewport_data) { - d3d_video_t *d3d = (d3d_video_t*)data; + d3d_video_t *d3d = (d3d_video_t*)data; cg_renderchain_t *chain = (cg_renderchain_t*)renderchain_data; - const D3DVIEWPORT *final_viewport = (const D3DVIEWPORT*)viewport_data; + const D3DVIEWPORT9 *final_viewport = (const D3DVIEWPORT9*)viewport_data; - if (chain) - chain->final_viewport = (D3DVIEWPORT*)final_viewport; + if (chain && final_viewport) + chain->final_viewport = (D3DVIEWPORT9*)final_viewport; d3d_recompute_pass_sizes(chain, d3d); } @@ -1324,7 +1324,7 @@ static void cg_d3d9_renderchain_set_vertices( static void cg_d3d9_renderchain_set_viewport( cg_renderchain_t *chain, - D3DVIEWPORT *vp) + D3DVIEWPORT9 *vp) { d3d_set_viewports(chain->dev, vp); } @@ -1505,9 +1505,9 @@ static bool d3d9_cg_renderchain_render( /* In-between render target passes. */ for (i = 0; i < chain->passes->count - 1; i++) { - D3DVIEWPORT viewport = {0}; - struct Pass *from_pass = (struct Pass*)&chain->passes->data[i]; - struct Pass *to_pass = (struct Pass*)&chain->passes->data[i + 1]; + D3DVIEWPORT9 viewport = {0}; + struct Pass *from_pass = (struct Pass*)&chain->passes->data[i]; + struct Pass *to_pass = (struct Pass*)&chain->passes->data[i + 1]; d3d_texture_get_surface_level(to_pass->tex, 0, (void**)&target); @@ -1653,13 +1653,13 @@ static bool d3d9_cg_renderchain_read_viewport( unsigned pitchpix = rect.Pitch / 4; const uint32_t *pixels = (const uint32_t*)rect.pBits; - pixels += d3d->final_viewport.X; - pixels += (d3d->final_viewport.Height - 1) * pitchpix; - pixels -= d3d->final_viewport.Y * pitchpix; + pixels += d3d->final_viewport.x; + pixels += (d3d->final_viewport.height - 1) * pitchpix; + pixels -= d3d->final_viewport.y * pitchpix; - for (y = 0; y < d3d->final_viewport.Height; y++, pixels -= pitchpix) + for (y = 0; y < d3d->final_viewport.height; y++, pixels -= pitchpix) { - for (x = 0; x < d3d->final_viewport.Width; x++) + for (x = 0; x < d3d->final_viewport.width; x++) { *buffer++ = (pixels[x] >> 0) & 0xff; *buffer++ = (pixels[x] >> 8) & 0xff; @@ -1691,10 +1691,10 @@ static void d3d9_cg_renderchain_viewport_info( video_driver_get_size(&width, &height); - vp->x = d3d->final_viewport.X; - vp->y = d3d->final_viewport.Y; - vp->width = d3d->final_viewport.Width; - vp->height = d3d->final_viewport.Height; + vp->x = d3d->final_viewport.x; + vp->y = d3d->final_viewport.y; + vp->width = d3d->final_viewport.width; + vp->height = d3d->final_viewport.height; vp->full_width = width; vp->full_height = height;