Is it possible to use OpenGL ES code with a WPF application through D3DImage and ANGLE?

Summary (TL: DR version)

Ultimately, our goal is to use the OpenGL ES code in the WPF application initially (i.e. not SharpGL, etc.) and without problems with Airspace or drivers, possibly using the Google ANGLE project.

Background:

One of the things I like about OpenGL over DirectX is the cross-platform feature. It has excellent support for both OS X and Linux, as well as Android and iOS via ES. However, on Windows, its use is overshadowed by problems with drivers or, even worse, many cards simply do not implement it properly.

Log in to the ANGLE project or the “Stand Alone Graphical Interface” project .

ANGLE is an OpenGL ES 2.0 shell around the Direct3D implementation, that is, you can write OpenGL ES 2.0 code to run on Windows without the need for real OpenGL drivers. Not only does it pass ES compatibility tests, but it’s actually how Chrome does all its graphical rendering, including WebGL, so it is definitely a proven technology.

Question:

, WPF D3DImage, Direct3D WPF, , WPF. , ANGLE Direct3D, D3DImage - Direct3D, , OpenGL ES WPF Windows,

" " .

, ANGLE, D3D, D3DImage, ANGLE . , . , , .

, , , OpenGL ( ES) WPF OpenGL. ANGLE/D3DImage - ... . "", , , . , , .

+4
1

github, , OpenGL WPF OpenTK.GLControl.

:

  • WindowsFormsHost WPF
  • OpenTK.GLControl WindowsFormsHost
    • Pass GraphicsContextFlags.Default OpenGL
    • GraphicsContextFlags.Embedded OpenGL ES (ANGLE)
  • Render OpenGL OpenGL ES

: OpenTK OpenTK.GLControl NuGet. ANGLE.

, WindowsFormsHost . , . .

// This code is public domain
#define USE_ANGLE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using OpenTK;
using OpenTK.Graphics;

#if USE_ANGLE
using OpenTK.Graphics.ES20;
#else
using OpenTK.Graphics.OpenGL;
#endif

namespace WPF.Angle
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        GLControl glControl;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void WindowsFormsHost_Initialized(object sender, EventArgs e)
        {
            var flags = GraphicsContextFlags.Default;
#if USE_ANGLE
            flags = GraphicsContextFlags.Embedded;
#endif
            glControl = new GLControl(new GraphicsMode(32, 24), 2, 0, flags);
            glControl.MakeCurrent();
            glControl.Paint += GLControl_Paint;
            glControl.Dock = DockStyle.Fill;
            (sender as WindowsFormsHost).Child = glControl;
        }

        private void GLControl_Paint(object sender, PaintEventArgs e)
        {
            GL.ClearColor(
                (float)Red.Value,
                (float)Green.Value,
                (float)Blue.Value,
                1);
            GL.Clear(
                ClearBufferMask.ColorBufferBit |
                ClearBufferMask.DepthBufferBit |
                ClearBufferMask.StencilBufferBit);

            glControl.SwapBuffers();
        }

        private void Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            glControl.Invalidate();
        }
    }
}
+2

All Articles