Files
t5de-renderer/include/t5de/imvu/render_engine.hpp
T
dhkatzandClaude Opus 5.5 83e0665681 Declare the renderer interface's data types
Transforms, matrices, colors, lights, blend modes, fog, texture transforms, vertex arrays and the engine's buffer and texture objects, worked out from IMVU's Direct3D engine. The pass-through logs the first calls' arguments read through them, to check them in the client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 04:36:37 -07:00

94 lines
5.2 KiB
C++

#pragma once
// IMVU's renderer interface, PiRenderEngine (SceneWindow.dll), declared to match its vtable: the order of the methods
// and their parameter types are what matter. The names are IMVU's, from SceneWindow.dll's exported RenderEngineDx
// methods; parameter names are ours, from what IMVU's Direct3D engine does with them. See docs/interface.md.
#include <cstdint>
#include "t5de/imvu/resources.hpp"
#include "t5de/imvu/shared_ptr.hpp"
#include "t5de/imvu/types.hpp"
namespace t5de::imvu {
class PiRenderEngine {
public:
PiRenderEngine() = default;
PiRenderEngine(const PiRenderEngine&) = delete;
PiRenderEngine& operator=(const PiRenderEngine&) = delete;
virtual ~PiRenderEngine() = default; // slot 0
virtual void resizeFrameBuffer(Vec2i size) = 0;
virtual void enable2dFrameBuffer() = 0;
virtual void clear(std::uint32_t flags, Color color) = 0; // ClearFlags
virtual void setProjection(Vec2i viewport, const Mat4f& projection) = 0;
virtual void setModelSpace(const Transform& model) = 0; // slot 5
virtual void setViewSpace(const Transform& view) = 0;
virtual void setTextures(PiRenderTexture* texture0, PiRenderTexture* texture1) = 0;
virtual void setDepthTestingOn(bool on) = 0;
virtual void setDepthWritingOn(bool on) = 0;
virtual void setBlendMode(RenderBlendMode mode) = 0; // slot 10
virtual void setAlphaTestingOn(bool on) = 0;
virtual void setAlphaTestValue(float value) = 0;
virtual void setBlendingOn(bool on) = 0;
virtual void setBackFaceCullingOn(bool on) = 0;
virtual void setNormalInvertingOn(bool on) = 0; // slot 15
virtual void setLightingOn(bool on) = 0;
virtual void setLightProperties(std::uint32_t index, const LightProperties& light) = 0;
virtual void setFogOn(bool on) = 0;
virtual void setFogAttributes(float start, float end, Color color) = 0;
virtual void setTextureTransformMatrixIdentity(std::uint32_t stage) = 0; // slot 20
virtual void setTextureTransformMatrix(std::uint32_t stage, const TextureTransform& transform) = 0;
virtual void setEnvironmentAmbient(Color color) = 0; // zero alpha
virtual PiRenderTexture* newRenderTexture(const Pixmap& pixmap, std::uint32_t flags) = 0;
virtual PiInternalIndexBuffer* newIndexBuffer(std::uint32_t count, const std::uint16_t* indices) = 0;
virtual PiInternalVertexBuffer* newStaticVertexBuffer(const void* data, std::uint32_t stride,
std::uint32_t elementSize,
std::uint32_t elementCount) = 0; // slot 25
// Filled later with PiInternalVertexBuffer::update.
virtual PiInternalVertexBuffer* newDynamicVertexBuffer(std::uint32_t elementSize, std::uint32_t elementCount) = 0;
virtual SharedPtr<PiPixmapRenderTarget> newPixmapRenderTarget(Vec2i size) = 0;
virtual SharedPtr<PiTextureRenderTarget> newTextureRenderTarget(Vec2i size) = 0;
virtual void beginRendering(PiRenderTarget* target) = 0;
virtual void endRendering() = 0; // slot 30
// Vertex buffers: positions (Vec3f), normals (Vec3f), texture coordinates (Vec2f), colors (Color); all but
// positions may be null.
virtual void drawTriangles(PiInternalIndexBuffer* indices, PiInternalVertexBuffer* positions,
PiInternalVertexBuffer* normals, PiInternalVertexBuffer* texCoords,
PiInternalVertexBuffer* colors) = 0;
virtual void drawLine(Vec3f from, Vec3f to, std::uint32_t color) = 0;
virtual void drawPointSprites(const PointSpriteVector& sprites) = 0;
virtual void drawTrianglesFromMemory(std::uint32_t vertexCount, std::uint32_t indexCount,
const std::uint16_t* indices, const VertexAttributeArray<Vec3f>& positions,
const VertexAttributeArray<Vec3f>& normals,
const VertexAttributeArray<Vec2f>& texCoords,
const VertexAttributeArray<Color>& colors) = 0; // slot 34
private:
// PiRenderEngine's own fields, after the vtable pointer: a magic number IMVU's destructor checks, and a size
// counter it reports from.
std::uint32_t magic_ = 0x3b913159;
std::uint32_t size_ = 0;
};
static_assert(sizeof(PiRenderEngine) == 12, "vtable pointer, magic, size");
// What SceneWindow.dll's createDLLRenderer looks up in a renderer plugin.
using IsRenderEngineSupported = int(__cdecl*)();
using CreateRenderEngine = SharedPtr<PiRenderEngine>(__cdecl*)(SharedPtr<INativeWindow> window);
// The renderers SceneWindow.dll's createRenderer makes (values from _avatarwindow.pyd's RendererType).
enum class RendererType : int {
Direct3D = 1, // RenderEngineDx, Direct3D 9
OpenGL = 2, // the plugin glRenderEngine.dll
SwiftShader = 9, // RenderEngineDx on swiftshader.dll
};
// SceneWindow.dll's createRenderer(boost::shared_ptr<INativeWindow>, RendererType), exported by this name.
using CreateRenderer = SharedPtr<PiRenderEngine>(__cdecl*)(SharedPtr<INativeWindow> window, RendererType type);
inline constexpr const char* createRendererName =
"?createRenderer@@YA?AV?$shared_ptr@VPiRenderEngine@@@boost@@V?$shared_ptr@VINativeWindow@@@2@W4RendererType@@@Z";
} // namespace t5de::imvu