Replies: 2 comments
-
I definitely considered it (I think I actually implemented it as a trait at some point), but each time I add a trait, the code becomes a bit more complex. It is also a bit harder to follow the code, an enum is very easy to reason about. Also, all the texture types have common functionality, but they also have a lot of fundamental differences. Finally, enums perform better than traits, however, I'm unsure how much it matters in practice. Can you give an example of a struct that would benefit from a texture/target trait? Could you use an enum instead of a generic struct? Maybe one that owns the actual texture/target and not just a reference to it. Note that it is cheap to generate a target every time it's needed, for example |
Beta Was this translation helpful? Give feedback.
-
So the motivating example is something like this: pub struct ShaderScreen<T: Texture> { Now I think about it though, perhaps an enum is necessary in any case: to allow for changing the texture type at runtime (although dyn exists I guess). The awkwardness is I'd be calling the same methods on every match arm (new_empty, width, height, as_color_target, etc). Anyway, I very much appreciate your reluctance to add more traits - I live in fear of trait-generated error messages. PS: I've been having a lot of fun and learning a great deal reading three-d's src, so many thanks for your work. |
Beta Was this translation helpful? Give feedback.
-
The various _Texture<'a> and _Target<'a> types:
Do you think it would be worth it to define some kind of 'Texture' trait? The _Texture and _Target enums are nice, but they're borrowed, so if you want to have some struct that is generic over what kind of texture it holds, but owns that texture, you're out of luck.
Beta Was this translation helpful? Give feedback.
All reactions