cbecker's picture

GLES error with latest OpenTK version

Hello, in this post I want to summarize some problems and possible solutions that we found when trying to build a simple OpenTK GLES app and run it.
I haven't tried previous versions of OpenTK, so maybe this problem was introduced in a recent changeset. This is basically the same problem in post http://www.opentk.com/node/2448, but I preferred to open a new topic since now the problem is clearer and the other topic was getting unclear now.

The first thing is that, even though GLES is detected and requested, OpenTK still wants to use libGL for some operations. This was fixed by adding the following to EGLX11PlatformFactory.cs:

        public override IGraphicsMode CreateGraphicsMode()
        {
            return new EglGraphicsMode();
        }

which just overrides the default method in X11Factory so that the correct graphics mode is chosen.
Running our simple example with this patch would go further but then crash when calling XGetVisualInfo() in X11GLNative.cs, in line 141. The problem here seems to be the mask XVisualInfoMask.ID. According to https://wiki.edubuntu.org/ARM/TEGRA/AC100, "The native visual ID for all EGL fbconfigs seems to be returned as 0" so the workaround would be to use XVisualInfoMask.No to call XGetVisualInfo(). However, I am not sure about how correct this is. So far this is what the line looks like with the .No mask:

window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
                    Functions.XGetVisualInfo(window.Display, XVisualInfoMask.No, ref info, out dummy), typeof(XVisualInfo));

Patching OpenTK with the modifications above makes our example work in the simulator (GLES on Ubuntu PC), but it crashes when executing it in the embedded system:

Unhandled Exception: OpenTK.Graphics.GraphicsContextException: Failed to initialize EGL, error 12296.
  at OpenTK.Platform.Egl.EglContext..ctor (OpenTK.Graphics.GraphicsMode mode, OpenTK.Platform.Egl.EglWindowInfo window, IGraphicsContext sharedContext, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0
  at OpenTK.Platform.Egl.EglX11PlatformFactory.CreateGLContext (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, Boolean directRendering, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0
  at OpenTK.Graphics.GraphicsContext..ctor (OpenTK.Graphics.GraphicsMode mode, IWindowInfo window, Int32 major, Int32 minor, GraphicsContextFlags flags) [0x00000] in <filename unknown>:0
  at OpenTK.GameWindow..ctor (Int32 width, Int32 height, OpenTK.Graphics.GraphicsMode mode, System.String title, GameWindowFlags options, OpenTK.DisplayDevice device, Int32 major, Int32 minor, GraphicsContextFlags flags, IGraphicsContext sharedContext) [0x00000] in <filename unknown>:0

Error 12296 is EGL BAD DISPLAY: "An EGLDisplay argument does not name a valid EGLDisplay; or, EGL is not initialized on the specified EGLDisplay", according to the GLES specs. From this point on it is not clear for me to know what to do. Does anyone has OpenTK currently working in an embedded, pure-GLES + X11 system? If so, is it the last version that is working or an older one?
I would like to keep working on the topic, so any suggestions are welcomed.

Thanks!


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cbecker's picture

We were able to make OpenTK work with our embedded platform. The necessary changes can be seen here (diff) https://bitbucket.org/alito/opentk-omap3530/changeset/1e5d8c42f780
As you may notice, some of them only make sure that certain conditions are being met, while others imply an important change.

Is there anyone else working with OpenTK in an embedded environment with GLES2 right now, with the latest version of OpenTK?