d3d11-samplerstate.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 <float.h>
  16. #include "d3d11-subsystem.hpp"
  17. static inline D3D11_TEXTURE_ADDRESS_MODE ConvertGSAddressMode(
  18. gs_address_mode mode)
  19. {
  20. switch (mode) {
  21. case GS_ADDRESS_WRAP: return D3D11_TEXTURE_ADDRESS_WRAP;
  22. case GS_ADDRESS_CLAMP: return D3D11_TEXTURE_ADDRESS_CLAMP;
  23. case GS_ADDRESS_MIRROR: return D3D11_TEXTURE_ADDRESS_MIRROR;
  24. case GS_ADDRESS_BORDER: return D3D11_TEXTURE_ADDRESS_BORDER;
  25. case GS_ADDRESS_MIRRORONCE: return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE;
  26. }
  27. return D3D11_TEXTURE_ADDRESS_WRAP;
  28. }
  29. static inline D3D11_FILTER ConvertGSFilter( gs_sample_filter filter)
  30. {
  31. switch (filter) {
  32. case GS_FILTER_POINT:
  33. return D3D11_FILTER_MIN_MAG_MIP_POINT;
  34. case GS_FILTER_LINEAR:
  35. return D3D11_FILTER_MIN_MAG_MIP_LINEAR;
  36. case GS_FILTER_MIN_MAG_POINT_MIP_LINEAR:
  37. return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR;
  38. case GS_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT:
  39. return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT;
  40. case GS_FILTER_MIN_POINT_MAG_MIP_LINEAR:
  41. return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR;
  42. case GS_FILTER_MIN_LINEAR_MAG_MIP_POINT:
  43. return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT;
  44. case GS_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR:
  45. return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR;
  46. case GS_FILTER_MIN_MAG_LINEAR_MIP_POINT:
  47. return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT;
  48. case GS_FILTER_ANISOTROPIC:
  49. return D3D11_FILTER_ANISOTROPIC;
  50. }
  51. return D3D11_FILTER_MIN_MAG_MIP_POINT;
  52. }
  53. gs_sampler_state::gs_sampler_state(gs_device_t *device,
  54. const gs_sampler_info *info)
  55. : device (device),
  56. info (*info)
  57. {
  58. D3D11_SAMPLER_DESC sd;
  59. HRESULT hr;
  60. vec4 v4;
  61. memset(&sd, 0, sizeof(sd));
  62. sd.AddressU = ConvertGSAddressMode(info->address_u);
  63. sd.AddressV = ConvertGSAddressMode(info->address_v);
  64. sd.AddressW = ConvertGSAddressMode(info->address_w);
  65. sd.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
  66. sd.Filter = ConvertGSFilter(info->filter);
  67. sd.MaxAnisotropy = info->max_anisotropy;
  68. sd.MaxLOD = FLT_MAX;
  69. vec4_from_rgba(&v4, info->border_color);
  70. memcpy(sd.BorderColor, v4.ptr, sizeof(v4));
  71. hr = device->device->CreateSamplerState(&sd, state.Assign());
  72. if (FAILED(hr))
  73. throw HRError("Failed to create sampler state", hr);
  74. }