diff --git a/source/obs/gs/gs-effect-pass.cpp b/source/obs/gs/gs-effect-pass.cpp index dbca7f22..86cab723 100644 --- a/source/obs/gs/gs-effect-pass.cpp +++ b/source/obs/gs/gs-effect-pass.cpp @@ -31,7 +31,9 @@ gs::effect_pass::~effect_pass() {} std::string gs::effect_pass::name() { - return std::string(get()->name, get()->name + strnlen_s(get()->name, 256)); + const char* name_c = get()->name; + size_t name_len = strnlen_s(name_c, 256); + return name_c ? std::string(name_c, name_c + name_len) : std::string(); } size_t gs::effect_pass::count_vertex_parameters() @@ -39,7 +41,69 @@ size_t gs::effect_pass::count_vertex_parameters() return static_cast(get()->vertshader_params.num); } +gs::effect_parameter gs::effect_pass::get_vertex_parameter(size_t idx) +{ + if (idx >= count_vertex_parameters()) + return nullptr; + + return gs::effect_parameter((get()->vertshader_params.array + idx)->eparam, this); +} + +gs::effect_parameter gs::effect_pass::get_vertex_parameter(std::string name) +{ + for (size_t idx = 0; idx < count_vertex_parameters(); idx++) { + auto ptr = get()->vertshader_params.array + idx; + if (strcmp(ptr->eparam->name, name.c_str()) == 0) + return gs::effect_parameter(ptr->eparam, this); + } + return nullptr; +} + +bool gs::effect_pass::has_vertex_parameter(std::string name) +{ + return (get_vertex_parameter(name) != nullptr); +} + +bool gs::effect_pass::has_vertex_parameter(std::string name, gs::effect_parameter::type type) +{ + if (auto el = get_vertex_parameter(name); el != nullptr) { + return el.get_type() == type; + } + return false; +} + size_t gs::effect_pass::count_pixel_parameters() { return static_cast(get()->pixelshader_params.num); } + +gs::effect_parameter gs::effect_pass::get_pixel_parameter(size_t idx) +{ + if (idx >= count_pixel_parameters()) + return nullptr; + + return gs::effect_parameter((get()->pixelshader_params.array + idx)->eparam, this); +} + +gs::effect_parameter gs::effect_pass::get_pixel_parameter(std::string name) +{ + for (size_t idx = 0; idx < count_pixel_parameters(); idx++) { + auto ptr = get()->pixelshader_params.array + idx; + if (strcmp(ptr->eparam->name, name.c_str()) == 0) + return gs::effect_parameter(ptr->eparam, this); + } + return nullptr; +} + +bool gs::effect_pass::has_pixel_parameter(std::string name) +{ + return (get_pixel_parameter(name) != nullptr); +} + +bool gs::effect_pass::has_pixel_parameter(std::string name, gs::effect_parameter::type type) +{ + if (auto el = get_pixel_parameter(name); el != nullptr) { + return el.get_type() == type; + } + return false; +} diff --git a/source/obs/gs/gs-effect-pass.hpp b/source/obs/gs/gs-effect-pass.hpp index 6fd11eac..9aefa51e 100644 --- a/source/obs/gs/gs-effect-pass.hpp +++ b/source/obs/gs/gs-effect-pass.hpp @@ -21,6 +21,7 @@ #include #include #include +#include "gs-effect-parameter.hpp" // OBS extern "C" { @@ -48,15 +49,15 @@ namespace gs { //gs::shader get_vertex_shader(); size_t count_vertex_parameters(); - //gs::parameter get_vertex_parameter(size_t idx); - //gs::parameter get_vertex_parameter(std::string name); - //bool has_vertex_parameter(std::string name); - //bool has_vertex_parameter(std::string name, ... type); + gs::effect_parameter get_vertex_parameter(size_t idx); + gs::effect_parameter get_vertex_parameter(std::string name); + bool has_vertex_parameter(std::string name); + bool has_vertex_parameter(std::string name, gs::effect_parameter::type type); size_t count_pixel_parameters(); - //gs::parameter get_vertex_parameter(size_t idx); - //gs::parameter get_vertex_parameter(std::string name); - //bool has_vertex_parameter(std::string name); - //bool has_vertex_parameter(std::string name, ... type); + gs::effect_parameter get_pixel_parameter(size_t idx); + gs::effect_parameter get_pixel_parameter(std::string name); + bool has_pixel_parameter(std::string name); + bool has_pixel_parameter(std::string name, gs::effect_parameter::type type); }; } // namespace gs