Kstars

texturemanager.h
1 /*
2  SPDX-FileCopyrightText: 2010 Henry de Valence <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include <QObject>
10 #include <QHash>
11 
12 #include <config-kstars.h>
13 
14 class QGLWidget;
15 class QImage;
16 
17 /**
18  * @brief a singleton class to manage texture loading/retrieval
19  */
20 class TextureManager : public QObject
21 {
22  Q_OBJECT
23  public:
24  /** @short Create the instance of TextureManager */
25  static TextureManager *Create();
26  /** @short Release the instance of TextureManager */
27  static void Release();
28 
29  /**
30  * Return texture image. If image is not found in cache tries to
31  * load it from disk if that fails too returns reference to empty image.
32  */
33  static const QImage &getImage(const QString &name);
34 
35  /**
36  * Clear the cache and discover the directories to load textures from.
37  */
38  static void discoverTextureDirs();
39 #ifdef HAVE_OPENGL
40  /**
41  * Bind OpenGL texture. Acts similarly to getImage but does
42  * nothing if image is not found in the end
43  */
44  static void bindTexture(const QString &name, QGLWidget *cxt);
45 
46  /** Bind OpenGL texture using QImage as source */
47  static void bindFromImage(const QImage &image, QGLWidget *cxt);
48 #endif
49 
50  private:
51  /** Shorthand for iterator to hashtable */
53 
54  /** Private constructor */
55  explicit TextureManager(QObject *parent = nullptr);
56  /** Try find image in the cache and then to load it from disk if it's not found */
57  static CacheIter findTexture(const QString &name);
58 
59  // Pointer to singleton instance
60  static TextureManager *m_p;
61  // List of named textures
62  QHash<QString, QImage> m_textures;
63 
64  // List of texture directories
65  std::vector<QString> m_texture_directories;
66 
67  // Prohibit copying
69  TextureManager &operator=(const TextureManager &);
70 };
Q_OBJECTQ_OBJECT
a singleton class to manage texture loading/retrieval
static TextureManager * Create()
Create the instance of TextureManager.
static const QImage & getImage(const QString &name)
Return texture image.
QObject * parent() const const
static void Release()
Release the instance of TextureManager.
static void discoverTextureDirs()
Clear the cache and discover the directories to load textures from.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:58 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.