Ejemplo n.º 1
0
        /// <summary>
        /// Set the device pixel format.
        /// </summary>
        /// <param name="pixelFormat">
        /// A <see cref="DevicePixelFormat"/> that specifies the pixel format to set.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="pixelFormat"/> is null.
        /// </exception>
        public override void SetPixelFormat(DevicePixelFormat pixelFormat)
        {
            if (pixelFormat == null)
            {
                throw new ArgumentNullException("pixelFormat");
            }

            List <int> configAttribs = new List <int>();

            if (Version >= Egl.Version_120)
            {
                configAttribs.AddRange(new int[] { Egl.RENDERABLE_TYPE, Egl.OPENGL_ES2_BIT });
            }
            configAttribs.AddRange(new int[] {
                Egl.CONFIG_ID, pixelFormat.FormatIndex,
            });
            configAttribs.Add(Egl.NONE);

            int[]    configCount = new int[1];
            IntPtr[] configs     = new IntPtr[1];

            if (Egl.ChooseConfig(_Display, configAttribs.ToArray(), configs, 1, configCount) == false)
            {
                throw new InvalidOperationException("unable to choose configuration");
            }
            if (configCount[0] == 0)
            {
                throw new InvalidOperationException("no available configuration");
            }

            IntPtr config = configs[0];

            _Config = config;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an OpenGL context from a Unix/Linux platform.
        /// </summary>
        /// <returns>
        /// A <see cref="IDeviceContext"/> that specify the device context.
        /// </returns>
        private static IntPtr CreateEglSimpleContext(IDeviceContext rDevice)
        {
            NativeDeviceContext eglDeviceCtx = (NativeDeviceContext)rDevice;
            IntPtr ctx;

            List <int> configAttribs = new List <int>();

            if (eglDeviceCtx.Version >= Egl.Version_120)
            {
                configAttribs.AddRange(new int[] { Egl.RENDERABLE_TYPE, Egl.OPENGL_ES2_BIT });
            }
            configAttribs.AddRange(new int[] {
                Egl.RED_SIZE, 8,
                Egl.GREEN_SIZE, 8,
                Egl.BLUE_SIZE, 8,
            });
            configAttribs.Add(Egl.NONE);

            int[]    configCount = new int[1];
            IntPtr[] configs     = new IntPtr[8];

            if (Egl.BindAPI(Egl.OPENGL_ES_API) == false)
            {
                throw new InvalidOperationException("no ES API");
            }

            if (Egl.ChooseConfig(eglDeviceCtx.Display, configAttribs.ToArray(), configs, configs.Length, configCount) == false)
            {
                throw new InvalidOperationException("unable to choose configuration");
            }
            if (configCount[0] == 0)
            {
                throw new InvalidOperationException("no available configuration");
            }

            List <int> contextAttribs = new List <int>();

            if (eglDeviceCtx.Version >= Egl.Version_130)
            {
                contextAttribs.AddRange(new int[] { Egl.CONTEXT_CLIENT_VERSION, 2 });
            }
            contextAttribs.Add(Egl.NONE);

            if ((ctx = Egl.CreateContext(eglDeviceCtx.Display, configs[configs.Length - 1], IntPtr.Zero, contextAttribs.ToArray())) == IntPtr.Zero)
            {
                throw new InvalidOperationException("unable to create context");
            }

            List <int> surfaceAttribs = new List <int>();

            surfaceAttribs.Add(Egl.NONE);
            // Egl.RENDER_BUFFER, Egl.BACK_BUFFER,

            eglDeviceCtx.Surface = Egl.CreateWindowSurface(eglDeviceCtx.Display, configs[configs.Length - 1], eglDeviceCtx.NativeWindow, surfaceAttribs.ToArray());

            return(ctx);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a simple context.
        /// </summary>
        /// <returns>
        /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be
        /// created, it returns IntPtr.Zero.
        /// </returns>
        internal override IntPtr CreateSimpleContext()
        {
            IntPtr ctx;

            int[]    configAttribs = DefaultConfigAttribs;
            int[]    configCount   = new int[1];
            IntPtr[] configs       = new IntPtr[8];

            if (Egl.ChooseConfig(Display, configAttribs, configs, configs.Length, configCount) == false)
            {
                throw new InvalidOperationException("unable to choose configuration");
            }
            if (configCount[0] == 0)
            {
                throw new InvalidOperationException("no available configuration");
            }

            int[] contextAttribs = DefaultContextAttribs;
            int[] surfaceAttribs = { Egl.NONE };

            if (Version >= Egl.Version_120)
            {
                if (Egl.BindAPI(Egl.OPENGL_ES_API) == false)
                {
                    throw new InvalidOperationException("no ES API");
                }
            }

            if ((ctx = Egl.CreateContext(Display, configs[0], IntPtr.Zero, contextAttribs)) == IntPtr.Zero)
            {
                throw new InvalidOperationException("unable to create context");
            }

            if (_NativeSurface.Handle == IntPtr.Zero)
            {
                List <int> pbufferAttribs = new List <int>(surfaceAttribs);

                pbufferAttribs.RemoveAt(pbufferAttribs.Count - 1);
                pbufferAttribs.AddRange(new[] { Egl.WIDTH, 1, Egl.HEIGHT, 1 });
                pbufferAttribs.Add(Egl.NONE);

                _NativeSurface.CreateHandle(configs[0], pbufferAttribs.ToArray());
            }

            return(ctx);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Set the device pixel format.
        /// </summary>
        /// <param name="pixelFormat">
        /// A <see cref="DevicePixelFormat"/> that specifies the pixel format to set.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Exception thrown if <paramref name="pixelFormat"/> is null.
        /// </exception>
        public override void SetPixelFormat(DevicePixelFormat pixelFormat)
        {
            if (pixelFormat == null)
            {
                throw new ArgumentNullException(nameof(pixelFormat));
            }
            if (_NativeSurface == null)
            {
                return;                 // Support EGL_KHR_surfaceless_context
            }
            if (_NativeSurface.Handle != IntPtr.Zero)
            {
                throw new InvalidOperationException("pixel format already set");
            }

            List <int> configAttribs = new List <int>();

            if (Version >= Egl.Version_120)
            {
                configAttribs.AddRange(new[] { Egl.RENDERABLE_TYPE, Egl.OPENGL_ES2_BIT });
            }
            configAttribs.AddRange(new[] {
                Egl.CONFIG_ID, pixelFormat.FormatIndex
            });
            configAttribs.Add(Egl.NONE);

            int[]    configCount = new int[1];
            IntPtr[] configs     = new IntPtr[1];

            if (Egl.ChooseConfig(Display, configAttribs.ToArray(), configs, 1, configCount) == false)
            {
                throw new InvalidOperationException("unable to choose configuration");
            }
            if (configCount[0] == 0)
            {
                throw new InvalidOperationException("no available configuration");
            }

            _Config = configs[0];

            IsPixelFormatSet = true;
        }
Ejemplo n.º 5
0
        private static IntPtr ChoosePixelFormat(IntPtr display, int configId)
        {
            List <int> configAttribs = new List <int>();

            int[]    configCount = new int[1];
            IntPtr[] configs     = new IntPtr[8];

            configAttribs.AddRange(new[] { Egl.CONFIG_ID, configId });
            configAttribs.Add(Egl.NONE);

            if (Egl.ChooseConfig(display, configAttribs.ToArray(), configs, configs.Length, configCount) == false)
            {
                throw new InvalidOperationException("unable to choose configuration");
            }
            if (configCount[0] == 0)
            {
                throw new InvalidOperationException("no available configuration");
            }

            return(configs[0]);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Set the device pixel format.
        /// </summary>
        /// <param name="pixelFormat">
        /// A <see cref="DevicePixelFormat"/> that specifies the pixel format to set.
        /// </param>
        private static IntPtr ChoosePixelFormat(IntPtr display, KhronosVersion version, DevicePixelFormat pixelFormat)
        {
            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }
            if (pixelFormat == null)
            {
                throw new ArgumentNullException(nameof(pixelFormat));
            }

            List <int> configAttribs = new List <int>();

            int[]    configCount = new int[1];
            IntPtr[] configs     = new IntPtr[8];
            int      surfaceType = 0;

            if (version >= Egl.Version_120)
            {
                configAttribs.AddRange(new[] { Egl.RENDERABLE_TYPE, Egl.OPENGL_ES2_BIT });
            }

            if (pixelFormat.RenderWindow)
            {
                surfaceType |= Egl.WINDOW_BIT;
            }
            if (pixelFormat.RenderPBuffer)
            {
                surfaceType |= Egl.PBUFFER_BIT;
            }
            if (surfaceType != 0)
            {
                configAttribs.AddRange(new[] { Egl.SURFACE_TYPE, surfaceType });
            }

            switch (pixelFormat.ColorBits)
            {
            case 24:
                configAttribs.AddRange(new[] { Egl.RED_SIZE, 8, Egl.GREEN_SIZE, 8, Egl.BLUE_SIZE, 8 });
                break;

            case 32:
                configAttribs.AddRange(new[] { Egl.RED_SIZE, 8, Egl.GREEN_SIZE, 8, Egl.BLUE_SIZE, 8, Egl.ALPHA_SIZE, 8 });
                break;

            default:
                configAttribs.AddRange(new[] { Egl.BUFFER_SIZE, pixelFormat.ColorBits });
                break;
            }
            if (pixelFormat.DepthBits > 0)
            {
                configAttribs.AddRange(new[] { Egl.DEPTH_SIZE, pixelFormat.DepthBits });
            }
            if (pixelFormat.StencilBits > 0)
            {
                configAttribs.AddRange(new[] { Egl.STENCIL_SIZE, pixelFormat.StencilBits });
            }

            configAttribs.Add(Egl.NONE);

            if (Egl.ChooseConfig(display, configAttribs.ToArray(), configs, configs.Length, configCount) == false)
            {
                throw new InvalidOperationException("unable to choose configuration");
            }
            if (configCount[0] == 0)
            {
                throw new InvalidOperationException("no available configuration");
            }

            return(configs[0]);
        }