Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions tsd/apps/interactive/network/client/RemoteViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,24 @@ RemoteViewport::~RemoteViewport()

void RemoteViewport::buildUI()
{
BaseViewport::buildUI();

bool isConnected = m_channel && m_channel->isConnected();
BaseViewport::viewport_setActive(isConnected);

if (m_wasConnected != isConnected)
viewport_reshape(m_viewport.size);
BaseViewport::buildUI();

if (!m_wasConnected && isConnected) {
m_receivedCameraIdx = TSD_INVALID_INDEX;
m_receivedRendererIdx = TSD_INVALID_INDEX;
m_channel->send(MessageType::SERVER_REQUEST_CURRENT_CAMERA);
m_channel->send(MessageType::SERVER_REQUEST_CURRENT_RENDERER);
m_clearPass->setClearColor(tsd::math::float4(0.f, 0.f, 0.f, 1.f));
} else if (m_wasConnected && !isConnected) {
disconnect();
m_incomingFramePass->setEnabled(false);
m_clearPass->setClearColor(tsd::math::float4(1.f, 0.f, 0.f, 1.f));
}

m_wasConnected = isConnected;
m_incomingFramePass->setEnabled(isConnected);

updateRenderer();
updateCamera();
Expand All @@ -70,17 +69,19 @@ void RemoteViewport::buildUI()
ui_menubar();
ImGui::EndDisabled();

if (m_outputPass) {
if (BaseViewport::imagePipeline_isSetup()) {
ImGui::Image((ImTextureID)m_outputPass->getTexture(),
ImGui::GetContentRegionAvail(),
ImVec2(0, 1),
ImVec2(1, 0));
}

BaseViewport::ui_gizmo();
const bool widgetActive = BaseViewport::ui_orientationWidget();
if (!widgetActive)
BaseViewport::ui_handleInput();
if (BaseViewport::viewport_isActive()) {
BaseViewport::ui_gizmo();
const bool widgetActive = BaseViewport::ui_orientationWidget();
if (!widgetActive)
BaseViewport::ui_handleInput();
}

// Render the overlay after input handling so it does not interfere.
if (m_showOverlay)
Expand Down Expand Up @@ -152,14 +153,12 @@ void RemoteViewport::disconnect()
void RemoteViewport::imagePipeline_populate(tsd::rendering::ImagePipeline &p)
{
m_clearPass = p.emplace_back<tsd::rendering::ClearBuffersPass>();
m_clearPass->setClearColor(tsd::math::float4(1.f, 0.f, 0.f, 1.f));
m_incomingFramePass = p.emplace_back<tsd::rendering::CopyToColorBufferPass>();
m_incomingFramePass->setExternalBuffer(m_incomingColorBuffer);
m_incomingFramePass->setEnabled(false);
m_outputPass = p.emplace_back<tsd::rendering::CopyToSDLTexturePass>(
m_app->sdlRenderer());

m_clearPass->setClearColor(tsd::math::float4(1.f, 0.f, 0.f, 1.f));
m_incomingFramePass->setExternalBuffer(m_incomingColorBuffer);

viewport_reshape(m_viewport.size);
}

void RemoteViewport::camera_resetView(bool /*resetAzEl*/)
Expand Down Expand Up @@ -189,12 +188,19 @@ void RemoteViewport::renderer_resetParameterDefaults()
"Renderer parameter reset is not currently supported in RemoteViewport.");
}

void RemoteViewport::viewport_reshape(tsd::math::int2 newSize)
void RemoteViewport::viewport_reshape(tsd::math::int2 _newSize)
{
if (newSize.x <= 0 || newSize.y <= 0)
if (_newSize.x <= 0 || _newSize.y <= 0)
return;

BaseViewport::viewport_reshape(newSize);
BaseViewport::viewport_reshape(_newSize);

if (!BaseViewport::viewport_isActive())
return;

auto newSize = tsd::math::uint2(_newSize.x, _newSize.y);
if (m_frameConfig.size == newSize)
return;

{
std::lock_guard lock(m_incomingFrameMutex);
Expand All @@ -205,7 +211,7 @@ void RemoteViewport::viewport_reshape(tsd::math::int2 newSize)
m_hasPendingFrame = false;
}

m_frameConfig.size = tsd::math::uint2(newSize.x, newSize.y);
m_frameConfig.size = newSize;

if (m_channel && m_channel->isConnected())
m_channel->send(MessageType::SERVER_SET_FRAME_CONFIG, &m_frameConfig);
Expand All @@ -219,6 +225,7 @@ void RemoteViewport::applyIncomingFrame()

m_incomingColorBuffer.swap(m_pendingColorBuffer);
m_hasPendingFrame = false;
m_incomingFramePass->setEnabled(true);
}

void RemoteViewport::updateRenderer()
Expand Down
4 changes: 0 additions & 4 deletions tsd/apps/interactive/viewer/tsdViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ class Application : public TSDApplication
}
};

#if 1
showTaskModal(populateScene, "Please Wait: Loading Scene...");
#else
populateScene();
#endif

return windows;
}
Expand Down
7 changes: 7 additions & 0 deletions tsd/src/tsd/rendering/pipeline/ImagePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ void ImagePipeline::setDimensions(uint32_t width, uint32_t height)
return;
m_size.x = width;
m_size.y = height;

cleanup();

const size_t totalSize = size_t(width) * size_t(height);
if (totalSize == 0)
return;

m_buffers.color = detail::allocate<uint32_t>(totalSize);
m_buffers.hdrColor = detail::allocate<float>(totalSize * 4);
m_buffers.depth = detail::allocate<float>(totalSize);
Expand All @@ -45,6 +50,7 @@ void ImagePipeline::setDimensions(uint32_t width, uint32_t height)
m_buffers.primitiveId = detail::allocate<uint32_t>(totalSize);
m_buffers.albedo = detail::allocate<tsd::math::float3>(totalSize);
m_buffers.normal = detail::allocate<tsd::math::float3>(totalSize);

for (auto &p : m_passes)
p->setDimensions(width, height);
}
Expand Down Expand Up @@ -89,6 +95,7 @@ bool ImagePipeline::empty() const
void ImagePipeline::clear()
{
m_passes.clear();
setDimensions(0, 0);
}

void ImagePipeline::cleanup()
Expand Down
22 changes: 18 additions & 4 deletions tsd/src/tsd/rendering/pipeline/passes/AnariSceneRenderPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include "AnariSceneRenderPass.h"
#include "tsd/core/Logging.hpp"
// tsd_algorithms
#include "tsd/algorithms/cpu/clearBuffers.hpp"
#ifdef TSD_ALGORITHMS_HAS_CUDA
#include "tsd/algorithms/cuda/clearBuffers.hpp"
#endif
#include "tsd/algorithms/cpu/depthCompositeFrame.hpp"
#ifdef TSD_ALGORITHMS_HAS_CUDA
#include "tsd/algorithms/cuda/depthCompositeFrame.hpp"
Expand Down Expand Up @@ -289,17 +293,27 @@ void AnariSceneRenderPass::render(ImageBuffers &b, int stageId)
if (m_firstFrame)
anari::render(m_device, m_frame);

if (m_firstFrame || !m_runAsync) {
if (!m_runAsync)
anari::wait(m_device, m_frame);
m_firstFrame = false;
}

if (anari::isReady(m_device, m_frame)) {
m_firstFrame = false;
copyFrameData();
anari::render(m_device, m_frame);
}

composite(b, stageId);
if (!m_firstFrame)
composite(b, stageId);
else {
const auto size = getDimensions();
const uint32_t totalPixels = uint32_t(size.x) * uint32_t(size.y);
#ifdef TSD_ALGORITHMS_HAS_CUDA
if (b.stream)
tsd::algorithms::cuda::fill(b.stream, b.color, totalPixels, 0);
#else
tsd::algorithms::cpu::fill(b.color, totalPixels, 0);
#endif
}
}

void AnariSceneRenderPass::copyFrameData()
Expand Down
25 changes: 20 additions & 5 deletions tsd/src/tsd/ui/imgui/modals/BlockingTaskModal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@ BlockingTaskModal::~BlockingTaskModal() = default;

void BlockingTaskModal::buildUI()
{
if (tsd::core::isReady(m_future))
std::lock_guard<std::mutex> lock(m_mutex);

if (m_tasks.empty()) {
this->hide();
return;
}

auto *t = &m_tasks.front();
while (tsd::core::isReady(t->future)) {
m_tasks.pop_front();
if (m_tasks.empty()) {
this->hide();
return;
}
t = &m_tasks.front();
}

ImGui::ProgressBar(
-1.0f * (float)ImGui::GetTime(), ImVec2(0.0f, 0.0f), m_text.c_str());
-1.0f * (float)ImGui::GetTime(), ImVec2(0.0f, 0.0f), t->text.c_str());

m_timer.end();
ImGui::NewLine();
Expand All @@ -26,9 +40,10 @@ void BlockingTaskModal::buildUI()

void BlockingTaskModal::activate(tsd::core::Future &&f, const char *text)
{
m_timer.start();
m_future = std::move(f);
m_text = text;
std::lock_guard<std::mutex> lock(m_mutex);
if (m_tasks.empty())
m_timer.start();
m_tasks.push_back({std::move(f), text});
this->show();
}

Expand Down
14 changes: 12 additions & 2 deletions tsd/src/tsd/ui/imgui/modals/BlockingTaskModal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// tsd_core
#include "tsd/core/TaskQueue.hpp"
#include "tsd/core/Timer.hpp"
// std
#include <deque>
#include <string>
#include <mutex>

namespace tsd::ui::imgui {

Expand All @@ -20,9 +24,15 @@ struct BlockingTaskModal : public Modal
void activate(tsd::core::Future &&f, const char *text = "Please Wait");

private:
tsd::core::Future m_future;
std::string m_text;
struct RunningTask
{
tsd::core::Future future;
std::string text;
};

std::deque<RunningTask> m_tasks;
tsd::core::Timer m_timer;
std::mutex m_mutex;
};

} // namespace tsd::ui::imgui
11 changes: 4 additions & 7 deletions tsd/src/tsd/ui/imgui/windows/BaseViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ BaseViewport::~BaseViewport()

void BaseViewport::buildUI()
{
ImVec2 _viewportSize = ImGui::GetContentRegionAvail();
tsd::math::int2 viewportSize(_viewportSize.x, _viewportSize.y);

if (m_viewport.size != viewportSize)
viewport_reshape(viewportSize);
ImVec2 viewportSize = ImGui::GetContentRegionAvail();
viewport_reshape({int(viewportSize.x), int(viewportSize.y)});
}

void BaseViewport::setManipulator(tsd::rendering::Manipulator *m)
Expand Down Expand Up @@ -127,7 +124,7 @@ void BaseViewport::imagePipeline_teardown()

void BaseViewport::camera_update(bool force)
{
if (!m_viewport.active)
if (!viewport_isActive())
return;

if (!m_camera.current)
Expand All @@ -146,7 +143,7 @@ void BaseViewport::camera_setCurrent(tsd::scene::CameraAppRef c)

bool BaseViewport::gizmo_canShow() const
{
if (!m_gizmo.active || !m_viewport.active)
if (!m_gizmo.active || !viewport_isActive())
return false;

// Check if we have a selected node with a transform
Expand Down
Loading
Loading