obs-studio/libobs-d3d11/d3d11-samplerstate.cpp
jp9000 c9df41c1e2 (API Change) Remove pointers from all typedefs
Typedef pointers are unsafe.  If you do:
typedef struct bla *bla_t;
then you cannot use it as a constant, such as: const bla_t, because
that constant will be to the pointer itself rather than to the
underlying data.  I admit this was a fundamental mistake that must
be corrected.

All typedefs that were pointer types will now have their pointers
removed from the type itself, and the pointers will be used when they
are actually used as variables/parameters/returns instead.

This does not break ABI though, which is pretty nice.
2014-09-25 21:48:11 -07:00

85 lines
3 KiB
C++

/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
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 "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, gs_sampler_info *info)
: device (device),
info (*info)
{
D3D11_SAMPLER_DESC sd;
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);
}