(D3D) Create wrapper function d3d_set_texture

This commit is contained in:
twinaphex 2014-09-12 19:19:11 +02:00
parent 37a7e56a9b
commit 402388e369
8 changed files with 37 additions and 20 deletions

View File

@ -333,7 +333,7 @@ static bool texture_image_render(void *data,
d3d->dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE); d3d->dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
/* Draw the quad. */ /* Draw the quad. */
d3dr->SetTexture(0, out_img->pixels); d3d_set_texture(d3dr, 0, out_img->pixels);
d3d_set_stream_source(d3dr, 0, d3d_set_stream_source(d3dr, 0,
out_img->vertex_buf, 0, sizeof(Vertex)); out_img->vertex_buf, 0, sizeof(Vertex));
d3dr->SetVertexShader(D3DFVF_CUSTOMVERTEX); d3dr->SetVertexShader(D3DFVF_CUSTOMVERTEX);

View File

@ -104,7 +104,7 @@ static void d3d_overlay_render(void *data, overlay_t *overlay)
} }
/* Render overlay. */ /* Render overlay. */
d3d->dev->SetTexture(0, overlay->tex); d3d_set_texture(d3d->dev, 0, overlay->tex);
d3d_set_sampler_address_u(d3d->dev, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_u(d3d->dev, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_address_v(d3d->dev, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(d3d->dev, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_minfilter(d3d->dev, 0, D3DTEXF_LINEAR); d3d_set_sampler_minfilter(d3d->dev, 0, D3DTEXF_LINEAR);

View File

@ -166,6 +166,24 @@ void d3d_set_viewport(LPDIRECT3DDEVICE dev, D3DVIEWPORT *vp)
#endif #endif
} }
void d3d_set_texture(LPDIRECT3DDEVICE dev, unsigned sampler,
LPDIRECT3DTEXTURE tex)
{
#if defined(_XBOX1)
D3DDevice_SetTexture(sampler, tex);
#elif defined(_XBOX360)
unsigned fetchConstant =
GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(sampler);
uint64_t pendingMask3 =
D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS)
+ fetchConstant, D3DTAG_START(D3DTAG_FETCHCONSTANTS)
+ fetchConstant);
D3DDevice_SetTexture(dev, sampler, tex, pendingMask3)
#else
dev->SetTexture(0, tex);
#endif
}
void d3d_textureblit(void *data, void *renderchain_data, void d3d_textureblit(void *data, void *renderchain_data,
LPDIRECT3DTEXTURE tex, D3DSURFACE_DESC desc, LPDIRECT3DTEXTURE tex, D3DSURFACE_DESC desc,
D3DLOCKED_RECT lr, const void *frame, D3DLOCKED_RECT lr, const void *frame,

View File

@ -50,6 +50,9 @@ void d3d_lockrectangle_clear(LPDIRECT3DTEXTURE tex,
unsigned level, D3DLOCKED_RECT lock_rect, RECT rect, unsigned level, D3DLOCKED_RECT lock_rect, RECT rect,
unsigned flags); unsigned flags);
void d3d_set_texture(LPDIRECT3DDEVICE dev, unsigned sampler,
LPDIRECT3DTEXTURE tex);
void d3d_textureblit(void *data, void d3d_textureblit(void *data,
LPDIRECT3DTEXTURE tex, D3DSURFACE_DESC desc, LPDIRECT3DTEXTURE tex, D3DSURFACE_DESC desc,
D3DLOCKED_RECT lr, const void *frame, D3DLOCKED_RECT lr, const void *frame,

View File

@ -132,10 +132,10 @@ bool renderchain_set_pass_size(void *data, unsigned pass_index,
&pass.tex, NULL))) &pass.tex, NULL)))
return false; return false;
d3dr->SetTexture(0, pass.tex); d3d_set_texture(d3dr, 0, pass.tex);
d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER);
d3dr->SetTexture(0, NULL); d3d_set_texture(d3dr, 0, NULL);
} }
return true; return true;
@ -173,10 +173,10 @@ bool renderchain_add_pass(void *data, const LinkInfo *info)
&pass.tex, NULL))) &pass.tex, NULL)))
return false; return false;
d3dr->SetTexture(0, pass.tex); d3d_set_texture(d3dr, 0, pass.tex);
d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER);
d3dr->SetTexture(0, NULL); d3d_set_texture(d3dr, 0, NULL);
chain->passes.push_back(pass); chain->passes.push_back(pass);
@ -211,10 +211,10 @@ bool renderchain_add_lut(void *data, const std::string &id,
&lut))) &lut)))
return false; return false;
d3dr->SetTexture(0, lut); d3d_set_texture(d3dr, 0, lut);
d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER);
d3dr->SetTexture(0, NULL); d3d_set_texture(d3dr, 0, NULL);
lut_info info = { lut, id, smooth }; lut_info info = { lut, id, smooth };
chain->luts.push_back(info); chain->luts.push_back(info);
@ -372,14 +372,14 @@ bool renderchain_create_first_pass(void *data, const LinkInfo *info,
&chain->prev.tex[i], NULL))) &chain->prev.tex[i], NULL)))
return false; return false;
d3dr->SetTexture(0, chain->prev.tex[i]); d3d_set_texture(d3dr, 0, chain->prev.tex[i]);
d3d_set_sampler_minfilter(d3dr, 0, d3d_set_sampler_minfilter(d3dr, 0,
translate_filter(info->pass->filter)); translate_filter(info->pass->filter));
d3d_set_sampler_magfilter(d3dr, 0, d3d_set_sampler_magfilter(d3dr, 0,
translate_filter(info->pass->filter)); translate_filter(info->pass->filter));
d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_u(d3dr, 0, D3DTADDRESS_BORDER);
d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER); d3d_set_sampler_address_v(d3dr, 0, D3DTADDRESS_BORDER);
d3dr->SetTexture(0, NULL); d3d_set_texture(d3dr, 0, NULL);
} }
renderchain_compile_shaders(chain, pass.fPrg, renderchain_compile_shaders(chain, pass.fPrg,
@ -550,7 +550,7 @@ void renderchain_render_pass(void *data, Pass &pass, unsigned pass_index)
LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev; LPDIRECT3DDEVICE d3dr = (LPDIRECT3DDEVICE)chain->dev;
renderchain_set_shaders(chain, pass.fPrg, pass.vPrg); renderchain_set_shaders(chain, pass.fPrg, pass.vPrg);
d3dr->SetTexture(0, pass.tex); d3d_set_texture(d3dr, 0, pass.tex);
d3d_set_sampler_minfilter(d3dr, 0, d3d_set_sampler_minfilter(d3dr, 0,
translate_filter(pass.info.pass->filter)); translate_filter(pass.info.pass->filter));
d3d_set_sampler_magfilter(d3dr, 0, d3d_set_sampler_magfilter(d3dr, 0,
@ -637,7 +637,7 @@ void renderchain_unbind_all(void *data)
chain->bound_tex[i], D3DTEXF_POINT); chain->bound_tex[i], D3DTEXF_POINT);
d3d_set_sampler_magfilter(d3dr, d3d_set_sampler_magfilter(d3dr,
chain->bound_tex[i], D3DTEXF_POINT); chain->bound_tex[i], D3DTEXF_POINT);
d3dr->SetTexture(chain->bound_tex[i], NULL); d3d_set_texture(d3dr, chain->bound_tex[i], NULL);
} }
for (unsigned i = 0; i < chain->bound_vert.size(); i++) for (unsigned i = 0; i < chain->bound_vert.size(); i++)

View File

@ -142,7 +142,7 @@ static void renderchain_render_pass(void *data, const void *frame, unsigned widt
renderchain_blit_to_texture(d3d, frame, width, height, pitch); renderchain_blit_to_texture(d3d, frame, width, height, pitch);
renderchain_set_vertices(d3d, 1, width, height); renderchain_set_vertices(d3d, 1, width, height);
RD3DDevice_SetTexture(d3dr, 0, d3d->tex); d3d_set_texture(d3dr, 0, d3d->tex);
d3d_set_viewport(d3d->dev, &d3d->final_viewport); d3d_set_viewport(d3d->dev, &d3d->final_viewport);
d3d_set_sampler_minfilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d_set_sampler_minfilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);
d3d_set_sampler_magfilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); d3d_set_sampler_magfilter(d3dr, 0, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT);

View File

@ -30,7 +30,6 @@
#define RD3DDevice_SetVertexShader(device, handle) D3DDevice_SetVertexShader(handle) #define RD3DDevice_SetVertexShader(device, handle) D3DDevice_SetVertexShader(handle)
#define RD3DVertexBuffer_Lock(device, OffsetToLock, SizeToLock, ppbData, Flags) *ppbData = D3DVertexBuffer_Lock2(device, Flags) + OffsetToLock #define RD3DVertexBuffer_Lock(device, OffsetToLock, SizeToLock, ppbData, Flags) *ppbData = D3DVertexBuffer_Lock2(device, Flags) + OffsetToLock
#define RD3DVertexBuffer_Unlock(device) #define RD3DVertexBuffer_Unlock(device)
#define RD3DDevice_SetTexture(device, Stage, pTexture) D3DDevice_SetTexture(Stage, pTexture)
#define RD3DDevice_Clear(device, Count, pRects, Flags, Color, Z, Stencil) D3DDevice_Clear(Count, pRects, Flags, Color, Z, Stencil) #define RD3DDevice_Clear(device, Count, pRects, Flags, Color, Z, Stencil) D3DDevice_Clear(Count, pRects, Flags, Color, Z, Stencil)
#define D3DDevice_CreateVertexBuffers(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, pUnusedSharedHandle) IDirect3DDevice8_CreateVertexBuffer(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer) #define D3DDevice_CreateVertexBuffers(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, pUnusedSharedHandle) IDirect3DDevice8_CreateVertexBuffer(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer)
@ -39,10 +38,6 @@
#define RD3DVertexBuffer_Lock(device, OffsetToLock, SizeToLock, ppbData, Flags) *ppbData = D3DVertexBuffer_Lock(device, OffsetToLock, SizeToLock, Flags) #define RD3DVertexBuffer_Lock(device, OffsetToLock, SizeToLock, ppbData, Flags) *ppbData = D3DVertexBuffer_Lock(device, OffsetToLock, SizeToLock, Flags)
#define RD3DVertexBuffer_Unlock(device) D3DVertexBuffer_Unlock(device) #define RD3DVertexBuffer_Unlock(device) D3DVertexBuffer_Unlock(device)
#define RD3DDevice_SetTexture(device, Stage, pTexture) \
fetchConstant = GPU_CONVERT_D3D_TO_HARDWARE_TEXTUREFETCHCONSTANT(Stage); \
pendingMask3 = D3DTAG_MASKENCODE(D3DTAG_START(D3DTAG_FETCHCONSTANTS) + fetchConstant, D3DTAG_START(D3DTAG_FETCHCONSTANTS) + fetchConstant); \
D3DDevice_SetTexture(device, Stage, pTexture, pendingMask3)
#define D3DDevice_CreateVertexBuffers(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, pUnusedSharedHandle) IDirect3DDevice9_CreateVertexBuffer(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, NULL) #define D3DDevice_CreateVertexBuffers(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, pUnusedSharedHandle) IDirect3DDevice9_CreateVertexBuffer(device, Length, Usage, UnusedFVF, UnusedPool, ppVertexBuffer, NULL)
#define RD3DDevice_Clear(device, Count, pRects, Flags, Color, Z, Stencil) D3DDevice_Clear(device, Count, pRects, Flags, Color, Z, Stencil, false) #define RD3DDevice_Clear(device, Count, pRects, Flags, Color, Z, Stencil) D3DDevice_Clear(device, Count, pRects, Flags, Color, Z, Stencil, false)

View File

@ -16,6 +16,7 @@
#include <xtl.h> #include <xtl.h>
#include "d3d_font.h" #include "d3d_font.h"
#include "../d3d.hpp"
#include "../gfx_common.h" #include "../gfx_common.h"
#include "../../general.h" #include "../../general.h"
#include "../../xdk/xdk_resources.h" #include "../../xdk/xdk_resources.h"
@ -277,7 +278,7 @@ static void xdk_render_msg_post(xdk360_video_font_t * font, void *video_data)
d3d_video_t *d3d = (d3d_video_t*)video_data; d3d_video_t *d3d = (d3d_video_t*)video_data;
LPDIRECT3DDEVICE d3dr = d3d->dev; LPDIRECT3DDEVICE d3dr = d3d->dev;
d3dr->SetTexture(0, NULL); d3d_set_texture(d3dr, 0, NULL);
d3dr->SetVertexDeclaration(NULL); d3dr->SetVertexDeclaration(NULL);
D3DDevice_SetVertexShader(d3dr, NULL); D3DDevice_SetVertexShader(d3dr, NULL);
D3DDevice_SetPixelShader(d3dr, NULL); D3DDevice_SetPixelShader(d3dr, NULL);
@ -297,7 +298,7 @@ static void xdk_render_msg_pre(xdk360_video_font_t * font, void *video_data)
D3DTexture_GetLevelDesc(font->m_pFontTexture, 0, &TextureDesc); // Get the description D3DTexture_GetLevelDesc(font->m_pFontTexture, 0, &TextureDesc); // Get the description
// Set render state // Set render state
d3dr->SetTexture(0, font->m_pFontTexture); d3d_set_texture(d3dr, 0, font->m_pFontTexture);
// Read the TextureDesc here to ensure no load/hit/store from GetLevelDesc() // Read the TextureDesc here to ensure no load/hit/store from GetLevelDesc()
float vTexScale[4]; float vTexScale[4];