Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
CAMP
campvis-public
Commits
e7e55015
Commit
e7e55015
authored
Jul 19, 2017
by
Jakob Weiss
Browse files
First steps replacing QGLWidget with QOpenGLWidget - currently crashes and burns horribly
parent
17f5574c
Changes
11
Hide whitespace changes
Inline
Side-by-side
core/glsl/tools/shading.frag
View file @
e7e55015
...
...
@@ -171,4 +171,9 @@ float getPhongShadingIntensity(in vec3 position, in LightSource light, in vec3 c
toReturn
*=
computeAttenuation
(
light
.
_attenuation
,
d
);
#endif
return
(
toReturn
.
x
+
toReturn
.
y
+
toReturn
.
z
)
/
3
.
0
;
}
\ No newline at end of file
}
vec3
calculateContourShading
(
in
vec3
position
,
in
vec3
camera
,
in
vec3
normal
,
in
vec3
materialColor
,
in
vec3
outlineColor
,
in
float
contourExponent
)
{
float
outlineStrength
=
1
.
-
pow
(
clamp
(
-
dot
(
normalize
(
normal
),
normalize
(
position
-
camera
)),
0
,
1
),
contourExponent
);
return
mix
(
materialColor
,
outlineColor
,
outlineStrength
);
}
core/init.cpp
View file @
e7e55015
...
...
@@ -99,7 +99,7 @@ namespace campvis {
CAMPVIS_CORE_API
void
startOpenGlThreadAndMoveQtThreadAffinity
(
cgt
::
Runnable
*
runnable
,
cgt
::
GLCanvas
*
canvas
)
{
// welcome to a complex signalling ping-pong to move the OpenGL context thread affinity
// we will use targetThread as signalling variable and initialize it with nullptr:
void
*
targetThread
=
nullptr
;
volatile
void
*
targetThread
=
nullptr
;
// start the new thread with special init function
runnable
->
start
([
&
]()
{
...
...
@@ -120,7 +120,7 @@ namespace campvis {
std
::
this_thread
::
yield
();
// set the QGLContext's thread affinity
canvas
->
moveThreadAffinity
(
targetThread
);
canvas
->
moveThreadAffinity
(
const_cast
<
void
*>
(
targetThread
)
)
;
// reset the signal variable so that the new thread can continue.
targetThread
=
nullptr
;
...
...
core/pipeline/abstractpipeline.cpp
View file @
e7e55015
...
...
@@ -40,6 +40,12 @@
namespace
campvis
{
const
std
::
string
AbstractPipeline
::
loggerCat_
=
"CAMPVis.core.datastructures.AbstractPipeline"
;
void
AbstractPipeline
::
debugMessageCallback
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
userParam
)
{
std
::
cerr
<<
"**** GL Debug Message Error: "
<<
type
<<
" "
<<
id
<<
" "
<<
severity
<<
" "
<<
std
::
endl
<<
message
<<
std
::
endl
;
}
AbstractPipeline
::
AbstractPipeline
(
DataContainer
&
dc
)
:
HasPropertyCollection
()
,
cgt
::
EventHandler
()
...
...
@@ -74,6 +80,11 @@ namespace campvis {
_painter
->
init
();
initAllProperties
();
glDebugMessageCallback
(
&
debugMessageCallback
,
this
);
LGL_ERROR
;
glDebugMessageControl
(
GL_DONT_CARE
,
GL_DONT_CARE
,
GL_DONT_CARE
,
0
,
nullptr
,
true
);
LGL_ERROR
;
// initialize all processors:
for
(
std
::
vector
<
AbstractProcessor
*>::
iterator
it
=
_processors
.
begin
();
it
!=
_processors
.
end
();
++
it
)
{
try
{
...
...
core/pipeline/abstractpipeline.h
View file @
e7e55015
...
...
@@ -230,6 +230,10 @@ namespace campvis {
sigslot
::
signal0
s_deinit
;
protected:
/// debug message callback registered to glDebugMessageCallback to catch OpenGL Errors
static
void
debugMessageCallback
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
userParam
);
/**
* Forces the execution of the given processor regardless of its invalidation or enabled state.
* \param processor Processor to execute.
...
...
ext/cgt/init.cpp
View file @
e7e55015
...
...
@@ -27,7 +27,6 @@
**********************************************************************/
#include
"cgt/init.h"
#include
"cgt/cgt_gl.h"
#include
"cgt/assert.h"
#include
"cgt/glcanvas.h"
...
...
@@ -102,11 +101,20 @@ void initGL(GLCanvas* backgroundGlContext, InitFeature::Features featureset) {
TextureManager
::
init
();
if
(
featureset
&
InitFeature
::
GPU_PROPERTIES
)
if
(
featureset
&
InitFeature
::
GPU_PROPERTIES
)
{
GpuCapabilities
::
init
();
#ifdef _MSC_VER
GpuCapabilitiesWindows
::
init
();
#endif
}
// setup debug callback
if
(
featureset
&
InitFeature
::
GL_DEBUG_CALLBACK
)
{
glDebugMessageCallback
(
&
debugMessageCallback
,
nullptr
);
LGL_ERROR
;
glDebugMessageControl
(
GL_DONT_CARE
,
GL_DONT_CARE
,
GL_DONT_CARE
,
0
,
nullptr
,
true
);
LGL_ERROR
;
}
// starting shadermanager
ShaderManager
::
init
();
...
...
@@ -132,4 +140,11 @@ void deinitGL() {
}
void
debugMessageCallback
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
userParam
)
{
std
::
cerr
<<
"**** GL Debug Message Error: "
<<
type
<<
" "
<<
id
<<
" "
<<
severity
<<
" "
<<
std
::
endl
<<
message
<<
std
::
endl
;
}
}
// namespace
ext/cgt/init.h
View file @
e7e55015
...
...
@@ -32,25 +32,28 @@
#include
"cgt/types.h"
#include
"cgt/logmanager.h"
#include
"cgt/cgt_gl.h"
namespace
cgt
{
class
GLCanvas
;
class
CGT_API
InitFeature
{
public:
enum
Features
{
NONE
=
0
,
LOG_MANAGER
=
1
<<
0
,
FILE_SYSTEM
=
1
<<
1
,
GPU_PROPERTIES
=
1
<<
2
,
SCRIPT_MANAGER
=
1
<<
3
,
SHADER_MANAGER
=
1
<<
4
,
TEXTURE_MANAGER
=
1
<<
6
,
TESSELATOR
=
1
<<
7
,
LOG_TO_CONSOLE
=
1
<<
30
,
ALL
=
(
NONE
=
0
,
LOG_MANAGER
=
1
<<
0
,
FILE_SYSTEM
=
1
<<
1
,
GPU_PROPERTIES
=
1
<<
2
,
SCRIPT_MANAGER
=
1
<<
3
,
SHADER_MANAGER
=
1
<<
4
,
TEXTURE_MANAGER
=
1
<<
6
,
TESSELATOR
=
1
<<
7
,
GL_DEBUG_CALLBACK
=
1
<<
8
,
LOG_TO_CONSOLE
=
1
<<
30
,
ALL
=
(
LOG_MANAGER
|
FILE_SYSTEM
|
GPU_PROPERTIES
|
SCRIPT_MANAGER
|
SHADER_MANAGER
|
TEXTURE_MANAGER
|
TESSELATOR
|
TEXTURE_MANAGER
|
TESSELATOR
|
GL_DEBUG_CALLBACK
|
LOG_TO_CONSOLE
)
};
...
...
@@ -66,7 +69,11 @@ CGT_API void initGL(GLCanvas* backgroundGlContext, InitFeature::Features feature
CGT_API
void
deinit
();
/// deinit the singletons of cgt
CGT_API
void
deinitGL
();
/// debug message callback registered to glDebugMessageCallback to catch OpenGL Errors
void
debugMessageCallback
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
userParam
);
};
#endif //CGT_INIT_H
ext/cgt/qt/qtcanvas.cpp
View file @
e7e55015
...
...
@@ -29,17 +29,18 @@
#include
"qtcanvas.h"
#include
<QThread>
#include
<QOpenGLContext>
namespace
cgt
{
// shared context widget
QGLWidget
*
QtCanvas
::
shareWidget_
=
0
;
Q
Open
GLWidget
*
QtCanvas
::
shareWidget_
=
0
;
QtCanvas
::
QtCanvas
(
const
std
::
string
&
title
,
const
ivec2
&
size
,
const
Buffers
buffers
,
QWidget
*
parent
,
bool
shared
,
Qt
::
WindowFlags
f
,
char
*
/*name*/
)
:
QGLWidget
(
getQGLFormat
(
buffers
),
0
,
(
shared
?
shareWidget_
:
0
)
,
f
)
:
Q
Open
GLWidget
(
parent
,
f
)
,
GLCanvas
(
title
,
size
,
buffers
)
{
resize
(
size
.
x
,
size
.
y
);
...
...
@@ -52,7 +53,7 @@ QtCanvas::QtCanvas(const std::string& title,
setSizePolicy
(
QSizePolicy
::
Expanding
,
QSizePolicy
::
Expanding
);
// we have our own AutoBufferSwap-mechanism (GLCanvas::setAutoFlush), so disable the one of qt
setAutoBufferSwap
(
false
);
//
setAutoBufferSwap(false);
// TODO jw: not sure what this does, figure out later
rgbaSize_
=
ivec4
(
format
().
redBufferSize
(),
format
().
greenBufferSize
(),
...
...
@@ -60,7 +61,7 @@ QtCanvas::QtCanvas(const std::string& title,
format
().
alphaBufferSize
());
stencilSize_
=
format
().
stencilBufferSize
();
depthSize_
=
format
().
depthBufferSize
();
doubleBuffered_
=
d
oubleBuffer
()
;
doubleBuffered_
=
format
().
swapBehavior
()
==
QSurfaceFormat
::
D
oubleBuffer
;
stereoViewing_
=
format
().
stereo
();
connect
(
this
,
&
QtCanvas
::
s_sizeChangedExternally
,
this
,
&
QtCanvas
::
sizeChangedExternally
);
...
...
@@ -68,13 +69,13 @@ QtCanvas::QtCanvas(const std::string& title,
}
QtCanvas
::
QtCanvas
(
QWidget
*
parent
,
bool
shared
,
Qt
::
WindowFlags
f
,
char
*
/*name*/
)
:
QGLWidget
(
getQGLFormat
(),
0
,
(
shared
?
shareWidget_
:
0
)
,
f
)
:
Q
Open
GLWidget
(
parent
,
f
)
{
if
(
shared
&&
shareWidget_
==
0
)
shareWidget_
=
this
;
// we have our own AutoBufferSwap-mechanism (GLCanvas::setAutoFlush), so disable the one of qt
setAutoBufferSwap
(
false
);
//
setAutoBufferSwap(false);
rgbaSize_
=
ivec4
(
format
().
redBufferSize
(),
format
().
greenBufferSize
(),
...
...
@@ -82,7 +83,7 @@ QtCanvas::QtCanvas(QWidget* parent, bool shared, Qt::WindowFlags f, char* /*name
format
().
alphaBufferSize
());
stencilSize_
=
format
().
stencilBufferSize
();
depthSize_
=
format
().
depthBufferSize
();
doubleBuffered_
=
d
oubleBuffer
()
;
doubleBuffered_
=
format
().
swapBehavior
()
==
QSurfaceFormat
::
D
oubleBuffer
;
stereoViewing_
=
format
().
stereo
();
}
...
...
@@ -90,7 +91,7 @@ QtCanvas::~QtCanvas() {}
void
QtCanvas
::
moveThreadAffinity
(
void
*
threadPointer
)
{
QThread
*
qThreadPointer
=
static_cast
<
QThread
*>
(
threadPointer
);
this
->
context
()
->
moveToThread
(
qThreadPointer
);
context
()
->
moveToThread
(
qThreadPointer
);
}
void
*
QtCanvas
::
getCurrentThreadPointer
()
{
...
...
@@ -109,16 +110,17 @@ void QtCanvas::paintGL() {
}
void
QtCanvas
::
repaint
()
{
update
GL
();
QOpenGLWidget
::
update
();
}
void
QtCanvas
::
update
()
{
QWidget
::
update
();
Q
OpenGL
Widget
::
update
();
}
void
QtCanvas
::
swap
()
{
QGLWidget
::
swapBuffers
();
QGLWidget
::
makeCurrent
();
//context()->swapBuffers();
//QOpenGLWidget::makeCurrent();
update
();
}
void
QtCanvas
::
toggleFullScreen
()
{
...
...
@@ -255,25 +257,37 @@ cgt::Event::Modifier QtCanvas::getModifier(QInputEvent* e) {
return
cgt
::
Event
::
Modifier
(
result
);
}
QGLFormat
QtCanvas
::
getQGLFormat
(
const
Buffers
buffers
)
{
QGLFormat
format
=
getQGLFormat
();
format
.
setAlpha
(
buffers
&
GLCanvas
::
ALPHA_BUFFER
);
format
.
setDepth
(
buffers
&
GLCanvas
::
DEPTH_BUFFER
);
format
.
setDoubleBuffer
(
buffers
&
GLCanvas
::
DOUBLE_BUFFER
);
format
.
setStencil
(
buffers
&
GLCanvas
::
STENCIL_BUFFER
);
format
.
setAccum
(
buffers
&
GLCanvas
::
ACCUM_BUFFER
);
format
.
setStereo
(
buffers
&
GLCanvas
::
STEREO_VIEWING
);
format
.
setSampleBuffers
(
buffers
&
GLCanvas
::
MULTISAMPLING
);
QSurfaceFormat
QtCanvas
::
getQGLSurfaceFormat
(
const
Buffers
buffers
)
{
QSurfaceFormat
format
=
getQGLSurfaceFormat
();
if
(
buffers
&
GLCanvas
::
ALPHA_BUFFER
)
format
.
setAlphaBufferSize
(
8
);
if
(
buffers
&
GLCanvas
::
DEPTH_BUFFER
)
format
.
setDepthBufferSize
(
24
);
if
(
buffers
&
GLCanvas
::
DOUBLE_BUFFER
)
format
.
setSwapBehavior
(
QSurfaceFormat
::
DoubleBuffer
);
if
(
buffers
&
GLCanvas
::
STENCIL_BUFFER
)
format
.
setStencilBufferSize
(
8
);
if
(
buffers
&
GLCanvas
::
ACCUM_BUFFER
)
{
// TODO QSurfaceFormat does not support htis anymore?
throw
std
::
logic_error
(
"Accumulation buffer not implemented directly on the surface."
);
}
if
(
buffers
&
GLCanvas
::
STEREO_VIEWING
)
{
format
.
setOption
(
QSurfaceFormat
::
StereoBuffers
);
}
if
(
buffers
&
GLCanvas
::
MULTISAMPLING
)
{
format
.
setSamples
(
2
);
}
return
format
;
}
Q
GL
Format
QtCanvas
::
getQGLFormat
()
Q
Surface
Format
QtCanvas
::
getQGL
Surface
Format
()
{
QGLFormat
format
=
QGLFormat
(
QGL
::
NoDeprecatedFunctions
);
format
=
QGLFormat
(
QGL
::
NoDeprecatedFunctions
);
format
.
setProfile
(
QGLFormat
::
CoreProfile
);
//format.setVersion(3, 3);
QSurfaceFormat
format
;
format
.
setVersion
(
4
,
3
);
format
.
setProfile
(
QSurfaceFormat
::
CoreProfile
);
format
.
setOption
(
QSurfaceFormat
::
DebugContext
);
format
.
setDepthBufferSize
(
24
);
format
.
setStencilBufferSize
(
8
);
//QSurfaceFormat::setDefaultFormat(format);
return
format
;
}
...
...
@@ -607,11 +621,11 @@ QSize QtCanvas::sizeHint() const {
}
void
QtCanvas
::
acquireAsCurrentContext
()
{
QGLWidget
::
makeCurrent
();
Q
Open
GLWidget
::
makeCurrent
();
}
void
QtCanvas
::
releaseAsCurrentContext
()
{
QGLWidget
::
doneCurrent
();
Q
Open
GLWidget
::
doneCurrent
();
}
void
QtCanvas
::
sizeChangedExternally
(
int
w
,
int
h
)
{
...
...
ext/cgt/qt/qtcanvas.h
View file @
e7e55015
...
...
@@ -32,7 +32,7 @@
#include
"cgt/glcanvas.h"
#include
"cgt/types.h"
#include
<QGLWidget>
#include
<Q
Open
GLWidget>
#include
<QGLFormat>
#include
<QMouseEvent>
#include
<QKeyEvent>
...
...
@@ -44,7 +44,7 @@ namespace cgt {
/**
* Qt implementation of GLCanvas. Inherits QGLWidget and combines the Qt methods and cgt methods.
*/
class
CGT_API
QtCanvas
:
public
QGLWidget
,
public
GLCanvas
{
class
CGT_API
QtCanvas
:
public
Q
Open
GLWidget
,
public
GLCanvas
{
Q_OBJECT
;
public:
...
...
@@ -150,8 +150,8 @@ public:
static
cgt
::
MouseEvent
::
MouseButtons
getButtons
(
QMouseEvent
*
e
);
static
cgt
::
Event
::
Modifier
getModifier
(
QInputEvent
*
e
);
static
KeyEvent
::
KeyCode
getKey
(
int
key
);
static
Q
GL
Format
getQGLFormat
(
const
Buffers
buffers
);
static
Q
GL
Format
getQGLFormat
();
static
Q
Surface
Format
getQGL
Surface
Format
(
const
Buffers
buffers
);
static
Q
Surface
Format
getQGL
Surface
Format
();
signals:
void
s_sizeChangedExternally
(
int
w
,
int
h
);
...
...
@@ -161,7 +161,8 @@ protected slots:
void
changeFullScreen
(
bool
fullscreen
);
protected:
static
QGLWidget
*
shareWidget_
;
///< widget that this canvas shares the OpenGL context with
static
QOpenGLWidget
*
shareWidget_
;
///< widget that this canvas shares the OpenGL context with
///< TODO: This is very bad design. Context sharing should happen on another level and not using a static
signals:
void
fullScreenChanged
(
bool
fullscreen
);
...
...
modules/vis/glsl/depthdarkening.frag
View file @
e7e55015
...
...
@@ -41,8 +41,8 @@ uniform float _lambda;
uniform
float
_minDepth
;
uniform
float
_maxDepth
;
uniform
vec
3
_coldColor
;
uniform
vec
3
_warmColor
;
uniform
vec
4
_coldColor
;
uniform
vec
4
_warmColor
;
int
_halfKernelDimension
;
float
[
25
]
_gaussKernel
;
...
...
@@ -116,10 +116,10 @@ void main() {
#ifdef USE_COLORCODING
float
deltaDPlus
=
(
deltaD
>
0
?
deltaD
:
0
.
0
);
float
deltaDMinus
=
(
deltaD
<
0
?
-
deltaD
:
0
.
0
);
curColor
.
rgb
+=
(
_coldColor
*
deltaDMinus
+
_warmColor
*
deltaDPlus
)
*
_lambda
;
curColor
.
rgb
+=
(
_coldColor
.
rgb
*
_coldColor
.
a
*
deltaDMinus
+
_warmColor
.
rgb
*
_warmColor
.
a
*
deltaDPlus
)
*
_lambda
;
#else
if
(
deltaD
<
0
.
0
)
{
curColor
.
rgb
+=
deltaD
*
_lambda
;
curColor
.
rgb
+=
deltaD
*
_lambda
*
_warmColor
.
rgb
;
}
#endif
...
...
modules/vis/processors/depthdarkening.cpp
View file @
e7e55015
...
...
@@ -46,8 +46,8 @@ namespace campvis {
,
p_sigma
(
"Sigma"
,
"Sigma of Gaussian Filter"
,
2.
f
,
0.
f
,
10.
f
,
0.1
f
)
,
p_lambda
(
"Lambda"
,
"Strength of Depth Darkening Effect"
,
10.
f
,
0.
f
,
150.
f
,
0.1
f
)
,
p_useColorCoding
(
"UseColorCoding"
,
"Cold/Warm Color Coding"
,
false
)
,
p_coldColor
(
"ColdColor"
,
"Cold Color (Far Objects)"
,
cgt
::
vec
3
(
0.
f
,
0.
f
,
1.
f
)
,
cgt
::
vec3
(
0.
f
),
cgt
::
vec3
(
1.
f
))
,
p_warmColor
(
"WarmColor"
,
"Warm Color (Near Objects)"
,
cgt
::
vec
3
(
1.
f
,
0.
f
,
0.
f
)
,
cgt
::
vec3
(
0.
f
),
cgt
::
vec3
(
1.
f
))
,
p_coldColor
(
"ColdColor"
,
"Cold Color (Far Objects)"
,
cgt
::
vec
4
(
0.
f
,
0.
f
,
1.
f
,
1.
0
f
))
,
p_warmColor
(
"WarmColor"
,
"Warm Color (Near Objects)"
,
cgt
::
vec
4
(
1.
f
,
0.
f
,
0.
f
,
1.
0
f
))
,
_shader
(
0
)
,
_glReduction
(
0
)
{
...
...
@@ -100,9 +100,9 @@ namespace campvis {
_shader
->
setUniform
(
"_lambda"
,
p_lambda
.
getValue
());
_shader
->
setUniform
(
"_minDepth"
,
minDepth
);
_shader
->
setUniform
(
"_maxDepth"
,
maxDepth
);
_shader
->
setUniform
(
"_warmColor"
,
p_warmColor
.
getValue
());
if
(
p_useColorCoding
.
getValue
())
{
_shader
->
setUniform
(
"_coldColor"
,
p_coldColor
.
getValue
());
_shader
->
setUniform
(
"_warmColor"
,
p_warmColor
.
getValue
());
}
createAndAttachColorTexture
();
...
...
modules/vis/processors/depthdarkening.h
View file @
e7e55015
...
...
@@ -30,6 +30,7 @@
#include
"core/pipeline/visualizationprocessor.h"
#include
"core/properties/datanameproperty.h"
#include
"core/properties/floatingpointproperty.h"
#include
"core/properties/colorproperty.h"
#include
"modules/modulesapi.h"
...
...
@@ -61,7 +62,7 @@ namespace campvis {
/// \see AbstractProcessor::deinit
virtual
void
deinit
();
/// To be used in ProcessorFactory static methods
static
const
std
::
string
getId
()
{
return
"DepthDarkening"
;
};
/// \see AbstractProcessor::getName()
...
...
@@ -80,8 +81,8 @@ namespace campvis {
FloatProperty
p_lambda
;
///< strength of depth effect
BoolProperty
p_useColorCoding
;
///< Flag whether to use depth color coding
Vec3
Property
p_coldColor
;
///< Cold color (color for far objects)
Vec3
Property
p_warmColor
;
///< Warm color (color for near objects)
Color
Property
p_coldColor
;
///< Cold color (color for far objects)
Color
Property
p_warmColor
;
///< Warm color (color for near objects)
protected:
/// \see AbstractProcessor::updateResult
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment