dwmkerr / sharpgl

Use OpenGL in .NET applications. SharpGL wraps all modern OpenGL features and offers a powerful scene graph to aid development.
MIT License
755 stars 299 forks source link

Multiple OpenGLControl on the same form #117

Open davidedec opened 8 years ago

davidedec commented 8 years ago

Hi. I found an issue when we have multiple OpenGLControl on the same form, but I think generally on the same thread. I can see that the situation is already handled within the PreGLCall, that does the MakeCurrent in case it is needed. The problem I have, with FBO RenderContext, is that when the control is resized (OnSizeChanged) strange things happens. For example the area is clipped and not all the area is usable.

I think the problem is that in the OnSizeChanged there is an OpenGL.SetDimensions called before any MakeCurrent. I tried to MakeCurrent before it and everything works.

Hope to be helpful. Davide

ChrisFof commented 8 years ago

Hi Davide, could you, please post your code modifications? running into the same issue here.

Regards, Chris

Yaazarai commented 8 years ago

I found this issue as well--application always crashes when I attempt to use more than one OpenGL control. Happens on WPF, not sure about WinForms.

Stone1974 commented 8 years ago

Have the same issue here - does anybody have a solution / code for this?

These a four SharpGL-controls in the mainwindow. Each control should exactly show the same model...: bug

bitzhuwei commented 8 years ago

I run into this problem too. It's difficult to solve this. Try to use glViewportArrayv(GLuint first, GLsizei count, const GLfloat * v); to avoid this problem.

weelihl commented 6 years ago

I have an application that has two OpenGLControls on the same winform. where I call updatedata1(), draw1(), updatedata2(), draw2() to render the real-time charts. Despite synchronous calls, there is a leak from openGlcontrol1 to openGLcontrol2.

After some investigations, I found out that the leak occurs during the VAO, VBO and VIO binding and the reason behind is that there is no PreGLCall() to make context current (or upload data to the correct context) when calling gl.BindBuffer(). To solve the issue, you may want to insert the following code in bind() method of vertexbufferarray, vertexbuffer, indexbuffer class.

        public void Bind(OpenGL gl)
        {
            if (Win32.wglGetCurrentContext() != gl.RenderContextProvider.RenderContextHandle)
                gl.MakeCurrent();
            gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexBufferObject);
        }

Note that the operation of switching render context is expensive, so we call gl.MakeCurrent() sparingly.