MNE-CPP  0.1.9
A Framework for Electrophysiology
abstractphongalphamaterial.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
41 
42 //=============================================================================================================
43 // QT INCLUDES
44 //=============================================================================================================
45 
46 #include <QColor>
47 #include <Qt3DRender/qeffect.h>
48 #include <Qt3DRender/qtechnique.h>
49 #include <Qt3DRender/qshaderprogram.h>
50 #include <Qt3DRender/qparameter.h>
51 #include <Qt3DRender/qrenderpass.h>
52 #include <QFilterKey>
53 #include <Qt3DRender/qgraphicsapifilter.h>
54 
55 //=============================================================================================================
56 // EIGEN INCLUDES
57 //=============================================================================================================
58 
59 //=============================================================================================================
60 // USED NAMESPACES
61 //=============================================================================================================
62 
63 using namespace DISP3DLIB;
64 using namespace Qt3DRender;
65 
66 //=============================================================================================================
67 // DEFINE GLOBAL METHODS
68 //=============================================================================================================
69 
70 //=============================================================================================================
71 // DEFINE MEMBER METHODS
72 //=============================================================================================================
73 
74 AbstractPhongAlphaMaterial::AbstractPhongAlphaMaterial(bool bUseSortPolicy, QNode *parent)
75  : QMaterial(parent)
76  , m_pEffect(new QEffect())
77  , m_pDiffuseParameter(new QParameter(QStringLiteral("kd"), QColor::fromRgbF(0.7f, 0.7f, 0.7f, 1.0f)))
78  , m_pSpecularParameter(new QParameter(QStringLiteral("ks"), QColor::fromRgbF(0.1f, 0.1f, 0.1f, 1.0f)))
79  , m_pShininessParameter(new QParameter(QStringLiteral("shininess"), 2.0f))
80  , m_pAlphaParameter(new QParameter("alpha", 0.75f))
81  , m_pDrawFilterKey(new QFilterKey)
82  , m_bUseSortPolicy(bUseSortPolicy)
83 {
84  connect(m_pAlphaParameter.data(), &QParameter::valueChanged,
86 
87  //Init filter keys
88  m_pDrawFilterKey->setName(QStringLiteral("renderingStyle"));
90 }
91 
92 //=============================================================================================================
93 
95 {
96  return m_pAlphaParameter->value().toFloat();
97 }
98 
99 //=============================================================================================================
100 
102 {
103  m_pAlphaParameter->setValue(fAlpha);
104 }
105 
106 //=============================================================================================================
107 
109 {
110  //Set OpenGL version
111  QTechnique *pVertexGL3Technique = new QTechnique;
112  QTechnique *pVertexGL2Technique = new QTechnique;
113  QTechnique *pVertexES2Technique = new QTechnique;
114 
115  pVertexGL3Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
116  pVertexGL3Technique->graphicsApiFilter()->setMajorVersion(3);
117  pVertexGL3Technique->graphicsApiFilter()->setMinorVersion(2);
118  pVertexGL3Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::CoreProfile);
119 
120  pVertexGL2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGL);
121  pVertexGL2Technique->graphicsApiFilter()->setMajorVersion(2);
122  pVertexGL2Technique->graphicsApiFilter()->setMinorVersion(0);
123  pVertexGL2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile);
124 
125  pVertexES2Technique->graphicsApiFilter()->setApi(QGraphicsApiFilter::OpenGLES);
126  pVertexES2Technique->graphicsApiFilter()->setMajorVersion(2);
127  pVertexES2Technique->graphicsApiFilter()->setMinorVersion(0);
128  pVertexES2Technique->graphicsApiFilter()->setProfile(QGraphicsApiFilter::NoProfile);
129 
130  pVertexGL3Technique->addFilterKey(m_pDrawFilterKey);
131  pVertexGL2Technique->addFilterKey(m_pDrawFilterKey);
132  pVertexES2Technique->addFilterKey(m_pDrawFilterKey);
133 
134  QRenderPass *pVertexGL3RenderPass = new QRenderPass;
135  QRenderPass *pVertexGL2RenderPass = new QRenderPass;
136  QRenderPass *pVertexES2RenderPass = new QRenderPass;
137 
138  //Set Names to find them in child materials
139  pVertexGL3RenderPass->setObjectName(QStringLiteral("pVertexGL3RenderPass"));
140  pVertexGL2RenderPass->setObjectName(QStringLiteral("pVertexGL2RenderPass"));
141  pVertexES2RenderPass->setObjectName(QStringLiteral("pVertexES2RenderPass"));
142 
143  pVertexGL3Technique->addRenderPass(pVertexGL3RenderPass);
144  pVertexGL2Technique->addRenderPass(pVertexGL2RenderPass);
145  pVertexES2Technique->addRenderPass(pVertexES2RenderPass);
146 
147  m_pEffect->addTechnique(pVertexGL3Technique);
148  m_pEffect->addTechnique(pVertexGL2Technique);
149  m_pEffect->addTechnique(pVertexES2Technique);
150 
151  m_pEffect->addParameter(m_pDiffuseParameter);
152  m_pEffect->addParameter(m_pSpecularParameter);
153  m_pEffect->addParameter(m_pShininessParameter);
154  m_pEffect->addParameter(m_pAlphaParameter);
155 
156  this->setEffect(m_pEffect);
157 }
158 
159 //=============================================================================================================
160 
161 void AbstractPhongAlphaMaterial::addShaderToRenderPass(const QString &sObjectName, QShaderProgram *pShaderProgramm)
162 {
163  if(QRenderPass *pRenderPass = this->findChild<QRenderPass*>(sObjectName)) {
164  pRenderPass->setShaderProgram(pShaderProgramm);
165  }
166  else {
167  qDebug() << "AbstractPhongAlphaMaterial::addShaderToRenderPass: Renderpass " << sObjectName << " not found!";
168  }
169 }
170 
171 //=============================================================================================================
172 
173 void AbstractPhongAlphaMaterial::onAlphaChanged(const QVariant &fAlpha)
174 {
175  if(fAlpha.canConvert<float>())
176  {
177  float tempAlpha = fAlpha.toFloat();
178 
179  if(tempAlpha >= 1.0f) {
180  m_pDrawFilterKey->setValue(QStringLiteral("forward"));
181  } else {
182  if(m_bUseSortPolicy) {
183  m_pDrawFilterKey->setValue(QStringLiteral("forwardSorted"));
184  } else {
185  m_pDrawFilterKey->setValue(QStringLiteral("forwardTransparent"));
186  }
187  }
188  }
189 }
190 
191 //=============================================================================================================
DISP3DLIB::AbstractPhongAlphaMaterial::m_pSpecularParameter
QPointer< Qt3DRender::QParameter > m_pSpecularParameter
Definition: abstractphongalphamaterial.h:161
DISP3DLIB::AbstractPhongAlphaMaterial::alpha
virtual float alpha() const
Definition: abstractphongalphamaterial.cpp:94
DISP3DLIB::AbstractPhongAlphaMaterial::setAlpha
virtual void setAlpha(float fAlpha)
Definition: abstractphongalphamaterial.cpp:101
DISP3DLIB::AbstractPhongAlphaMaterial::m_pAlphaParameter
QPointer< Qt3DRender::QParameter > m_pAlphaParameter
Definition: abstractphongalphamaterial.h:163
DISP3DLIB::AbstractPhongAlphaMaterial::init
virtual void init()
Definition: abstractphongalphamaterial.cpp:108
DISP3DLIB::AbstractPhongAlphaMaterial::m_bUseSortPolicy
bool m_bUseSortPolicy
Definition: abstractphongalphamaterial.h:167
DISP3DLIB::AbstractPhongAlphaMaterial::AbstractPhongAlphaMaterial
AbstractPhongAlphaMaterial(bool bUseSortPolicy, QNode *parent)
Definition: abstractphongalphamaterial.cpp:74
DISP3DLIB::AbstractPhongAlphaMaterial::m_pEffect
QPointer< Qt3DRender::QEffect > m_pEffect
Definition: abstractphongalphamaterial.h:158
DISP3DLIB::AbstractPhongAlphaMaterial::m_pDiffuseParameter
QPointer< Qt3DRender::QParameter > m_pDiffuseParameter
Definition: abstractphongalphamaterial.h:160
DISP3DLIB::AbstractPhongAlphaMaterial::m_pShininessParameter
QPointer< Qt3DRender::QParameter > m_pShininessParameter
Definition: abstractphongalphamaterial.h:162
DISP3DLIB::AbstractPhongAlphaMaterial::m_pDrawFilterKey
QPointer< Qt3DRender::QFilterKey > m_pDrawFilterKey
Definition: abstractphongalphamaterial.h:165
DISP3DLIB::AbstractPhongAlphaMaterial::addShaderToRenderPass
virtual void addShaderToRenderPass(const QString &sObjectName, Qt3DRender::QShaderProgram *pShaderProgramm)
Definition: abstractphongalphamaterial.cpp:161
DISP3DLIB::AbstractPhongAlphaMaterial::onAlphaChanged
virtual void onAlphaChanged(const QVariant &fAlpha)
Definition: abstractphongalphamaterial.cpp:173
abstractphongalphamaterial.h
AbstractPhongAlphaMaterial class declaration.