mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-15 08:15:06 +00:00
obs/gs/effect: Use the actual shared_ptr, not a pointer to it
Fixes several warnings and potential memory corruptions that could happen. Also makes the entire thing easier to read.
This commit is contained in:
parent
2a4f771d85
commit
ad64314b37
7 changed files with 28 additions and 29 deletions
|
@ -44,19 +44,18 @@ gs::effect_parameter::effect_parameter(gs_eparam_t* param)
|
||||||
reset(param, [](void*) {});
|
reset(param, [](void*) {});
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_effect_t>* parent)
|
gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_effect_t> parent)
|
||||||
: effect_parameter(param)
|
: effect_parameter(param)
|
||||||
{
|
{
|
||||||
_effect_parent = parent;
|
_effect_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_epass_t>* parent)
|
gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_epass_t> parent) : effect_parameter(param)
|
||||||
: effect_parameter(param)
|
|
||||||
{
|
{
|
||||||
_pass_parent = parent;
|
_pass_parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_eparam_t>* parent)
|
gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_eparam_t> parent)
|
||||||
: effect_parameter(param)
|
: effect_parameter(param)
|
||||||
{
|
{
|
||||||
_param_parent = parent;
|
_param_parent = parent;
|
||||||
|
@ -161,7 +160,7 @@ gs::effect_parameter gs::effect_parameter::get_annotation(std::size_t idx)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return effect_parameter(get()->annotations.array + idx, this);
|
return effect_parameter(get()->annotations.array + idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter gs::effect_parameter::get_annotation(const std::string_view name)
|
gs::effect_parameter gs::effect_parameter::get_annotation(const std::string_view name)
|
||||||
|
@ -169,7 +168,7 @@ gs::effect_parameter gs::effect_parameter::get_annotation(const std::string_view
|
||||||
for (std::size_t idx = 0; idx < get()->annotations.num; idx++) {
|
for (std::size_t idx = 0; idx < get()->annotations.num; idx++) {
|
||||||
auto ptr = get()->annotations.array + idx;
|
auto ptr = get()->annotations.array + idx;
|
||||||
if (name == std::string_view{ptr->name}) {
|
if (name == std::string_view{ptr->name}) {
|
||||||
return gs::effect_parameter(ptr, this);
|
return gs::effect_parameter(ptr, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
|
|
||||||
namespace gs {
|
namespace gs {
|
||||||
class effect_parameter : public std::shared_ptr<gs_eparam_t> {
|
class effect_parameter : public std::shared_ptr<gs_eparam_t> {
|
||||||
std::shared_ptr<gs_effect_t>* _effect_parent;
|
std::shared_ptr<gs_effect_t> _effect_parent;
|
||||||
std::shared_ptr<gs_epass_t>* _pass_parent;
|
std::shared_ptr<gs_epass_t> _pass_parent;
|
||||||
std::shared_ptr<gs_eparam_t>* _param_parent;
|
std::shared_ptr<gs_eparam_t> _param_parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class type {
|
enum class type {
|
||||||
|
@ -50,9 +50,9 @@ namespace gs {
|
||||||
public:
|
public:
|
||||||
effect_parameter();
|
effect_parameter();
|
||||||
effect_parameter(gs_eparam_t* param);
|
effect_parameter(gs_eparam_t* param);
|
||||||
effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_effect_t>* parent);
|
effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_effect_t> parent);
|
||||||
effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_epass_t>* parent);
|
effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_epass_t> parent);
|
||||||
effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_eparam_t>* parent);
|
effect_parameter(gs_eparam_t* param, std::shared_ptr<gs_eparam_t> parent);
|
||||||
~effect_parameter();
|
~effect_parameter();
|
||||||
|
|
||||||
effect_parameter(const effect_parameter& rhs);
|
effect_parameter(const effect_parameter& rhs);
|
||||||
|
|
|
@ -31,7 +31,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_pass::effect_pass(gs_epass_t* pass, std::shared_ptr<gs_technique_t>* parent) : _parent(parent)
|
gs::effect_pass::effect_pass(gs_epass_t* pass, std::shared_ptr<gs_technique_t> parent) : _parent(parent)
|
||||||
{
|
{
|
||||||
reset(pass, [](void*) {});
|
reset(pass, [](void*) {});
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ gs::effect_parameter gs::effect_pass::get_vertex_parameter(std::size_t idx)
|
||||||
if (idx >= count_vertex_parameters())
|
if (idx >= count_vertex_parameters())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return gs::effect_parameter((get()->vertshader_params.array + idx)->eparam, this);
|
return gs::effect_parameter((get()->vertshader_params.array + idx)->eparam, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter gs::effect_pass::get_vertex_parameter(std::string name)
|
gs::effect_parameter gs::effect_pass::get_vertex_parameter(std::string name)
|
||||||
|
@ -63,7 +63,7 @@ gs::effect_parameter gs::effect_pass::get_vertex_parameter(std::string name)
|
||||||
for (std::size_t idx = 0; idx < count_vertex_parameters(); idx++) {
|
for (std::size_t idx = 0; idx < count_vertex_parameters(); idx++) {
|
||||||
auto ptr = get()->vertshader_params.array + idx;
|
auto ptr = get()->vertshader_params.array + idx;
|
||||||
if (strcmp(ptr->eparam->name, name.c_str()) == 0)
|
if (strcmp(ptr->eparam->name, name.c_str()) == 0)
|
||||||
return gs::effect_parameter(ptr->eparam, this);
|
return gs::effect_parameter(ptr->eparam, *this);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ gs::effect_parameter gs::effect_pass::get_pixel_parameter(std::size_t idx)
|
||||||
if (idx >= count_pixel_parameters())
|
if (idx >= count_pixel_parameters())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
return gs::effect_parameter((get()->pixelshader_params.array + idx)->eparam, this);
|
return gs::effect_parameter((get()->pixelshader_params.array + idx)->eparam, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter gs::effect_pass::get_pixel_parameter(std::string name)
|
gs::effect_parameter gs::effect_pass::get_pixel_parameter(std::string name)
|
||||||
|
@ -99,7 +99,7 @@ gs::effect_parameter gs::effect_pass::get_pixel_parameter(std::string name)
|
||||||
for (std::size_t idx = 0; idx < count_pixel_parameters(); idx++) {
|
for (std::size_t idx = 0; idx < count_pixel_parameters(); idx++) {
|
||||||
auto ptr = get()->pixelshader_params.array + idx;
|
auto ptr = get()->pixelshader_params.array + idx;
|
||||||
if (strcmp(ptr->eparam->name, name.c_str()) == 0)
|
if (strcmp(ptr->eparam->name, name.c_str()) == 0)
|
||||||
return gs::effect_parameter(ptr->eparam, this);
|
return gs::effect_parameter(ptr->eparam, *this);
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,16 +23,17 @@
|
||||||
|
|
||||||
namespace gs {
|
namespace gs {
|
||||||
class effect_pass : public std::shared_ptr<gs_epass_t> {
|
class effect_pass : public std::shared_ptr<gs_epass_t> {
|
||||||
std::shared_ptr<gs_technique_t>* _parent;
|
std::shared_ptr<gs_technique_t> _parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
effect_pass(gs_epass_t* pass, std::shared_ptr<gs_technique_t>* parent = nullptr);
|
effect_pass(gs_epass_t* pass, std::shared_ptr<gs_technique_t> parent = nullptr);
|
||||||
~effect_pass();
|
~effect_pass();
|
||||||
|
|
||||||
std::string name();
|
std::string name();
|
||||||
|
|
||||||
//gs::shader get_pixel_shader();
|
//gs::shader get_pixel_shader();
|
||||||
//gs::shader get_vertex_shader();
|
//gs::shader get_vertex_shader();
|
||||||
|
//
|
||||||
|
|
||||||
std::size_t count_vertex_parameters();
|
std::size_t count_vertex_parameters();
|
||||||
gs::effect_parameter get_vertex_parameter(std::size_t idx);
|
gs::effect_parameter get_vertex_parameter(std::size_t idx);
|
||||||
|
|
|
@ -32,8 +32,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_technique::effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t>* parent)
|
gs::effect_technique::effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t> parent) : _parent(parent)
|
||||||
: _parent(parent)
|
|
||||||
{
|
{
|
||||||
reset(technique, [](void*) {});
|
reset(technique, [](void*) {});
|
||||||
}
|
}
|
||||||
|
@ -58,7 +57,7 @@ gs::effect_pass gs::effect_technique::get_pass(std::size_t idx)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gs::effect_pass(get()->passes.array + idx, this);
|
return gs::effect_pass(get()->passes.array + idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_pass gs::effect_technique::get_pass(std::string name)
|
gs::effect_pass gs::effect_technique::get_pass(std::string name)
|
||||||
|
@ -66,7 +65,7 @@ gs::effect_pass gs::effect_technique::get_pass(std::string name)
|
||||||
for (std::size_t idx = 0; idx < get()->passes.num; idx++) {
|
for (std::size_t idx = 0; idx < get()->passes.num; idx++) {
|
||||||
auto ptr = get()->passes.array + idx;
|
auto ptr = get()->passes.array + idx;
|
||||||
if (strcmp(ptr->name, name.c_str()) == 0)
|
if (strcmp(ptr->name, name.c_str()) == 0)
|
||||||
return gs::effect_pass(ptr, this);
|
return gs::effect_pass(ptr, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -23,10 +23,10 @@
|
||||||
|
|
||||||
namespace gs {
|
namespace gs {
|
||||||
class effect_technique : public std::shared_ptr<gs_technique_t> {
|
class effect_technique : public std::shared_ptr<gs_technique_t> {
|
||||||
std::shared_ptr<gs_effect_t>* _parent;
|
std::shared_ptr<gs_effect_t> _parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t>* parent = nullptr);
|
effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t> parent = nullptr);
|
||||||
~effect_technique();
|
~effect_technique();
|
||||||
|
|
||||||
std::string name();
|
std::string name();
|
||||||
|
|
|
@ -77,7 +77,7 @@ gs::effect_technique gs::effect::get_technique(std::size_t idx)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return gs::effect_technique(get()->techniques.array + idx, this);
|
return gs::effect_technique(get()->techniques.array + idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_technique gs::effect::get_technique(const std::string& name)
|
gs::effect_technique gs::effect::get_technique(const std::string& name)
|
||||||
|
@ -85,7 +85,7 @@ gs::effect_technique gs::effect::get_technique(const std::string& name)
|
||||||
for (std::size_t idx = 0; idx < count_techniques(); idx++) {
|
for (std::size_t idx = 0; idx < count_techniques(); idx++) {
|
||||||
auto ptr = get()->techniques.array + idx;
|
auto ptr = get()->techniques.array + idx;
|
||||||
if (strcmp(ptr->name, name.c_str()) == 0) {
|
if (strcmp(ptr->name, name.c_str()) == 0) {
|
||||||
return gs::effect_technique(ptr, this);
|
return gs::effect_technique(ptr, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ gs::effect_parameter gs::effect::get_parameter(std::size_t idx)
|
||||||
throw std::out_of_range("Index is out of range.");
|
throw std::out_of_range("Index is out of range.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return gs::effect_parameter(get()->params.array + idx, this);
|
return gs::effect_parameter(get()->params.array + idx, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::effect_parameter gs::effect::get_parameter(const std::string& name)
|
gs::effect_parameter gs::effect::get_parameter(const std::string& name)
|
||||||
|
@ -118,7 +118,7 @@ gs::effect_parameter gs::effect::get_parameter(const std::string& name)
|
||||||
for (std::size_t idx = 0; idx < count_parameters(); idx++) {
|
for (std::size_t idx = 0; idx < count_parameters(); idx++) {
|
||||||
auto ptr = get()->params.array + idx;
|
auto ptr = get()->params.array + idx;
|
||||||
if (strcmp(ptr->name, name.c_str()) == 0) {
|
if (strcmp(ptr->name, name.c_str()) == 0) {
|
||||||
return gs::effect_parameter(ptr, this);
|
return gs::effect_parameter(ptr, *this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue