Skip to content

Commit

Permalink
(XDK1) Aspect ratios/integer scaling works correctly now
Browse files Browse the repository at this point in the history
  • Loading branch information
twinaphex committed Mar 5, 2014
1 parent c94bb7d commit 7331fd3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
25 changes: 20 additions & 5 deletions xdk/xdk_d3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static void xdk_d3d_set_viewport(void *data, int x, int y, unsigned width, unsig
viewport.Y = y;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
RD3DDevice_SetViewport(d3d->dev, &viewport);
d3d->final_viewport = viewport;
}

static void xdk_d3d_calculate_rect(void *data, unsigned width, unsigned height,
Expand Down Expand Up @@ -628,7 +628,9 @@ static void xdk_d3d_draw_texture(void *data)
static void clear_texture(void *data)
{
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
LPDIRECT3DDEVICE d3dr = d3d->dev;
D3DLOCKED_RECT d3dlr;

D3DTexture_LockRect(d3d->lpTexture, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
memset(d3dlr.pBits, 0, d3d->tex_w * d3dlr.Pitch);
}
Expand Down Expand Up @@ -713,7 +715,8 @@ static void set_vertices(void *data, unsigned pass, unsigned width, unsigned hei
}
}

static void render_pass(void *data, unsigned pass_index)
static void render_pass(void *data, const void *frame, unsigned width, unsigned height,
unsigned pitch, unsigned rotation)
{
xdk_d3d_video_t *d3d = (xdk_d3d_video_t*)data;
LPDIRECT3DDEVICE d3dr = d3d->dev;
Expand All @@ -722,7 +725,11 @@ static void render_pass(void *data, unsigned pass_index)
UINT64 pendingMask3;
#endif

blit_to_texture(d3d, frame, width, height, pitch);
set_vertices(d3d, 1, width, height);

RD3DDevice_SetTexture(d3dr, 0, d3d->lpTexture);
RD3DDevice_SetViewport(d3d->dev, &d3d->final_viewport);
RD3DDevice_SetSamplerState_MinFilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
RD3DDevice_SetSamplerState_MagFilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
RD3DDevice_SetSamplerState_AddressU(d3dr, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
Expand Down Expand Up @@ -757,8 +764,16 @@ static bool xdk_d3d_frame(void *data, const void *frame,
d3d->should_resize = false;
}

blit_to_texture(d3d, frame, width, height, pitch);
set_vertices(d3d, 1, width, height);
// render_chain() only clears out viewport, clear out everything
D3DVIEWPORT screen_vp;
screen_vp.X = 0;
screen_vp.Y = 0;
screen_vp.MinZ = 0;
screen_vp.MaxZ = 1;
screen_vp.Width = d3d->screen_width;
screen_vp.Height = d3d->screen_height;
d3dr->SetViewport(&screen_vp);
d3dr->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0);

// Insert black frame first, so we can screenshot, etc.
if (g_settings.video.black_frame_insertion)
Expand All @@ -767,7 +782,7 @@ static bool xdk_d3d_frame(void *data, const void *frame,
d3dr->Clear(0, 0, D3DCLEAR_TARGET, 0, 1, 0);
}

render_pass(d3d, 1);
render_pass(d3d, frame, width, height, pitch, d3d->dev_rotation);

#ifdef HAVE_MENU
#ifdef HAVE_RMENU_XUI
Expand Down
1 change: 1 addition & 0 deletions xdk/xdk_d3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ typedef struct xdk_d3d_video
const d3d_font_renderer_t *font_ctx;
D3DFORMAT internal_fmt;
D3DFORMAT texture_fmt;
D3DVIEWPORT final_viewport;
unsigned base_size;
LPDIRECT3DSURFACE lpSurface;
video_info_t video_info;
Expand Down

0 comments on commit 7331fd3

Please sign in to comment.