Files
dhkatzandClaude Opus 5.5 6e4fe589e5
CI / build (push) Successful in 48s
Draw render targets in the renderer process
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]>
2026-10-28 19:09:48 -07:00

142 lines
5.0 KiB
C++

#pragma once
// The textures and buffers the adapter's engine hands to the client: each wraps the client renderer's own (which the
// client renderer still draws with) and mirrors it, by id, to the renderer process. The client deletes them through
// their virtual destructors.
#include <cstddef>
#include <cstdint>
#include <memory>
#include <span>
#include "pixmap.hpp"
#include "recorder.hpp"
#include "t5de/imvu/resources.hpp"
namespace t5de {
class Texture final : public imvu::PiRenderTexture {
public:
Texture(imvu::PiRenderTexture* inner, std::shared_ptr<Recorder> recorder, std::uint32_t id);
// What's been drawn into one of our texture render targets (TextureTarget): no texture of the client renderer's,
// and the id stays the target's.
Texture(std::shared_ptr<Recorder> recorder, std::uint32_t targetId, imvu::Vec2i size);
~Texture() override;
imvu::Vec2i size() const override;
void updateRegions(const imvu::Pixmap& pixmap, const imvu::CompoundRegion& regions) override;
void update(const imvu::Pixmap& pixmap) override;
imvu::Pixmap* read(imvu::Pixmap* result) const override;
[[nodiscard]] imvu::PiRenderTexture* inner() const { return inner_; }
[[nodiscard]] std::uint32_t id() const { return id_; }
private:
imvu::PiRenderTexture* inner_;
std::shared_ptr<Recorder> recorder_;
std::uint32_t id_;
imvu::Vec2i size_{};
bool ownsId_ = true;
};
// Render targets the renderer process draws (made while it runs; otherwise the client renderer makes its own).
class PixmapTarget final : public imvu::PiPixmapRenderTarget {
public:
PixmapTarget(std::shared_ptr<Recorder> recorder, imvu::Vec2i size);
~PixmapTarget() override;
imvu::Pixmap* getPixmap(imvu::Pixmap* result) const override;
// Copies a frame's pixels, read back from the renderer process (rows packed, 0xAARRGGBB), into the pixmap.
void setPixels(std::span<const std::byte> pixels);
[[nodiscard]] std::uint32_t id() const { return id_; }
private:
std::shared_ptr<Recorder> recorder_;
std::uint32_t id_;
imvu::Vec2i size_;
OwnedPixmap pixmap_;
};
class TextureTarget final : public imvu::PiTextureRenderTarget {
public:
TextureTarget(std::shared_ptr<Recorder> recorder, imvu::Vec2i size);
~TextureTarget() override;
imvu::TextureArea* area(imvu::TextureArea* result) const override;
imvu::SharedPtr<imvu::PiRenderTexture>* texture(imvu::SharedPtr<imvu::PiRenderTexture>* result) const override;
[[nodiscard]] std::uint32_t id() const { return id_; }
private:
std::shared_ptr<Recorder> recorder_;
std::uint32_t id_;
imvu::Vec2i size_;
};
class IndexBuffer final : public imvu::PiInternalIndexBuffer {
public:
IndexBuffer(imvu::PiInternalIndexBuffer* inner, std::shared_ptr<Recorder> recorder, std::uint32_t id);
~IndexBuffer() override;
[[nodiscard]] imvu::PiInternalIndexBuffer* inner() const { return inner_; }
[[nodiscard]] std::uint32_t id() const { return id_; }
private:
imvu::PiInternalIndexBuffer* inner_;
std::shared_ptr<Recorder> recorder_;
std::uint32_t id_;
};
class VertexBuffer final : public imvu::PiInternalVertexBuffer {
public:
VertexBuffer(imvu::PiInternalVertexBuffer* inner, std::shared_ptr<Recorder> recorder, std::uint32_t id);
~VertexBuffer() override;
void update(const void* data, std::uint32_t stride, std::uint32_t elementSize,
std::uint32_t elementCount) override;
void unknown2() override;
[[nodiscard]] imvu::PiInternalVertexBuffer* inner() const { return inner_; }
[[nodiscard]] std::uint32_t id() const { return id_; }
private:
imvu::PiInternalVertexBuffer* inner_;
std::shared_ptr<Recorder> recorder_;
std::uint32_t id_;
};
// Whether an object is one of ours (live Texture, IndexBuffer, VertexBuffer, PixmapTarget or TextureTarget): the client
// can also hand the engine objects the client renderer made itself (its render targets, and their textures), which
// must reach it unchanged.
bool ours(const void* object);
// The client renderer's object, and our id, for what the client passes in: ours unwrapped, others unchanged (id 0).
inline imvu::PiRenderTexture* inner(imvu::PiRenderTexture* texture)
{
return ours(texture) ? static_cast<Texture*>(texture)->inner() : texture;
}
inline std::uint32_t id(imvu::PiRenderTexture* texture)
{
return ours(texture) ? static_cast<Texture*>(texture)->id() : 0;
}
inline imvu::PiInternalIndexBuffer* inner(imvu::PiInternalIndexBuffer* buffer)
{
return ours(buffer) ? static_cast<IndexBuffer*>(buffer)->inner() : buffer;
}
inline std::uint32_t id(imvu::PiInternalIndexBuffer* buffer)
{
return ours(buffer) ? static_cast<IndexBuffer*>(buffer)->id() : 0;
}
inline imvu::PiInternalVertexBuffer* inner(imvu::PiInternalVertexBuffer* buffer)
{
return ours(buffer) ? static_cast<VertexBuffer*>(buffer)->inner() : buffer;
}
inline std::uint32_t id(imvu::PiInternalVertexBuffer* buffer)
{
return ours(buffer) ? static_cast<VertexBuffer*>(buffer)->id() : 0;
}
} // namespace t5de