Coverage Report

Created: 2026-09-14 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreFroxelizer.h
Line
Count
Source
1
#ifndef OGRE_FROXELIZER_H
2
#define OGRE_FROXELIZER_H
3
4
#include "OgreLight.h"
5
#include "OgrePrerequisites.h"
6
#include "OgreVector.h"
7
#include <vector>
8
9
namespace Ogre
10
{
11
12
/** Builds a frustum-voxel ("froxel") grid for the active camera and bins
13
    lights into it, in the style of Filament's Froxelizer. The result feeds
14
    two GPU buffers (grid + records) consumed by clustered shading. */
15
struct Froxelizer
16
{
17
0
    Froxelizer() = default;
18
19
    /// Rebuild the layout
20
    void updateLayout(const Camera* cam, const Viewport* viewport);
21
22
    /// bin the lights into the froxel grid
23
    /// @return true if the light binning was updated
24
    bool binLights(const Camera* cam, const LightList& lights);
25
26
    // shader-facing scalars
27
0
    const Vector4f& getTileParams() const { return mTileParams; } // (countX, countY, yFix, tileSizePx)
28
0
    const Vector4f& getDepthParams() const { return mDepthParams; } // (scaleZ, biasZ, linZ, sliceCount)
29
30
    // GPU buffer data
31
0
    const std::vector<uint32>& getGrid() const { return mGrid; }      // (offset << 8) | count per froxel
32
0
    const std::vector<uint32>& getRecords() const { return mRecords; } // flat light-index list
33
34
    enum : uint32
35
    {
36
        /// 4096 froxels fit in a 16 KiB buffer, the minimum guaranteed in GLES 3.x and Vulkan 1.1
37
        MAX_FROXELS = 4096,
38
        MAX_FROXEL_SLICES = 16,
39
        /// 16384 light indices (uint8) fit in a 16 KiB buffer
40
        MAX_FROXEL_RECORDS = 16384,
41
        MAX_LIGHTS = 255 ///< @note stored as uint8 in the froxel records
42
    };
43
44
private:
45
    void rebuildLayout(const Viewport* viewport);
46
47
    void updateDepthParams(const Camera* cam);
48
    int findSliceZ(float viewSpaceZ) const;
49
50
    int mLastWidth = 0, mLastHeight = 0;
51
    float mZLightNear = 0.0f, mZLightFar = 0.0f;
52
    uint32 mLastHash = 0;
53
54
    Vector4f mTileParams = Vector4f(0);
55
    Vector4f mDepthParams = Vector4f(0);
56
    // fixed 4096 entries: (offset << 8) | count
57
    std::vector<uint32> mGrid;
58
    // one byte per light index (max 255 lights), packed into words
59
    std::vector<uint32> mRecords;
60
    // temporary per-froxel light lists
61
    std::vector<std::vector<uint8>> mFroxelLights;
62
};
63
64
} // namespace Ogre
65
66
#endif