Draw render targets in the renderer process
CI / build (push) Successful in 48s

While the renderer process runs, the adapter makes the client's render targets
itself and the renderer process draws frames into them: texture targets are
drawn with like any texture, and a pixmap target's frame is read back through
the channel into its Pixmap (protocol version 4: BeginFrame names its target,
CreateRenderTarget, Channel::readSize and the -read event). Frames into render
targets are drawn even while the window is hidden.

The client uses pixmap targets for snapshots (outfit pictures, photos), checked
to look right. The render target interfaces are declared from IMVU's vtables.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-10-28 19:09:48 -07:00
1 parent fa883892db
commit 6e4fe589e5
18 files changed
+523 -58

No files matched your search

+25 -2
View File
@@ -5,9 +5,11 @@
#include <cstddef>
#include <cstdint>
#include <functional>
#include <span>
#include <string>
#include <unordered_map>
#include <vector>
#include "EngineFactoryD3D11.h"
#include "RefCntAutoPtr.hpp"
@@ -20,10 +22,14 @@ public:
Scene(Diligent::IRenderDevice* device, Diligent::IDeviceContext* context, Diligent::ISwapChain* swapChain);
// Carries out one frame's commands. offsetX is where the window starts within the client's 3D view; without draw,
// only the frame's changes are made (textures, buffers, state). True if the frame was drawn into the window (to
// present).
// only the frame's changes are made (textures, buffers, state) and frames into the window aren't drawn (frames into
// render targets always are). True if the frame was drawn into the window (to present).
bool execute(std::span<const std::byte> commands, int offsetX, bool draw);
// Receives the pixels of frames that read their render target back (protocol::BeginFrame::readBack): rows packed,
// 0xAARRGGBB; empty if they couldn't be read. Valid during the call.
void setReadBack(std::function<void(std::span<const std::byte>)> readBack) { readBack_ = std::move(readBack); }
// Replaces the shaders' source (the built-in one by default): for trying changes while the client runs.
void setShaderSource(std::string source);
@@ -33,6 +39,7 @@ public:
private:
struct Texture {
Diligent::RefCntAutoPtr<Diligent::ITexture> texture;
Diligent::RefCntAutoPtr<Diligent::ITexture> depth; // render targets only
std::uint32_t width = 0;
std::uint32_t height = 0;
std::uint32_t flags = 0;
@@ -86,6 +93,13 @@ private:
};
void createTexture(const protocol::Command& command);
void createRenderTarget(const protocol::CreateRenderTarget& create);
void beginFrame(const protocol::BeginFrame& begin);
void endFrame();
// Sets the viewport for the last projection, in what the frame draws into.
void setViewport();
// The render target's pixels, rows packed, 0xAARRGGBB; empty if it can't be read.
std::span<const std::byte> readTarget(const Texture& target);
void updateTexture(const protocol::Command& command);
void createBuffer(const protocol::Command& command);
void updateBuffer(const protocol::Command& command);
@@ -119,7 +133,16 @@ private:
Constants constants_{};
State state_;
// What the current frame draws into: the window, a render target, or nothing (a frame not drawn).
bool onscreen_ = false; // in a frame drawn into the window
Texture* target_ = nullptr; // in a frame drawn into this render target
bool readsBack_ = false; // the frame's render target is read back at its end
Diligent::ITextureView* colorView_ = nullptr;
Diligent::ITextureView* depthView_ = nullptr;
std::int32_t projectionWidth_ = 0;
std::int32_t projectionHeight_ = 0;
std::function<void(std::span<const std::byte>)> readBack_;
std::vector<std::byte> readPixels_;
bool draw_ = true;
std::uint64_t lastSentAt_ = 0;
int offsetX_ = 0;