Unable to use two GlControls in the same form
See original GitHub issueStep to reproduce:
- Open HelloTriangle Project
- Open SampleForm
- Select RenderControl, set Dock to None
- Copy and paste GlControl somewhere else in Form
- Build and Run
On my system the original control is solid white and the second one is black. Nothing else is shown. Property ContextSharing
is set to OwnContext
for both controls.
I was not able to find what is causing the issue in the code. Here is what I have found:
- Setting the Animation to false for the second control fix the issue
- Resizing the window to mask the second control and show only the first one fix the issue!!
- Turning off animation for both controls and adding a timer that invalidates both controls works
A possible cause is the Invalidate you use inside OnPaint() to animate.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Two submit buttons in one form
The best way to deal with multiple submit buttons is using a switch case in the server script <form action="demo_form.php" method="get"> ...
Read more >Is it possible to have two buttons with the same ID? - Discussion
I am wondering is it possible to have the same button on a form but in two different locations? I want to have...
Read more >Why can't I select form and ActiveX controls?
For a Form control, click the control and make sure that the control border is displayed. Control border. For an ActiveX control: If...
Read more >Can not move my buttons in forms - Microsoft Q&A
i am learning C# and i got to microsoft forms. so in my book it tells me to create a "TabControl" and add...
Read more >Power App Mutli Screen Form Controls - YouTube
PowerApps #PowerAppsForms In this video I show how you can break out a form control over multiple screens. This helps provide a better...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Each
GlControl
creates its own GL context by default. The function pointers relative to the underlying context may depends on the device context which the GL context is bound to. I say “may” because this is a Windows specific issue: if the two GL contexts are bound to different device contexts, they can share GL function pointers only if all device contexts have the same pixel format set; in the other case, function pointers must be reloaded.Being said this, OpenGL.Net ignore the pixel format set on the
GlControl
instances; this means thatDeviceContext.MakeCurrent
will reload all function pointers anyway, causing sensible delays, each time a differentGlControl
is updated. With a singleGlControl
instance, a single GL context is current on the thread.DeviceContext.MakeCurrent
optimize this case, avoiding function pointers reloading if the GL context made current does not change. Remember that GL function pointer have are scoped to TLS.Indeed, having more than one
GlControl
instance cause updating all those, and because they have different device contexts, function pointers are continuously reloaded. This is noticeable applying animation to twoGlControl
instances and apply the patch of the previous post: animations are no more fluid as the simple example HelloTriangle.I’ve not profiled it, but I bet that
Gl.BindAPI()
is the bottleneck: it uses reflection to query and set function pointers. Maybe it could be optimized by emitting optimized methods.Indeed my experiments lead to some awkward conclusion:
Invalidate(
) executed byOnPaint()
causes a synchronous refresh of theUserControl
, leading to other control to the previous contents. Calling Invalidate() on other contexts (i.e. in a timer callback) works correctly.Invalidate()
invokesUnsafeNativeMethods.InvalidateRect
, which points to WIN32 InvalidateRect; the man says:I wonder why the message is processed “immediately”. If the Animation property is set on the last GlControl within the form, both controls can be redrawn, with a resize operation, while animating; but invalidating the first controls will lead to the same behavior (only the invalidated control will be redrawn).
I tried to invoke asynchronously
Invalidate()
usingBeginInvoke
without luck. At the moment I’m out of ideas.