Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
GlOffscreenRenderer.h
1/*
2 *
3 * This file is part of Tulip (https://tulip.labri.fr)
4 *
5 * Authors: David Auber and the Tulip development Team
6 * from LaBRI, University of Bordeaux
7 *
8 * Tulip is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * Tulip is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 */
19///@cond DOXYGEN_HIDDEN
20
21#ifndef GLOFFSCREENRENDERER_H_
22#define GLOFFSCREENRENDERER_H_
23
24#include <tulip/tulipconf.h>
25#include <tulip/Coord.h>
26#include <tulip/GlScene.h>
27
28#include <tulip/OpenGlIncludes.h>
29
30#include <QImage>
31
32class QOpenGLContext;
33class QOffscreenSurface;
34class QOpenGLFramebufferObject;
35
36namespace tlp {
37
38class GlSimpleEntity;
39class GlGraphComposite;
40class GlMainWidget;
41
42/**
43 * @brief Render a scene in an image or in a texture.
44 *
45 * Here is an example to render a graph in a QImage to use it as preview.
46 * @code
47 * //Get the renderer
48 * glOffscreenRenderer *glOffscreenRenderer = GlOffscreenRenderer::getInstance();
49 * //Define the viewport size. Needed to initialize the offscreen rederer.
50 * glOffscreenRenderer->setViewPortSize(200,200);
51 * //Erase old elements
52 * glOffscreenRenderer->clearScene();
53 * //Change the background color of the scene to white
54 * glOffscreenRenderer->setSceneBackgroundColor(Color(255,255,255,255));
55 * //Add
56 * //Center and render the scene.
57 * glOffscreenRenderer->renderScene(true);
58 * //Get the result
59 * QImage preview = glOffscreenRenderer->getGLTexture(true);
60 * @endcode
61 **/
62class TLP_QT_SCOPE GlOffscreenRenderer {
63
64public:
65 /**
66 * @brief Get the renderer instance.
67 **/
68 inline static GlOffscreenRenderer *getInstance() {
69 return instance;
70 }
71
72 ~GlOffscreenRenderer();
73
74 /**
75 * @brief Define the viewport size.
76 **/
77 void setViewPortSize(const unsigned int viewPortWidth, const unsigned int viewPortHeight);
78 unsigned int getViewportWidth();
79 unsigned int getViewportHeight();
80
81 GlScene *getScene() {
82 return &scene;
83 }
84 void setZoomFactor(double zoomFactor) {
85 this->zoomFactor = zoomFactor;
86 }
87 void setCameraCenter(const Coord &cameraCenter) {
88 this->cameraCenter = cameraCenter;
89 }
90
91 void setSceneBackgroundColor(const Color &color);
92 /**
93 * @brief Add an entity to the scene. The scene become the owner of the object.
94 **/
95 void addGlEntityToScene(GlSimpleEntity *entity);
96 /**
97 * @brief Add a graph composite to the scene. The scene become the owner of the object.
98 **/
99 void addGraphCompositeToScene(GlGraphComposite *graphComposite);
100
101 /**
102 * @brief Add a graph to the scene. Just create a new GraphComposite and call GlGraphComposite.
103 **/
104 void addGraphToScene(Graph *graph);
105
106 /**
107 * @brief Delete all the elements of the scene and clear it.
108 **/
109 void clearScene(bool deleteGlEntities = false);
110
111 /**
112 * @brief Render the scene in a buffer. You need to call this function before getting the result
113 *with getImage or getGlTexture.
114 **/
115 void renderScene(const bool centerScene = true, const bool antialiased = false);
116
117 void renderExternalScene(GlScene *scene, const bool antialiased = false);
118
119 QImage renderGlMainWidget(GlMainWidget *glWidget, bool redrawNeeded);
120
121 /**
122 * @brief Generate a QImage from the scene. You need to call the renderScene function before this
123 *function.
124 **/
125 QImage getImage(bool alpha = false);
126 /**
127 * @brief Generate an open gl texture from the scene. You need to call the renderScene function
128 *before this function.
129 **/
130 GLuint getGLTexture(const bool generateMipMaps = false);
131
132 QOpenGLContext *getOpenGLContext();
133 void makeOpenGLContextCurrent();
134 void doneOpenGLContextCurrent();
135
136private:
137 GlOffscreenRenderer();
138
139 void initFrameBuffers(const bool antialiased);
140
141 static GlOffscreenRenderer *instance;
142
143 QOpenGLContext *glContext;
144 QOffscreenSurface *offscreenSurface;
145
146 unsigned int vPWidth, vPHeight;
147 QOpenGLFramebufferObject *glFrameBuf, *glFrameBuf2;
148 GlScene scene;
149 GlLayer *mainLayer;
150 unsigned int entitiesCpt;
151 double zoomFactor;
152 Coord cameraCenter;
153 bool antialiasedFbo;
154};
155} // namespace tlp
156
157#endif /* GLOFFSCREENRENDERER_H_ */
158///@endcond