refactor OpenGL UboManager, UboBlocks, and Legacy cleanup - #506
Merged
Conversation
Reviewer's GuideRefactors the OpenGL UboManager and related UBO block types out of the Legacy namespace, tightens type aliases and const‑correctness, improves discard/nodiscard annotations, and does minor API visibility and comment cleanups across legacy OpenGL helpers. Sequence diagram for UboManager updateIfInvalid and bind flowsequenceDiagram
actor Caller
participant Manager as Legacy_UboManager
participant GL as Functions
participant SharedVbos as SharedVboManager
participant Vbo as VBO
Caller->>Manager: bind(GL, block)
Manager->>Manager: updateIfInvalid(GL, block)
alt buffer already bound
Manager-->>Manager: return cached buffer
else buffer invalid
Manager->>Manager: lookup rebuild function for block
alt rebuild function registered
Manager->>GL: call rebuildFunction(GL)
GL->>SharedVbos: getSharedVbos()
SharedVbos-->>GL: sharedVboHandle
GL->>Vbo: ensure VBO exists
Vbo-->>GL: bufferId
GL-->>Manager: rebuild completed
Manager->>Manager: bind_internal(GL, block, bufferId)
Manager-->>Manager: cache bufferId in m_boundBuffers
else no rebuild function
Manager-->>Caller: throw runtime_error
end
end
Manager-->>GL: glBindBufferBase(GL_UNIFORM_BUFFER, bindingIndex, bufferId)
GL-->>Caller: UBO bound
Sequence diagram for UboManager syncFields partial UBO updatesequenceDiagram
actor Caller
participant Manager as Legacy_UboManager
participant GL as Functions
participant Vbo as VBO
Caller->>Manager: syncFields<Block,T,Us...>(GL, members...)
Manager->>Manager: static_assert T == BlockType_t<Block>
Manager->>Manager: compute offsets of members
Manager->>Manager: blockData = get<Block>()
Manager->>Manager: getOrCreateVbo(GL, Block)
Manager->>GL: glBindBuffer(GL_UNIFORM_BUFFER, Vbo.get())
loop for each member
Manager->>GL: glBufferSubData(GL_UNIFORM_BUFFER, offset, size, pointer)
end
Manager->>GL: glBindBuffer(GL_UNIFORM_BUFFER, 0)
Manager->>Manager: bind_internal(GL, Block, Vbo.get())
Manager-->>Caller: return
Class diagram for refactored OpenGL UboManager and UBO block typesclassDiagram
direction LR
class Legacy_UboManager {
<<final>>
+typedef RebuildFunction
-EnumIndexedArray~RebuildFunction,SharedVboEnum~ m_rebuildFunctions
-EnumIndexedArray~OptionalGLuint,SharedVboEnum~ m_boundBuffers
-SharedVboBlocks m_shadowBlocks
+UboManager()
+~UboManager()
+BlockType_t~Block~ & get~Block~()
+const BlockType_t~Block~ & get~Block~() const
+void invalidate(const SharedVboEnum block)
+void invalidateAll()
+void registerRebuildFunction(const SharedVboEnum block, RebuildFunction func, bool allowOverwrite = false)
+void unregisterRebuildFunction(const SharedVboEnum block)
+bool isInvalid(const SharedVboEnum block) const
+GLuint updateIfInvalid(Functions &gl, const SharedVboEnum block)
+GLuint update~T,A~(Functions &gl, const SharedVboEnum block, const vector~T,A~ &data)
+GLuint update~T~(Functions &gl, const SharedVboEnum block, const T &data)
+GLuint update~Block~(Functions &gl, const BlockType_t~Block~ &data)
+GLuint sync~Block~(Functions &gl)
+void syncFields~Block,T,Us...~(Functions &gl, Us T::* members...)
+void syncField~Block,T,U~(Functions &gl, U T::* member)
+void bind(Functions &gl, const SharedVboEnum block)
-VBO & getOrCreateVbo(Functions &gl, const SharedVboEnum block)
-GLuint bind_internal(Functions &gl, const SharedVboEnum block, const GLuint buffer)
}
class Functions {
<<abstract>>
-virtual bool virt_canRenderQuads()
-virtual optional~GLenum~ virt_toGLenum(DrawModeEnum mode)
-virtual void virt_enableProgramPointSize(bool enable)
-virtual const char * virt_getShaderVersion() const
+bool canRenderQuads()
+optional~GLenum~ toGLenum(const DrawModeEnum mode)
+const char * getShaderVersion() const
+static const char * getUniformBlockName(SharedVboEnum block)
+SharedVboManager & getSharedVbos()
}
class VBO {
+VBO()
+VBO(const VBO &)
+VBO(VBO &&)
+VBO & operator=(const VBO &)
+VBO & operator=(VBO &&)
+GLuint get() const
+void emplace(shared_ptr~Functions~ gl)
+operator bool() const
}
class EnumIndexedArray~T,E~ {
-T data[ ]
+T & operator[] (E index)
+const T & operator[] (E index) const
+size_t size() const
}
class SharedVboEnum {
<<enumeration>>
}
class BlockType~T~ {
+typedef type
}
class SharedVboBlocks {
<<typedef>>
}
class BlockType_t~T~ {
<<alias>>
}
class OptionalGLuint {
<<typedef>>
}
Functions <|-- ConcreteFunctions
Legacy_UboManager --> Functions : uses
Legacy_UboManager --> VBO : manages
Legacy_UboManager --> EnumIndexedArray~RebuildFunction,SharedVboEnum~ : owns
Legacy_UboManager --> EnumIndexedArray~OptionalGLuint,SharedVboEnum~ : owns
Legacy_UboManager --> SharedVboBlocks : owns
EnumIndexedArray~T,E~ --> SharedVboEnum : indexed_by
BlockType_t~T~ --> BlockType~T~ : alias_of
SharedVboBlocks --> BlockType_t~SharedVboEnum~ : tuple_of
Functions --> SharedVboEnum : parameter
Legacy_UboManager --> SharedVboEnum : parameter
Class diagram for updated SharedVboBlocks and BlockType_t utilitiesclassDiagram
direction LR
class SharedVboEnum {
<<enumeration>>
+NUM_SHARED_VBOS
}
class BlockType~T~ {
+typedef type
}
class BlockType_t~T~ {
<<alias>>
}
class SharedVboBlocks {
<<typedef>>
}
BlockType_t~T~ --> BlockType~T~ : uses_type
SharedVboBlocks ..> BlockType_t~T~ : tuple_expansion
class MakeSharedVboBlocksHelper {
<<template_function>>
+auto MakeSharedVboBlocksHelper(index_sequence~Is...~) : tuple~BlockType_t~static_cast~SharedVboEnum~(Is)~~...~
}
MakeSharedVboBlocksHelper ..> SharedVboEnum
MakeSharedVboBlocksHelper ..> BlockType_t~T~
SharedVboBlocks ..> MakeSharedVboBlocksHelper : decltype_of
Class diagram for GLWeather::TransitionPair and Legacy::TFO updatesclassDiagram
direction LR
class GLWeather {
+template~T~ T applyTransition(float startTime, T startVal, T targetVal) const
+template~T~ class TransitionPair
}
class GLWeather_TransitionPair~T~ {
<<final>>
+T & start
+T target
}
GLWeather *-- GLWeather_TransitionPair~T~ : nested
class Legacy_TFO {
<<final>>
-GLuint id
+TFO()
+~TFO()
+void bind()
+void unbind()
}
note for Legacy_TFO "Comment: TFO = Transform Feedback Object"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
Legacy::Functions, the access specifiers are now a bit odd (private:for the virtual helpers plus a trailingprotected:/private:pair); consider cleaning this up and deciding clearly whether thevirt_*methods should remainprotectedfor derived classes or be fullyprivate. - Several parameters are now passed as
constby value (e.g.,const SharedVboEnum block,const GLuint buffer); sinceconston by-value parameters has no effect on the caller and can reduce readability, consider dropping these qualifiers unless they serve a specific purpose in your codebase conventions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `Legacy::Functions`, the access specifiers are now a bit odd (`private:` for the virtual helpers plus a trailing `protected:`/`private:` pair); consider cleaning this up and deciding clearly whether the `virt_*` methods should remain `protected` for derived classes or be fully `private`.
- Several parameters are now passed as `const` by value (e.g., `const SharedVboEnum block`, `const GLuint buffer`); since `const` on by-value parameters has no effect on the caller and can reduce readability, consider dropping these qualifiers unless they serve a specific purpose in your codebase conventions.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #506 +/- ##
=======================================
Coverage 25.10% 25.10%
=======================================
Files 511 511
Lines 42286 42289 +3
Branches 4574 4574
=======================================
+ Hits 10615 10617 +2
- Misses 31671 31672 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
Refine OpenGL legacy utilities by modernizing UBO management and tightening API contracts.
Enhancements: