From 4522fbb6afb2f68ec6304e238af81a0dd300dd4d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 9 Jun 2014 01:07:43 +0200 Subject: [PATCH] (D3D) Create macro D3DTexture_Blit --- gfx/d3d9/d3d9.hpp | 12 ++++++++++++ gfx/d3d9/render_chain.cpp | 22 ++-------------------- xdk/xdk_d3d.cpp | 31 +++++++++++++++++-------------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/gfx/d3d9/d3d9.hpp b/gfx/d3d9/d3d9.hpp index 4d052cf51e..c9f2dc9006 100644 --- a/gfx/d3d9/d3d9.hpp +++ b/gfx/d3d9/d3d9.hpp @@ -79,6 +79,18 @@ class RenderChain; #define D3DDevice_CreateVertexBuffers(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, pUnusedSharedHandle) device->CreateVertexBuffer(Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, NULL) #define D3DDevice_SetStreamSources(device, streamNumber, pStreamData, OffsetInBytes, Stride) device->SetStreamSource(streamNumber, pStreamData, OffsetInBytes, Stride) + +#define D3DTexture_Blit(d3d, desc, d3dlr, frame, width, height, pitch) \ + if (SUCCEEDED(first.tex->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK))) \ + { \ + for (unsigned y = 0; y < height; y++) \ + { \ + const uint8_t *in = (const uint8_t*)frame + y * pitch; \ + uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; \ + memcpy(out, in, width * d3d->pixel_size); \ + } \ + first.tex->UnlockRect(0); \ + } #endif diff --git a/gfx/d3d9/render_chain.cpp b/gfx/d3d9/render_chain.cpp index 8fff193b74..323a36c12a 100644 --- a/gfx/d3d9/render_chain.cpp +++ b/gfx/d3d9/render_chain.cpp @@ -518,6 +518,7 @@ void renderchain_blit_to_texture(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch) { + D3DSURFACE_DESC desc; D3DLOCKED_RECT d3dlr; renderchain_t *chain = (renderchain_t*)data; Pass &first = chain->passes[0]; @@ -526,26 +527,7 @@ void renderchain_blit_to_texture(void *data, const void *frame, D3DTexture_LockRectClear(first, first.tex, 0, d3dlr, NULL, D3DLOCK_NOSYSLOCK); } -#ifdef _XBOX360 - D3DSURFACE_DESC desc; - D3DTexture_LockRect(first.tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); - first.tex->GetLevelDesc(0, &desc); - XGCopySurface(d3dlr.pBits, d3dlr.Pitch, width, height, desc.Format, NULL, frame, - pitch, desc.Format, NULL, 0, 0); - -#else - if (SUCCEEDED(first.tex->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK))) - { - for (unsigned y = 0; y < height; y++) - { - const uint8_t *in = (const uint8_t*)frame + y * pitch; - uint8_t *out =(uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; - memcpy(out, in, width * chain->pixel_size); - } - - first.tex->UnlockRect(0); - } -#endif + D3DTexture_Blit(chain, desc, d3dlr, frame, width, height, pitch); } void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index) diff --git a/xdk/xdk_d3d.cpp b/xdk/xdk_d3d.cpp index 62f6a2fb76..733d04cb2e 100644 --- a/xdk/xdk_d3d.cpp +++ b/xdk/xdk_d3d.cpp @@ -512,9 +512,25 @@ static void d3d_draw_texture(void *data) } #endif +#if defined(_XBOX360) +#define D3DTexture_Blit(d3d, desc, d3dlr, frame, width, height, pitch) \ + d3d->tex->GetLevelDesc(0, &desc); \ + XGCopySurface(d3dlr.pBits, d3dlr.Pitch, width, height, desc.Format, NULL, frame, + pitch, desc.Format, NULL, 0, 0) +#else +#define D3DTexture_Blit(d3d, desc, d3dlr, frame, width, height, pitch) \ + for (unsigned y = 0; y < height; y++) \ + { \ + const uint8_t *in = (const uint8_t*)frame + y * pitch; \ + uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; \ + memcpy(out, in, width * d3d->pixel_size); \ + } +#endif + static void blit_to_texture(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch) { + D3DSURFACE_DESC desc; D3DLOCKED_RECT d3dlr; d3d_video_t *d3d = (d3d_video_t*)data; @@ -524,20 +540,7 @@ static void blit_to_texture(void *data, const void *frame, } D3DTexture_LockRect(d3d->tex, 0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); - -#if defined(_XBOX360) - D3DSURFACE_DESC desc; - d3d->tex->GetLevelDesc(0, &desc); - XGCopySurface(d3dlr.pBits, d3dlr.Pitch, width, height, desc.Format, NULL, frame, - pitch, desc.Format, NULL, 0, 0); -#elif defined(_XBOX1) - for (unsigned y = 0; y < height; y++) - { - const uint8_t *in = (const uint8_t*)frame + y * pitch; - uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; - memcpy(out, in, width * d3d->pixel_size); - } -#endif + D3DTexture_Blit(d3d, desc, d3dlr, frame, width, height, pitch); } static void set_vertices(void *data, unsigned pass, unsigned width, unsigned height)