Repository navigation
Non GL Renderers #8611
Replies: 5 comments 1 reply
Yeah!! I think this choice is the big one to figure out. |
|
In your sample, while I love infinite recursion ❤️ , I'd prefer the defines, but I generally prefer templated code when it makes sense, but it depends on the purpose. From a contributor/maintainer point of view, templated code is good for enforcing certain logic that makes it easier to read and better "canalises" future code contributions (ex: v1 requires "manually" maintaining perfect 1-to-1 compatibility, templates pre-architectures future code better). But many people are lost as soon as they see templated code; so you might lose contribution power ? 😝 This said, pre-existing template code is understandable (and good to learn) and doesn't prevent getting one's hands dirty. And it facilitates future maintenance by preventing some mistakes. Performance should be identical, the produced binary code should be quite the same (the example), it's mostly the syntax that changes. Templates are good but I'd prevent dynamic_casting as much as possible for performance; inheritance+virtuals are still good at that. Sometimes template calls can be resolved on compile time (performance boost), mostly by "chaining" member calls, but with usage of Some time ago, I've done some benchmarks on trying to beat the cost of virtual calls. They showed that virtual tables (member calls) slow down the object calling in debug, but not that much in release. But usage of dynamic_cast compared to compile-time resolved template calls is definitely a performance loss in both release and debug. // Demo
ChildClass child;
child->myFn<X>(); // faster
std::vector<BaseClass*> list;
list.push_back(&child);
for(auto i : list){
i->virtualFn(); // ok in release
dynamic_cast<ChildClass>(i)->myFn<X>(); // slower
}In terms of usage from code, I personally don't really care, I believe it's hard to globalise such abstractions and I often end up using their underlying "lower level" interfaces/objects directly. My code will break anyways, but I also don't rely too much on them. There's a lot of specific OpenGL code in the wild which is inevitably gonna break (imo). Of course it's better if member signatures don't change too much, so that's great. Having worked a lot with ImGui, I like their flags system very much, I think it could fit somewhere here too. (but not for mapping GL enums) // Dummy example
typedef int TextureFlags;
enum TextureFlags_ {
TextureFlags_None = 0,
TextureFlags_Compression_SRGB = 1 << 1,
TextureFlags_Compression_ARB = 1 << 2,
#ifdef TARGET_OPENGLES
TextureFlags_XYZ = 1 << 3,
#endif
TextureFlags_NormaliseCoords
}
// Typed argument, ide autocompletion, performant, stable&flexible API/signature across targets
ofTexture createTexture(int width, int height, TextureFlags flags = TextureFlags_Compression_None){
#ifdef DEBUG // runtime sanity checking
assert( (flags & TextureFlags_Compression_SRGB) && (flags & TextureFlags_Compression_ARB)) // double compression
#endif
if(flags & TextureFlags_Compression_ARB){ }
}
// Multiple values can be defined at once trough 1 argument.
createTexture(100,100, TextureFlags_Compression_ARB & TextureFlags_NormaliseCoords); |
|
Oh haha! Yeah we should avoid infinite loops. |
|
Hey I'm so glad that you guys are working on this! On implementing Dawn and/or Angle and also thinking about how OF classes and core could/would look in the future. A few thoughts, which hopefully are helpful: I feel like templates and base classes would work well now and in the future. Templates and class inheritance have an elegance, are common in the current core classes, and might offer a more flexible future as c++ changes over time. Compiler directives feel more like older c to me, though they are universal and still very useful, but also maybe antiquated and somehow less elegant. I feel like "base" (and/or virtual) classes could/would be helpful for modifying the OF core in the future: ofBaseRenderer; ofBaseTexture; ofBaseVbo; ofBaseFont; etc. A chain of virtual classes that define a "base" functionality (a tree of sorts) is also just fine. And while c++ ideas like "friend class" have their uses, I feel like traditional inheritance (parents and children) is easier to understand, modify, and maintain. I like protected inheritance over private, but I feel like base classes can have all inheritance types if needed. For instance, I feel like ofNode is a base class, and it has a mix of public, protected, and private members. And I like NickHardeman's idea above about using enums to translate library-specific constants into OF-centric values. But I wonder if these could somehow derive directly from the appropriate source. So for instance Finally, lots of OF is very very nicely commented. And I think continuing to use comments with new templates and base classes can help humans understand how OF works, in terms code, design, and intent. |
|
This is awesome discussion and will really propel the engine into next gen. I think the solution is a mixture of the proposed solutions but leveraging modern C++17 features such as constexpr ! For now though, keep cutting parts out into seperate classes and GL things into locations like @NickHardeman is doing!
OpenFrameworks is fast, C++ hardened and still leveraging 15 years of examples and addons. In the future of AI slops, we have real coded engineer developed code. |
Uh oh!
There was an error while loading. Please reload this page.
GL based classes like
ofTexturehave become integrated into the OF core. Since it is GL based, implementing non-GL based renderers proves difficult. Especially for commonly used classes likeofTrueTypeFont,ofVideoPlayer,ofVideoGrabber, etc. that rely on ofTexture.Adopting a BaseClass, implementation structure similar to
ofVideoGrabberorofAppBaseWindowwould allow for class abstraction and access to the underlying backend texture type. The current public class keeps its existing signature. Possibly deprecating very specific GL functions to begin phasing them out.For example.
Should the texture types be set by a define or by the renderer that is created by the window? Defines would make it clear what is used and may allow for faster compiles. Texture type by the renderer would allow for a bit more flexibility.
GL specific calls could be abstracted, similar to the current ofTexCompression enum.
For backwards compatibility, functions that take in GL specific arguments like GL_RGB, GL_RGBA, etc. could have an enum that maps to their GL counterparts. Some defines may be necessary for ES specific or missing types.
So functions like allocate() would not break in existing projects.
void allocate(int w, int h, int glInternalFormat, bool bUseARBExtension);And would also have an enum counterpart
void allocate(int w, int h, ofTextureFormat fmt, bool bUseARB);Advanced use cases where
ofTextureDatais accessed and set by users directly proves a bit more difficult.Other GL based classes could adopt the same approach,
ofFbo,ofShader,ofVbo,ofBufferObject,ofCubeMap,ofShadow, etc.The goal being to transition away from GL dependent code while also supporting as many current code bases as possible.
Curious what the community thinks about approaches that allow for the inclusion of non-GL renderers.
All reactions