Overte C++ Documentation
TextureBaker.h
1 //
2 // TextureBaker.h
3 // tools/oven/src
4 //
5 // Created by Stephen Birarda on 4/5/17.
6 // Copyright 2017 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_TextureBaker_h
13 #define hifi_TextureBaker_h
14 
15 #include <QtCore/QObject>
16 #include <QtCore/QUrl>
17 #include <QtCore/QRunnable>
18 #include <QDir>
19 #include <QImageReader>
20 
21 #include <image/TextureProcessing.h>
22 
23 #include "Baker.h"
24 
25 #include <graphics/Material.h>
26 
27 extern const QString BAKED_TEXTURE_KTX_EXT;
28 extern const QString BAKED_META_TEXTURE_SUFFIX;
29 
30 class TextureBaker : public Baker {
31  Q_OBJECT
32 
33 public:
34  TextureBaker(const QUrl& textureURL, image::TextureUsage::Type textureType,
35  const QDir& outputDirectory, const QString& baseFilename = QString(),
36  const QByteArray& textureContent = QByteArray());
37 
38  const QByteArray& getOriginalTexture() const { return _originalTexture; }
39 
40  QUrl getTextureURL() const { return _textureURL; }
41 
42  QString getBaseFilename() const { return _baseFilename; }
43 
44  QString getMetaTextureFileName() const { return _metaTextureFileName; }
45 
46  virtual void setWasAborted(bool wasAborted) override;
47 
48  static void setCompressionEnabled(bool enabled) { _compressionEnabled = enabled; }
49 
50  void setMapChannel(graphics::Material::MapChannel mapChannel) { _mapChannel = mapChannel; }
51  graphics::Material::MapChannel getMapChannel() const { return _mapChannel; }
52  image::TextureUsage::Type getTextureType() const { return _textureType; }
53 
54 public slots:
55  virtual void bake() override;
56  virtual void abort() override;
57 
58 signals:
59  void originalTextureLoaded();
60 
61 private slots:
62  void processTexture();
63 
64 private:
65  void loadTexture();
66  void handleTextureNetworkReply();
67 
68  QUrl _textureURL;
69  QByteArray _originalTexture;
70  image::TextureUsage::Type _textureType;
71  graphics::Material::MapChannel _mapChannel;
72  bool _mapChannelSet { false };
73 
74  QString _baseFilename;
75  QDir _outputDirectory;
76  QString _metaTextureFileName;
77  QUrl _originalCopyFilePath;
78 
79  std::atomic<bool> _abortProcessing { false };
80 
81  static bool _compressionEnabled;
82 };
83 
84 #endif // hifi_TextureBaker_h