private void OnCompTargetRender(object sender, EventArgs e)
        {
            if (_context == null || _renderer == null)
            {
                return;
            }
            if (!ReferenceEquals(GraphicsContext.CurrentContext, _context))
            {
                _context?.MakeCurrent(_windowInfo);
            }
            if (_resizeStartStamp != 0)
            {
                if (_resizeStartStamp + ResizeUpdateInterval > _stopwatch.ElapsedMilliseconds)
                {
                    return;
                }
                _renderer?.DeleteBuffers();
                var width  = (int)RenderSize.Width;
                var height = (int)RenderSize.Height;
                _renderer         = new GLWpfControlRenderer(width, height, _image, _settings.UseHardwareRender, _settings.PixelBufferObjectCount);
                _resizeStartStamp = 0;
            }


            GL.BindFramebuffer(FramebufferTarget.Framebuffer, FrameBuffer);

            TimeSpan deltaTime = _stopwatch.Elapsed - _lastFrameStamp;

            Render?.Invoke(deltaTime);

            _renderer.UpdateImage();
            InvalidateVisual();
            _lastFrameStamp = _stopwatch.Elapsed;
        }
Exemplo n.º 2
0
        private void InitOpenGL()
        {
            var mode = new GraphicsMode(ColorFormat.Empty, 0, 0, 0, 0, 0, false);

            _context = new GraphicsContext(mode, _windowInfo, _settings.MajorVersion, _settings.MinorVersion, _settings.GraphicsContextFlags);
            _context.LoadAll();
            _context.MakeCurrent(_windowInfo);
            var width  = (int)RenderSize.Width;
            var height = (int)RenderSize.Height;

            _renderer = new GLWpfControlRenderer(width, height, _image, _settings.UseHardwareRender, _settings.PixelBufferObjectCount);
        }
        private void OnLoaded(object sender, RoutedEventArgs args)
        {
            if (_context != null)
            {
                return;
            }
            if (_settings.ContextToUse == null)
            {
                var window     = Window.GetWindow(this);
                var baseHandle = window is null ? IntPtr.Zero : new WindowInteropHelper(window).Handle;
                _hwnd       = new HwndSource(0, 0, 0, 0, 0, "GLWpfControl", baseHandle);
                _windowInfo = Utilities.CreateWindowsWindowInfo(_hwnd.Handle);

                var mode = new GraphicsMode(ColorFormat.Empty, 0, 0, 0, 0, 0, false);
                _context = new GraphicsContext(mode, _windowInfo, _settings.MajorVersion, _settings.MinorVersion,
                                               _settings.GraphicsContextFlags);
                _context.LoadAll();
                _context.MakeCurrent(_windowInfo);
            }
            else
            {
                _context = _settings.ContextToUse;
            }

            if (_renderer == null)
            {
                var width  = (int)RenderSize.Width;
                var height = (int)RenderSize.Height;
                _renderer = new GLWpfControlRenderer(width, height, _image, _settings.UseHardwareRender, _settings.PixelBufferObjectCount);
            }

            _imageRectangle     = new Rect(0, 0, RenderSize.Width, RenderSize.Height);
            _translateTransform = new TranslateTransform(0, RenderSize.Height);

            GL.Viewport(0, 0, (int)RenderSize.Width, (int)RenderSize.Height);
            Ready?.Invoke();
        }