obs/gs/rendertarget: Add support for color spaces

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2022-10-30 02:09:33 +01:00
parent 596841e6f8
commit 15eaec2e09
2 changed files with 65 additions and 36 deletions

View File

@ -1,21 +1,22 @@
/* // Copyright (c) 2017-2022 Michael Fabian Dirks <info@xaymar.com>
* Modern effects for a modern Streamer //
* Copyright (C) 2017 Michael Fabian Dirks // Permission is hereby granted, free of charge, to any person obtaining a copy
* // of this software and associated documentation files (the "Software"), to deal
* This program is free software; you can redistribute it and/or modify // in the Software without restriction, including without limitation the rights
* it under the terms of the GNU General Public License as published by // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* the Free Software Foundation; either version 2 of the License, or // copies of the Software, and to permit persons to whom the Software is
* (at your option) any later version. // furnished to do so, subject to the following conditions:
* //
* This program is distributed in the hope that it will be useful, // The above copyright notice and this permission notice shall be included in all
* but WITHOUT ANY WARRANTY; without even the implied warranty of // copies or substantial portions of the Software.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
* GNU General Public License for more details. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* You should have received a copy of the GNU General Public License // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* along with this program; if not, write to the Free Software // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*/ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "gs-rendertarget.hpp" #include "gs-rendertarget.hpp"
#include "obs/gs/gs-helper.hpp" #include "obs/gs/gs-helper.hpp"
@ -46,6 +47,12 @@ streamfx::obs::gs::rendertarget_op streamfx::obs::gs::rendertarget::render(uint3
return {this, width, height}; return {this, width, height};
} }
streamfx::obs::gs::rendertarget_op streamfx::obs::gs::rendertarget::render(uint32_t width, uint32_t height,
gs_color_space cs)
{
return {this, width, height, cs};
}
gs_texture_t* streamfx::obs::gs::rendertarget::get_object() gs_texture_t* streamfx::obs::gs::rendertarget::get_object()
{ {
auto gctx = streamfx::obs::gs::context(); auto gctx = streamfx::obs::gs::context();
@ -100,6 +107,23 @@ streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertar
parent->_is_being_rendered = true; parent->_is_being_rendered = true;
} }
streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width,
uint32_t height, gs_color_space cs)
: parent(rt)
{
if (parent == nullptr)
throw std::invalid_argument("rt");
if (parent->_is_being_rendered)
throw std::logic_error("Can't start rendering to the same render target twice.");
auto gctx = streamfx::obs::gs::context();
gs_texrender_reset(parent->_render_target);
if (!gs_texrender_begin_with_color_space(parent->_render_target, width, height, cs)) {
throw std::runtime_error("Failed to begin rendering to render target.");
}
parent->_is_being_rendered = true;
}
streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget_op&& r) noexcept streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget_op&& r) noexcept
{ {
this->parent = r.parent; this->parent = r.parent;

View File

@ -1,21 +1,22 @@
/* // Copyright (c) 2017-2022 Michael Fabian Dirks <info@xaymar.com>
* Modern effects for a modern Streamer //
* Copyright (C) 2017 Michael Fabian Dirks // Permission is hereby granted, free of charge, to any person obtaining a copy
* // of this software and associated documentation files (the "Software"), to deal
* This program is free software; you can redistribute it and/or modify // in the Software without restriction, including without limitation the rights
* it under the terms of the GNU General Public License as published by // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* the Free Software Foundation; either version 2 of the License, or // copies of the Software, and to permit persons to whom the Software is
* (at your option) any later version. // furnished to do so, subject to the following conditions:
* //
* This program is distributed in the hope that it will be useful, // The above copyright notice and this permission notice shall be included in all
* but WITHOUT ANY WARRANTY; without even the implied warranty of // copies or substantial portions of the Software.
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
* GNU General Public License for more details. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* You should have received a copy of the GNU General Public License // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* along with this program; if not, write to the Free Software // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
*/ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once #pragma once
#include "common.hpp" #include "common.hpp"
@ -54,6 +55,8 @@ namespace streamfx::obs::gs {
gs_zstencil_format get_zstencil_format(); gs_zstencil_format get_zstencil_format();
streamfx::obs::gs::rendertarget_op render(uint32_t width, uint32_t height); streamfx::obs::gs::rendertarget_op render(uint32_t width, uint32_t height);
streamfx::obs::gs::rendertarget_op render(uint32_t width, uint32_t height, gs_color_space cs);
}; };
class rendertarget_op { class rendertarget_op {
@ -64,6 +67,8 @@ namespace streamfx::obs::gs {
rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, uint32_t height); rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, uint32_t height);
rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, uint32_t height, gs_color_space cs);
// Move Constructor // Move Constructor
rendertarget_op(streamfx::obs::gs::rendertarget_op&&) noexcept; rendertarget_op(streamfx::obs::gs::rendertarget_op&&) noexcept;