Kstars

texturemanager.h
1/*
2 SPDX-FileCopyrightText: 2010 Henry de Valence <hdevalence@gmail.com>
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
14class QGLWidget;
15class QImage;
16
17/**
18 * @brief a singleton class to manage texture loading/retrieval
19 */
20class TextureManager : public QObject
21{
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};
a singleton class to manage texture loading/retrieval
static const QImage & getImage(const QString &name)
Return texture image.
static void discoverTextureDirs()
Clear the cache and discover the directories to load textures from.
static void Release()
Release the instance of TextureManager.
static TextureManager * Create()
Create the instance of TextureManager.
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.