mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-30 23:33:02 +00:00
gs-rendertarget: Formatting and refactoring
This commit is contained in:
parent
ded5896fca
commit
faeb5af45b
2 changed files with 65 additions and 47 deletions
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#include "gs-rendertarget.h"
|
#include "gs-rendertarget.h"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4201)
|
#pragma warning(disable : 4201)
|
||||||
|
@ -26,67 +27,77 @@ extern "C" {
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::rendertarget::rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat) {
|
gs::rendertarget::~rendertarget()
|
||||||
m_isBeingRendered = false;
|
{
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
m_renderTarget = gs_texrender_create(colorFormat, zsFormat);
|
gs_texrender_destroy(render_target);
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::rendertarget::~rendertarget() {
|
gs::rendertarget::rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat)
|
||||||
|
{
|
||||||
|
is_being_rendered = false;
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
gs_texrender_destroy(m_renderTarget);
|
render_target = gs_texrender_create(colorFormat, zsFormat);
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::rendertarget_op gs::rendertarget::render(uint32_t width, uint32_t height) {
|
gs::rendertarget_op gs::rendertarget::render(uint32_t width, uint32_t height)
|
||||||
|
{
|
||||||
return {this, width, height};
|
return {this, width, height};
|
||||||
}
|
}
|
||||||
|
|
||||||
gs_texture_t* gs::rendertarget::get_object() {
|
gs_texture_t* gs::rendertarget::get_object()
|
||||||
|
{
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
gs_texture_t* tex = gs_texrender_get_texture(m_renderTarget);
|
gs_texture_t* tex = gs_texrender_get_texture(render_target);
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
return tex;
|
return tex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::rendertarget::get_texture(gs::texture& tex) {
|
void gs::rendertarget::get_texture(gs::texture& tex)
|
||||||
|
{
|
||||||
tex = gs::texture(get_object(), false);
|
tex = gs::texture(get_object(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::rendertarget::get_texture(std::shared_ptr<gs::texture>& tex) {
|
void gs::rendertarget::get_texture(std::shared_ptr<gs::texture>& tex)
|
||||||
|
{
|
||||||
tex = std::make_shared<gs::texture>(get_object(), false);
|
tex = std::make_shared<gs::texture>(get_object(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gs::rendertarget::get_texture(std::unique_ptr<gs::texture>& tex) {
|
void gs::rendertarget::get_texture(std::unique_ptr<gs::texture>& tex)
|
||||||
|
{
|
||||||
tex = std::make_unique<gs::texture>(get_object(), false);
|
tex = std::make_unique<gs::texture>(get_object(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::rendertarget_op::rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height) : m_renderTarget(rt) {
|
gs::rendertarget_op::rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height) : parent(rt)
|
||||||
if (m_renderTarget == nullptr)
|
{
|
||||||
|
if (parent == nullptr)
|
||||||
throw std::invalid_argument("rt");
|
throw std::invalid_argument("rt");
|
||||||
if (m_renderTarget->m_isBeingRendered)
|
if (parent->is_being_rendered)
|
||||||
throw std::logic_error("Can't start rendering to the same render target twice.");
|
throw std::logic_error("Can't start rendering to the same render target twice.");
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
gs_texrender_reset(m_renderTarget->m_renderTarget);
|
gs_texrender_reset(parent->render_target);
|
||||||
if (!gs_texrender_begin(m_renderTarget->m_renderTarget, width, height)) {
|
if (!gs_texrender_begin(parent->render_target, width, height)) {
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
throw std::runtime_error("Failed to begin rendering to render target.");
|
throw std::runtime_error("Failed to begin rendering to render target.");
|
||||||
}
|
}
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
m_renderTarget->m_isBeingRendered = true;
|
parent->is_being_rendered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::rendertarget_op::rendertarget_op(gs::rendertarget_op&& r) {
|
gs::rendertarget_op::rendertarget_op(gs::rendertarget_op&& r)
|
||||||
this->m_renderTarget = r.m_renderTarget;
|
{
|
||||||
r.m_renderTarget = nullptr;
|
this->parent = r.parent;
|
||||||
|
r.parent = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gs::rendertarget_op::~rendertarget_op() {
|
gs::rendertarget_op::~rendertarget_op()
|
||||||
if (m_renderTarget == nullptr)
|
{
|
||||||
|
if (parent == nullptr)
|
||||||
return;
|
return;
|
||||||
obs_enter_graphics();
|
obs_enter_graphics();
|
||||||
gs_texrender_end(m_renderTarget->m_renderTarget);
|
gs_texrender_end(parent->render_target);
|
||||||
obs_leave_graphics();
|
obs_leave_graphics();
|
||||||
m_renderTarget->m_isBeingRendered = false;
|
parent->is_being_rendered = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <inttypes.h>
|
#include <cinttypes>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "gs-texture.h"
|
#include "gs-texture.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4201)
|
#pragma warning(disable : 4201)
|
||||||
|
@ -32,34 +33,40 @@ namespace gs {
|
||||||
class rendertarget {
|
class rendertarget {
|
||||||
friend class rendertarget_op;
|
friend class rendertarget_op;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
gs_texrender_t* render_target;
|
||||||
|
bool is_being_rendered;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~rendertarget();
|
||||||
|
|
||||||
rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat);
|
rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat);
|
||||||
virtual ~rendertarget();
|
|
||||||
|
|
||||||
gs_texture_t* get_object();
|
gs_texture_t* get_object();
|
||||||
void get_texture(gs::texture& tex);
|
|
||||||
void get_texture(std::shared_ptr<gs::texture>& tex);
|
|
||||||
void get_texture(std::unique_ptr<gs::texture>& tex);
|
|
||||||
gs::rendertarget_op render(uint32_t width, uint32_t height);
|
|
||||||
|
|
||||||
protected:
|
void get_texture(gs::texture& tex);
|
||||||
gs_texrender_t* m_renderTarget;
|
|
||||||
bool m_isBeingRendered;
|
void get_texture(std::shared_ptr<gs::texture>& tex);
|
||||||
|
|
||||||
|
void get_texture(std::unique_ptr<gs::texture>& tex);
|
||||||
|
|
||||||
|
gs::rendertarget_op render(uint32_t width, uint32_t height);
|
||||||
};
|
};
|
||||||
|
|
||||||
class rendertarget_op {
|
class rendertarget_op {
|
||||||
|
gs::rendertarget* parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~rendertarget_op();
|
||||||
|
|
||||||
rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height);
|
rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height);
|
||||||
virtual ~rendertarget_op();
|
|
||||||
|
|
||||||
// Move Constructor
|
// Move Constructor
|
||||||
rendertarget_op(gs::rendertarget_op&&);
|
rendertarget_op(gs::rendertarget_op&&);
|
||||||
|
|
||||||
// Copy Constructor
|
// Copy Constructor
|
||||||
rendertarget_op(const gs::rendertarget_op&) = delete;
|
rendertarget_op(const gs::rendertarget_op&) = delete;
|
||||||
rendertarget_op& operator=(const gs::rendertarget_op& r) = delete;
|
|
||||||
|
|
||||||
protected:
|
rendertarget_op& operator=(const gs::rendertarget_op& r) = delete;
|
||||||
gs::rendertarget* m_renderTarget;
|
|
||||||
};
|
};
|
||||||
}
|
} // namespace gs
|
||||||
|
|
Loading…
Reference in a new issue