I have a few questions in general, and about everyone's favorite: Threads. :D
I have a system with 4 threads (Grapferuit JUCE):
- Message (of course)
- GL (with it's ThreadPool mechanism)
Now I run Processing at 60 FPS, and the Consumer thread waits. When a Processing cycle finishes, it ends up with a buffer of ints. I use double buffering, so swap them, wake up Consumer, and start the next Processing cycle. It works nicely. (Now I've just had the idea to change the Consumer stuff to a ThreadPool with a copy of the buffer, because consuming large buffers may takes more time than processing, and switching buffers too early leads to another problem. :D)
So the first question is about the GL stuff. I have different Objects, and they 'live' in the Processor. Some of them are Renderable, others are not. The problem is I can't render stuff based on the raw buffer data, but I'd like to let the renderable Object draw itself, when Processing is ready. It's a problem because the most important thing is to Process (create) and Consume (send) the data, GL is only for a visual feedback about what the user is actually doing. So I really don't want to wait with the processing until rendering finishes, but this way the next processing cycle changes my Objects during GL rendering. And it results visual glitches (first half of my Objects render their newly processed state, the other half renders their previous state.
Do you have any idea how to solve this? I was thinking about some caching mechanism, but it means I have to double all GL-related parameters, isn't it? These parameters usually really simple stuff (position, color, size, etc), but this kind of caching looks like a noobish way. :D
And now the other problem. As I wrote, I have objects, and all of them are subclasses of (let's say) Object. To let JUCE manage their lifetime, Object is subclass of ReferenceCountedObject, and all the Objects are sitting in a ReferenceCountedArray<Object> in Process. But some of them are Renderable also (with a virtual render() method). Renderable is also a ReferenceCountedObject, and all renderables are sitting in the GLComponent's ReferenceCountedArray<Renderable>. Ande here comes the problem, the compiler doesn't really like that eg. MyCustomRenderableObject inherits twice from a ReferenceCountedObject. (class MyCustomRenderableObject : public Object, public Renderable). What is the righta pproach in this situation? Maybe I overuse this refcount stuff? :)
As I see, for example Component is not ReferenceCountedObject (as I thought), and it holds it's child Components in a ScopedPointer<Array<Component*>>. Is it safe to use it this way? JUCE says to avoid raw pointers as much as possible. I'm confused...
Thank you for any replies!