LevelRenderer class is responsible for rendering the Minecraft world terrain, managing chunks, and coordinating level-wide visual effects.
Class Overview
LevelRenderer.h:35
Core Responsibilities
- Chunk rendering and management
- Frustum and occlusion culling
- Sky and atmospheric effects
- Weather rendering
- Entity and tile entity coordination
- Particle system integration
Chunk Architecture
Chunk Dimensions
LevelRenderer.h:39-45
Command Buffer Allocation
Platform-specific memory limits for chunk rendering:| Platform | Buffer Size |
|---|---|
| Xbox One | 512 MB |
| PS4 (Orbis) | 448 MB |
| PS3 | 110 MB |
| Vita/Mobile | 55 MB |
| Windows 64 | 2047 MB |
LevelRenderer.h:46-56
Global Chunk System
Chunks are managed in a global indexing system that supports multiple dimensions:Dimension Layout
LevelRenderer.cpp:80-99
Chunk Flags
Each chunk has flags stored in a global array:CHUNK_FLAG_COMPILED(0x01) - Chunk has compiled geometryCHUNK_FLAG_DIRTY(0x02) - Chunk needs rebuildingCHUNK_FLAG_EMPTY0(0x04) - Opaque layer is emptyCHUNK_FLAG_EMPTY1(0x08) - Transparent layer is emptyCHUNK_FLAG_NOTSKYLIT(0x10) - Chunk is not lit by skyCHUNK_FLAG_CRITICAL(0x20) - Critical chunk (Vita only)CHUNK_FLAG_CUT_OUT(0x40) - Contains alpha cutout geometry- Reference count bits - Track player references
LevelRenderer.h:243-258
Rendering Pipeline
Main Render Function
LevelRenderer.cpp:672
Parameters:
player- The viewing player/moblayer- Render layer (0 = opaque, 1 = transparent)alpha- Frame interpolation (0.0 to 1.0)updateChunks- Whether to update dirty chunks
Render Order
- Chunk Sorting - Position chunks relative to player
- Frustum Culling - Determine visible chunks
- Layer Rendering - Render opaque, then transparent
- Lighting - Apply light texture
Render Chunk Implementation
LevelRenderer.cpp:737
On PS3, this uses SPU-accelerated culling:
LevelRenderer.cpp:757-770
Chunk Culling
Frustum Culling
SPU Culling (PS3)
LevelRenderer.h:102-106
Offloads culling calculations to the PS3’s SPU cores:
- LevelRenderer_cull - Frustum culling task
- LevelRenderer_FindNearestChunk - Nearest chunk finding
- LevelRenderer_zSort - Depth sorting for transparency
LevelRenderer_cull.h:14-34 (SPU data structures)
Dirty Chunk Management
Marking Chunks Dirty
LevelRenderer.h:96
Updating Dirty Chunks
LevelRenderer.h:89
Lock-Free Stack
Dirty chunks are tracked using a lock-free stack:LevelRenderer.h:260
Multi-Threading
Chunk Rebuild Threads
For large worlds, chunks can be rebuilt on background threads:LevelRenderer.h:266-274
Sky Rendering
Sky System
LevelRenderer.cpp:932
Features:
- Dimension-specific skies
- Sun and moon rendering with phases
- Star field (1500 procedural stars)
- Sunrise/sunset gradient
- Rain brightness adjustment
- Anaglyph 3D support
Halo Ring (Special Sky)
LevelRenderer.cpp:1184
Renders a special Halo-themed ring in the sky (texture pack feature).
Cloud Rendering
Simple Clouds
LevelRenderer.cpp:1234
Fast cloud rendering using textured quads.
Advanced Clouds
LevelRenderer.cpp:1506
Full 3D volumetric clouds:
- Cube-per-texel geometry
- 6 directional render lists + 1 combined
- Conditional backface culling based on player height
- Frustum culling per 8×8 section
- Reduced radius in 3-4 player split-screen
Cloud Mesh Generation
LevelRenderer.cpp:1340
Pre-generates cloud geometry into 7 display lists:
- Lists 0-5: Individual face directions
- List 6: All faces combined
Platform-Specific Optimizations
PS Vita Alpha Cutout
Vita renders alpha cutout geometry in a separate pass:LevelRenderer.cpp:775-824
Large World Support
Large worlds use different parameters:LevelRenderer.h:212-217
Split-Screen Support
The renderer supports up to 4 simultaneous players:LevelRenderer.h:132-157
Dynamic Render Distance
LevelRenderer.cpp:420
Destroyed Tile Management
Temporary collision tracking for recently destroyed blocks:LevelRenderer.h:175-200
Provides temporary collision while chunk render data updates.
Entity and Tile Entity Rendering
Entity Rendering
LevelRenderer.cpp:494
- Prepares render dispatchers
- Culls entities to frustum
- Renders regular entities
- Renders global entities (always visible)
- Renders tile entities
Tile Entity Storage
LevelRenderer.h:123
Stored by global chunk index for fast dimension filtering.
Statistics
Chunk Statistics
"C: rendered/total. F: frustum_culled, O: occluded, E: empty"
See: LevelRenderer.cpp:606
Entity Statistics
"E: rendered/total. B: culled, I: invisible"
See: LevelRenderer.cpp:611
Related Classes
- Chunk - Individual chunk rendering
- Culler - Frustum culling
- Entity Renderer - Entity rendering
- Particle Engine - Particle effects