d3d11-samplerstate.cpp 3.0 KB

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