mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-27 22:03:01 +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,74 +19,85 @@
|
|||
|
||||
#include "gs-rendertarget.h"
|
||||
#include <stdexcept>
|
||||
|
||||
extern "C" {
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4201 )
|
||||
#include <obs.h>
|
||||
#pragma warning( pop )
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4201)
|
||||
#include <obs.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
gs::rendertarget::rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat) {
|
||||
m_isBeingRendered = false;
|
||||
gs::rendertarget::~rendertarget()
|
||||
{
|
||||
obs_enter_graphics();
|
||||
m_renderTarget = gs_texrender_create(colorFormat, zsFormat);
|
||||
gs_texrender_destroy(render_target);
|
||||
obs_leave_graphics();
|
||||
}
|
||||
|
||||
gs::rendertarget::~rendertarget() {
|
||||
gs::rendertarget::rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat)
|
||||
{
|
||||
is_being_rendered = false;
|
||||
obs_enter_graphics();
|
||||
gs_texrender_destroy(m_renderTarget);
|
||||
render_target = gs_texrender_create(colorFormat, zsFormat);
|
||||
obs_leave_graphics();
|
||||
}
|
||||
|
||||
gs::rendertarget_op gs::rendertarget::render(uint32_t width, uint32_t height) {
|
||||
return { this, width, height };
|
||||
gs::rendertarget_op gs::rendertarget::render(uint32_t width, uint32_t height)
|
||||
{
|
||||
return {this, width, height};
|
||||
}
|
||||
|
||||
gs_texture_t* gs::rendertarget::get_object() {
|
||||
gs_texture_t* gs::rendertarget::get_object()
|
||||
{
|
||||
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();
|
||||
return tex;
|
||||
}
|
||||
|
||||
void gs::rendertarget::get_texture(gs::texture& tex) {
|
||||
void gs::rendertarget::get_texture(gs::texture& tex)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
gs::rendertarget_op::rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height) : m_renderTarget(rt) {
|
||||
if (m_renderTarget == nullptr)
|
||||
gs::rendertarget_op::rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height) : parent(rt)
|
||||
{
|
||||
if (parent == nullptr)
|
||||
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.");
|
||||
obs_enter_graphics();
|
||||
gs_texrender_reset(m_renderTarget->m_renderTarget);
|
||||
if (!gs_texrender_begin(m_renderTarget->m_renderTarget, width, height)) {
|
||||
gs_texrender_reset(parent->render_target);
|
||||
if (!gs_texrender_begin(parent->render_target, width, height)) {
|
||||
obs_leave_graphics();
|
||||
throw std::runtime_error("Failed to begin rendering to render target.");
|
||||
}
|
||||
obs_leave_graphics();
|
||||
m_renderTarget->m_isBeingRendered = true;
|
||||
parent->is_being_rendered = true;
|
||||
}
|
||||
|
||||
gs::rendertarget_op::rendertarget_op(gs::rendertarget_op&& r) {
|
||||
this->m_renderTarget = r.m_renderTarget;
|
||||
r.m_renderTarget = nullptr;
|
||||
gs::rendertarget_op::rendertarget_op(gs::rendertarget_op&& r)
|
||||
{
|
||||
this->parent = r.parent;
|
||||
r.parent = nullptr;
|
||||
}
|
||||
|
||||
gs::rendertarget_op::~rendertarget_op() {
|
||||
if (m_renderTarget == nullptr)
|
||||
gs::rendertarget_op::~rendertarget_op()
|
||||
{
|
||||
if (parent == nullptr)
|
||||
return;
|
||||
obs_enter_graphics();
|
||||
gs_texrender_end(m_renderTarget->m_renderTarget);
|
||||
gs_texrender_end(parent->render_target);
|
||||
obs_leave_graphics();
|
||||
m_renderTarget->m_isBeingRendered = false;
|
||||
parent->is_being_rendered = false;
|
||||
}
|
||||
|
|
|
@ -18,48 +18,55 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
#include <inttypes.h>
|
||||
#include <cinttypes>
|
||||
#include <memory>
|
||||
#include "gs-texture.h"
|
||||
|
||||
extern "C" {
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4201 )
|
||||
#include <graphics/graphics.h>
|
||||
#pragma warning( pop )
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4201)
|
||||
#include <graphics/graphics.h>
|
||||
#pragma warning(pop)
|
||||
}
|
||||
|
||||
namespace gs {
|
||||
class rendertarget {
|
||||
friend class rendertarget_op;
|
||||
|
||||
protected:
|
||||
gs_texrender_t* render_target;
|
||||
bool is_being_rendered;
|
||||
|
||||
public:
|
||||
~rendertarget();
|
||||
|
||||
rendertarget(gs_color_format colorFormat, gs_zstencil_format zsFormat);
|
||||
virtual ~rendertarget();
|
||||
|
||||
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:
|
||||
gs_texrender_t* m_renderTarget;
|
||||
bool m_isBeingRendered;
|
||||
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);
|
||||
};
|
||||
|
||||
class rendertarget_op {
|
||||
gs::rendertarget* parent;
|
||||
|
||||
public:
|
||||
~rendertarget_op();
|
||||
|
||||
rendertarget_op(gs::rendertarget* rt, uint32_t width, uint32_t height);
|
||||
virtual ~rendertarget_op();
|
||||
|
||||
// Move Constructor
|
||||
rendertarget_op(gs::rendertarget_op&&);
|
||||
|
||||
// Copy Constructor
|
||||
rendertarget_op(const gs::rendertarget_op&) = delete;
|
||||
rendertarget_op& operator=(const gs::rendertarget_op& r) = delete;
|
||||
|
||||
protected:
|
||||
gs::rendertarget* m_renderTarget;
|
||||
rendertarget_op& operator=(const gs::rendertarget_op& r) = delete;
|
||||
};
|
||||
}
|
||||
} // namespace gs
|
||||
|
|
Loading…
Reference in a new issue