2014-09-11 21:05:58 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2014 - Daniel De Matteis
|
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
#include "d3d_wrapper.h"
|
2014-09-11 21:05:58 +00:00
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_swap(d3d_video_t *d3d, LPDIRECT3DDEVICE dev)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
|
|
|
D3DDevice_Swap(0);
|
|
|
|
#elif defined(_XBOX360)
|
|
|
|
D3DDevice_Present(dev);
|
|
|
|
#else
|
|
|
|
if (dev->Present(NULL, NULL, NULL, NULL) != D3D_OK)
|
|
|
|
{
|
|
|
|
RARCH_ERR("[D3D]: Present() failed.\n");
|
|
|
|
d3d->needs_restore = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
HRESULT d3d_create_vertex_buffer(LPDIRECT3DDEVICE dev,
|
|
|
|
unsigned length, unsigned usage, unsigned fvf,
|
2014-09-11 22:00:20 +00:00
|
|
|
D3DPOOL pool, LPDIRECT3DVERTEXBUFFER vert_buf, void *handle)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2014-09-11 21:43:01 +00:00
|
|
|
IDirect3DDevice8_CreateVertexBuffer(dev, length, usage, fvf, pool,
|
2014-09-11 21:51:23 +00:00
|
|
|
&vert_buf);
|
2014-09-11 21:05:58 +00:00
|
|
|
#elif defined(_XBOX360)
|
2014-09-11 21:43:01 +00:00
|
|
|
IDirect3DDevice9_CreateVertexBuffer(dev, length, usage, fvf, pool,
|
2014-09-11 21:51:23 +00:00
|
|
|
&vert_buf, NULL);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
2014-09-11 21:51:23 +00:00
|
|
|
dev->CreateVertexBuffer(length, usage, fvf, pool, &vert_buf, NULL);
|
2014-09-11 21:05:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_set_stream_source(LPDIRECT3DDEVICE dev, unsigned stream_no,
|
2014-09-11 21:05:58 +00:00
|
|
|
LPDIRECT3DVERTEXBUFFER stream_vertbuf, unsigned offset_bytes,
|
|
|
|
unsigned stride)
|
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2014-09-11 21:43:01 +00:00
|
|
|
IDirect3DDevice8_SetStreamSource(dev, stream_no, stream_vertbuf, stride);
|
2014-09-11 21:05:58 +00:00
|
|
|
#elif defined(_XBOX360)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3DDevice_SetStreamSource_Inline(dev, stream_no, stream_vertbuf,
|
|
|
|
offset_bytes, stride);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
|
|
|
dev->SetStreamSource(steam_no, stream_vertbuf, offset_bytes, stride);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_set_sampler_address_u(LPDIRECT3DDEVICE dev,
|
|
|
|
unsigned sampler, unsigned type, unsigned value)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3D__DirtyFlags |= (D3DDIRTYFLAG_TEXTURE_STATE_0 << sampler);
|
|
|
|
D3D__TextureState[sampler][D3DTSS_ADDRESSU] = value;
|
2014-09-11 21:05:58 +00:00
|
|
|
#elif defined(_XBOX360)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3DDevice_SetSamplerState_AddressU_Inline(dev, sampler, value);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
|
|
|
dev->SetSamplerState(sampler, D3DSAMP_ADDRESSU, type);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_set_sampler_address_v(LPDIRECT3DDEVICE dev,
|
|
|
|
unsigned sampler, unsigned type, unsigned value)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3D__DirtyFlags |= (D3DDIRTYFLAG_TEXTURE_STATE_0 << sampler);
|
|
|
|
D3D__TextureState[sampler][D3DTSS_ADDRESSV] = value;
|
2014-09-11 21:05:58 +00:00
|
|
|
#elif defined(_XBOX360)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3DDevice_SetSamplerState_AddressV_Inline(dev, sampler, value);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
|
|
|
dev->SetSamplerState(sampler, D3DSAMP_ADDRESSV, type);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_set_sampler_minfilter(LPDIRECT3DDEVICE dev,
|
|
|
|
unsigned sampler, unsigned type, unsigned value)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3D__DirtyFlags |= (D3DDIRTYFLAG_TEXTURE_STATE_0 << sampler);
|
|
|
|
D3D__TextureState[sampler][D3DTSS_MINFILTER] = value;
|
2014-09-11 21:05:58 +00:00
|
|
|
#elif defined(_XBOX360)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3DDevice_SetSamplerState_MinFilter(dev, sampler, value);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
2014-09-11 21:43:01 +00:00
|
|
|
dev->SetSamplerState(sampler, D3DSAMP_MINFILTER, type);
|
2014-09-11 21:05:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_set_sampler_magfilter(LPDIRECT3DDEVICE dev,
|
2014-09-11 22:00:20 +00:00
|
|
|
unsigned sampler, unsigned type, unsigned value)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
#if defined(_XBOX1)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3D__DirtyFlags |= (D3DDIRTYFLAG_TEXTURE_STATE_0 << sampler);
|
|
|
|
D3D__TextureState[sampler][D3DTSS_MAGFILTER] = value;
|
2014-09-11 21:05:58 +00:00
|
|
|
#elif defined(_XBOX360)
|
2014-09-11 21:43:01 +00:00
|
|
|
D3DDevice_SetSamplerState_MagFilter(dev, sampler, value);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
2014-09-11 21:43:01 +00:00
|
|
|
dev->SetSamplerState(sampler, D3DSAMP_MAGFILTER, type);
|
2014-09-11 21:05:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_draw_primitive(LPDIRECT3DDEVICE dev,
|
2014-09-11 22:00:20 +00:00
|
|
|
D3DPRIMITIVETYPE type, unsigned start, unsigned count)
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
2014-09-11 21:43:01 +00:00
|
|
|
#if defined(_XBOX1)
|
|
|
|
D3DDevice_DrawVertices(type, start, D3DVERTEXCOUNT(type, count));
|
|
|
|
#elif defined(_XBOX360)
|
|
|
|
D3DDevice_DrawVertices(dev, type, start, D3DVERTEXCOUNT(type, count));
|
|
|
|
#else
|
2014-09-11 21:05:58 +00:00
|
|
|
if (SUCCEEDED(dev->BeginScene()))
|
|
|
|
{
|
|
|
|
dev->DrawPrimitive(type, start, count);
|
|
|
|
dev->EndScene();
|
|
|
|
}
|
2014-09-11 21:43:01 +00:00
|
|
|
#endif
|
2014-09-11 21:05:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_lockrectangle_clear(LPDIRECT3DTEXTURE tex,
|
|
|
|
unsigned tex_width, unsigned tex_height,
|
2014-09-11 21:05:58 +00:00
|
|
|
unsigned level, D3DLOCKED_RECT lock_rect, RECT rect,
|
|
|
|
unsigned flags)
|
|
|
|
{
|
2014-09-11 21:43:01 +00:00
|
|
|
#if defined(_XBOX)
|
2014-09-11 22:00:20 +00:00
|
|
|
D3DTexture_LockRect(tex, level, &lock_rect, &rect, flags);
|
|
|
|
memset(lock_rect.pBits, 0, tex_height * lock_rect.Pitch);
|
2014-09-11 21:05:58 +00:00
|
|
|
#else
|
2014-09-11 22:00:20 +00:00
|
|
|
if (SUCCEEDED(tex->LockRect(level, &lock_rect, rect, flags)))
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
2014-09-11 22:00:20 +00:00
|
|
|
memset(lock_rect.pBits, level, tex_height * lock_rect.Pitch);
|
2014-09-11 21:05:58 +00:00
|
|
|
tex->UnlockRect(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-11 21:43:01 +00:00
|
|
|
void d3d_textureblit(d3d_video_t *d3d,
|
2014-09-11 21:05:58 +00:00
|
|
|
LPDIRECT3DTEXTURE tex, D3DSURFACE_DESC desc,
|
2014-09-11 22:00:20 +00:00
|
|
|
D3DLOCKED_RECT lr, const void *frame,
|
2014-09-11 21:05:58 +00:00
|
|
|
unsigned width, unsigned height, unsigned pitch)
|
|
|
|
{
|
2014-09-11 21:43:01 +00:00
|
|
|
#if 1
|
2014-09-11 22:00:20 +00:00
|
|
|
if (SUCCEEDED(tex->LockRect(0, &lr, NULL, D3DLOCK_NOSYSLOCK)))
|
2014-09-11 21:05:58 +00:00
|
|
|
{
|
|
|
|
for (unsigned y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
const uint8_t *in = (const uint8_t*)frame + y * pitch;
|
2014-09-11 22:00:20 +00:00
|
|
|
uint8_t *out = (uint8_t*)lr.pBits + y * lr.Pitch;
|
2014-09-11 21:05:58 +00:00
|
|
|
memcpy(out, in, width * d3d->pixel_size);
|
|
|
|
}
|
|
|
|
tex->UnlockRect(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|