mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 10:51:52 -04:00
(D3D9) Cleanups
This commit is contained in:
parent
eaf98919a9
commit
609c56b7cd
6 changed files with 44 additions and 113 deletions
|
@ -62,6 +62,13 @@ static dylib_t g_d3d9x_dll;
|
|||
static bool d3d9_dylib_initialized = false;
|
||||
#endif
|
||||
|
||||
struct d3d9_texture_info
|
||||
{
|
||||
void *userdata;
|
||||
void *data;
|
||||
enum texture_filter_type type;
|
||||
};
|
||||
|
||||
typedef IDirect3D9 *(__stdcall *D3D9Create_t)(UINT);
|
||||
#ifdef HAVE_D3DX
|
||||
typedef HRESULT (__stdcall
|
||||
|
@ -1063,9 +1070,9 @@ void d3d9_overlay_render(d3d9_video_t *d3d,
|
|||
vert[2].v = overlay->tex_coords[1] + overlay->tex_coords[3];
|
||||
vert[3].v = overlay->tex_coords[1] + overlay->tex_coords[3];
|
||||
|
||||
verts = d3d9_vertex_buffer_lock((LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf);
|
||||
IDirect3DVertexBuffer9_Lock((LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf, 0, 0, &verts, 0);
|
||||
memcpy(verts, vert, sizeof(vert));
|
||||
d3d9_vertex_buffer_unlock((LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf);
|
||||
IDirect3DVertexBuffer9_Unlock((LPDIRECT3DVERTEXBUFFER9)overlay->vert_buf);
|
||||
|
||||
IDirect3DDevice9_SetRenderState(d3d->dev, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||
IDirect3DDevice9_SetRenderState(d3d->dev, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||
|
@ -1203,8 +1210,8 @@ void d3d9_set_menu_texture_frame(void *data,
|
|||
|
||||
d3d->menu->alpha_mod = alpha;
|
||||
|
||||
if (d3d9_lock_rectangle((LPDIRECT3DTEXTURE9)d3d->menu->tex, 0, &d3dlr,
|
||||
NULL, 0, D3DLOCK_NOSYSLOCK))
|
||||
IDirect3DTexture9_LockRect((LPDIRECT3DTEXTURE9)d3d->menu->tex,
|
||||
0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
||||
{
|
||||
unsigned h, w;
|
||||
if (rgb32)
|
||||
|
@ -1224,7 +1231,9 @@ void d3d9_set_menu_texture_frame(void *data,
|
|||
uint32_t *dst = (uint32_t*)d3dlr.pBits;
|
||||
const uint16_t *src = (const uint16_t*)frame;
|
||||
|
||||
for (h = 0; h < height; h++, dst += d3dlr.Pitch >> 2, src += width)
|
||||
for (h = 0; h < height; h++,
|
||||
dst += d3dlr.Pitch >> 2,
|
||||
src += width)
|
||||
{
|
||||
for (w = 0; w < width; w++)
|
||||
{
|
||||
|
@ -1241,10 +1250,9 @@ void d3d9_set_menu_texture_frame(void *data,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (d3d->menu)
|
||||
IDirect3DTexture9_UnlockRect((LPDIRECT3DTEXTURE9)d3d->menu->tex, 0);
|
||||
}
|
||||
|
||||
IDirect3DTexture9_UnlockRect((LPDIRECT3DTEXTURE9)d3d->menu->tex, 0);
|
||||
}
|
||||
|
||||
void d3d9_set_menu_texture_enable(void *data,
|
||||
|
@ -1259,13 +1267,6 @@ void d3d9_set_menu_texture_enable(void *data,
|
|||
d3d->menu->fullscreen = full_screen;
|
||||
}
|
||||
|
||||
struct d3d9_texture_info
|
||||
{
|
||||
void *userdata;
|
||||
void *data;
|
||||
enum texture_filter_type type;
|
||||
};
|
||||
|
||||
static void d3d9_video_texture_load_d3d(
|
||||
struct d3d9_texture_info *info,
|
||||
uintptr_t *id)
|
||||
|
@ -1291,23 +1292,18 @@ static void d3d9_video_texture_load_d3d(
|
|||
NULL, NULL, want_mipmap);
|
||||
|
||||
if (!tex)
|
||||
{
|
||||
RARCH_ERR("[D3D9]: Failed to create texture\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (d3d9_lock_rectangle(tex, 0, &d3dlr,
|
||||
NULL, 0, D3DLOCK_NOSYSLOCK))
|
||||
IDirect3DTexture9_LockRect(tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
||||
{
|
||||
unsigned i;
|
||||
uint32_t *dst = (uint32_t*)(d3dlr.pBits);
|
||||
const uint32_t *src = ti->pixels;
|
||||
unsigned pitch = d3dlr.Pitch >> 2;
|
||||
|
||||
for (i = 0; i < ti->height; i++, dst += pitch, src += ti->width)
|
||||
memcpy(dst, src, ti->width << 2);
|
||||
IDirect3DTexture9_UnlockRect(tex, 0);
|
||||
}
|
||||
IDirect3DTexture9_UnlockRect(tex, 0);
|
||||
|
||||
*id = (uintptr_t)tex;
|
||||
}
|
||||
|
@ -1518,24 +1514,26 @@ void d3d9_blit_to_texture(
|
|||
unsigned last_width, unsigned last_height,
|
||||
unsigned pitch, unsigned pixel_size)
|
||||
{
|
||||
D3DLOCKED_RECT d3dlr = {0, NULL};
|
||||
unsigned y;
|
||||
D3DLOCKED_RECT d3dlr;
|
||||
d3dlr.Pitch = 0;
|
||||
d3dlr.pBits = NULL;
|
||||
|
||||
if (
|
||||
(last_width != width || last_height != height)
|
||||
)
|
||||
if ((last_width != width || last_height != height))
|
||||
{
|
||||
d3d9_lock_rectangle(tex, 0, &d3dlr,
|
||||
NULL, tex_height, D3DLOCK_NOSYSLOCK);
|
||||
d3d9_lock_rectangle_clear(tex, 0, &d3dlr,
|
||||
NULL, tex_height, D3DLOCK_NOSYSLOCK);
|
||||
IDirect3DTexture9_LockRect(tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
||||
memset(d3dlr.pBits, 0, tex_height * d3dlr.Pitch);
|
||||
IDirect3DTexture9_UnlockRect((LPDIRECT3DTEXTURE9)tex, 0);
|
||||
}
|
||||
|
||||
if (d3d9_lock_rectangle(tex, 0, &d3dlr, NULL, 0, 0))
|
||||
IDirect3DTexture9_LockRect(tex, 0, &d3dlr, NULL, 0);
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
d3d9_texture_blit(pixel_size, tex,
|
||||
&d3dlr, frame, width, height, pitch);
|
||||
IDirect3DTexture9_UnlockRect(tex, 0);
|
||||
const uint8_t *in = (const uint8_t*)frame + y * pitch;
|
||||
uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch;
|
||||
memcpy(out, in, width * pixel_size);
|
||||
}
|
||||
IDirect3DTexture9_UnlockRect(tex, 0);
|
||||
}
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
|
@ -1622,17 +1620,15 @@ static bool d3d9_overlay_load(void *data,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (d3d9_lock_rectangle((LPDIRECT3DTEXTURE9)overlay->tex, 0, &d3dlr,
|
||||
NULL, 0, D3DLOCK_NOSYSLOCK))
|
||||
IDirect3DTexture9_LockRect((LPDIRECT3DTEXTURE9)overlay->tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK);
|
||||
{
|
||||
uint32_t *dst = (uint32_t*)(d3dlr.pBits);
|
||||
const uint32_t *src = images[i].pixels;
|
||||
unsigned pitch = d3dlr.Pitch >> 2;
|
||||
|
||||
for (y = 0; y < height; y++, dst += pitch, src += width)
|
||||
memcpy(dst, src, width << 2);
|
||||
IDirect3DTexture9_UnlockRect((LPDIRECT3DTEXTURE9)overlay->tex, 0);
|
||||
}
|
||||
IDirect3DTexture9_UnlockRect((LPDIRECT3DTEXTURE9)overlay->tex, 0);
|
||||
|
||||
overlay->tex_w = width;
|
||||
overlay->tex_h = height;
|
||||
|
|
|
@ -87,21 +87,6 @@ void *d3d9_vertex_buffer_new(void *dev,
|
|||
unsigned length, unsigned usage, unsigned fvf,
|
||||
INT32 pool, void *handle);
|
||||
|
||||
static INLINE void *d3d9_vertex_buffer_lock(LPDIRECT3DVERTEXBUFFER9 vertbuf)
|
||||
{
|
||||
void *buf = NULL;
|
||||
if (!vertbuf)
|
||||
return NULL;
|
||||
IDirect3DVertexBuffer9_Lock(vertbuf, 0, 0, &buf, 0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static INLINE void d3d9_vertex_buffer_unlock(LPDIRECT3DVERTEXBUFFER9 vertbuf)
|
||||
{
|
||||
if (vertbuf)
|
||||
IDirect3DVertexBuffer9_Unlock(vertbuf);
|
||||
}
|
||||
|
||||
void d3d9_vertex_buffer_free(void *vertex_data, void *vertex_declaration);
|
||||
|
||||
static INLINE bool d3d9_texture_get_surface_level(
|
||||
|
@ -135,36 +120,6 @@ static INLINE void d3d9_set_stream_source(
|
|||
stride);
|
||||
}
|
||||
|
||||
static INLINE bool d3d9_lock_rectangle(
|
||||
LPDIRECT3DTEXTURE9 tex,
|
||||
unsigned level,
|
||||
D3DLOCKED_RECT *lr,
|
||||
const RECT *rect,
|
||||
unsigned rectangle_height, unsigned flags)
|
||||
{
|
||||
if (!tex)
|
||||
return false;
|
||||
#ifdef _XBOX
|
||||
IDirect3DTexture9_LockRect(tex, level, lr, rect, flags);
|
||||
#else
|
||||
if (IDirect3DTexture9_LockRect(tex, level, lr, rect, flags) != D3D_OK)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static INLINE void d3d9_lock_rectangle_clear(void *tex,
|
||||
unsigned level, D3DLOCKED_RECT *lr, RECT *rect,
|
||||
unsigned rectangle_height, unsigned flags)
|
||||
{
|
||||
#if defined(_XBOX)
|
||||
level = 0;
|
||||
#endif
|
||||
memset(lr->pBits, level, rectangle_height * lr->Pitch);
|
||||
IDirect3DTexture9_UnlockRect((LPDIRECT3DTEXTURE9)tex, 0);
|
||||
}
|
||||
|
||||
static INLINE bool d3d9_create_vertex_shader(
|
||||
LPDIRECT3DDEVICE9 dev, const DWORD *a, void **b)
|
||||
{
|
||||
|
@ -184,22 +139,6 @@ static INLINE bool d3d9_create_pixel_shader(
|
|||
return false;
|
||||
}
|
||||
|
||||
static INLINE void d3d9_texture_blit(
|
||||
unsigned pixel_size,
|
||||
void *tex,
|
||||
D3DLOCKED_RECT *lr, const void *frame,
|
||||
unsigned width, unsigned height, unsigned pitch)
|
||||
{
|
||||
unsigned y;
|
||||
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
const uint8_t *in = (const uint8_t*)frame + y * pitch;
|
||||
uint8_t *out = (uint8_t*)lr->pBits + y * lr->Pitch;
|
||||
memcpy(out, in, width * pixel_size);
|
||||
}
|
||||
}
|
||||
|
||||
static INLINE bool d3d9_vertex_declaration_new(
|
||||
LPDIRECT3DDEVICE9 dev,
|
||||
const void *vertex_data, void **decl_data)
|
||||
|
|
|
@ -1012,9 +1012,9 @@ static INLINE void d3d9_cg_renderchain_set_vertices_on_change(
|
|||
vert[i].y += 0.5f;
|
||||
}
|
||||
|
||||
verts = d3d9_vertex_buffer_lock(pass->vertex_buf);
|
||||
IDirect3DVertexBuffer9_Lock(pass->vertex_buf, 0, 0, &verts, 0);
|
||||
memcpy(verts, vert, sizeof(vert));
|
||||
d3d9_vertex_buffer_unlock(pass->vertex_buf);
|
||||
IDirect3DVertexBuffer9_Unlock(pass->vertex_buf);
|
||||
}
|
||||
|
||||
static void d3d9_cg_renderchain_set_vertices(
|
||||
|
|
|
@ -424,9 +424,9 @@ static INLINE void d3d9_hlsl_renderchain_set_vertices_on_change(
|
|||
}
|
||||
*/
|
||||
|
||||
verts = d3d9_vertex_buffer_lock(pass->vertex_buf);
|
||||
IDirect3DVertexBuffer9_Lock(pass->vertex_buf, 0, 0, &verts, 0);
|
||||
memcpy(verts, vert, sizeof(vert));
|
||||
d3d9_vertex_buffer_unlock(pass->vertex_buf);
|
||||
IDirect3DVertexBuffer9_Unlock(pass->vertex_buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -126,10 +126,8 @@ static void gfx_display_d3d9_cg_draw(gfx_display_ctx_draw_t *draw,
|
|||
> (unsigned)d3d->menu_display.size)
|
||||
return;
|
||||
|
||||
pv = (Vertex*)
|
||||
d3d9_vertex_buffer_lock((LPDIRECT3DVERTEXBUFFER9)
|
||||
d3d->menu_display.buffer);
|
||||
|
||||
IDirect3DVertexBuffer9_Lock((LPDIRECT3DVERTEXBUFFER9)
|
||||
d3d->menu_display.buffer, 0, 0, (void**)&pv, 0);
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
|
@ -166,7 +164,7 @@ static void gfx_display_d3d9_cg_draw(gfx_display_ctx_draw_t *draw,
|
|||
colors[2] /* B */
|
||||
);
|
||||
}
|
||||
d3d9_vertex_buffer_unlock((LPDIRECT3DVERTEXBUFFER9)
|
||||
IDirect3DVertexBuffer9_Unlock((LPDIRECT3DVERTEXBUFFER9)
|
||||
d3d->menu_display.buffer);
|
||||
|
||||
if (!draw->matrix_data)
|
||||
|
|
|
@ -145,10 +145,8 @@ static void gfx_display_d3d9_hlsl_draw(gfx_display_ctx_draw_t *draw,
|
|||
> (unsigned)d3d->menu_display.size)
|
||||
return;
|
||||
|
||||
pv = (Vertex*)
|
||||
d3d9_vertex_buffer_lock((LPDIRECT3DVERTEXBUFFER9)
|
||||
d3d->menu_display.buffer);
|
||||
|
||||
IDirect3DVertexBuffer9_Lock((LPDIRECT3DVERTEXBUFFER9)
|
||||
d3d->menu_display.buffer, 0, 0, (void**)&pv, 0);
|
||||
if (!pv)
|
||||
return;
|
||||
|
||||
|
@ -185,7 +183,7 @@ static void gfx_display_d3d9_hlsl_draw(gfx_display_ctx_draw_t *draw,
|
|||
colors[2] /* B */
|
||||
);
|
||||
}
|
||||
d3d9_vertex_buffer_unlock((LPDIRECT3DVERTEXBUFFER9)
|
||||
IDirect3DVertexBuffer9_Unlock((LPDIRECT3DVERTEXBUFFER9)
|
||||
d3d->menu_display.buffer);
|
||||
|
||||
if (!draw->matrix_data)
|
||||
|
|
Loading…
Add table
Reference in a new issue