Map projections' depth like the client's renderer
IMVU's projections give depth from -1 to 1; its Direct3D renderer maps it to 0 to 1, and now so does ours. Without that, the nearer half of the depth range was clipped, the whole 2D overlay (name tags, the frame rate, the room's title) with it. The adapter also draws drawTrianglesFromMemory without indices, and sums up what the client draws in its log. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
299cd8c312
commit
3cdda4c7ed
6 files changed
+78
-43
No files matched your search
+34
-2
@@ -5,6 +5,7 @@
|
||||
#include <bit>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "log.hpp"
|
||||
#include "resources.hpp"
|
||||
@@ -53,6 +54,9 @@ void Engine::clear(std::uint32_t flags, imvu::Color color)
|
||||
void Engine::setProjection(imvu::Vec2i viewport, const imvu::Mat4f& projection)
|
||||
{
|
||||
inner_->setProjection(viewport, projection);
|
||||
if (projection.m[2][3] == 0.0f) {
|
||||
++stats_.flat;
|
||||
}
|
||||
protocol::SetProjection command{viewport.x, viewport.y, {}};
|
||||
std::memcpy(command.m, &projection.m[0][0], sizeof(command.m));
|
||||
recorder_->add(Op::SetProjection, command);
|
||||
@@ -253,6 +257,14 @@ void Engine::endRendering()
|
||||
recorder_->add(Op::EndFrame, protocol::EndFrame{static_cast<std::uint64_t>(now.QuadPart)});
|
||||
recorder_->flush(true);
|
||||
++frames_;
|
||||
if (frames_ % 300 == 0 && statsLogged_ < 6) {
|
||||
++statsLogged_;
|
||||
log::info("engine: last 300 frames: drawTriangles {} (and {} with buffers not ours), drawTrianglesFromMemory {} "
|
||||
"(and {} without indices), point sprites {}, lines {}, 2D projections {}",
|
||||
stats_.triangles, stats_.foreignTriangles, stats_.indexed, stats_.unindexed, stats_.sprites, stats_.lines,
|
||||
stats_.flat);
|
||||
stats_ = {};
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::drawTriangles(imvu::PiInternalIndexBuffer* indices, imvu::PiInternalVertexBuffer* positions,
|
||||
@@ -260,15 +272,21 @@ void Engine::drawTriangles(imvu::PiInternalIndexBuffer* indices, imvu::PiInterna
|
||||
imvu::PiInternalVertexBuffer* colors)
|
||||
{
|
||||
inner_->drawTriangles(inner(indices), inner(positions), inner(normals), inner(texCoords), inner(colors));
|
||||
++(id(indices) != 0 && id(positions) != 0 ? stats_.triangles : stats_.foreignTriangles);
|
||||
recorder_->add(Op::DrawTriangles,
|
||||
protocol::DrawTriangles{id(indices), id(positions), id(normals), id(texCoords), id(colors)});
|
||||
}
|
||||
|
||||
void Engine::drawLine(imvu::Vec3f from, imvu::Vec3f to, imvu::Color color) { inner_->drawLine(from, to, color); }
|
||||
void Engine::drawLine(imvu::Vec3f from, imvu::Vec3f to, imvu::Color color)
|
||||
{
|
||||
inner_->drawLine(from, to, color);
|
||||
++stats_.lines;
|
||||
}
|
||||
|
||||
void Engine::drawPointSprites(const imvu::PointSpriteVector& sprites)
|
||||
{
|
||||
inner_->drawPointSprites(sprites);
|
||||
++stats_.sprites;
|
||||
if (sprites.first == nullptr || sprites.last <= sprites.first) {
|
||||
return;
|
||||
}
|
||||
@@ -287,9 +305,23 @@ void Engine::drawTrianglesFromMemory(std::uint32_t vertexCount, std::uint32_t in
|
||||
const imvu::VertexAttributeArray<imvu::Color>& colors)
|
||||
{
|
||||
inner_->drawTrianglesFromMemory(vertexCount, indexCount, indices, positions, normals, texCoords, colors);
|
||||
if (indices == nullptr || positions.data == nullptr || vertexCount == 0) {
|
||||
++(indices != nullptr ? stats_.indexed : stats_.unindexed);
|
||||
if (positions.data == nullptr || vertexCount == 0) {
|
||||
return;
|
||||
}
|
||||
// Without indices: the vertices in order, as a triangle list.
|
||||
std::vector<std::uint16_t> sequence;
|
||||
if (indices == nullptr) {
|
||||
if (vertexCount > 0xffff) {
|
||||
return;
|
||||
}
|
||||
sequence.resize(vertexCount - vertexCount % 3);
|
||||
for (std::size_t i = 0; i < sequence.size(); ++i) {
|
||||
sequence[i] = static_cast<std::uint16_t>(i);
|
||||
}
|
||||
indices = sequence.data();
|
||||
indexCount = static_cast<std::uint32_t>(sequence.size());
|
||||
}
|
||||
const bool hasNormals = normals.data != nullptr && normals.count >= vertexCount;
|
||||
const bool hasTexCoords = texCoords.data != nullptr && texCoords.count >= vertexCount;
|
||||
const bool hasColors = colors.data != nullptr && colors.count >= vertexCount;
|
||||
|
||||
@@ -69,6 +69,19 @@ private:
|
||||
std::uint64_t frames_ = 0;
|
||||
int foreignLogged_ = 0; // diagnostics: textures the client renderer made, render targets
|
||||
|
||||
// Diagnostics: what the client draws, summed over 300 frames and logged (the first few times).
|
||||
struct Stats {
|
||||
std::uint32_t triangles = 0; // drawTriangles with our buffers
|
||||
std::uint32_t foreignTriangles = 0; // drawTriangles with buffers that aren't ours (not drawn)
|
||||
std::uint32_t indexed = 0; // drawTrianglesFromMemory with indices
|
||||
std::uint32_t unindexed = 0; // drawTrianglesFromMemory without
|
||||
std::uint32_t sprites = 0;
|
||||
std::uint32_t lines = 0;
|
||||
std::uint32_t flat = 0; // setProjection with an orthographic projection (2D)
|
||||
};
|
||||
Stats stats_;
|
||||
int statsLogged_ = 0;
|
||||
|
||||
};
|
||||
|
||||
} // namespace t5de
|
||||
Reference in new issue
Block a user