Files
t5de-renderer/adapter/resources.cpp
T
dhkatzandClaude Opus 5.5 299cd8c312 Fix particle sizes, and add tools for comparing renderers
Particles: Direct3D 9's size limit evidently isn't the documented 64 pixels; unclamped (up to 2048) they match the client's renderer. A compare view shows the left half's scene over the right half, both renderers side by side; %TEMP%\t5de-renderer-view.txt switches views and %TEMP%\t5de-renderer-shaders\fixed_function.hlsl replaces the shaders while the client runs. The renderer process runs from a copy, so the program can be replaced meanwhile. The adapter recognizes only the textures and buffers it made (others reach the client renderer unchanged) and logs the others and render targets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 06:43:34 -07:00

109 lines
2.7 KiB
C++

#include "resources.hpp"
#include <mutex>
#include <unordered_set>
namespace t5de {
namespace {
// Our live resources, by address.
struct Registry {
std::mutex mutex;
std::unordered_set<const void*> objects;
};
Registry& registry()
{
static Registry instance;
return instance;
}
void add(const void* object)
{
const std::scoped_lock lock(registry().mutex);
registry().objects.insert(object);
}
void remove(const void* object)
{
const std::scoped_lock lock(registry().mutex);
registry().objects.erase(object);
}
} // namespace
bool ours(const void* object)
{
if (object == nullptr) {
return false;
}
const std::scoped_lock lock(registry().mutex);
return registry().objects.contains(object);
}
Texture::Texture(imvu::PiRenderTexture* inner, std::shared_ptr<Recorder> recorder, std::uint32_t id)
: inner_(inner), recorder_(std::move(recorder)), id_(id)
{
add(static_cast<imvu::PiRenderTexture*>(this));
}
Texture::~Texture()
{
remove(static_cast<imvu::PiRenderTexture*>(this));
delete inner_; // through its virtual destructor: IMVU's code frees it
recorder_->destroyTexture(id_);
}
imvu::Vec2i Texture::size() const { return inner_->size(); }
void Texture::updateRegions(const imvu::Pixmap& pixmap, const imvu::CompoundRegion& regions)
{
inner_->updateRegions(pixmap, regions);
recorder_->updateTexture(id_, pixmap); // all of it: the regions' layout isn't known
}
void Texture::update(const imvu::Pixmap& pixmap)
{
inner_->update(pixmap);
recorder_->updateTexture(id_, pixmap);
}
imvu::Pixmap* Texture::read(imvu::Pixmap* result) const { return inner_->read(result); }
IndexBuffer::IndexBuffer(imvu::PiInternalIndexBuffer* inner, std::shared_ptr<Recorder> recorder, std::uint32_t id)
: inner_(inner), recorder_(std::move(recorder)), id_(id)
{
add(static_cast<imvu::PiInternalIndexBuffer*>(this));
}
IndexBuffer::~IndexBuffer()
{
remove(static_cast<imvu::PiInternalIndexBuffer*>(this));
delete inner_;
recorder_->destroyBuffer(id_);
}
VertexBuffer::VertexBuffer(imvu::PiInternalVertexBuffer* inner, std::shared_ptr<Recorder> recorder, std::uint32_t id)
: inner_(inner), recorder_(std::move(recorder)), id_(id)
{
add(static_cast<imvu::PiInternalVertexBuffer*>(this));
}
VertexBuffer::~VertexBuffer()
{
remove(static_cast<imvu::PiInternalVertexBuffer*>(this));
delete inner_;
recorder_->destroyBuffer(id_);
}
void VertexBuffer::update(const void* data, std::uint32_t stride, std::uint32_t elementSize, std::uint32_t elementCount)
{
inner_->update(data, stride, elementSize, elementCount);
recorder_->updateBuffer(id_, data, stride, elementSize, elementCount);
}
void VertexBuffer::unknown2() { inner_->unknown2(); }
} // namespace t5de