From 708235e0416fae85f5a026c19827be3a267af338 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 22 Dec 2025 22:03:53 -0600 Subject: [PATCH] use GetConstantDesc for sampler register index --- main.cpp | 19 +++++++++++++++---- main.psh | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index d1bc3dc..22e814b 100644 --- a/main.cpp +++ b/main.cpp @@ -32,6 +32,7 @@ IDirect3DVertexShader9 * g_pVertexShader = NULL; ID3DXConstantTable * g_pPixelConstantTable = NULL; IDirect3DPixelShader9 * g_pPixelShader = NULL; IDirect3DTexture9 * g_pTexture = NULL; +D3DXCONSTANT_DESC g_TextureConstDesc; IDirectInput8 * g_pDI = NULL; IDirectInputDevice8 * g_pdiDevice; @@ -154,10 +155,11 @@ void Render() g_pd3dDevice->SetVertexShader(g_pVertexShader); g_pd3dDevice->SetPixelShader(g_pPixelShader); - g_pd3dDevice->SetTexture(0, g_pTexture); - g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); - g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); + UINT registerIndex = g_TextureConstDesc.RegisterIndex; + g_pd3dDevice->SetTexture(registerIndex, g_pTexture); + g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_MINFILTER, D3DTEXF_POINT); + g_pd3dDevice->Setsamplerstate(registerIndex, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP); + g_pd3dDevice->SetSamplerState(registerIndex, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP); g_pd3dDevice->SetStreamSource(0, g_pVB, 0, (sizeof (CUSTOMVERTEX))); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); @@ -420,6 +422,15 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine return res; } + D3DXHANDLE handle; + handle = g_pPixelConstantTable->GetConstantByName(NULL, "BearTextureSampler"); + assert(handle != NULL); + + UINT count; + g_pPixelConstantTable->GetConstantDesc(handle, &g_TextureConstDesc, &count); + assert(g_TextureConstDesc.RegisterSet = D3DXRS_SAMPLER); + assert(count == 1); + ////////////////////////////////////////////////////////////////////// // texture ////////////////////////////////////////////////////////////////////// diff --git a/main.psh b/main.psh index ae38799..0ad7b3c 100644 --- a/main.psh +++ b/main.psh @@ -1,4 +1,4 @@ -sampler2D BearTextureSampler; +sampler BearTextureSampler; struct VS_OUTPUT {