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