diff --git a/UI/window-basic-main-transitions.cpp b/UI/window-basic-main-transitions.cpp index b9ca17e4d..66b16ee7b 100644 --- a/UI/window-basic-main-transitions.cpp +++ b/UI/window-basic-main-transitions.cpp @@ -1222,7 +1222,7 @@ void OBSBasic::RenderProgram(void *data, uint32_t cx, uint32_t cy) window->DrawBackdrop(float(ovi.base_width), float(ovi.base_height)); - obs_render_main_view(); + obs_render_main_texture(); gs_load_vertexbuffer(nullptr); /* --------------------------------------- */ diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index a41773e35..a32c8c6d9 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -2968,7 +2968,7 @@ void OBSBasic::RenderMain(void *data, uint32_t cx, uint32_t cy) if (source) obs_source_video_render(source); } else { - obs_render_main_view(); + obs_render_main_texture(); } gs_load_vertexbuffer(nullptr); diff --git a/UI/window-projector.cpp b/UI/window-projector.cpp index e28e01ada..62ef69af1 100644 --- a/UI/window-projector.cpp +++ b/UI/window-projector.cpp @@ -408,7 +408,7 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy) if (studioMode) { obs_source_video_render(previewSrc); } else { - obs_render_main_view(); + obs_render_main_texture(); } resetRegion(); @@ -453,7 +453,7 @@ void OBSProjector::OBSRenderMultiview(void *data, uint32_t cx, uint32_t cy) gs_matrix_scale3f(hiScaleX, hiScaleY, 1.0f); setRegion(halfCX + 2.0f, 2.0f, hiCX, hiCY); - obs_render_main_view(); + obs_render_main_texture(); resetRegion(); gs_matrix_pop(); @@ -540,7 +540,7 @@ void OBSProjector::OBSRender(void *data, uint32_t cx, uint32_t cy) if (source) { obs_source_video_render(source); } else { - obs_render_main_view(); + obs_render_main_texture(); } gs_projection_pop(); diff --git a/docs/sphinx/frontends.rst b/docs/sphinx/frontends.rst index 9ddd0599b..b375a2e29 100644 --- a/docs/sphinx/frontends.rst +++ b/docs/sphinx/frontends.rst @@ -57,7 +57,7 @@ display, then you must assign a draw callback with callback, call :c:func:`obs_display_remove_draw_callback()` similarly. When drawing, to draw the main preview window (if any), call -:c:func:`obs_render_main_view()`. If you need to render a specific +:c:func:`obs_render_main_texture()`. If you need to render a specific source on a secondary display, you can increment its "showing" state with :c:func:`obs_source_inc_showing()` while it's showing in the secondary display, draw it with :c:func:`obs_source_video_render()` in diff --git a/docs/sphinx/reference-core.rst b/docs/sphinx/reference-core.rst index 9fcf3543b..d5655b8c2 100644 --- a/docs/sphinx/reference-core.rst +++ b/docs/sphinx/reference-core.rst @@ -380,6 +380,15 @@ Video, Audio, and Graphics Renders the main view. + Note: This function is deprecated. + +--------------------- + +.. function:: void obs_render_main_texture(void) + + Renders the main output texture. Useful for rendering a preview pane + of the main output. + --------------------- .. function:: void obs_set_master_volume(float volume) diff --git a/libobs/obs-video.c b/libobs/obs-video.c index acac2628e..9ad873c8e 100644 --- a/libobs/obs-video.c +++ b/libobs/obs-video.c @@ -614,14 +614,14 @@ void *obs_graphics_thread(void *param) last_time = tick_sources(obs->video.video_time, last_time); profile_end(tick_sources_name); - profile_start(render_displays_name); - render_displays(); - profile_end(render_displays_name); - profile_start(output_frame_name); output_frame(); profile_end(output_frame_name); + profile_start(render_displays_name); + render_displays(); + profile_end(render_displays_name); + frame_time_ns = os_gettime_ns() - frame_start; profile_end(video_thread_name); diff --git a/libobs/obs.c b/libobs/obs.c index 0b5154313..5d1a9b77d 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -1430,6 +1430,32 @@ void obs_render_main_view(void) obs_view_render(&obs->data.main_view); } +void obs_render_main_texture(void) +{ + struct obs_core_video *video = &obs->video; + gs_texture_t *tex; + gs_effect_t *effect; + gs_eparam_t *param; + int last_tex; + + if (!obs) return; + + last_tex = video->cur_texture == 0 + ? NUM_TEXTURES - 1 + : video->cur_texture - 1; + + if (!video->textures_rendered[last_tex]) + return; + + tex = video->render_textures[last_tex]; + effect = obs_get_base_effect(OBS_EFFECT_DEFAULT); + param = gs_effect_get_param_by_name(effect, "image"); + gs_effect_set_texture(param, tex); + + while (gs_effect_loop(effect, "Draw")) + gs_draw_sprite(tex, 0, 0, 0); +} + void obs_set_master_volume(float volume) { struct calldata data = {0}; diff --git a/libobs/obs.h b/libobs/obs.h index 9a62872b1..d745bd0e1 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -550,8 +550,12 @@ EXPORT signal_handler_t *obs_get_signal_handler(void); EXPORT proc_handler_t *obs_get_proc_handler(void); /** Renders the main view */ +DEPRECATED EXPORT void obs_render_main_view(void); +/** Renders the last main output texture */ +EXPORT void obs_render_main_texture(void); + /** Sets the master user volume */ EXPORT void obs_set_master_volume(float volume); diff --git a/test/osx/test.mm b/test/osx/test.mm index 9a9381a9f..136b51340 100644 --- a/test/osx/test.mm +++ b/test/osx/test.mm @@ -146,7 +146,7 @@ static SceneContext SetupScene() obs_display_add_draw_callback(display.get(), [](void *, uint32_t, uint32_t) { - obs_render_main_view(); + obs_render_main_texture(); }, nullptr); } catch (char const *error) { diff --git a/test/win/test.cpp b/test/win/test.cpp index c0e60caf4..5f966c6ac 100644 --- a/test/win/test.cpp +++ b/test/win/test.cpp @@ -150,7 +150,7 @@ static HWND CreateTestWindow(HINSTANCE instance) static void RenderWindow(void *data, uint32_t cx, uint32_t cy) { - obs_render_main_view(); + obs_render_main_texture(); UNUSED_PARAMETER(data); UNUSED_PARAMETER(cx);