Archived issue #0023028
Visualization, TKOpenGl - eliminate global static variables
Description
Current implementation exploits the fact that only one graphic driver instance can be used in application and a lot of static variables and collections are placed in global scope.
However there are no any protection from creation of multiple instance and in this case behaviour of TKOpenGl module become undefined.
For example shared instance 'Handle(OpenGl_Display) openglDisplay' is nullified on Graphic3d_{WNT}GraphicDevice destruction and means memory corruption if there any other Graphic3d_{WNT}GraphicDevice instance exists and used.
As a side-effect of this problem, currently OpenGl_Window instances are never destroyed, to keep GL rendering contexts for proper GL resource deallocation.
This is suggested either:
- To move all global variables into OpenGl_GraphicDriver definition (user will be responsible for usage of multiple instances / sharing common instance);
- Make OpenGl_GraphicDriver singleton (protect usage of TKOpenGl library in undesigned manner).
However there are no any protection from creation of multiple instance and in this case behaviour of TKOpenGl module become undefined.
For example shared instance 'Handle(OpenGl_Display) openglDisplay' is nullified on Graphic3d_{WNT}GraphicDevice destruction and means memory corruption if there any other Graphic3d_{WNT}GraphicDevice instance exists and used.
As a side-effect of this problem, currently OpenGl_Window instances are never destroyed, to keep GL rendering contexts for proper GL resource deallocation.
This is suggested either:
- To move all global variables into OpenGl_GraphicDriver definition (user will be responsible for usage of multiple instances / sharing common instance);
- Make OpenGl_GraphicDriver singleton (protect usage of TKOpenGl library in undesigned manner).
Steps to reproduce
N/A
Public activity
23 archived notes
Participants are labeled by their role within this record.
Notice there also regression related to this bug introduced by #0022819 patch:
OpenGl_telem_view.cxx, line 71
> /* prp between front and back planes */
> if (!openglDisplay.IsNull() || !openglDisplay->Walkthrough())
Wrong condition followed by NULL handle access if shared openglDisplay instance is NULL.
OpenGl_telem_view.cxx, line 71
> /* prp between front and back planes */
> if (!openglDisplay.IsNull() || !openglDisplay->Walkthrough())
Wrong condition followed by NULL handle access if shared openglDisplay instance is NULL.
OpenGl_Display is no more global since #0024228.
However there are still several global variables like
in OpenGl_Workspace::UpdateMaterial().
However there are still several global variables like
static float mAmb[4];
in OpenGl_Workspace::UpdateMaterial().
Remaining artifacts,
in OpenGl_CappingAlgo::RenderCapping():
should be moved outside function body;
in OpenGl_CappingAlgo.hxx:
in OpenGl_AspectFace.cxx:
seems to be constants;
in OpenGl_GraphicDriver_Layer.cxx:
should be removed within #0025789.
in OpenGl_Trihedron.cxx:
should be removed within #0025974.
in OpenGl_Workspace_Raytrace.cxx:
to be moved outside the function body;
in OpenGl_AVIWriter.hxx:
should be removed within #0025382.
in OpenGl_ShaderProgram.hxx:
in OpenGl_CappingAlgo::RenderCapping():
static Handle(OpenGl_CappingAlgoFilter) aCappingFilter
should be moved outside function body;
in OpenGl_CappingAlgo.hxx:
static Handle(OpenGl_RenderFilter) myRenderFilter; static OpenGl_AspectFace myFrontCulling; static OpenGl_AspectFace myNoneCulling; static Standard_Boolean myIsInit;
in OpenGl_AspectFace.cxx:
static OPENGL_SURF_PROP THE_DEFAULT_MATERIAL static TEL_POFFSET_PARAM THE_DEFAULT_POFFSET
seems to be constants;
in OpenGl_GraphicDriver_Layer.cxx:
static Standard_Boolean TheLayerIsOpen = Standard_False; static OpenGl_LAYER_PROP TheLayerProp;
should be removed within #0025789.
in OpenGl_Trihedron.cxx:
static TEL_COLOUR theXColor = {{ 1.F, 0.F, 0.F, 0.6F }};
static TEL_COLOUR theYColor = {{ 0.F, 1.F, 0.F, 0.6F }};
static TEL_COLOUR theZColor = {{ 0.F, 0.F, 1.F, 0.6F }};
static float theRatio = 0.8f;
static float theDiameter = 0.05f;
static int theNbFacettes = 12;
should be removed within #0025974.
in OpenGl_Workspace_Raytrace.cxx:
TCollection_AsciiString OpenGl_Workspace::ShaderSource::Source() const
{
static const TCollection_AsciiString aVersion = "#version 140";
to be moved outside the function body;
in OpenGl_AVIWriter.hxx:
static OpenGl_AVIWriter * MyAVIWriterInstance;
should be removed within #0025382.
in OpenGl_ShaderProgram.hxx:
static OpenGl_VariableSetterSelector mySetterSelector;
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 8 17:28:39 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 8 17:28:39 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Fri Apr 10 13:28:45 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
[revision removed]
Detailed log of new commits:
Author: isk
Date: Fri Apr 10 13:28:45 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Apr 27 16:59:04 2015 +0300
Remove static variables from OpenGl_CappingAlgo
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Apr 27 16:59:04 2015 +0300
Remove static variables from OpenGl_CappingAlgo
- static Handle(OpenGl_CappingAlgoFilter) aCappingFilter = new OpenGl_CappingAlgoFilter(); - Handle(OpenGl_RenderFilter) aRenderFilter = theWorkspace->GetRenderFilter(); + Handle(OpenGl_CappingAlgoFilter) aCappingFilter = new OpenGl_CappingAlgoFilter(); + Handle(OpenGl_RenderFilter) aRenderFilter = theWorkspace->GetRenderFilter(); theWorkspace->SetRenderFilter (aCappingFilter); + // create empty culling + OpenGl_AspectFace aCulling;
please preserve optimizations in new code; default filters and aspects can be stored in OpenGl_Workspace.
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 29 10:56:19 2015 +0300
Default CappinAlgo filters and aspects are stored in OpenGl_Workspace.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 29 10:56:19 2015 +0300
Default CappinAlgo filters and aspects are stored in OpenGl_Workspace.
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 29 15:08:39 2015 +0300
Static variables in OpenGl_View_2.cxx is deleted.
Default ambient and spot are stored in OpenGl_Workspace.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 29 15:08:39 2015 +0300
Static variables in OpenGl_View_2.cxx is deleted.
Default ambient and spot are stored in OpenGl_Workspace.
Branch [archived branch] has been updated by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 29 16:08:27 2015 +0300
Cosmetics
[revision removed]
Detailed log of new commits:
Author: isk
Date: Wed Apr 29 16:08:27 2015 +0300
Cosmetics
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Jun 8 10:17:01 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Jun 8 10:17:01 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
Dear Kirill,
please review the branch CR23028_3.
please review the branch CR23028_3.
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Jun 22 14:57:45 2015 +0300
0025305: Visualization, TKOpenGl - support stipple line aspects within built-in GLSL programs
OpenGl_LineAttributes - drop display lists for stipple lines.
OpenGl_Context - add methods OpenGl_Context::SetTypeOfLine() and OpenGl_Context::SetLineWidth() to setup line aspects.
OpenGl_ShaderManager::prepareStdProgramFlat() - support new bit OpenGl_PO_StippleLine.
vaspects command - add -setlinetype option.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Jun 22 14:57:45 2015 +0300
0025305: Visualization, TKOpenGl - support stipple line aspects within built-in GLSL programs
OpenGl_LineAttributes - drop display lists for stipple lines.
OpenGl_Context - add methods OpenGl_Context::SetTypeOfLine() and OpenGl_Context::SetLineWidth() to setup line aspects.
OpenGl_ShaderManager::prepareStdProgramFlat() - support new bit OpenGl_PO_StippleLine.
vaspects command - add -setlinetype option.
Please test the patch in branch CR23028_4.
Branch [archived branch] has been updated forcibly by Author.
[revision removed]
[revision removed]
Dear Commenter 1,
Branch CR23028_4 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component:
Linux: 25 (25 on master)
Windows: 0 (0 on master)
products component:
Linux: 37 (37 on master)
Windows: 0 (0 on master)
Regressions/Differences:
Not detected
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 97570995 / 97808123 [-0.24%]
Total CPU difference: 18207.119999999763 / 18376.230000000123 [-0.92%]
Testing on Windows:
Total MEMORY difference: 56913676 / 56863564 [+0.09%]
Total CPU difference: 17806.125741098847 / 17659.42240069884 [+0.83%]
Branch CR23028_4 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component:
Linux: 25 (25 on master)
Windows: 0 (0 on master)
products component:
Linux: 37 (37 on master)
Windows: 0 (0 on master)
Regressions/Differences:
Not detected
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 97570995 / 97808123 [-0.24%]
Total CPU difference: 18207.119999999763 / 18376.230000000123 [-0.92%]
Testing on Windows:
Total MEMORY difference: 56913676 / 56863564 [+0.09%]
Total CPU difference: 17806.125741098847 / 17659.42240069884 [+0.83%]
Branch [archived branch] has been created by Author.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Jun 22 15:01:37 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
OpenGl_CappingAlgo - move global variables to OpenGl_Workspace class fields.
OpenGl_View::ShaderSource::Source() - drop static for local variable.
OpenGl_Window - drop redundant global constant THE_DEFAULT_BG_COLOR.
[revision removed]
Detailed log of new commits:
Author: isk
Date: Mon Jun 22 15:01:37 2015 +0300
0023028: Visualization, TKOpenGl - eliminate global static variables
OpenGl_CappingAlgo - move global variables to OpenGl_Workspace class fields.
OpenGl_View::ShaderSource::Source() - drop static for local variable.
OpenGl_Window - drop redundant global constant THE_DEFAULT_BG_COLOR.
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Author.
[revision removed]
[revision removed]
Related records
- #0022819 · related to · closedRedesign of OpenGl driver
- #0024847 · related to · closedCLang warnings -Wdeprecated-writable-strings in OpenGl_Display
- #0024291 · related to · closedVisualization - move Z-buffer trihedron presentation from TKOpenGl to TKV3d
- #0025789 · related to · closedVisualization - get rid of obsolete 2d layers implementation
- #0025382 · related to · closedVisualization, TKOpenGl - improved video recording capability
- #0023544 · parent of · closedTexture management in TKOpenGl should be redesigned
- #0024131 · parent of · closedTKOpenGL redesign GPU memory management for markers presentation
- #0024228 · parent of · closedTKOpenGL - destroy GL context at view close