Fixed-capacity ring buffer of GL textures for temporal shaders. More...
Public Member Functions | |
| std::size_t | capacity () const |
| Maximum number of frames retained by the ring. | |
| void | cleanup () |
| Release all GL textures and reset the ring state. | |
| void | fill (const cv::Mat &frame) |
| Pre-fill every slot with copies of a single frame. | |
| FrameCache (const FrameCache &)=delete | |
| FrameCache (std::size_t num, bool use_array=false) | |
| GLuint | historyTexture () const |
| Array texture containing the physical history ring layers. | |
| void | init (int w, int h, bool hdr=false) |
Allocate the ring of GL textures sized to w x h. | |
| bool | isFull () const |
| True when the ring is fully populated. | |
| int | oldestLayer () const |
| Physical array layer corresponding to logical history index zero. | |
| FrameCache & | operator= (const FrameCache &)=delete |
| void | push (const cv::Mat &frame) |
Upload frame (BGR) into the next ring slot. | |
| void | pushFromFBO (GLuint src_fbo, int w, int h) |
| GPU-side push from a source FBO into the next ring slot. | |
| void | pushFromTexture (GLuint src_tex, int w, int h) |
| GPU-side push from an existing GL texture into the next ring slot. | |
| std::size_t | size () const |
| Number of frames currently retained (0 ≤ n ≤ capacity). | |
| GLuint | textureAt (std::size_t index) const |
Return the GL texture at logical index index. | |
| ~FrameCache () | |
Private Member Functions | |
| void | advance () |
| void | allocateHistoryTexture () |
| Allocate the optional array texture using the cache's dimensions and pixel format. | |
| void | finishPush () |
| bool | hasStorage () const |
Private Attributes | |
| std::size_t | count = 0 |
| std::size_t | head = 0 |
| int | height = 0 |
| GLuint | history_texture = 0 |
| Optional array-backed history ring. | |
| bool | is_hdr = false |
| std::size_t | num_frames |
| GLuint | scratch_fbo = 0 |
| Scratch FBO used by pushFromTexture(). | |
| std::vector< GLuint > | textures |
| bool | use_history_array = false |
| int | width = 0 |
Fixed-capacity ring buffer of GL textures for temporal shaders.
Legacy shaders whose filename contains "cache" receive previous frames as separate sampler2D uniforms. Array-cache shaders instead receive one sampler2DArray whose layers form the ring. In either mode only the newest frame is uploaded into the next physical slot. The "oldest → newest" indexing used by shaders is preserved via a logical-to-physical offset.
This mirrors the texture-ring approach used by gl_compute_cv and eliminates 7 BGR→RGBA conversions plus 7 texture uploads per push.
Definition at line 2052 of file ACMX2/acmx.cpp.
|
inlineexplicit |
| num | Maximum number of frames to retain. |
| use_array | Store the ring in one GL_TEXTURE_2D_ARRAY instead of separate GL_TEXTURE_2D objects. |
Definition at line 2059 of file ACMX2/acmx.cpp.
References num_frames, and use_history_array.
Referenced by FrameCache(), and operator=().
|
inline |
Definition at line 2060 of file ACMX2/acmx.cpp.
References cleanup().
|
delete |
References FrameCache().
|
inlineprivate |
Definition at line 2382 of file ACMX2/acmx.cpp.
References count, head, and num_frames.
Referenced by finishPush(), and push().
|
inlineprivate |
Allocate the optional array texture using the cache's dimensions and pixel format.
Definition at line 2401 of file ACMX2/acmx.cpp.
References height, history_texture, is_hdr, num_frames, use_history_array, and width.
Referenced by fill(), init(), pushFromFBO(), and pushFromTexture().
|
inline |
Maximum number of frames retained by the ring.
Definition at line 2324 of file ACMX2/acmx.cpp.
References num_frames.
|
inline |
Release all GL textures and reset the ring state.
Definition at line 2111 of file ACMX2/acmx.cpp.
References count, head, height, history_texture, is_hdr, scratch_fbo, textures, and width.
Referenced by init(), and ~FrameCache().
|
inline |
Pre-fill every slot with copies of a single frame.
Seeds the entire cache with one frame and marks the ring as full.
Definition at line 2340 of file ACMX2/acmx.cpp.
References allocateHistoryTexture(), count, hasStorage(), head, height, history_texture, num_frames, textures, use_history_array, and width.
Referenced by push().
|
inlineprivate |
Definition at line 2388 of file ACMX2/acmx.cpp.
References advance(), count, head, and num_frames.
Referenced by pushFromFBO(), and pushFromTexture().
|
inlineprivate |
Definition at line 2380 of file ACMX2/acmx.cpp.
References history_texture, textures, and use_history_array.
Referenced by fill(), push(), pushFromFBO(), and pushFromTexture().
|
inline |
Array texture containing the physical history ring layers.
Definition at line 2330 of file ACMX2/acmx.cpp.
References history_texture.
Referenced by ACView::bindPassHistoryTextures().
|
inline |
Allocate the ring of GL textures sized to w x h.
Must be called once a GL context is current. Existing textures (if any) are released first. The ring remains empty until the first source frame is replicated into every slot by one of the push methods.
| w | Texture width in pixels. |
| h | Texture height in pixels. |
| hdr | When true, allocate textures as GL_RGBA16F (matching the HDR linear-light pipeline) instead of GL_RGBA. |
Definition at line 2077 of file ACMX2/acmx.cpp.
References allocateHistoryTexture(), cleanup(), count, head, height, is_hdr, num_frames, textures, use_history_array, and width.
|
inline |
True when the ring is fully populated.
Definition at line 2327 of file ACMX2/acmx.cpp.
References count, and num_frames.
Referenced by ACView::bindPassHistoryTextures(), and oldestLayer().
|
inline |
Physical array layer corresponding to logical history index zero.
Definition at line 2333 of file ACMX2/acmx.cpp.
|
delete |
References FrameCache().
|
inline |
Upload frame (BGR) into the next ring slot.
When the ring is full this overwrites the oldest slot in place, which becomes the new "newest" frame. Only one BGR→RGBA conversion and one texture upload occur per call.
Definition at line 2209 of file ACMX2/acmx.cpp.
References advance(), count, fill(), hasStorage(), head, height, history_texture, textures, use_history_array, and width.
|
inline |
GPU-side push from a source FBO into the next ring slot.
Used by the HDR pipeline to copy the post-decode linear BT.2020 texture into an RGBA16F ring without any CPU readback or pixel format conversion. The source FBO must have a colour attachment sized at least w x h and using a compatible internal format (e.g. GL_RGBA16F when the cache was initialised with hdr=true).
| src_fbo | Read framebuffer object containing the new frame. |
| w,h | Region to copy (typically the full FBO dimensions). |
Definition at line 2143 of file ACMX2/acmx.cpp.
References allocateHistoryTexture(), count, finishPush(), hasStorage(), head, height, history_texture, is_hdr, num_frames, textures, use_history_array, and width.
|
inline |
GPU-side push from an existing GL texture into the next ring slot.
Uses a small scratch FBO so the per-frame BGR->RGBA conversion and second host->GPU upload that push() performs can be avoided entirely once the camera texture has already been populated for the shader chain. This is the path that keeps zero-copy interop intact when expensive CPU passes (e.g. ONNX) run earlier in the frame and the redundant cv::Mat upload starts dropping frames.
| src_tex | GL texture currently containing the new frame. |
| w,h | Region to copy (typically the full texture size). |
Definition at line 2245 of file ACMX2/acmx.cpp.
References allocateHistoryTexture(), count, finishPush(), hasStorage(), head, height, history_texture, is_hdr, num_frames, scratch_fbo, textures, use_history_array, and width.
|
inline |
Number of frames currently retained (0 ≤ n ≤ capacity).
Definition at line 2321 of file ACMX2/acmx.cpp.
References count.
|
inline |
Return the GL texture at logical index index.
| index | 0 = oldest retained frame, size()-1 = newest. |
Definition at line 2315 of file ACMX2/acmx.cpp.
References count, head, num_frames, and textures.
Referenced by ACView::bindPassHistoryTextures().
|
private |
Definition at line 2424 of file ACMX2/acmx.cpp.
Referenced by advance(), cleanup(), fill(), finishPush(), init(), isFull(), push(), pushFromFBO(), pushFromTexture(), size(), and textureAt().
|
private |
Definition at line 2423 of file ACMX2/acmx.cpp.
Referenced by advance(), cleanup(), fill(), finishPush(), init(), oldestLayer(), push(), pushFromFBO(), pushFromTexture(), and textureAt().
|
private |
Definition at line 2420 of file ACMX2/acmx.cpp.
Referenced by allocateHistoryTexture(), cleanup(), fill(), init(), push(), pushFromFBO(), and pushFromTexture().
|
private |
Optional array-backed history ring.
Definition at line 2427 of file ACMX2/acmx.cpp.
Referenced by allocateHistoryTexture(), cleanup(), fill(), hasStorage(), historyTexture(), push(), pushFromFBO(), and pushFromTexture().
|
private |
Definition at line 2421 of file ACMX2/acmx.cpp.
Referenced by allocateHistoryTexture(), cleanup(), init(), pushFromFBO(), and pushFromTexture().
|
private |
Definition at line 2418 of file ACMX2/acmx.cpp.
Referenced by advance(), allocateHistoryTexture(), capacity(), fill(), finishPush(), FrameCache(), init(), isFull(), pushFromFBO(), pushFromTexture(), and textureAt().
|
private |
Scratch FBO used by pushFromTexture().
Definition at line 2426 of file ACMX2/acmx.cpp.
Referenced by cleanup(), and pushFromTexture().
|
private |
Definition at line 2425 of file ACMX2/acmx.cpp.
Referenced by cleanup(), fill(), hasStorage(), init(), push(), pushFromFBO(), pushFromTexture(), and textureAt().
|
private |
Definition at line 2422 of file ACMX2/acmx.cpp.
Referenced by allocateHistoryTexture(), fill(), FrameCache(), hasStorage(), init(), push(), pushFromFBO(), and pushFromTexture().
|
private |
Definition at line 2419 of file ACMX2/acmx.cpp.
Referenced by allocateHistoryTexture(), cleanup(), fill(), init(), push(), pushFromFBO(), and pushFromTexture().