24 #include <qmatrix4x4.h>
25 #include <qopenglbuffer.h>
26 #include <qopenglcontext.h>
27 #include <qopenglfunctions_4_3_core.h>
28 #include <qopenglshaderprogram.h>
29 #include <qopengltexture.h>
30 #include <qopenglvertexarrayobject.h>
31 #include <qtransform.h>
32 #include <qvector2d.h>
33 #include <qvector3d.h>
52 #include <QOpenGLFunctions_4_3_Core>
65 QMatrix4x4 bboxTranslation;
66 bboxTranslation.translate(QVector3D((boundingBox.
_min.
_x + boundingBox.
_max.
_x),
71 QVector3D bboxDimensions(boundingBox.
_max.
_x - boundingBox.
_min.
_x,
77 std::shared_ptr<OGLMesh> bboxMesh = std::make_shared<OGLBoxMesh>(bboxDimensions);
79 meshInstances.emplace_back(bboxMesh, modelMatrix);
82 std::shared_ptr<OGLArrayMesh> points = std::make_shared<OGLArrayMesh>();
83 points->fromMeshVertices(*bboxMesh);
85 meshInstances.emplace_back(points, modelMatrix);
89 std::vector<OGLMeshInstance>& meshInstances,
92 if (elementGraphic !=
nullptr)
103 bool showGeometry =
true;
121 elementGraphic->
getChilds(children,
false);
122 for (
auto child : children)
131 const QMatrix4x4& view,
const QMatrix4x4& projection)
134 QOpenGLFunctions_4_3_Core gl;
135 gl.initializeOpenGLFunctions();
137 QOpenGLVertexArrayObject vao;
142 QOpenGLBuffer positionBuffer(QOpenGLBuffer::VertexBuffer);
143 positionBuffer.create();
144 positionBuffer.bind();
145 positionBuffer.allocate(mesh.
vertices().data(), mesh.
vertices().size() *
sizeof(QVector3D));
147 int vertexLocation = shaderProgram->attributeLocation(
"vPosition");
148 shaderProgram->enableAttributeArray(vertexLocation);
149 shaderProgram->setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 3, 0);
152 QOpenGLBuffer colorsBuffer(QOpenGLBuffer::VertexBuffer);
153 int colorsLocation = shaderProgram->attributeLocation(
"vColor");
156 colorsBuffer.create();
160 shaderProgram->enableAttributeArray(colorsLocation);
161 shaderProgram->setAttributeBuffer(colorsLocation, GL_FLOAT, 0, 4, 0);
165 shaderProgram->disableAttributeArray(colorsLocation);
166 shaderProgram->setAttributeValue(colorsLocation, mesh.
material().
color);
170 QOpenGLBuffer textureCoordinatesBuffer(QOpenGLBuffer::VertexBuffer);
171 int textureCoordinatesLocation = shaderProgram->attributeLocation(
"vTextureCoordinates");
174 textureCoordinatesBuffer.create();
175 textureCoordinatesBuffer.bind();
179 shaderProgram->enableAttributeArray(textureCoordinatesLocation);
180 shaderProgram->setAttributeBuffer(textureCoordinatesLocation, GL_FLOAT, 0, 2, 0);
184 shaderProgram->disableAttributeArray(textureCoordinatesLocation);
185 shaderProgram->setAttributeValue(textureCoordinatesLocation, QVector2D(0.5, 0.5));
189 QOpenGLBuffer normalBuffer(QOpenGLBuffer::VertexBuffer);
190 int normalLocation = shaderProgram->attributeLocation(
"vNormal");
193 normalBuffer.create();
195 normalBuffer.allocate(mesh.
normals().data(), mesh.
normals().size() *
sizeof(QVector3D));
197 shaderProgram->enableAttributeArray(normalLocation);
198 shaderProgram->setAttributeBuffer(normalLocation, GL_FLOAT, 0, 3, 0);
202 shaderProgram->disableAttributeArray(normalLocation);
203 shaderProgram->setAttributeValue(normalLocation, QVector3D(0.0, 0.0, 1.0));
206 int modelLocation = shaderProgram->uniformLocation(
"uModel");
207 shaderProgram->setUniformValue(modelLocation, meshInstance.
globalMatrix());
208 int viewLocation = shaderProgram->uniformLocation(
"uView");
209 shaderProgram->setUniformValue(viewLocation, view);
210 int projectionLocation = shaderProgram->uniformLocation(
"uProjection");
211 shaderProgram->setUniformValue(projectionLocation, projection);
213 int textureBlendLocation = shaderProgram->uniformLocation(
"uTextureBlend");
216 int lightingModeLocation = shaderProgram->uniformLocation(
"uLightingMode");
219 int texLocation = shaderProgram->uniformLocation(
"uTexture");
222 auto texture = image ==
nullptr ? textureManager->whiteTexture() : textureManager->getTexture(image);
224 shaderProgram->setUniformValue(texLocation, 0);
226 QOpenGLBuffer indexBuffer(QOpenGLBuffer::IndexBuffer);
227 indexBuffer.create();
229 indexBuffer.allocate(mesh.
indices().data(), mesh.
indices().size() *
sizeof(
unsigned int));
231 switch (meshInstance.
mesh()->primitiveType())
234 glDrawElements(GL_LINES, mesh.
indices().size(), GL_UNSIGNED_INT, 0);
237 glDrawElements(GL_LINE_STRIP, mesh.
indices().size(), GL_UNSIGNED_INT, 0);
240 glDrawElements(GL_LINE_LOOP, mesh.
indices().size(), GL_UNSIGNED_INT, 0);
243 glDrawElements(GL_POINTS, mesh.
indices().size(), GL_UNSIGNED_INT, 0);
246 glDrawElements(GL_TRIANGLES, mesh.
indices().size(), GL_UNSIGNED_INT, 0);
250 glDrawElements(GL_QUADS, mesh.
indices().size(), GL_UNSIGNED_INT, 0);
253 gl.glBindTexture(GL_TEXTURE_2D, 0);
255 indexBuffer.destroy();
259 normalBuffer.destroy();
263 textureCoordinatesBuffer.destroy();
265 positionBuffer.release(QOpenGLBuffer::VertexBuffer);
266 positionBuffer.destroy();
308 glColor3f(1.0, 0.0, 0.0);
312 glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
316 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
320 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
324 glShadeModel(GL_FLAT);
328 glShadeModel(GL_SMOOTH);
332 glEnable(GL_LIGHTING);
333 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
335 static GLfloat ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
336 static GLfloat ambientBIS[] = {0.8f, 0.8f, 0.8f, 0.8f};
337 static GLfloat diffuse[] = {0.8f, 0.8f, 0.8f, 1.0f};
338 static GLfloat specular[] = {0.8f, 0.8f, 0.8f, 1.0f};
339 static GLfloat shininess = 50.;
340 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientBIS);
341 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
342 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
343 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
344 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
346 glMatrixMode(GL_PROJECTION);
367 if (pElement->
isA(
"TYGeometryNode"))
410 GLint polygon_mode[2];
411 glGetIntegerv(GL_POLYGON_MODE, polygon_mode);
417 glMatrixMode(GL_PROJECTION);
419 glMatrixMode(GL_MODELVIEW);
420 glLoadMatrixf(currentCamera->
viewMatrix().constData());
424 glMatrixMode(GL_MODELVIEW);
434 for (
int il = 0; il <
_tabLights.size(); il++)
440 float colorSpec[] = {0.0, 0.0, 0.0, 1.0};
441 float colorShine[] = {127.0};
442 glMaterialfv(GL_FRONT, GL_SPECULAR, colorSpec);
443 glMaterialfv(GL_FRONT, GL_SHININESS, colorShine);
444 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
445 glEnable(GL_COLOR_MATERIAL);
448 glEnable(GL_MULTISAMPLE);
450 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
452 glEnable(GL_NORMALIZE);
453 glEnable(GL_DEPTH_TEST);
456 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
463 glGetFloatv(GL_PROJECTION_MATRIX, proj);
465 glGetIntegerv(GL_VIEWPORT, viewport);
467 glMatrixMode(GL_PROJECTION);
473 glMatrixMode(GL_MODELVIEW);
477 glMatrixMode(GL_PROJECTION);
488 std::vector<TYElement*>::iterator iterElements;
498 if (*iterElements !=
nullptr)
501 if (pTYElementGraphic !=
nullptr)
503 pTYElementGraphic->
display(renderContext);
513 glMatrixMode(GL_MODELVIEW);
517 std::vector<OGLMeshInstance> meshInstances;
520 std::vector<OGLMeshInstance> meshInstancesInProjectSpace;
522 meshInstancesInProjectSpace, &renderContext);
523 std::vector<OGLMeshInstance> meshInstancesInModelerSpace;
524 for (
auto& meshInstance : meshInstancesInProjectSpace)
526 meshInstances.emplace_back(meshInstance.mesh(),
538 glDisable(GL_LIGHTING);
539 std::vector<OGLElement*>::iterator iter;
547 glPolygonMode(GL_FRONT_AND_BACK, polygon_mode[0]);
559 std::vector<OGLMeshInstance> meshInstances = {};
566 if (pParent && pParent->
isA(
"TYProjet"))
568 pGraphObj = pParent->getGraphicObject();
572 glRotatef(-90.0, 1.0, 0.0, 0.0);
575 pGraphObj->
display(renderContext);
582 bool _bFinded =
false;
583 std::vector<OGLElement*>::iterator iter;
614 std::vector<OGLElement*>::iterator iter;
615 bool _bFinded =
false;
629 bool _bFinded =
false;
630 std::vector<TYElement*>::iterator iter;
646 std::vector<TYElement*>::iterator iter;
647 bool _bFinded =
false;
664 void gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, GLint viewport[4])
666 if (deltax <= 0 || deltay <= 0)
672 glTranslated((viewport[2] - 2 * (x - viewport[0])) / deltax,
673 (viewport[3] - 2 * (y - viewport[1])) / deltay, 0);
674 glScaled(viewport[2] / deltax, viewport[3] / deltay, 1.0);
678 const std::vector<OGLMeshInstance>& meshInstances)
const
685 viewMatrix.rotate(90, -1, 0, 0);
687 QMatrix4x4 projectionMatrix = camera->projectionMatrix();
691 QMatrix4x4 invView = viewMatrix.inverted(&ok);
693 const QVector3D camPosWS = invView.map(QVector3D(0.0f, 0.0f, 0.0f));
695 QVector3D camFwdWS = invView.mapVector(QVector3D(0.0f, 0.0f, -1.0f));
696 camFwdWS.normalize();
699 const QVector3D downDirWS(0.0f, 0.0f, -1.0f);
703 shaderProgram->bind();
706 shaderProgram->setUniformValue(
"uCamPosWS", camPosWS);
707 shaderProgram->setUniformValue(
"uCamFwdWS", camFwdWS);
710 shaderProgram->setUniformValue(
"uGlobalAmbient", QVector3D(0.8f, 0.8f, 0.8f));
711 shaderProgram->setUniformValue(
"uKa", 0.8f);
712 shaderProgram->setUniformValue(
"uKd", 0.8f);
713 shaderProgram->setUniformValue(
"uKsDown", 0.0f);
714 shaderProgram->setUniformValue(
"uKsHeadlight", 0.0f);
715 shaderProgram->setUniformValue(
"uShininess", 50.0f);
718 shaderProgram->setUniformValue(
"uDownDirWS", QVector3D(0.0f, 0.0f, -1.0f));
719 shaderProgram->setUniformValue(
"uDownIntensity", 1.0f);
720 shaderProgram->setUniformValue(
"uHeadlightIntensity", 1.0f);
723 shaderProgram->setUniformValue(
"uCamWrap", 0.0f);
724 shaderProgram->setUniformValue(
"uCamPointWeight", 0.0f);
725 shaderProgram->setUniformValue(
"uGrazingFill", 0.0f);
726 shaderProgram->setUniformValue(
"uHeadlightFloor", 0.0f);
733 std::shared_ptr<OGLArrayMesh> lineMesh = std::make_shared<OGLArrayMesh>();
734 lineMesh->material() = meshInstance.mesh()->material();
735 lineMesh->fromQuadMeshEdges(*meshInstance.mesh());
736 OGLMeshInstance lineMeshInstance(lineMesh, meshInstance.globalMatrix());
737 drawMeshInstance(lineMeshInstance, shaderProgram, viewMatrix, projectionMatrix);
741 drawMeshInstance(meshInstance, shaderProgram, viewMatrix, projectionMatrix);
744 shaderProgram->release();
Gestionnaire de textures.
Representation graphique d'un ensemble de volumes acoustiques (fichier header)
Representation graphique de l'altimetrie (fichier header)
Representation graphique d'une courbe de niveau (fichier header)
Representation graphique d'un element de base (fichier header)
list< TYElementGraphic * > TYListPtrTYElementGraphic
List de pointeur de TYElement.
Representation graphique d'un GeometryNode (fichier header)
void gluPickMatrix(GLdouble x, GLdouble y, GLdouble deltax, GLdouble deltay, GLint viewport[4])
void drawMeshInstance(const OGLMeshInstance &meshInstance, QOpenGLShaderProgram *shaderProgram, const QMatrix4x4 &view, const QMatrix4x4 &projection)
Realise le rendu VTK et le rendu OpenGL (fichier header)
Contexte de rendu utilisé par les fonctions d'affichage.
@ Display
The current render is intended to be displayed on screen.
@ Picking
The current render is only done for picking purpose.
@ Overlay
The current render pass is for overlay elements.
@ Default
The current render pass is for 3D elements.
Representation graphique d'un reseau electrique (fichier header)
Representation graphique d'un ensemble de sites (fichier header)
OPoint3D _min
Minimal coordinates of the OBox.
OPoint3D _max
Maximal coordinates of the OBox.
double _y
y coordinate of OCoord3D
double _z
z coordinate of OCoord3D
double _x
x coordinate of OCoord3D
void getPosition(double &x, double &y, double &z) const
const QMatrix4x4 & projectionMatrix() const
const QMatrix4x4 & viewMatrix() const
const QMatrix4x4 & globalMatrix() const
std::shared_ptr< const OGLMesh > mesh() const
const std::vector< unsigned int > & indices() const
const std::vector< QVector3D > & normals() const
const std::vector< QVector3D > & vertices() const
const std::vector< QVector2D > & textureCoordinates() const
OGLSimpleMaterial & material()
const std::vector< float > & verticesColors() const
static OGLShaderManager * instance(QOpenGLContext *context)
QOpenGLShaderProgram * getShaderProgram(ShaderId shaderId)
TextureBlend textureBlend
LightingMode lightingMode
static OGLSimpleMaterial BOUNDING_BOX
std::shared_ptr< QImage > image
static OGLTextureManager * instance(QOpenGLContext *context)
bool isA(const char *className) const
classe graphique pour une ligne acoustique
classe graphique pour un ensemble de volumes acoustiques
classe graphique pour une altimetrie
classe graphique pour une courbe de niveau
classe graphique pour un element de base
virtual void update(bool force=false)
bool isBoundingBoxVisible() const
virtual void getChilds(TYListPtrTYElementGraphic &childs, bool recursif=true)
virtual void display(TYRenderContext &renderContext)
QMatrix4x4 globalMatrix() const
virtual void collectMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext) const
void setVisible(bool visible=true)
TYElement * getParent() const
classe graphique pour un GeometryNode
void displayPushingParentMatrix(TYRenderContext &renderContext, TYGeometryNode *pDansCeRepere)
TYGeometryNode * GetGeoNodeParent() const
static TYGeometryNode * GetGeoNode(TYElement *pElement)
std::vector< TYElement * > _tabSelectedElements
Elements selectionnes.
void _renderScene(TYRenderContext &renderContext) const
0 --> render all, 1 --> render 2D, 2 --> render 3D
void removeSelectedElement(TYElement *pElement)
void addLight(OGLLightElement *pOGLElementLight)
void addOGLElement(OGLElement *pOGLElement)
void invalidateScene(void)
void clearTabSelectedElement()
void removeOGLElement(OGLElement *pOGLElement)
std::vector< OGLLightElement * > _tabLights
Liste des lumieres dans la scene 3D.
void collectMeshInstances(TYElementGraphic *elementGraphic, std::vector< OGLMeshInstance > &meshInstances, TYRenderContext *renderContext)
QMatrix4x4 _boundingBoxScaleMatrix
GLuint _displayList
Display liste globale.
void addBoundingBoxMeshInstances(std::vector< OGLMeshInstance > &meshInstances, TYElementGraphic *element)
RenderMode _renderMode
Mode de rendu.
OGLCamera * _pActiveCamera
void updateDisplayListOverlay(TYRenderContext &renderContext, TYGeometryNode *pElement, TYGeometryNode *pDansCeRepere)
std::vector< OGLElement * > _tabOGLElement
void setRenderMode(RenderMode mode)
double * _pBackgroundColor
std::vector< OGLLightElement * > getLights()
void drawMeshInstances(TYRenderContext &renderContext, const std::vector< OGLMeshInstance > &meshInstances) const
GLuint _displayListOverlay
Display liste pour les deplacements.
void drawElement(TYRenderContext &renderContext) const
RenderMode getRenderMode()
bool _sceneRenderCacheIsDirty
void OpenGLRender(TYRenderContext &renderContext, int x=0, int y=0)
void addSelectedElement(TYElement *pElement)
TYRenderViewport viewport
TYElement * modelerElement
QMatrix4x4 globalToModelerMatrix
const OGLCamera * camera() const
clase graphique pour un ensemble de sites