mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-24 04:15:11 +00:00
gs-effect-pass: Implement parameter getter and fix possible crash
This commit is contained in:
parent
570b70479f
commit
cd82e2cac7
2 changed files with 74 additions and 9 deletions
|
@ -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<size_t>(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<size_t>(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;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#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
|
||||
|
|
Loading…
Reference in a new issue