Skip to content

Sync issues and artifacts when redrawing on layout change #171

@sigmasaur

Description

@sigmasaur

I apologize if this is not the right place to report this. I'm developing a small WPF application that needs to draw some complex 2D graphics, for which I would like to use a modified version of SkiaSharp's SKGLElement which is based on GLWpfControl. I plan to have a single instance of GLWpfControl via SKGLElement so I can draw everything on that surface. The UI should be responsive so the GLWpfControl should redraw its contents every time one of the placeholder windows is moved or resized. In the following example code, I removed all references to SkiaSharp to demonstrate that the issue can be traced back to GLWpfControl:

MainWindow.xaml:

<Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Test"
        xmlns:tk="clr-namespace:OpenTK.Wpf;assembly=GLWpfControl"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Canvas IsHitTestVisible="False">
            <tk:GLWpfControl x:Name="MyElement" Loaded="MyElement_Loaded" Render="MyElement_Render"/>
        </Canvas>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <!-- placeholder window -->
            <Canvas Background="Transparent" Name="MyCanvas" Grid.Column="0" SizeChanged="MyCanvas_SizeChanged"/>
            <GridSplitter Background="DarkGray" Grid.Column="1" Width="30" HorizontalAlignment="Stretch"/>
        </Grid>
    </Grid>
</Window>

MainWindow.xaml.cs:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void MyCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        MyElement.InvalidateVisual();
    }

    private void MyElement_Loaded(object sender, RoutedEventArgs e)
    {
        MyElement.Width = SystemParameters.WorkArea.Width;
        MyElement.Height = SystemParameters.WorkArea.Height;

        MyElement.Start(new GLWpfControlSettings()
        {
            MajorVersion = 2,
            MinorVersion = 1,
        });
    }

    private void MyElement_Render(TimeSpan obj)
    {
        GL.ClearColor(System.Drawing.Color.White);
        GL.Clear(ClearBufferMask.ColorBufferBit);

        GL.Color3(System.Drawing.Color.Red);
        Point p = MyCanvas.TranslatePoint(new Point(0, 0), this);
        GL.Rect(
            +2 * (p.X / MyElement.Width - 0.5),
            -2 * ((p.Y + MyCanvas.ActualHeight) / MyElement.Height - 0.5),
            +2 * ((p.X + MyCanvas.ActualWidth) / MyElement.Width - 0.5),
            -2 * (p.Y / MyElement.Height - 0.5)
        );
    }
}

In the above code, I expected the red portion to fully cover the left part of the screen at all times. However, if I drag the GridSplitter left and right across the screen, I can see some artifacts near the GridSplitter that become more noticeable the faster I drag it:

I tested this on two other machines and the issue does not arise on one of them so it's definitely machine-dependent. Is this expected behavior? I'm using version 4.3.4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions