Closed tumblingstuff closed 6 years ago
You are required to update controls using a timer. GLcontrol implementation already provide this in Animation properties.
Running one with the animation timer while loading a 3D texture into the second results in an "invalid operation" failure of the second. And even without the timer updating the first, I still get occasional failures. I'm at the point of looking for other C#/OpenGL interfaces, which stinks because yours is the 3rd I've tried... 3D textures (volume rendering) aren't supported by most of them (for example, OpenTK).
I'm going to try overriding the OnPaint calls, setting a flag for timer updates, and see if I can improve matters.
Does .Refresh work better than .Invalidate (which I've been using so far) for the GlControls?
Sorry if I sound grumpy - I'm learning OpenGL at the same time, and while I've (finally) worked through the functionality I need these last bugs are preventing project completion.
Sigh - overrode OnPaint for the UserControl wrapping the GlControls, just setting a flag for update picked up by a timer and calling .Refresh on the control. The two GlControls are still trashing each other, whether animated or not.
It's nice framework, but this bug is a project killer for me. Now looking for alternative bindings...
You must be sure to have the correct GL context current, otherwise state and objects are mixed up.
Despite it seems related to the project, the problem you're facing is caused by how GL is designed, and how GL relates with the underlying windowing system.
Even if you try to change bindings, you will end up to the same conclusion.
Little tip.
If you need two widgets for splitting vertically a view, you should use a single control and use glViewport to manage updated areas.
Where/how can I make the context current? I've looked for but not found a .MakeCurrent function...
The project I'm working on requires a 3D volumetric view and a 'terrain' plot of a single slice, in two windows.
Or rather, two panes or usercontrols on the main form.
Scratch that, just found .MakeCurrentContext - now to figure out (a) how to determine the context of the current control/window, and (b) properly set context.
...And MakeCurrentContext, while visible in the Object browser, isn't exposed when coding. Hmm. I've tried obtaining the .BindingContext on context creation, and setting the bindingcontext in my locking mutex, no success.
How do I make the context for a GlControl current?
Isn't this template working for you?
Let me dig into that - I had the impression the sample was for sharing a single context in multiple views, rather than two separate scenes/viewers.
How do I make the context for a GlControl current?
Cache the RenderContext field of the argument of the GlControl.ContextCreated event.
Then you can call GlControl.Device.MakeCurrent(cachedRenderContext)
; Or just inherith from GlControl, and call MakeCurrentContext()
.
At the moment _RenderContext protected field is not exposed as public API. Or just checkout the project and modify for your needs. The code is not complicated as it seems.
That looks like it's eliminated the errors - thanks, and thanks for putting up with an OpenGL novice. Now, just a bit more cleanup on my LUT transfer functions, and I should be good to go...
Did you ever come up with a solution to this? My application requires two contexts in a single form, and I keep getting failures when both contexts are updated - whether trying to update one while the other is animated (always), or even just occasionally. I've tried blocking so that only one context is sending Gl commands at a time with a mutex - no luck.