Draw distance slider (#44)

Helps render performance on integrated GPUs.
Added render culling for baked compounds.
This commit is contained in:
Erin Catto 2026-07-03 20:26:19 -07:00 • committed by GitHub
commit 1bec63c9ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 200 additions and 8 deletions

View file

@ -102,6 +102,7 @@ void SampleContext::Save()
fprintf( file, " \"exposure\": %g,\n", GetExposure() );
fprintf( file, " \"sunStrength\": %g,\n", GetSun().strength );
fprintf( file, " \"debugView\": %d,\n", debugView );
fprintf( file, " \"drawDistance\": %g,\n", drawDistance );
fprintf( file, " \"showHullEdges\": %s,\n", GetEdgeOverlayParams().showHulls ? "true" : "false" );
fprintf( file, " \"showEdgeConvexity\": %s,\n", GetEdgeOverlayParams().showEdgeConvexity ? "true" : "false" );
fprintf( file, " \"replayKeyframeBudgetMB\": %d,\n", replayKeyframeBudgetMB );
@ -237,6 +238,15 @@ void SampleContext::Load()
buffer[count] = 0;
debugView = b3ClampInt( (int)strtol( buffer, nullptr, 10 ), 0, 4 );
}
else if ( jsoneq( data, &tokens[i], "drawDistance" ) == 0 )
{
int count = tokens[i + 1].end - tokens[i + 1].start;
assert( count < 32 );
const char* s = data + tokens[i + 1].start;
strncpy( buffer, s, count );
buffer[count] = 0;
drawDistance = b3ClampFloat( strtof( buffer, nullptr ), 1.0f, Camera::kViewDistance );
}
else if ( jsoneq( data, &tokens[i], "showHullEdges" ) == 0 )
{
const char* s = data + tokens[i + 1].start;
@ -491,6 +501,9 @@ void Sample::Step()
// around the simulation eye, matching the broad-phase tree and the far plane.
debugDraw.drawingBounds = m_camera->DrawBounds();
// Same view box drives compound child culling in the adapter.
SetViewBounds( debugDraw.drawingBounds );
ApplyGuiFlags( &debugDraw );
b3World_Draw( m_worldId, &debugDraw, B3_DEFAULT_MASK_BITS );
@ -1643,6 +1656,9 @@ static void DrawMenuBar( SampleContext* context )
}
ImGui::Separator();
ImGui::MenuItem( "Diagnostics", "M", &context->showMetrics );
ImGui::PushItemWidth( 8.0f * fontSize );
ImGui::SliderFloat( "Draw Distance", &context->drawDistance, 10.0f, Camera::kViewDistance, "%.0f m" );
ImGui::PopItemWidth();
ImGui::Separator();
if ( ImGui::BeginMenu( "Scale" ) )
{