2019-12-15 08:05:23 +00:00
|
|
|
/*
|
|
|
|
* Modern effects for a modern Streamer
|
|
|
|
* Copyright (C) 2019 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-effect-technique.hpp"
|
|
|
|
#include <cstring>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2020-04-02 18:29:00 +00:00
|
|
|
extern "C" {
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201)
|
|
|
|
#endif
|
2019-12-15 08:05:23 +00:00
|
|
|
#include <graphics/effect.h>
|
2020-04-02 18:29:00 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
}
|
2019-12-15 08:05:23 +00:00
|
|
|
|
2019-12-15 09:37:57 +00:00
|
|
|
gs::effect_technique::effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t>* parent)
|
|
|
|
: _parent(parent)
|
2019-12-15 08:05:23 +00:00
|
|
|
{
|
|
|
|
reset(technique, [](void*) {});
|
|
|
|
}
|
|
|
|
|
|
|
|
gs::effect_technique::~effect_technique() {}
|
|
|
|
|
|
|
|
std::string gs::effect_technique::name()
|
|
|
|
{
|
2019-12-21 16:04:38 +00:00
|
|
|
const char* name_c = get()->name;
|
2020-04-08 21:38:42 +00:00
|
|
|
std::size_t name_len = strnlen(name_c, 256);
|
2019-12-18 05:35:06 +00:00
|
|
|
return name_c ? std::string(name_c, name_c + name_len) : std::string();
|
2019-12-15 08:05:23 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 21:38:42 +00:00
|
|
|
std::size_t gs::effect_technique::count_passes()
|
2019-12-15 08:05:23 +00:00
|
|
|
{
|
|
|
|
return static_cast<size_t>(get()->passes.num);
|
|
|
|
}
|
|
|
|
|
2020-04-08 21:38:42 +00:00
|
|
|
gs::effect_pass gs::effect_technique::get_pass(std::size_t idx)
|
2019-12-15 08:05:23 +00:00
|
|
|
{
|
|
|
|
if (idx >= get()->passes.num) {
|
2019-12-15 09:37:57 +00:00
|
|
|
return nullptr;
|
2019-12-15 08:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gs::effect_pass(get()->passes.array + idx, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
gs::effect_pass gs::effect_technique::get_pass(std::string name)
|
|
|
|
{
|
2020-04-08 21:38:42 +00:00
|
|
|
for (std::size_t idx = 0; idx < get()->passes.num; idx++) {
|
2019-12-15 08:05:23 +00:00
|
|
|
auto ptr = get()->passes.array + idx;
|
|
|
|
if (strcmp(ptr->name, name.c_str()) == 0)
|
|
|
|
return gs::effect_pass(ptr, this);
|
|
|
|
}
|
|
|
|
|
2019-12-15 09:37:57 +00:00
|
|
|
return nullptr;
|
2019-12-15 08:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gs::effect_technique::has_pass(std::string name)
|
|
|
|
{
|
2019-12-15 10:39:57 +00:00
|
|
|
if (get_pass(name) != nullptr)
|
|
|
|
return true;
|
2019-12-15 08:05:23 +00:00
|
|
|
return false;
|
|
|
|
}
|