d3d11-samplerstate.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <graphics/vec4.h>
  15. #include "d3d11-subsystem.hpp"
  16. static inline D3D11_TEXTURE_ADDRESS_MODE ConvertGSAddressMode(
  17. gs_address_mode mode)
  18. {
  19. switch (mode) {
  20. case GS_ADDRESS_WRAP: return D3D11_TEXTURE_ADDRESS_WRAP;
  21. case GS_ADDRESS_CLAMP: return D3D11_TEXTURE_ADDRESS_CLAMP;
  22. case GS_ADDRESS_MIRROR: return D3D11_TEXTURE_ADDRESS_MIRROR;
  23. case GS_ADDRESS_BORDER: return D3D11_TEXTURE_ADDRESS_BORDER;
  24. case GS_ADDRESS_MIRRORONCE: return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE;
  25. }
  26. return D3D11_TEXTURE_ADDRESS_WRAP;
  27. }
  28. static inline D3D11_FILTER ConvertGSFilter( gs_sample_filter filter)
  29. {
  30. switch (filter) {
  31. case GS_FILTER_POINT:
  32. return D3D11_FILTER_MIN_MAG_MIP_POINT;
  33. case GS_FILTER_LINEAR:
  34. return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
  35. case GS_FILTER_MIN_MAG_POINT_MIP_LINEAR:
  36. return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
  37. case GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT:
  38. return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
  39. case GS_FILTER_MIN_POINT_MAG_MIP_LINEAR:
  40. return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
  41. case GS_FILTER_MIN_LINEAR_MAG_MIP_POINT:
  42. return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
  43. case GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR:
  44. return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
  45. case GS_FILTER_MIN_MAG_LINEAR_MIP_POINT:
  46. return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  47. case GS_FILTER_ANISOTROPIC:
  48. return D3D11_FILTER_ANISOTROPIC;
  49. }
  50. return D3D11_FILTER_MIN_MAG_MIP_POINT;
  51. }
  52. gs_sampler_state::gs_sampler_state(gs_device_t *device, gs_sampler_info *info)
  53. : device (device),
  54. info (*info)
  55. {
  56. D3D11_SAMPLER_DESC sd;
  57. HRESULT hr;
  58. vec4 v4;
  59. memset(&sd, 0, sizeof(sd));
  60. sd.AddressU = ConvertGSAddressMode(info->address_u);
  61. sd.AddressV = ConvertGSAddressMode(info->address_v);
  62. sd.AddressW = ConvertGSAddressMode(info->address_w);
  63. sd.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
  64. sd.Filter = ConvertGSFilter(info->filter);
  65. sd.MaxAnisotropy = info->max_anisotropy;
  66. sd.MaxLOD = FLT_MAX;
  67. vec4_from_rgba(&v4, info->border_color);
  68. memcpy(sd.BorderColor, v4.ptr, sizeof(v4));
  69. hr = device->device->CreateSamplerState(&sd, state.Assign());
  70. if (FAILED(hr))
  71. throw HRError("Failed to create sampler state", hr);
  72. }