mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-10 22:05:06 +00:00
gs-effect: Formatting
This commit is contained in:
parent
1923a724d7
commit
391fca7497
2 changed files with 133 additions and 98 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "gs-effect.h"
|
#include "gs-effect.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4201)
|
#pragma warning(disable : 4201)
|
||||||
|
@ -26,11 +27,10 @@ extern "C" {
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect::effect() {
|
gs::effect::effect() : m_effect(nullptr) {}
|
||||||
m_effect = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
gs::effect::effect(std::string file) {
|
gs::effect::effect(std::string file)
|
||||||
|
{
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
char* errorMessage = nullptr;
|
char* errorMessage = nullptr;
|
||||||
m_effect = gs_effect_create_from_file(file.c_str(), &errorMessage);
|
m_effect = gs_effect_create_from_file(file.c_str(), &errorMessage);
|
||||||
|
@ -46,7 +46,8 @@ gs::effect::effect(std::string file) {
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect::effect(std::string code, std::string name) {
|
gs::effect::effect(std::string code, std::string name)
|
||||||
|
{
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
char* errorMessage = nullptr;
|
char* errorMessage = nullptr;
|
||||||
m_effect = gs_effect_create(code.c_str(), name.c_str(), &errorMessage);
|
m_effect = gs_effect_create(code.c_str(), name.c_str(), &errorMessage);
|
||||||
|
@ -62,21 +63,25 @@ gs::effect::effect(std::string code, std::string name) {
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect::~effect() {
|
gs::effect::~effect()
|
||||||
|
{
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
gs_effect_destroy(m_effect);
|
gs_effect_destroy(m_effect);
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
gs_effect_t* gs::effect::get_object() {
|
gs_effect_t* gs::effect::get_object()
|
||||||
|
{
|
||||||
return m_effect;
|
return m_effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t gs::effect::count_parameters() {
|
size_t gs::effect::count_parameters()
|
||||||
|
{
|
||||||
return (size_t)gs_effect_get_num_params(m_effect);
|
return (size_t)gs_effect_get_num_params(m_effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<gs::effect_parameter> gs::effect::get_parameters() {
|
std::list<gs::effect_parameter> gs::effect::get_parameters()
|
||||||
|
{
|
||||||
size_t num = gs_effect_get_num_params(m_effect);
|
size_t num = gs_effect_get_num_params(m_effect);
|
||||||
std::list<gs::effect_parameter> ps;
|
std::list<gs::effect_parameter> ps;
|
||||||
for (size_t idx = 0; idx < num; idx++) {
|
for (size_t idx = 0; idx < num; idx++) {
|
||||||
|
@ -85,19 +90,22 @@ std::list<gs::effect_parameter> gs::effect::get_parameters() {
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter gs::effect::get_parameter(size_t idx) {
|
gs::effect_parameter gs::effect::get_parameter(size_t idx)
|
||||||
|
{
|
||||||
gs_eparam_t* param = gs_effect_get_param_by_idx(m_effect, idx);
|
gs_eparam_t* param = gs_effect_get_param_by_idx(m_effect, idx);
|
||||||
if (!param)
|
if (!param)
|
||||||
throw std::invalid_argument("parameter with index not found");
|
throw std::invalid_argument("parameter with index not found");
|
||||||
return effect_parameter(param);
|
return effect_parameter(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gs::effect::has_parameter(std::string name) {
|
bool gs::effect::has_parameter(std::string name)
|
||||||
|
{
|
||||||
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
|
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
|
||||||
return (param != nullptr);
|
return (param != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gs::effect::has_parameter(std::string name, effect_parameter::type type) {
|
bool gs::effect::has_parameter(std::string name, effect_parameter::type type)
|
||||||
|
{
|
||||||
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
|
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
|
||||||
if (param == nullptr)
|
if (param == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
@ -105,14 +113,16 @@ bool gs::effect::has_parameter(std::string name, effect_parameter::type type) {
|
||||||
return eprm.get_type() == type;
|
return eprm.get_type() == type;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter gs::effect::get_parameter(std::string name) {
|
gs::effect_parameter gs::effect::get_parameter(std::string name)
|
||||||
|
{
|
||||||
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
|
gs_eparam_t* param = gs_effect_get_param_by_name(m_effect, name.c_str());
|
||||||
if (!param)
|
if (!param)
|
||||||
throw std::invalid_argument("parameter with name not found");
|
throw std::invalid_argument("parameter with name not found");
|
||||||
return effect_parameter(param);
|
return effect_parameter(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter::effect_parameter(gs_eparam_t* param) {
|
gs::effect_parameter::effect_parameter(gs_eparam_t* param)
|
||||||
|
{
|
||||||
if (!param)
|
if (!param)
|
||||||
throw std::invalid_argument("param is null");
|
throw std::invalid_argument("param is null");
|
||||||
|
|
||||||
|
@ -120,11 +130,13 @@ gs::effect_parameter::effect_parameter(gs_eparam_t* param) {
|
||||||
gs_effect_get_param_info(m_param, &m_paramInfo);
|
gs_effect_get_param_info(m_param, &m_paramInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string gs::effect_parameter::get_name() {
|
std::string gs::effect_parameter::get_name()
|
||||||
|
{
|
||||||
return m_paramInfo.name;
|
return m_paramInfo.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter::type gs::effect_parameter::get_type() {
|
gs::effect_parameter::type gs::effect_parameter::get_type()
|
||||||
|
{
|
||||||
switch (m_paramInfo.type) {
|
switch (m_paramInfo.type) {
|
||||||
case GS_SHADER_PARAM_BOOL:
|
case GS_SHADER_PARAM_BOOL:
|
||||||
return type::Boolean;
|
return type::Boolean;
|
||||||
|
@ -156,127 +168,149 @@ gs::effect_parameter::type gs::effect_parameter::get_type() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_bool(bool v) {
|
void gs::effect_parameter::set_bool(bool v)
|
||||||
|
{
|
||||||
if (get_type() != type::Boolean)
|
if (get_type() != type::Boolean)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_bool(m_param, v);
|
gs_effect_set_bool(m_param, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_bool_array(bool v[], size_t sz) {
|
void gs::effect_parameter::set_bool_array(bool v[], size_t sz)
|
||||||
|
{
|
||||||
if (get_type() != type::Boolean)
|
if (get_type() != type::Boolean)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_val(m_param, v, sz);
|
gs_effect_set_val(m_param, v, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float(float_t x) {
|
void gs::effect_parameter::set_float(float_t x)
|
||||||
|
{
|
||||||
if (get_type() != type::Float)
|
if (get_type() != type::Float)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_float(m_param, x);
|
gs_effect_set_float(m_param, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float2(vec2& v) {
|
void gs::effect_parameter::set_float2(vec2& v)
|
||||||
|
{
|
||||||
if (get_type() != type::Float2)
|
if (get_type() != type::Float2)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_vec2(m_param, &v);
|
gs_effect_set_vec2(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float2(float_t x, float_t y) {
|
void gs::effect_parameter::set_float2(float_t x, float_t y)
|
||||||
|
{
|
||||||
if (get_type() != type::Float2)
|
if (get_type() != type::Float2)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
vec2 v = {x, y};
|
vec2 v = {x, y};
|
||||||
gs_effect_set_vec2(m_param, &v);
|
gs_effect_set_vec2(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float3(vec3& v) {
|
void gs::effect_parameter::set_float3(vec3& v)
|
||||||
|
{
|
||||||
if (get_type() != type::Float3)
|
if (get_type() != type::Float3)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_vec3(m_param, &v);
|
gs_effect_set_vec3(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float3(float_t x, float_t y, float_t z) {
|
void gs::effect_parameter::set_float3(float_t x, float_t y, float_t z)
|
||||||
|
{
|
||||||
if (get_type() != type::Float3)
|
if (get_type() != type::Float3)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
vec3 v = {x, y, z};
|
vec3 v = {x, y, z};
|
||||||
gs_effect_set_vec3(m_param, &v);
|
gs_effect_set_vec3(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float4(vec4& v) {
|
void gs::effect_parameter::set_float4(vec4& v)
|
||||||
|
{
|
||||||
if (get_type() != type::Float4)
|
if (get_type() != type::Float4)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_vec4(m_param, &v);
|
gs_effect_set_vec4(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float4(float_t x, float_t y, float_t z, float_t w) {
|
void gs::effect_parameter::set_float4(float_t x, float_t y, float_t z, float_t w)
|
||||||
|
{
|
||||||
if (get_type() != type::Float4)
|
if (get_type() != type::Float4)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
vec4 v = {x, y, z, w};
|
vec4 v = {x, y, z, w};
|
||||||
gs_effect_set_vec4(m_param, &v);
|
gs_effect_set_vec4(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_float_array(float_t v[], size_t sz) {
|
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))
|
{
|
||||||
|
if ((get_type() != type::Float) && (get_type() != type::Float2) && (get_type() != type::Float3)
|
||||||
|
&& (get_type() != type::Float4))
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_val(m_param, v, sizeof(float_t) * sz);
|
gs_effect_set_val(m_param, v, sizeof(float_t) * sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_int(int32_t x) {
|
void gs::effect_parameter::set_int(int32_t x)
|
||||||
|
{
|
||||||
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
|
if ((get_type() != type::Integer) && (get_type() != type::Unknown))
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_int(m_param, x);
|
gs_effect_set_int(m_param, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_int2(int32_t x, int32_t y) {
|
void gs::effect_parameter::set_int2(int32_t x, int32_t y)
|
||||||
|
{
|
||||||
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
|
if ((get_type() != type::Integer2) && (get_type() != type::Unknown))
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
int32_t v[2] = {x, y};
|
int32_t v[2] = {x, y};
|
||||||
gs_effect_set_val(m_param, v, sizeof(int) * 2);
|
gs_effect_set_val(m_param, v, sizeof(int) * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_int3(int32_t x, int32_t y, int32_t z) {
|
void gs::effect_parameter::set_int3(int32_t x, int32_t y, int32_t z)
|
||||||
|
{
|
||||||
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
|
if ((get_type() != type::Integer3) && (get_type() != type::Unknown))
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
int32_t v[3] = {x, y, z};
|
int32_t v[3] = {x, y, z};
|
||||||
gs_effect_set_val(m_param, v, sizeof(int) * 3);
|
gs_effect_set_val(m_param, v, sizeof(int) * 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_int4(int32_t x, int32_t y, int32_t z, int32_t w) {
|
void gs::effect_parameter::set_int4(int32_t x, int32_t y, int32_t z, int32_t w)
|
||||||
|
{
|
||||||
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
|
if ((get_type() != type::Integer4) && (get_type() != type::Unknown))
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
int32_t v[4] = {x, y, z, w};
|
int32_t v[4] = {x, y, z, w};
|
||||||
gs_effect_set_val(m_param, v, sizeof(int) * 4);
|
gs_effect_set_val(m_param, v, sizeof(int) * 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_int_array(int32_t v[], size_t sz) {
|
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))
|
{
|
||||||
|
if ((get_type() != type::Integer) && (get_type() != type::Integer2) && (get_type() != type::Integer3)
|
||||||
|
&& (get_type() != type::Integer4) && (get_type() != type::Unknown))
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_val(m_param, v, sizeof(int) * sz);
|
gs_effect_set_val(m_param, v, sizeof(int) * sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_matrix(matrix4& v) {
|
void gs::effect_parameter::set_matrix(matrix4& v)
|
||||||
|
{
|
||||||
if (get_type() != type::Matrix)
|
if (get_type() != type::Matrix)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_matrix4(m_param, &v);
|
gs_effect_set_matrix4(m_param, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_texture(std::shared_ptr<gs::texture> v) {
|
void gs::effect_parameter::set_texture(std::shared_ptr<gs::texture> v)
|
||||||
|
{
|
||||||
if (get_type() != type::Texture)
|
if (get_type() != type::Texture)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_texture(m_param, v->get_object());
|
gs_effect_set_texture(m_param, v->get_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_texture(gs_texture_t* v) {
|
void gs::effect_parameter::set_texture(gs_texture_t* v)
|
||||||
|
{
|
||||||
if (get_type() != type::Texture)
|
if (get_type() != type::Texture)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_texture(m_param, v);
|
gs_effect_set_texture(m_param, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_sampler(std::shared_ptr<gs::sampler> v) {
|
void gs::effect_parameter::set_sampler(std::shared_ptr<gs::sampler> v)
|
||||||
|
{
|
||||||
if (get_type() != type::Texture)
|
if (get_type() != type::Texture)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_next_sampler(m_param, v->get_object());
|
gs_effect_set_next_sampler(m_param, v->get_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::effect_parameter::set_sampler(gs_sampler_state* v) {
|
void gs::effect_parameter::set_sampler(gs_sampler_state* v)
|
||||||
|
{
|
||||||
if (get_type() != type::Texture)
|
if (get_type() != type::Texture)
|
||||||
throw std::bad_cast();
|
throw std::bad_cast();
|
||||||
gs_effect_set_next_sampler(m_param, v);
|
gs_effect_set_next_sampler(m_param, v);
|
||||||
|
|
|
@ -18,12 +18,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "gs-texture.h"
|
|
||||||
#include "gs-sampler.h"
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include "gs-sampler.h"
|
||||||
|
#include "gs-texture.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4201)
|
#pragma warning(disable : 4201)
|
||||||
|
@ -105,4 +106,4 @@ namespace gs {
|
||||||
protected:
|
protected:
|
||||||
gs_effect_t* m_effect;
|
gs_effect_t* m_effect;
|
||||||
};
|
};
|
||||||
}
|
} // namespace gs
|
||||||
|
|
Loading…
Reference in a new issue