mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-27 22:03:01 +00:00
project: Optimize to use single fullscreen tri instead
This commit is contained in:
parent
775e27caff
commit
a9bb56c5ee
13 changed files with 72 additions and 37 deletions
|
@ -504,11 +504,11 @@ void blur_instance::video_render(gs_effect_t* effect)
|
|||
|
||||
try {
|
||||
auto op = this->_output_rt->render(baseW, baseH);
|
||||
gs_ortho(0, (float)baseW, 0, (float)baseH, -1, 1);
|
||||
gs_ortho(0, 1, 0, 1, -1, 1);
|
||||
|
||||
// Render
|
||||
while (gs_effect_loop(_effect_mask.get_object(), technique.c_str())) {
|
||||
gs_draw_sprite(_output_texture->get_object(), 0, baseW, baseH);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
} catch (const std::exception&) {
|
||||
gs_blend_state_pop();
|
||||
|
|
|
@ -230,7 +230,7 @@ void color_grade_instance::video_render(gs_effect_t* effect)
|
|||
gs_enable_depth_test(false);
|
||||
gs_enable_stencil_test(false);
|
||||
gs_enable_stencil_write(false);
|
||||
gs_ortho(0, static_cast<float_t>(width), 0, static_cast<float_t>(height), -1., 1.);
|
||||
gs_ortho(0, 1, 0, 1, -1., 1.);
|
||||
|
||||
_effect.get_parameter("image").set_texture(_tex_source);
|
||||
_effect.get_parameter("pLift").set_float4(_lift);
|
||||
|
@ -246,7 +246,7 @@ void color_grade_instance::video_render(gs_effect_t* effect)
|
|||
_effect.get_parameter("pCorrection").set_float4(_correction);
|
||||
|
||||
while (gs_effect_loop(_effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, width, height);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
|
||||
gs_blend_state_pop();
|
||||
|
|
|
@ -280,7 +280,7 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect)
|
|||
gs_enable_stencil_write(false);
|
||||
gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS);
|
||||
gs_stencil_op(GS_STENCIL_BOTH, GS_KEEP, GS_KEEP, GS_KEEP);
|
||||
gs_ortho(0, (float)width, 0, (float)height, -1., 1.);
|
||||
gs_ortho(0, 1, 0, 1, -1., 1.);
|
||||
|
||||
_effect.get_parameter("pMaskInputA").set_texture(_filter_texture);
|
||||
_effect.get_parameter("pMaskInputB").set_texture(_input_texture);
|
||||
|
@ -290,7 +290,7 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect)
|
|||
_effect.get_parameter("pMaskMultiplier").set_float4(_precalc.scale);
|
||||
|
||||
while (gs_effect_loop(_effect.get(), "Mask")) {
|
||||
gs_draw_sprite(0, 0, width, height);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
|
||||
gs_blend_state_pop();
|
||||
|
|
|
@ -354,7 +354,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
#endif
|
||||
|
||||
auto op = _sdf_write->render(uint32_t(sdfW), uint32_t(sdfH));
|
||||
gs_ortho(0, (float)sdfW, 0, (float)sdfH, -1, 1);
|
||||
gs_ortho(0, 1, 0, 1, -1, 1);
|
||||
gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &color_transparent, 0, 0);
|
||||
|
||||
_sdf_producer_effect.get_parameter("_image").set_texture(_source_texture);
|
||||
|
@ -363,7 +363,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
_sdf_producer_effect.get_parameter("_threshold").set_float(_sdf_threshold);
|
||||
|
||||
while (gs_effect_loop(_sdf_producer_effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(_sdf_texture->get_object(), 0, uint32_t(sdfW), uint32_t(sdfH));
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
std::swap(_sdf_read, _sdf_write);
|
||||
|
@ -421,7 +421,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
gs_effect_set_texture(param, _output_texture->get_object());
|
||||
}
|
||||
while (gs_effect_loop(default_effect, "Draw")) {
|
||||
gs_draw_sprite(0, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
|
||||
gs_enable_blending(true);
|
||||
|
@ -436,7 +436,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
_sdf_consumer_effect.get_parameter("pShadowOffset")
|
||||
.set_float2(_outer_shadow_offset_x / float_t(baseW), _outer_shadow_offset_y / float_t(baseH));
|
||||
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "ShadowOuter")) {
|
||||
gs_draw_sprite(0, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
if (_inner_shadow) {
|
||||
|
@ -449,7 +449,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
_sdf_consumer_effect.get_parameter("pShadowOffset")
|
||||
.set_float2(_inner_shadow_offset_x / float_t(baseW), _inner_shadow_offset_y / float_t(baseH));
|
||||
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "ShadowInner")) {
|
||||
gs_draw_sprite(0, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
if (_outer_glow) {
|
||||
|
@ -461,7 +461,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
_sdf_consumer_effect.get_parameter("pGlowSharpness").set_float(_outer_glow_sharpness);
|
||||
_sdf_consumer_effect.get_parameter("pGlowSharpnessInverse").set_float(_outer_glow_sharpness_inv);
|
||||
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "GlowOuter")) {
|
||||
gs_draw_sprite(0, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
if (_inner_glow) {
|
||||
|
@ -473,7 +473,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
_sdf_consumer_effect.get_parameter("pGlowSharpness").set_float(_inner_glow_sharpness);
|
||||
_sdf_consumer_effect.get_parameter("pGlowSharpnessInverse").set_float(_inner_glow_sharpness_inv);
|
||||
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "GlowInner")) {
|
||||
gs_draw_sprite(0, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
if (_outline) {
|
||||
|
@ -486,7 +486,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect)
|
|||
_sdf_consumer_effect.get_parameter("pOutlineSharpness").set_float(_outline_sharpness);
|
||||
_sdf_consumer_effect.get_parameter("pOutlineSharpnessInverse").set_float(_outline_sharpness_inv);
|
||||
while (gs_effect_loop(_sdf_consumer_effect.get_object(), "Outline")) {
|
||||
gs_draw_sprite(0, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
} catch (...) {
|
||||
|
|
|
@ -285,7 +285,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear::render()
|
|||
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +371,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box_linear_directional::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,7 +293,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box::render()
|
|||
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box_directional::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -455,7 +455,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box_rotational::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Rotate")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -520,7 +520,7 @@ std::shared_ptr<::gs::texture> gfx::blur::box_zoom::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Zoom")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -289,7 +289,7 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render()
|
|||
auto op = _rts[n]->render(owidth, oheight);
|
||||
gs_ortho(0., 1., 0., 1., 0., 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Down")) {
|
||||
gs_draw_sprite(tex_cur->get_object(), 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render()
|
|||
auto op = _rts[n - 1]->render(owidth, oheight);
|
||||
gs_ortho(0., 1., 0., 1., 0., 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Up")) {
|
||||
gs_draw_sprite(tex_in->get_object(), 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -338,7 +338,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render()
|
|||
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear::render()
|
|||
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -438,7 +438,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_linear_directional::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -344,7 +344,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian::render()
|
|||
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian::render()
|
|||
auto op = _rendertarget2->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_directional::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Draw")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,7 +503,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_rotational::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Rotate")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -583,7 +583,7 @@ std::shared_ptr<::gs::texture> gfx::blur::gaussian_zoom::render()
|
|||
auto op = _rendertarget->render(uint32_t(width), uint32_t(height));
|
||||
gs_ortho(0, 1., 0, 1., 0, 1.);
|
||||
while (gs_effect_loop(effect.get_object(), "Zoom")) {
|
||||
gs_draw_sprite(nullptr, 0, 1, 1);
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -475,7 +475,7 @@ void gfx::shader::shader::render()
|
|||
if (!_rt_up_to_date) {
|
||||
auto op = _rt->render(width(), height());
|
||||
vec4 zero = {0, 0, 0, 0};
|
||||
gs_ortho(0, width(), 0, height(), 0, 1);
|
||||
gs_ortho(0, 1, 0, 1, 0, 1);
|
||||
gs_clear(GS_CLEAR_COLOR, &zero, 0, 0);
|
||||
|
||||
gs_blend_state_push();
|
||||
|
@ -485,7 +485,7 @@ void gfx::shader::shader::render()
|
|||
gs_blend_function_separate(GS_BLEND_ONE, GS_BLEND_ZERO, GS_BLEND_ONE, GS_BLEND_ZERO);
|
||||
gs_enable_color(true, true, true, true);
|
||||
while (gs_effect_loop(_shader.get_object(), _shader_tech.c_str())) {
|
||||
gs_draw_sprite(nullptr, 0, width(), height());
|
||||
streamfx::gs_draw_fullscreen_tri();
|
||||
}
|
||||
|
||||
gs_blend_state_pop();
|
||||
|
|
|
@ -33,7 +33,7 @@ gs::context::~context()
|
|||
gs::debug_marker::debug_marker(const float color[4], const char* format, ...)
|
||||
{
|
||||
std::size_t size;
|
||||
std::vector<char> buffer(128);
|
||||
std::vector<char> buffer(64);
|
||||
|
||||
va_list vargs;
|
||||
va_start(vargs, format);
|
||||
|
|
|
@ -67,7 +67,8 @@
|
|||
#include "ui/ui.hpp"
|
||||
#endif
|
||||
|
||||
static std::shared_ptr<util::threadpool> _threadpool;
|
||||
static std::shared_ptr<util::threadpool> _threadpool;
|
||||
static std::shared_ptr<gs::vertex_buffer> _gs_fstri_vb;
|
||||
|
||||
MODULE_EXPORT bool obs_module_load(void)
|
||||
try {
|
||||
|
@ -82,6 +83,27 @@ try {
|
|||
// Initialize Source Tracker
|
||||
obs::source_tracker::initialize();
|
||||
|
||||
// GS Stuff
|
||||
{
|
||||
_gs_fstri_vb = std::make_shared<gs::vertex_buffer>(3, 1);
|
||||
{
|
||||
auto vtx = _gs_fstri_vb->at(0);
|
||||
vec3_set(vtx.position, 0, 0, 0);
|
||||
vec4_set(vtx.uv[0], 0, 0, 0, 0);
|
||||
}
|
||||
{
|
||||
auto vtx = _gs_fstri_vb->at(1);
|
||||
vec3_set(vtx.position, 2, 0, 0);
|
||||
vec4_set(vtx.uv[0], 2, 0, 0, 0);
|
||||
}
|
||||
{
|
||||
auto vtx = _gs_fstri_vb->at(2);
|
||||
vec3_set(vtx.position, 0, 2, 0);
|
||||
vec4_set(vtx.uv[0], 0, 2, 0, 0);
|
||||
}
|
||||
_gs_fstri_vb->update();
|
||||
}
|
||||
|
||||
// Encoders
|
||||
{
|
||||
#ifdef ENABLE_ENCODER_FFMPEG
|
||||
|
@ -138,7 +160,7 @@ try {
|
|||
#endif
|
||||
}
|
||||
|
||||
// Frontend
|
||||
// Frontend
|
||||
#ifdef ENABLE_FRONTEND
|
||||
streamfx::ui::handler::initialize();
|
||||
#endif
|
||||
|
@ -215,6 +237,11 @@ try {
|
|||
#endif
|
||||
}
|
||||
|
||||
// GS Stuff
|
||||
{
|
||||
_gs_fstri_vb.reset();
|
||||
}
|
||||
|
||||
// Finalize Source Tracker
|
||||
obs::source_tracker::finalize();
|
||||
|
||||
|
@ -233,3 +260,9 @@ std::shared_ptr<util::threadpool> streamfx::threadpool()
|
|||
{
|
||||
return _threadpool;
|
||||
}
|
||||
|
||||
void streamfx::gs_draw_fullscreen_tri()
|
||||
{
|
||||
gs_load_vertexbuffer(_gs_fstri_vb->update(false));
|
||||
gs_draw(GS_TRIS, 0, 3); //_gs_fstri_vb->size());
|
||||
}
|
||||
|
|
|
@ -23,4 +23,6 @@
|
|||
namespace streamfx {
|
||||
// Threadpool
|
||||
std::shared_ptr<util::threadpool> threadpool();
|
||||
|
||||
void gs_draw_fullscreen_tri();
|
||||
} // namespace streamfx
|
||||
|
|
Loading…
Reference in a new issue