2017-09-17 19:55:16 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "gs-effect.hpp"
|
2019-01-31 01:30:18 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
2019-04-02 22:16:13 +00:00
|
|
|
#include <stdexcept>
|
2019-01-31 01:30:18 +00:00
|
|
|
#include <vector>
|
2019-04-02 22:16:13 +00:00
|
|
|
#include "obs/gs/gs-helper.hpp"
|
2018-09-28 12:18:09 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
// OBS
|
|
|
|
#ifdef _MSC_VER
|
2018-09-28 12:18:09 +00:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201)
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
2018-09-28 12:18:09 +00:00
|
|
|
#include <obs.h>
|
2019-01-14 10:23:21 +00:00
|
|
|
#ifdef _MSC_VER
|
2018-09-28 12:18:09 +00:00
|
|
|
#pragma warning(pop)
|
2019-01-14 10:23:21 +00:00
|
|
|
#endif
|
2017-09-17 19:55:16 +00:00
|
|
|
|
2019-01-31 01:30:18 +00:00
|
|
|
//#define OBS_LOAD_EFFECT_FILE
|
|
|
|
|
2019-08-04 21:18:54 +00:00
|
|
|
gs::effect::effect(std::string file)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-01-31 01:30:18 +00:00
|
|
|
#ifdef OBS_LOAD_EFFECT_FILE
|
2017-09-17 19:55:16 +00:00
|
|
|
char* errorMessage = nullptr;
|
2019-04-02 22:16:13 +00:00
|
|
|
auto gctx = gs::context();
|
2018-09-28 12:18:09 +00:00
|
|
|
m_effect = gs_effect_create_from_file(file.c_str(), &errorMessage);
|
2017-09-17 19:55:16 +00:00
|
|
|
if (!m_effect || errorMessage) {
|
2017-11-05 20:31:05 +00:00
|
|
|
std::string error = "Generic Error";
|
|
|
|
if (errorMessage) {
|
|
|
|
error = std::string(errorMessage);
|
|
|
|
bfree((void*)errorMessage);
|
|
|
|
}
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::runtime_error(error);
|
|
|
|
}
|
2019-01-31 01:30:18 +00:00
|
|
|
#else
|
|
|
|
std::ifstream filestream = std::ifstream(file, std::ios::binary);
|
|
|
|
if (!filestream.is_open()) {
|
|
|
|
throw std::runtime_error("Failed to open file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
filestream.ignore(std::numeric_limits<std::streamsize>::max());
|
|
|
|
std::streamsize length = filestream.gcount();
|
|
|
|
filestream.clear(); // Since ignore will have set eof.
|
|
|
|
filestream.seekg(0, std::ios_base::beg);
|
|
|
|
|
|
|
|
if (length > 256 * 1024 * 1024) {
|
|
|
|
throw std::runtime_error("Shader too large (>256mb)");
|
|
|
|
}
|
|
|
|
|
2019-04-19 07:42:15 +00:00
|
|
|
std::vector<char> shader_buf(size_t(length + 1), 0);
|
2019-01-31 01:30:18 +00:00
|
|
|
filestream.read(shader_buf.data(), length);
|
|
|
|
|
|
|
|
char* errorMessage = nullptr;
|
2019-04-02 22:16:13 +00:00
|
|
|
auto gctx = gs::context();
|
2019-08-04 20:44:46 +00:00
|
|
|
_effect = gs_effect_create(shader_buf.data(), file.c_str(), &errorMessage);
|
2019-08-04 14:20:26 +00:00
|
|
|
if (!_effect || errorMessage) {
|
2019-01-31 01:30:18 +00:00
|
|
|
std::string error = "Generic Error";
|
|
|
|
if (errorMessage) {
|
|
|
|
error = std::string(errorMessage);
|
|
|
|
bfree((void*)errorMessage);
|
|
|
|
}
|
|
|
|
throw std::runtime_error(error);
|
|
|
|
}
|
|
|
|
#endif
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:18:54 +00:00
|
|
|
gs::effect::effect(std::string code, std::string name)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2017-09-17 19:55:16 +00:00
|
|
|
char* errorMessage = nullptr;
|
2019-04-02 22:16:13 +00:00
|
|
|
auto gctx = gs::context();
|
2019-08-04 20:44:46 +00:00
|
|
|
_effect = gs_effect_create(code.c_str(), name.c_str(), &errorMessage);
|
2019-08-04 14:20:26 +00:00
|
|
|
if (!_effect || errorMessage) {
|
2017-11-05 20:31:05 +00:00
|
|
|
std::string error = "Generic Error";
|
|
|
|
if (errorMessage) {
|
|
|
|
error = std::string(errorMessage);
|
|
|
|
bfree((void*)errorMessage);
|
|
|
|
}
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::runtime_error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
gs::effect::~effect()
|
|
|
|
{
|
2019-04-02 22:16:13 +00:00
|
|
|
auto gctx = gs::context();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_destroy(_effect);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
gs_effect_t* gs::effect::get_object()
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
return _effect;
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
size_t gs::effect::count_parameters()
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
return (size_t)gs_effect_get_num_params(_effect);
|
2017-11-05 15:46:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
std::list<std::shared_ptr<gs::effect_parameter>> gs::effect::get_parameters()
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-08-04 21:12:30 +00:00
|
|
|
size_t num = gs_effect_get_num_params(_effect);
|
|
|
|
std::list<std::shared_ptr<gs::effect_parameter>> ps;
|
2017-09-17 19:55:16 +00:00
|
|
|
for (size_t idx = 0; idx < num; idx++) {
|
2018-03-20 11:43:37 +00:00
|
|
|
ps.emplace_back(get_parameter(idx));
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
std::shared_ptr<gs::effect_parameter> gs::effect::get_parameter(size_t idx)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_eparam_t* param = gs_effect_get_param_by_idx(_effect, idx);
|
2017-11-05 15:46:28 +00:00
|
|
|
if (!param)
|
2019-08-04 21:12:30 +00:00
|
|
|
return nullptr;
|
|
|
|
return std::make_shared<effect_parameter>(this->shared_from_this(), param);
|
2017-11-05 15:46:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
std::shared_ptr<gs::effect_parameter> gs::effect::get_parameter(std::string name)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_eparam_t* param = gs_effect_get_param_by_name(_effect, name.c_str());
|
2019-08-04 21:12:30 +00:00
|
|
|
if (!param)
|
|
|
|
return nullptr;
|
|
|
|
return std::make_shared<effect_parameter>(this->shared_from_this(), param);
|
2018-01-25 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
bool gs::effect::has_parameter(std::string name)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-08-04 21:12:30 +00:00
|
|
|
auto eprm = get_parameter(name);
|
|
|
|
if (eprm)
|
|
|
|
return true;
|
|
|
|
return false;
|
2018-01-25 08:12:47 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
bool gs::effect::has_parameter(std::string name, effect_parameter::type type)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-08-04 21:12:30 +00:00
|
|
|
auto eprm = get_parameter(name);
|
|
|
|
if (eprm)
|
|
|
|
return eprm->get_type() == type;
|
|
|
|
return false;
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:18:54 +00:00
|
|
|
std::shared_ptr<gs::effect> gs::effect::create(std::string file)
|
|
|
|
{
|
|
|
|
return std::shared_ptr<gs::effect>(new gs::effect(file));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<gs::effect> gs::effect::create(std::string code, std::string name)
|
|
|
|
{
|
|
|
|
return std::shared_ptr<gs::effect>(new gs::effect(code, name));
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
gs::effect_parameter::effect_parameter(std::shared_ptr<gs::effect> effect, gs_eparam_t* param)
|
|
|
|
: _effect(effect), _param(param)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2019-08-07 14:17:12 +00:00
|
|
|
if (!effect)
|
2019-08-04 21:12:30 +00:00
|
|
|
throw std::invalid_argument("effect");
|
2017-09-17 19:55:16 +00:00
|
|
|
if (!param)
|
2019-08-04 21:12:30 +00:00
|
|
|
throw std::invalid_argument("param");
|
2017-09-17 19:55:16 +00:00
|
|
|
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_get_param_info(_param, &_param_info);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
std::string gs::effect_parameter::get_name()
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
return _param_info.name;
|
2017-11-05 20:50:38 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
gs::effect_parameter::type gs::effect_parameter::get_type()
|
|
|
|
{
|
2019-08-04 14:20:26 +00:00
|
|
|
switch (_param_info.type) {
|
2018-09-28 12:18:09 +00:00
|
|
|
case GS_SHADER_PARAM_BOOL:
|
|
|
|
return type::Boolean;
|
|
|
|
case GS_SHADER_PARAM_FLOAT:
|
|
|
|
return type::Float;
|
|
|
|
case GS_SHADER_PARAM_VEC2:
|
|
|
|
return type::Float2;
|
|
|
|
case GS_SHADER_PARAM_VEC3:
|
|
|
|
return type::Float3;
|
|
|
|
case GS_SHADER_PARAM_VEC4:
|
|
|
|
return type::Float4;
|
|
|
|
case GS_SHADER_PARAM_INT:
|
|
|
|
return type::Integer;
|
|
|
|
case GS_SHADER_PARAM_INT2:
|
|
|
|
return type::Integer2;
|
|
|
|
case GS_SHADER_PARAM_INT3:
|
|
|
|
return type::Integer3;
|
|
|
|
case GS_SHADER_PARAM_INT4:
|
|
|
|
return type::Integer4;
|
|
|
|
case GS_SHADER_PARAM_MATRIX4X4:
|
|
|
|
return type::Matrix;
|
|
|
|
case GS_SHADER_PARAM_TEXTURE:
|
|
|
|
return type::Texture;
|
2019-08-04 20:44:46 +00:00
|
|
|
case GS_SHADER_PARAM_STRING:
|
|
|
|
return type::String;
|
2018-09-28 12:18:09 +00:00
|
|
|
default:
|
|
|
|
case GS_SHADER_PARAM_UNKNOWN:
|
|
|
|
return type::Unknown;
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_bool(bool v)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Boolean)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_bool(_param, v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_bool(bool& v)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Boolean)
|
|
|
|
throw std::bad_cast();
|
|
|
|
void* ptr = gs_effect_get_val(_param);
|
|
|
|
if (ptr) {
|
|
|
|
v = *reinterpret_cast<bool*>(ptr);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
v = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_bool(bool& v)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Boolean)
|
|
|
|
throw std::bad_cast();
|
|
|
|
void* ptr = gs_effect_get_default_val(_param);
|
|
|
|
if (ptr) {
|
|
|
|
v = *reinterpret_cast<bool*>(ptr);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
v = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_bool_array(bool v[], size_t sz)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Boolean)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_val(_param, v, sz);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_float(float_t x)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_float(_param, x);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_float(float_t& x)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float)
|
|
|
|
throw std::bad_cast();
|
|
|
|
void* ptr = gs_effect_get_val(_param);
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_float(float_t& x)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float)
|
|
|
|
throw std::bad_cast();
|
|
|
|
void* ptr = gs_effect_get_default_val(_param);
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::set_float2(vec2 const& v)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float2)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_vec2(_param, &v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_float2(vec2& v)
|
|
|
|
{
|
|
|
|
get_float2(v.x, v.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_float2(vec2& v)
|
|
|
|
{
|
|
|
|
get_default_float2(v.x, v.y);
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_float2(float_t x, float_t y)
|
2019-08-04 20:44:46 +00:00
|
|
|
{
|
|
|
|
vec2 data;
|
|
|
|
data.x = x;
|
|
|
|
data.y = y;
|
|
|
|
set_float2(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_float2(float_t& x, float_t& y)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float2)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 20:44:46 +00:00
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y = 0;
|
|
|
|
}
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_default_float2(float_t& x, float_t& y)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float2)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::set_float3(vec3 const& v)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float3)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_vec3(_param, &v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_float3(vec3& v)
|
|
|
|
{
|
|
|
|
get_float3(v.x, v.y, v.z);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_float3(vec3& v)
|
|
|
|
{
|
|
|
|
get_default_float3(v.x, v.y, v.z);
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_float3(float_t x, float_t y, float_t z)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float3)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-04-19 07:42:15 +00:00
|
|
|
vec3 v = {{x, y, z, 0}};
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_vec3(_param, &v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_float3(float_t& x, float_t& y, float_t& z)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float3)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
|
|
|
|
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_float3(float_t& x, float_t& y, float_t& z)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float3)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
|
|
|
|
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::set_float4(vec4 const& v)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float4)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_vec4(_param, &v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_float4(vec4& v)
|
|
|
|
{
|
|
|
|
get_float4(v.x, v.y, v.z, v.w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_float4(vec4& v)
|
|
|
|
{
|
|
|
|
get_default_float4(v.x, v.y, v.z, v.w);
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_float4(float_t x, float_t y, float_t z, float_t w)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Float4)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-04-19 07:42:15 +00:00
|
|
|
vec4 v = {{x, y, z, w}};
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_vec4(_param, &v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_float4(float_t& x, float_t& y, float_t& z, float_t& w)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float4)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
|
|
|
|
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
|
|
|
|
w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z, w = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_float4(float_t& x, float_t& y, float_t& z, float_t& w)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Float4)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<float_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t));
|
|
|
|
z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
|
|
|
|
w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z, w = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_float_array(float_t v[], size_t sz)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Float) && (get_type() != type::Float2) && (get_type() != type::Float3)
|
|
|
|
&& (get_type() != type::Float4))
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_val(_param, v, sizeof(float_t) * sz);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_int(int32_t x)
|
|
|
|
{
|
2018-04-29 01:01:07 +00:00
|
|
|
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_int(_param, x);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_int(int32_t& x)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_int(int32_t& x)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_int2(int32_t x, int32_t y)
|
|
|
|
{
|
2018-04-29 01:01:07 +00:00
|
|
|
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2018-09-28 12:18:09 +00:00
|
|
|
int32_t v[2] = {x, y};
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_val(_param, v, sizeof(int) * 2);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_int2(int32_t& x, int32_t& y)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_int2(int32_t& x, int32_t& y)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_int3(int32_t x, int32_t y, int32_t z)
|
|
|
|
{
|
2018-04-29 01:01:07 +00:00
|
|
|
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2018-09-28 12:18:09 +00:00
|
|
|
int32_t v[3] = {x, y, z};
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_val(_param, v, sizeof(int) * 3);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_int3(int32_t& x, int32_t& y, int32_t& z)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
|
|
|
|
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_int3(int32_t& x, int32_t& y, int32_t& z)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
|
|
|
|
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_int4(int32_t x, int32_t y, int32_t z, int32_t w)
|
|
|
|
{
|
2018-04-29 01:01:07 +00:00
|
|
|
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2018-09-28 12:18:09 +00:00
|
|
|
int32_t v[4] = {x, y, z, w};
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_val(_param, v, sizeof(int) * 4);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_int4(int32_t& x, int32_t& y, int32_t& z, int32_t& w)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
|
|
|
|
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
|
|
|
|
w = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 3);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z, w = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_int4(int32_t& x, int32_t& y, int32_t& z, int32_t& w)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
x = *reinterpret_cast<int32_t*>(ptr);
|
|
|
|
y = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t));
|
|
|
|
z = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 2);
|
|
|
|
w = *reinterpret_cast<int32_t*>(ptr + sizeof(int32_t) * 3);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
x, y, z, w = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_int_array(int32_t v[], size_t sz)
|
|
|
|
{
|
|
|
|
if ((get_type() != type::Integer) && (get_type() != type::Integer2) && (get_type() != type::Integer3)
|
|
|
|
&& (get_type() != type::Integer4) && (get_type() != type::Unknown))
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_val(_param, v, sizeof(int) * sz);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::set_matrix(matrix4 const& v)
|
2018-09-28 12:18:09 +00:00
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Matrix)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_matrix4(_param, &v);
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 20:44:46 +00:00
|
|
|
void gs::effect_parameter::get_matrix(matrix4& v)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Matrix)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
v.x.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 0);
|
|
|
|
v.x.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 1);
|
|
|
|
v.x.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
|
|
|
|
v.x.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
|
|
|
|
v.y.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 4);
|
|
|
|
v.y.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 5);
|
|
|
|
v.y.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 6);
|
|
|
|
v.y.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 7);
|
|
|
|
v.z.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 8);
|
|
|
|
v.z.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 9);
|
|
|
|
v.z.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 10);
|
|
|
|
v.z.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 11);
|
|
|
|
v.t.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 12);
|
|
|
|
v.t.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 13);
|
|
|
|
v.t.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 14);
|
|
|
|
v.t.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 15);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
v.x = vec4{};
|
|
|
|
v.y = vec4{};
|
|
|
|
v.z = vec4{};
|
|
|
|
v.t = vec4{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_matrix(matrix4& v)
|
|
|
|
{
|
|
|
|
if (get_type() != type::Matrix)
|
|
|
|
throw std::bad_cast();
|
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
v.x.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 0);
|
|
|
|
v.x.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 1);
|
|
|
|
v.x.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 2);
|
|
|
|
v.x.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 3);
|
|
|
|
v.y.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 4);
|
|
|
|
v.y.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 5);
|
|
|
|
v.y.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 6);
|
|
|
|
v.y.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 7);
|
|
|
|
v.z.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 8);
|
|
|
|
v.z.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 9);
|
|
|
|
v.z.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 10);
|
|
|
|
v.z.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 11);
|
|
|
|
v.t.x = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 12);
|
|
|
|
v.t.y = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 13);
|
|
|
|
v.t.z = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 14);
|
|
|
|
v.t.w = *reinterpret_cast<float_t*>(ptr + sizeof(float_t) * 15);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
v.x = vec4{};
|
|
|
|
v.y = vec4{};
|
|
|
|
v.z = vec4{};
|
|
|
|
v.t = vec4{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_texture(std::shared_ptr<gs::texture> v)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Texture)
|
2017-09-17 19:55:16 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_texture(_param, v->get_object());
|
2017-09-17 19:55:16 +00:00
|
|
|
}
|
2018-01-19 04:10:10 +00:00
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_texture(gs_texture_t* v)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Texture)
|
2018-01-19 06:00:46 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_texture(_param, v);
|
2018-01-19 06:00:46 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_sampler(std::shared_ptr<gs::sampler> v)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Texture)
|
2018-01-19 04:10:10 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_next_sampler(_param, v->get_object());
|
2018-01-19 04:10:10 +00:00
|
|
|
}
|
2018-01-19 06:00:46 +00:00
|
|
|
|
2018-09-28 12:18:09 +00:00
|
|
|
void gs::effect_parameter::set_sampler(gs_sampler_state* v)
|
|
|
|
{
|
2018-03-20 11:43:37 +00:00
|
|
|
if (get_type() != type::Texture)
|
2018-01-19 06:00:46 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-04 14:20:26 +00:00
|
|
|
gs_effect_set_next_sampler(_param, v);
|
2018-01-19 06:00:46 +00:00
|
|
|
}
|
2019-08-04 20:44:46 +00:00
|
|
|
|
|
|
|
void gs::effect_parameter::set_string(std::string const& v)
|
|
|
|
{
|
|
|
|
if (get_type() != type::String)
|
|
|
|
throw std::bad_cast();
|
|
|
|
gs_effect_set_val(_param, v.c_str(), v.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_string(std::string& v)
|
|
|
|
{
|
2019-08-07 14:41:26 +00:00
|
|
|
if (get_type() != type::String)
|
2019-08-04 20:44:46 +00:00
|
|
|
throw std::bad_cast();
|
|
|
|
size_t ptr_len = gs_effect_get_val_size(_param);
|
2019-08-04 21:12:30 +00:00
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_val(_param));
|
2019-08-04 20:44:46 +00:00
|
|
|
if (ptr) {
|
|
|
|
v = std::string(ptr, ptr + ptr_len);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
v = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void gs::effect_parameter::get_default_string(std::string& v)
|
|
|
|
{
|
2019-08-07 14:41:26 +00:00
|
|
|
if (get_type() != type::String)
|
2019-08-04 20:44:46 +00:00
|
|
|
throw std::bad_cast();
|
2019-08-07 15:07:54 +00:00
|
|
|
size_t ptr_len = gs_effect_get_default_val_size(_param);
|
2019-08-04 20:44:46 +00:00
|
|
|
uint8_t* ptr = static_cast<uint8_t*>(gs_effect_get_default_val(_param));
|
|
|
|
if (ptr) {
|
|
|
|
v = std::string(ptr, ptr + ptr_len);
|
|
|
|
bfree(ptr);
|
|
|
|
} else {
|
|
|
|
v = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t gs::effect_parameter::count_annotations()
|
|
|
|
{
|
|
|
|
return gs_param_get_num_annotations(_param);
|
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
std::shared_ptr<gs::effect_parameter> gs::effect_parameter::get_annotation(size_t idx)
|
2019-08-04 20:44:46 +00:00
|
|
|
{
|
|
|
|
gs_eparam_t* param = gs_param_get_annotation_by_idx(_param, idx);
|
|
|
|
if (!param)
|
2019-08-04 21:12:30 +00:00
|
|
|
return nullptr;
|
|
|
|
return std::make_shared<effect_parameter>(_effect, param);
|
2019-08-04 20:44:46 +00:00
|
|
|
}
|
|
|
|
|
2019-08-04 21:12:30 +00:00
|
|
|
std::shared_ptr<gs::effect_parameter> gs::effect_parameter::get_annotation(std::string name)
|
2019-08-04 20:44:46 +00:00
|
|
|
{
|
|
|
|
gs_eparam_t* param = gs_param_get_annotation_by_name(_param, name.c_str());
|
|
|
|
if (!param)
|
2019-08-04 21:12:30 +00:00
|
|
|
return nullptr;
|
|
|
|
return std::make_shared<effect_parameter>(_effect, param);
|
2019-08-04 20:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gs::effect_parameter::has_annotation(std::string name)
|
|
|
|
{
|
2019-08-04 21:12:30 +00:00
|
|
|
auto eprm = get_annotation(name);
|
|
|
|
if (eprm)
|
|
|
|
return true;
|
|
|
|
return false;
|
2019-08-04 20:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool gs::effect_parameter::has_annotation(std::string name, effect_parameter::type type)
|
|
|
|
{
|
2019-08-04 21:12:30 +00:00
|
|
|
auto eprm = get_annotation(name);
|
|
|
|
if (eprm)
|
|
|
|
return eprm->get_type() == type;
|
|
|
|
return false;
|
2019-08-04 20:44:46 +00:00
|
|
|
}
|