-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make TextureSequence a public class #1999
Open
RoboDoig
wants to merge
2
commits into
bonsai-rx:main
Choose a base branch
from
RoboDoig:issue-1968
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RoboDoig I think this method signature is probably the main reason why I didn't make this class public in the original design.
Having a
GetEnumerator
method in a class that doesn't implementIEnumerable
and having it take a custom extra parameter would probably make some people raise their eyebrows. The original idea was to provide an allocation-free path for looping through infinite texture sequences without having to reallocate an iterator at the boundaries.Unfortunately to top it off, the method also mutates the class state, by changing the
Id
property inside the loop, which is what allows it to pose as a regularTexture
object at the same time. This was to allow creating simple video textures that you allocate globally and are constantly looping (i.e. you can set them to an object using the normalBindTexture
).There is something about this overall class design that feels very broken. It feels like I maybe ran out of time while implementing the infrastructure for BonVision video textures, had meant to come back to this but never did.
You can see there is another internal class
TextureStream
with very similar behavior but where there is only one texture which is updated / mutated in place (by copying frame data) as the iteration progresses.What these two share in common is that they both implement
ITextureSequence
which specifies an interface for an object providing a generic streaming sequence of textures.TextureSequence
implements bothTexture
andITextureSequence
, but essentially ideally you never want to use these two interfaces at the same time.Maybe it would be cleaner to make
ITextureSequence
public and leave the details of these concrete implementations internal, but I'm not sure even that interface would be enough for your case. Do you need theTextureArray
which is stored internally insideTextureSequence
?If you need random access to the textures inside, another alternative might be to have
TextureSequence
implementIReadOnlyList<Texture>
. This way we can expose an array-like interface to the internal textures which would allow indexing without getting tangled up in all these messy implementation details.@PathogenDavid any thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternately we could make
TextureSequence
implementIReadOnlyList<int>
(or maybe better being explicit and make a new interfaceITextureArray : IEnumerable<int>
mimickingTextureArray
).An example implementation might be:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly reiterating my stance from dev club, but yeah I agree with the interface implementation approach here.
This class is basically just a wrapper that adapts
TextureArray
toTexture
so that seems like a good way to expose the functionality without broadening the public API surface with a redundantish type that has weird quirks.