mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-11 06:15:05 +00:00
gs-effect-pass/technique: Implement wrapper code based on std::shared_ptr
These two wrap the underlying gs_epass and gs_effect_technique objects, to allow direct and improved access to them without relying on the libobs API to provide this access for us. Additionally these make it safe for us to use them instead of relying on C-like code to deal with it.
This commit is contained in:
parent
d53e9eeadf
commit
738b08de36
5 changed files with 217 additions and 0 deletions
|
@ -317,6 +317,10 @@ set(PROJECT_PRIVATE_SOURCE
|
|||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-helper.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-effect.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-effect.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-effect-pass.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-effect-pass.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-effect-technique.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-effect-technique.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-indexbuffer.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-indexbuffer.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/source/obs/gs/gs-limits.hpp"
|
||||
|
|
45
source/obs/gs/gs-effect-pass.cpp
Normal file
45
source/obs/gs/gs-effect-pass.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Modern effects for a modern Streamer
|
||||
* Copyright (C) 2019 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
|
||||
*/
|
||||
|
||||
#include "gs-effect-pass.hpp"
|
||||
#include <cstring>
|
||||
|
||||
#include <graphics/effect.h>
|
||||
|
||||
gs::effect_pass::effect_pass(gs_epass_t* pass, std::shared_ptr<gs_technique_t>* parent) : _parent(parent)
|
||||
{
|
||||
reset(pass, [](void*) {});
|
||||
}
|
||||
|
||||
gs::effect_pass::~effect_pass() {}
|
||||
|
||||
std::string gs::effect_pass::name()
|
||||
{
|
||||
return std::string(get()->name, get()->name + strnlen_s(get()->name, 256));
|
||||
}
|
||||
|
||||
size_t gs::effect_pass::count_vertex_parameters()
|
||||
{
|
||||
return static_cast<size_t>(get()->vertshader_params.num);
|
||||
}
|
||||
|
||||
size_t gs::effect_pass::count_pixel_parameters()
|
||||
{
|
||||
return static_cast<size_t>(get()->pixelshader_params.num);
|
||||
}
|
52
source/obs/gs/gs-effect-pass.hpp
Normal file
52
source/obs/gs/gs-effect-pass.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Modern effects for a modern Streamer
|
||||
* Copyright (C) 2019 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <graphics/graphics.h>
|
||||
|
||||
namespace gs {
|
||||
class effect_pass : public std::shared_ptr<gs_epass_t> {
|
||||
std::shared_ptr<gs_technique_t>* _parent;
|
||||
|
||||
public:
|
||||
effect_pass(gs_epass_t* pass, std::shared_ptr<gs_technique_t>* parent = nullptr);
|
||||
~effect_pass();
|
||||
|
||||
std::string name();
|
||||
|
||||
//gs::shader get_pixel_shader();
|
||||
//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);
|
||||
|
||||
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);
|
||||
};
|
||||
} // namespace gs
|
72
source/obs/gs/gs-effect-technique.cpp
Normal file
72
source/obs/gs/gs-effect-technique.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Modern effects for a modern Streamer
|
||||
* Copyright (C) 2019 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
|
||||
*/
|
||||
|
||||
#include "gs-effect-technique.hpp"
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <graphics/effect.h>
|
||||
|
||||
gs::effect_technique::effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t>* parent) : _parent(parent)
|
||||
{
|
||||
reset(technique, [](void*) {});
|
||||
}
|
||||
|
||||
gs::effect_technique::~effect_technique() {}
|
||||
|
||||
std::string gs::effect_technique::name()
|
||||
{
|
||||
|
||||
return std::string(get()->name, get()->name + strnlen_s(get()->name, 256));
|
||||
}
|
||||
|
||||
size_t gs::effect_technique::count_passes()
|
||||
{
|
||||
return static_cast<size_t>(get()->passes.num);
|
||||
}
|
||||
|
||||
gs::effect_pass gs::effect_technique::get_pass(size_t idx)
|
||||
{
|
||||
if (idx >= get()->passes.num) {
|
||||
throw std::out_of_range("Index is out of range.");
|
||||
}
|
||||
|
||||
return gs::effect_pass(get()->passes.array + idx, this);
|
||||
}
|
||||
|
||||
gs::effect_pass gs::effect_technique::get_pass(std::string name)
|
||||
{
|
||||
for (size_t idx = 0; idx < get()->passes.num; idx++) {
|
||||
auto ptr = get()->passes.array + idx;
|
||||
if (strcmp(ptr->name, name.c_str()) == 0)
|
||||
return gs::effect_pass(ptr, this);
|
||||
}
|
||||
|
||||
throw std::invalid_argument("Pass with given name does not exist.");
|
||||
}
|
||||
|
||||
bool gs::effect_technique::has_pass(std::string name)
|
||||
{
|
||||
for (size_t idx = 0; idx < get()->passes.num; idx++) {
|
||||
auto ptr = get()->passes.array + idx;
|
||||
if (strcmp(ptr->name, name.c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
44
source/obs/gs/gs-effect-technique.hpp
Normal file
44
source/obs/gs/gs-effect-technique.hpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Modern effects for a modern Streamer
|
||||
* Copyright (C) 2019 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "gs-effect-pass.hpp"
|
||||
|
||||
#include <graphics/graphics.h>
|
||||
|
||||
namespace gs {
|
||||
class effect_technique : public std::shared_ptr<gs_technique_t> {
|
||||
std::shared_ptr<gs_effect_t>* _parent;
|
||||
|
||||
public:
|
||||
effect_technique(gs_technique_t* technique, std::shared_ptr<gs_effect_t>* parent = nullptr);
|
||||
~effect_technique();
|
||||
|
||||
std::string name();
|
||||
|
||||
size_t count_passes();
|
||||
gs::effect_pass get_pass(size_t idx);
|
||||
gs::effect_pass get_pass(std::string name);
|
||||
bool has_pass(std::string name);
|
||||
|
||||
};
|
||||
} // namespace gs
|
Loading…
Reference in a new issue