obs-StreamFX/source/obs/gs/gs-sampler.cpp

136 lines
3.3 KiB
C++
Raw Normal View History

/*
* Modern effects for a modern Streamer
* Copyright (C) 2017 Michael Fabian Dirks
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "gs-sampler.hpp"
#include <stdexcept>
2018-11-07 14:24:25 +00:00
gs::sampler::sampler()
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info = {GS_FILTER_LINEAR, GS_ADDRESS_WRAP, GS_ADDRESS_WRAP, GS_ADDRESS_WRAP, 1, 0};
_sampler_state = nullptr;
}
2018-11-07 14:24:25 +00:00
gs::sampler::~sampler()
{
2019-08-04 14:20:26 +00:00
if (_sampler_state)
gs_samplerstate_destroy(_sampler_state);
}
2018-11-07 14:24:25 +00:00
void gs::sampler::set_filter(gs_sample_filter v)
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info.filter = v;
}
2018-11-07 14:24:25 +00:00
gs_sample_filter gs::sampler::get_filter()
{
2019-08-04 14:20:26 +00:00
return _sampler_info.filter;
}
2018-11-07 14:24:25 +00:00
void gs::sampler::set_address_mode_u(gs_address_mode v)
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info.address_u = v;
}
2018-11-07 14:24:25 +00:00
gs_address_mode gs::sampler::get_address_mode_u()
{
2019-08-04 14:20:26 +00:00
return _sampler_info.address_u;
}
2018-11-07 14:24:25 +00:00
void gs::sampler::set_address_mode_v(gs_address_mode v)
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info.address_v = v;
}
2018-11-07 14:24:25 +00:00
gs_address_mode gs::sampler::get_address_mode_v()
{
2019-08-04 14:20:26 +00:00
return _sampler_info.address_v;
}
2018-11-07 14:24:25 +00:00
void gs::sampler::set_address_mode_w(gs_address_mode v)
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info.address_w = v;
}
2018-11-07 14:24:25 +00:00
gs_address_mode gs::sampler::get_address_mode_w()
{
2019-08-04 14:20:26 +00:00
return _sampler_info.address_w;
}
2020-04-08 21:38:42 +00:00
void gs::sampler::set_max_anisotropy(std::int32_t v)
2018-11-07 14:24:25 +00:00
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info.max_anisotropy = v;
}
2020-04-08 21:38:42 +00:00
std::int32_t gs::sampler::get_max_anisotropy()
2018-11-07 14:24:25 +00:00
{
2019-08-04 14:20:26 +00:00
return _sampler_info.max_anisotropy;
}
2020-04-08 21:38:42 +00:00
void gs::sampler::set_border_color(std::uint32_t v)
2018-11-07 14:24:25 +00:00
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2019-08-04 14:20:26 +00:00
_sampler_info.border_color = v;
}
2020-04-08 21:38:42 +00:00
void gs::sampler::set_border_color(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a)
2018-11-07 14:24:25 +00:00
{
2019-08-24 10:59:32 +00:00
_dirty = true;
2020-04-08 21:38:42 +00:00
_sampler_info.border_color = (static_cast<std::uint32_t>(a) << 24) | (static_cast<std::uint32_t>(r) << 16)
| (static_cast<std::uint32_t>(g) << 8) | static_cast<std::uint32_t>(b);
}
2020-04-08 21:38:42 +00:00
std::uint32_t gs::sampler::get_border_color()
2018-11-07 14:24:25 +00:00
{
2019-08-04 14:20:26 +00:00
return _sampler_info.border_color;
}
2020-04-08 21:38:42 +00:00
std::uint8_t gs::sampler::get_border_color(bool r, bool g, bool b, bool a)
2018-11-07 14:24:25 +00:00
{
if (a)
2019-08-04 14:20:26 +00:00
return (_sampler_info.border_color >> 24) & 0xFF;
if (r)
2019-08-04 14:20:26 +00:00
return (_sampler_info.border_color >> 16) & 0xFF;
if (g)
2019-08-04 14:20:26 +00:00
return (_sampler_info.border_color >> 8) & 0xFF;
if (b)
2019-08-04 14:20:26 +00:00
return _sampler_info.border_color & 0xFF;
return 0;
}
2018-11-07 14:24:25 +00:00
gs_sampler_state* gs::sampler::refresh()
{
2019-08-04 14:20:26 +00:00
gs_samplerstate_destroy(_sampler_state);
_sampler_state = gs_samplerstate_create(&_sampler_info);
2019-08-24 10:59:32 +00:00
_dirty = false;
2019-08-04 14:20:26 +00:00
return _sampler_state;
}
2018-11-07 14:24:25 +00:00
gs_sampler_state* gs::sampler::get_object()
{
2019-08-04 14:20:26 +00:00
if (_dirty)
return refresh();
2019-08-04 14:20:26 +00:00
return _sampler_state;
}