Saturday, October 15, 2016

directx - How to fill/initialize D3D11_SAMPLER_DESC properly?


If I want to set explicitly every parameter of the structure I just do so and that's it. But what if I want to set only some of them and leave the rest with default values? I've seen in some tutorial zeroing the structure:


ZeroMemory(&samplerDesc, sizeof(D3D11_SAMPLER_DESC));

but the default values (http://msdn.microsoft.com/en-us/library/windows/desktop/ff476207%28v=vs.85%29.aspx) aren't always 0. Is this incorrect? Should I always specify all values explicitly (especially LOD values seem tricky)?



I'm asking about D3D11_SAMPLER_DESC but maybe the same rules apply to other DX structures?



Answer




but the default values aren't always 0. Is this incorrect?



If it was just the default values being different from 0, then zeroing the desc struct wouldn't necessarily be incorrect, it just wouldn't give you a default sampler state.


However for some of the members (such as D3D11_TEXTURE_ADDRESS_MODE AddressU, AddressV, AddressW) 0 is not even a valid value and creating the sampler state will fail, so yes it's incorrect here.


To avoid having to specify the defaults every time, you could write a wrapper, an init or "factory" function, or store a const instance with the default values set somewhere.
D3D already comes with some Helper Structures which wrap many of the DESC structs and can intialize them with the proper default values for you (as long as you don't define D3D11_NO_HELPERS).


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...