Code_TYMPAN  4.4.0
Industrial site acoustic simulation
OGLTextureManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012-2024> <EDF-DTG> <FRANCE>
3  * This file is part of Code_TYMPAN (R).
4  * Code_TYMPAN (R) is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * Code_TYMPAN (R) is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  * See the GNU General Public License for more details.
12  * You should have received a copy of the GNU General Public License along
13  * with Code_TYMPAN (R). If not, see <https://www.gnu.org/licenses/>.
14  */
15 
27 #ifndef __O_TEXTURE_MANAGER__
28 #define __O_TEXTURE_MANAGER__
29 
34 #include <memory>
35 #include <qobject.h>
36 #include <qoffscreensurface.h>
37 #include <qopenglcontext.h>
38 #include <qopengltexture.h>
39 
51 {
52 public:
53  static OGLTextureManager* instance(QOpenGLContext* context);
54  QOpenGLTexture* getTexture(const std::shared_ptr<QImage>& image);
55  QOpenGLTexture* whiteTexture();
56  QOpenGLTexture* fallbackTexture();
57 
58 private:
59  /*
60  * Initialize a new texture manager usable by a given context.
61  */
62  OGLTextureManager(QOpenGLContext* context);
63 
64  ~OGLTextureManager() = default;
65 
66  void initializeTextures();
67 
68  std::map<std::weak_ptr<QImage>, std::unique_ptr<QOpenGLTexture>, std::owner_less<>> imageTextures;
69  QOpenGLTexture _fallbackTexture;
70  QOpenGLTexture _whiteTexture;
71 
72  static QMap<QOpenGLContext*, OGLTextureManager*> instances;
73 };
74 
75 #endif // __O_TEXTURE_MANAGER__
Class allowing to handle textures lifetime.
static QMap< QOpenGLContext *, OGLTextureManager * > instances
QOpenGLTexture * fallbackTexture()
OGLTextureManager(QOpenGLContext *context)
QOpenGLTexture _fallbackTexture
QOpenGLTexture _whiteTexture
static OGLTextureManager * instance(QOpenGLContext *context)
~OGLTextureManager()=default
std::map< std::weak_ptr< QImage >, std::unique_ptr< QOpenGLTexture >, std::owner_less<> > imageTextures
QOpenGLTexture * getTexture(const std::shared_ptr< QImage > &image)
QOpenGLTexture * whiteTexture()