20 #include <Qt3DExtras/QGoochMaterial>
21 #include <Qt3DRender/QAttribute>
22 #include <Qt3DRender/QBuffer>
23 #include <Qt3DRender/QGeometry>
24 #include <Qt3DRender/QParameter>
25 #include <Qt3DRender/QEffect>
26 #include <Qt3DRender/QTechnique>
27 #include <Qt3DRender/QGraphicsApiFilter>
32 return QStringLiteral(
"gooch" );
69 mShininess = elem.attribute( QStringLiteral(
"shininess2" ), QStringLiteral(
"100" ) ).toFloat();
70 mAlpha = elem.attribute( QStringLiteral(
"alpha" ), QStringLiteral(
"0.25" ) ).toFloat();
71 mBeta = elem.attribute( QStringLiteral(
"beta" ), QStringLiteral(
"0.5" ) ).toFloat();
82 elem.setAttribute( QStringLiteral(
"shininess2" ), mShininess );
83 elem.setAttribute( QStringLiteral(
"alpha" ), mAlpha );
84 elem.setAttribute( QStringLiteral(
"beta" ), mBeta );
91 return QMap<QString, QString>();
104 return dataDefinedMaterial();
105 Qt3DExtras::QGoochMaterial *material =
new Qt3DExtras::QGoochMaterial;
106 material->setDiffuse( mDiffuse );
107 material->setWarm( mWarm );
108 material->setCool( mCool );
110 material->setSpecular( mSpecular );
111 material->setShininess( mShininess );
112 material->setAlpha( mAlpha );
113 material->setBeta( mBeta );
145 array.resize(
sizeof(
unsigned char ) * 12 );
146 unsigned char *fptr =
reinterpret_cast<unsigned char *
>( array.data() );
148 *fptr++ =
static_cast<unsigned char>(
diffuse.red() );
149 *fptr++ =
static_cast<unsigned char>(
diffuse.green() );
150 *fptr++ =
static_cast<unsigned char>(
diffuse.blue() );
152 *fptr++ =
static_cast<unsigned char>(
warm.red() );
153 *fptr++ =
static_cast<unsigned char>(
warm.green() );
154 *fptr++ =
static_cast<unsigned char>(
warm.blue() );
156 *fptr++ =
static_cast<unsigned char>(
cool.red() );
157 *fptr++ =
static_cast<unsigned char>(
cool.green() );
158 *fptr++ =
static_cast<unsigned char>(
cool.blue() );
160 *fptr++ =
static_cast<unsigned char>(
specular.red() );
161 *fptr++ =
static_cast<unsigned char>(
specular.green() );
162 *fptr++ =
static_cast<unsigned char>(
specular.blue() );
169 return 12 *
sizeof(
unsigned char );
174 Qt3DRender::QBuffer *dataBuffer =
new Qt3DRender::QBuffer( geometry );
176 Qt3DRender::QAttribute *diffuseAttribute =
new Qt3DRender::QAttribute( geometry );
177 diffuseAttribute->setName( QStringLiteral(
"dataDefinedDiffuseColor" ) );
178 diffuseAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedByte );
179 diffuseAttribute->setVertexSize( 3 );
180 diffuseAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
181 diffuseAttribute->setBuffer( dataBuffer );
182 diffuseAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
183 diffuseAttribute->setByteOffset( 0 );
184 diffuseAttribute->setCount( vertexCount );
185 geometry->addAttribute( diffuseAttribute );
187 Qt3DRender::QAttribute *warmAttribute =
new Qt3DRender::QAttribute( geometry );
188 warmAttribute->setName( QStringLiteral(
"dataDefinedWarmColor" ) );
189 warmAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedByte );
190 warmAttribute->setVertexSize( 3 );
191 warmAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
192 warmAttribute->setBuffer( dataBuffer );
193 warmAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
194 warmAttribute->setByteOffset( 3 *
sizeof(
unsigned char ) );
195 warmAttribute->setCount( vertexCount );
196 geometry->addAttribute( warmAttribute
199 Qt3DRender::QAttribute *coolAttribute =
new Qt3DRender::QAttribute( geometry );
200 coolAttribute->setName( QStringLiteral(
"dataDefinedCoolColor" ) );
201 coolAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedByte );
202 coolAttribute->setVertexSize( 3 );
203 coolAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
204 coolAttribute->setBuffer( dataBuffer );
205 coolAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
206 coolAttribute->setByteOffset( 6 *
sizeof(
unsigned char ) );
207 coolAttribute->setCount( vertexCount );
208 geometry->addAttribute( coolAttribute );
211 Qt3DRender::QAttribute *specularAttribute =
new Qt3DRender::QAttribute( geometry );
212 specularAttribute->setName( QStringLiteral(
"dataDefinedSpecularColor" ) );
213 specularAttribute->setVertexBaseType( Qt3DRender::QAttribute::UnsignedByte );
214 specularAttribute->setVertexSize( 3 );
215 specularAttribute->setAttributeType( Qt3DRender::QAttribute::VertexAttribute );
216 specularAttribute->setBuffer( dataBuffer );
217 specularAttribute->setByteStride( 12 *
sizeof(
unsigned char ) );
218 specularAttribute->setByteOffset( 9 *
sizeof(
unsigned char ) );
219 specularAttribute->setCount( vertexCount );
220 geometry->addAttribute( specularAttribute );
222 dataBuffer->setData( data );
225 Qt3DRender::QMaterial *QgsGoochMaterialSettings::dataDefinedMaterial()
const
227 Qt3DRender::QMaterial *material =
new Qt3DRender::QMaterial;
229 Qt3DRender::QEffect *eff =
new Qt3DRender::QEffect( material );
231 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
232 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
233 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
234 technique->graphicsApiFilter()->setMajorVersion( 3 );
235 technique->graphicsApiFilter()->setMinorVersion( 3 );
236 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey();
237 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
238 filterKey->setValue( QStringLiteral(
"forward" ) );
239 technique->addFilterKey( filterKey );
241 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass();
242 Qt3DRender::QShaderProgram *shaderProgram =
new Qt3DRender::QShaderProgram();
245 const QUrl urlVert( QStringLiteral(
"qrc:/shaders/goochDataDefined.vert" ) );
246 shaderProgram->setShaderCode( Qt3DRender::QShaderProgram::Vertex, Qt3DRender::QShaderProgram::loadSource( urlVert ) );
247 const QUrl urlFrag( QStringLiteral(
"qrc:/shaders/goochDataDefined.frag" ) );
248 shaderProgram->setShaderCode( Qt3DRender::QShaderProgram::Fragment, Qt3DRender::QShaderProgram::loadSource( urlFrag ) );
250 renderPass->setShaderProgram( shaderProgram );
251 technique->addRenderPass( renderPass );
253 technique->addParameter(
new Qt3DRender::QParameter( QStringLiteral(
"shininess" ), mShininess ) );
254 technique->addParameter(
new Qt3DRender::QParameter( QStringLiteral(
"alpha" ), mAlpha ) );
255 technique->addParameter(
new Qt3DRender::QParameter( QStringLiteral(
"beta" ), mBeta ) );
257 eff->addTechnique( technique );
258 material->setEffect( eff );