View Issue Details

IDProjectCategoryView StatusLast Update
0027543CommunityOCCT:Samplespublic2016-12-09 16:39
ReporterTimo Assigned Tobugmaster  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
PlatformWindowsOSVC++ 2010 
Product Version6.7.1 
Target Version7.1.0Fixed in Version7.1.0 
Summary0027543: Samples - flickering when view is resized in MFC samples
DescriptionWhen using the MFC samples, e.g. Viewer3d, there is a flickering when the view is resized.
When using Draw, there is no flickering.

The flickering looks as if the scene is first cleared in White and then drawn again in dark grey.

The Problem occurs in all OCC versions (I didn't try earlier than 6.7.1).

I don't know if this has to be so or if it is a problem of my graphics card.

OpenGL info:
  GLvendor    = 'ATI Technologies Inc.'
  GLdevice    = 'ATI FirePro V5800 (FireGL) Graphics Adapter'
  GLversion   = '4.5.13399 Compatibility Profile Context FireGL 15.200.1062.1004'
  GLSLversion = '4.40'
Steps To ReproduceStart Viewer3d MFC sample and resize the view / window.
TagsNo tags attached.
Test case number

Relationships

related to 0027736 closedbugmaster Open CASCADE Samples - rectangle selection issues within MFC sample Viewer3d 

Activities

kgv

2016-06-15 13:56

developer   ~0055005

> When using the MFC samples, e.g. Viewer3d, there is a flickering when the view is resized.
> When using Draw, there is no flickering.
In this case, I suppose this should be considered as issue of samples (there is dedicated category), not Viewer3d (which does nothing more than redrawing view on resize).

git

2016-07-30 19:08

administrator   ~0056309

Branch CR27543 has been created by kgv.

SHA-1: 64ddee758820bfbfb47752aad6b759538033023f


Detailed log of new commits:

Author: kgv
Date: Sat Jul 30 19:07:34 2016 +0300

    0027543: Samples - flickering when view is resized in MFC samples
    
    Define proper window class for OpenGL window within
    overridden method CView::PreCreateWindow().

kgv

2016-07-30 19:08

developer   ~0056310

Patch is ready for review.

san

2016-08-01 12:26

developer   ~0056327

Branch CR27543 reviewed without remarks, please test MFC samples.

bugmaster

2016-08-02 12:31

administrator   ~0056369

Last edited: 2016-08-02 12:42

Viewer3d
Flickering during resize of the shape does not observed.
But behavior of rectangle selection regarding others samples is very inarticulate and flickering is present.

kgv

2016-08-02 12:42

developer   ~0056370

Last edited: 2016-08-02 12:43

Please provide more details - which MFC samples exactly suffers from issue / and is it regression or not.
As far as I can see, not all MFC samples have been updated to use AIS_RubberBand in scope of 0025338.
But I suppose this is dedicated issue anyway.

bugmaster

2016-08-02 13:03

administrator   ~0056375

I speak about sample Viewer3d only. And it is not regression.
But from my point of view for this sample such behavior is unacceptableÑŽ

kgv

2016-08-02 13:07

developer   ~0056377

Viewer3d does not use OCC_BaseView::drawRectangle().
We should register dedicated bug for fixing rubber-band issue.

git

2016-08-26 16:25

administrator   ~0057181

Branch CR27543 has been deleted by inv.

SHA-1: 64ddee758820bfbfb47752aad6b759538033023f

Timo

2016-11-17 13:33

developer   ~0060491

I tested it with 7.1.0 beta. It works well.

Could you still explain a bit what was the reason for this behaviour and how you solved it as we experience similar effects in our Delphi application using OCC via CSharp-wrapper.

kgv

2016-11-17 13:53

developer   ~0060493

Last edited: 2016-11-17 13:58

The patch specifies parameters for defining window class:
cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);

Before the patch, window class with default parameters has been created implicitly by MFC, which are suboptimal for creating OpenGL context.

The flags CS_HREDRAW and CS_VREDRAW requires that window content should be redrawn during window resize (e.g. to generate WM_PAINT event on resize or something like that).

The flag CS_OWNDC specifies that window should have own unique device context - without this flag system can use the same context for several windows at ones, so that reducing memory usage. Since Vista+ the behavior has been changed (since window composition is performed independently for each window), but this flag still has some effect. So, for OpenGL it is still preferred to set this flag.

In C#/WinForms window class parameters can be specified by sub-classing UserControl and overriding method ::CreateParams():
  //! Define the WinForms control for using as OpenGL window for OCCT 3D Viewer.
  public partial class OpenGl_ViewControl : UserControl
  {
    public OpenGl_ViewControl()
    {
      if (DesignMode) return; // avoid calling native code within Designer

      SetStyle (ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
      SetStyle (ControlStyles.OptimizedDoubleBuffer, false);
      InitializeComponent();
    }

    //! Request own device context.
    protected override CreateParams CreateParams
    {
      get
      {
        if (DesignMode) return base.CreateParams;

        const int VREDRAW = 0x00000001;
        const int HREDRAW = 0x00000002;
        const int OWNDC   = 0x00000020;
        CreateParams aParams = base.CreateParams;
        aParams.ClassStyle |= VREDRAW | HREDRAW | OWNDC;
        return aParams;
      }
    }


You can search web for discussions about WinAPI window class parameters for OpenGL windows for more details.

Timo

2016-11-18 17:02

developer   ~0060557

I'm unsure whether CS_HREDRAW and CS_VREDRAW are really necessary.

If CS_HREDRAW and CS_VREDRAW are defined, always a resize and a paint message are created when the window is resized and in the paint event handler you can redraw the view.

If they are not defined, only a resize message is created.
But if you call view.MustBeResized(); in the resize event handler, then it also redraws the view and then CS_HREDRAW and CS_VREDRAW wouldn't be necessary.

But maybe it is more safe to always create a paint message if the view is resized.


In Delphi, you can change the window class style by overriding the CreateParams method:

procedure TOCCPanel.CreateParams(var Params: TCreateParams);
begin
  inherited;

  Params.WindowClass.style := Params.WindowClass.style or CS_HREDRAW or CS_VREDRAW or CS_OWNDC;
end;

In our application, there was another reason for the flickering:
We used a panel for drawing the OpenGL view and there were other controls on top of this panel. When the window was resized all the controls were realigned which caused the background of the panel to be drawn. The drawing of the background is now avoided by:

procedure TOCCPanel.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  message.Result:=-1;
end;

Related Changesets

occt: master d01ed5fd

2016-07-30 16:07:34

kgv


Committer: bugmaster Details Diff
0027543: Samples - flickering when view is resized in MFC samples

Define proper window class for OpenGL window within
overridden method CView::PreCreateWindow().
Affected Issues
0027543
mod - samples/mfc/standard/01_Geometry/src/GeometryView2D.cpp Diff File
mod - samples/mfc/standard/04_Viewer3d/src/Viewer3dView.cpp Diff File
mod - samples/mfc/standard/04_Viewer3d/src/Viewer3dView.h Diff File
mod - samples/mfc/standard/09_Animation/src/AnimationView3D.cpp Diff File
mod - samples/mfc/standard/10_Convert/src/WNT/OCCDemoView.cpp Diff File
mod - samples/mfc/standard/Common/OCC_2dView.cpp Diff File
mod - samples/mfc/standard/Common/OCC_3dView.cpp Diff File
mod - samples/mfc/standard/Common/Primitive/Sample2D_Text.cpp Diff File

Issue History

Date Modified Username Field Change
2016-05-26 12:57 Timo New Issue
2016-05-26 12:57 Timo Assigned To => kgv
2016-06-15 13:56 kgv Note Added: 0055005
2016-06-15 13:56 kgv Category OCCT:Visualization => OCCT:Samples
2016-06-15 13:56 kgv Summary Flickering when view is resized => Samples - flickering when view is resized
2016-06-15 13:56 kgv Description Updated
2016-07-30 19:06 kgv Summary Samples - flickering when view is resized => Samples - flickering when view is resized in MFC samples
2016-07-30 19:08 git Note Added: 0056309
2016-07-30 19:08 kgv Note Added: 0056310
2016-07-30 19:08 kgv Assigned To kgv => san
2016-07-30 19:08 kgv Status new => resolved
2016-08-01 12:26 san Note Added: 0056327
2016-08-01 12:26 san Assigned To san => bugmaster
2016-08-01 12:26 san Status resolved => reviewed
2016-08-02 12:31 bugmaster Note Added: 0056369
2016-08-02 12:31 bugmaster Assigned To bugmaster => kgv
2016-08-02 12:31 bugmaster Status reviewed => feedback
2016-08-02 12:38 bugmaster Note Edited: 0056369
2016-08-02 12:42 bugmaster Note Edited: 0056369
2016-08-02 12:42 kgv Note Added: 0056370
2016-08-02 12:42 kgv Assigned To kgv => bugmaster
2016-08-02 12:43 kgv Note Edited: 0056370
2016-08-02 13:03 bugmaster Note Added: 0056375
2016-08-02 13:07 kgv Note Added: 0056377
2016-08-02 13:45 bugmaster Status feedback => tested
2016-08-02 14:45 kgv Relationship added related to 0027736
2016-08-05 13:30 bugmaster Changeset attached => occt master d01ed5fd
2016-08-05 13:30 bugmaster Status tested => verified
2016-08-05 13:30 bugmaster Resolution open => fixed
2016-08-26 16:25 git Note Added: 0057181
2016-11-17 13:33 Timo Note Added: 0060491
2016-11-17 13:53 kgv Note Added: 0060493
2016-11-17 13:54 kgv Note Edited: 0060493
2016-11-17 13:56 kgv Note Edited: 0060493
2016-11-17 13:58 kgv Note Edited: 0060493
2016-11-18 17:02 Timo Note Added: 0060557
2016-12-09 16:30 aiv Status verified => closed
2016-12-09 16:39 aiv Fixed in Version => 7.1.0