Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
652665f8
Commit
652665f8
authored
6 years ago
by
Pospelov, Gennady
Browse files
Options
Downloads
Patches
Plain Diff
Preparation in Canvas for proper release of OpenGL resources
parent
eee8e5fb
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GUI/ba3d/ba3d/view/canvas.cpp
+27
-7
27 additions, 7 deletions
GUI/ba3d/ba3d/view/canvas.cpp
GUI/ba3d/ba3d/view/canvas.h
+5
-0
5 additions, 0 deletions
GUI/ba3d/ba3d/view/canvas.h
with
32 additions
and
7 deletions
GUI/ba3d/ba3d/view/canvas.cpp
+
27
−
7
View file @
652665f8
...
...
@@ -52,7 +52,7 @@ namespace RealSpace
Canvas
::
Canvas
()
:
aspectRatio
(
1
),
colorBgR
(
1
),
colorBgG
(
1
),
colorBgB
(
1
),
currentZoomLevel
(
0
),
camera
(
nullptr
),
program
(
nullptr
),
model
(
nullptr
)
program
(
nullptr
),
model
(
nullptr
)
,
m_isInitializedGL
(
false
)
{
setCamera
((
camera
=
new
Camera
));
setProgram
((
program
=
new
Program
));
...
...
@@ -65,6 +65,7 @@ Canvas::~Canvas()
releaseBuffers
();
delete
camera
;
delete
program
;
cleanup
();
}
void
Canvas
::
setBgColor
(
QColor
const
&
c
)
...
...
@@ -91,6 +92,7 @@ void Canvas::setProgram(Program* p)
void
Canvas
::
setModel
(
Model
*
m
)
{
qDebug
()
<<
"Canvas::setModel()"
;
releaseBuffers
();
disconnect
(
modelUpdated
);
...
...
@@ -102,8 +104,9 @@ void Canvas::setModel(Model* m)
update
();
});
Q_ASSERT
(
camera
);
setCamera
();
//connect(camera, &RealSpace::Camera::updated, model, &Model::cameraUpdated);
camera
->
set
();
}
...
...
@@ -125,9 +128,15 @@ void Canvas::setCamera(bool full)
void
Canvas
::
initializeGL
()
{
qDebug
()
<<
"Canvas::initializeGL()"
;
Q_ASSERT
(
m_isInitializedGL
==
false
);
connect
(
context
(),
&
QOpenGLContext
::
aboutToBeDestroyed
,
this
,
&
Canvas
::
cleanup
);
initializeOpenGLFunctions
();
glEnable
(
GL_DEPTH_TEST
);
glEnable
(
GL_CULL_FACE
);
m_isInitializedGL
=
true
;
}
void
Canvas
::
resizeGL
(
int
w
,
int
h
)
...
...
@@ -286,10 +295,21 @@ void Canvas::draw(QColor const& color, QMatrix4x4 const& mat, Geometry const& ge
buf
->
draw
();
}
void
Canvas
::
cleanup
()
{
qDebug
()
<<
"Canvas::cleanup()"
;
m_isInitializedGL
=
false
;
}
bool
Canvas
::
isInitialized
()
const
{
return
m_isInitializedGL
&&
model
!=
nullptr
;
}
void
Canvas
::
defaultView
()
{
// Default view
if
(
model
)
{
if
(
isInitialized
()
)
{
RealSpace
::
Camera
::
Position
defPos
(
RealSpace
::
Vector3D
(
0
,
cameraDefaultPosY
,
cameraDefaultPosZ
),
// eye
RealSpace
::
Vector3D
(
0
,
0
,
0
),
// center
...
...
@@ -308,7 +328,7 @@ void Canvas::defaultView()
void
Canvas
::
sideView
()
{
// Side view at current zoom level
if
(
model
)
{
if
(
isInitialized
()
)
{
RealSpace
::
Vector3D
eye
(
0
,
cameraDefaultPosY
,
0
);
// Side view 3D axes is zoom scale independent
...
...
@@ -334,7 +354,7 @@ void Canvas::sideView()
void
Canvas
::
topView
()
{
// Top view at current zoom level
if
(
model
)
{
if
(
isInitialized
()
)
{
// Setting a tiny offset in y value of eye such that eye and up vectors are not parallel
RealSpace
::
Vector3D
eye
(
0
,
-
0.5
,
-
cameraDefaultPosY
);
...
...
@@ -360,7 +380,7 @@ void Canvas::topView()
void
Canvas
::
horizontalCameraTurn
(
float
angle
)
{
if
(
model
)
{
if
(
isInitialized
()
)
{
float
theta
=
angle
*
static_cast
<
float
>
(
M_PI
/
180.0
);
// in radians
...
...
@@ -406,7 +426,7 @@ void Canvas::horizontalCameraTurn(float angle)
void
Canvas
::
verticalCameraTurn
(
float
angle
)
{
if
(
model
)
{
if
(
isInitialized
()
)
{
float
theta
=
angle
*
static_cast
<
float
>
(
M_PI
/
180.0
);
// in radians
...
...
This diff is collapsed.
Click to expand it.
GUI/ba3d/ba3d/view/canvas.h
+
5
−
0
View file @
652665f8
...
...
@@ -92,6 +92,11 @@ private:
void
releaseBuffers
();
void
draw
(
QColor
const
&
,
QMatrix4x4
const
&
,
Geometry
const
&
);
void
cleanup
();
bool
isInitialized
()
const
;
bool
m_isInitializedGL
;
};
}
// namespace RealSpace
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment