Blender  V2.93
StrokeRenderer.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
22 #include "StrokeRenderer.h"
23 
24 #include "../geometry/GeomUtils.h"
25 
26 using namespace std;
27 
28 namespace Freestyle {
29 
30 /**********************************/
31 /* */
32 /* */
33 /* StrokeRenderer */
34 /* */
35 /* */
36 /**********************************/
37 
38 TextureManager *StrokeRenderer::_textureManager = nullptr;
39 
40 StrokeRenderer::~StrokeRenderer() = default;
41 
42 bool StrokeRenderer::loadTextures()
43 {
44  _textureManager->load();
45  return true;
46 }
47 
48 /**********************************/
49 /* */
50 /* */
51 /* TextureManager */
52 /* */
53 /* */
54 /**********************************/
55 
56 TextureManager *TextureManager::_pInstance = nullptr;
57 
58 string TextureManager::_patterns_path;
59 
60 string TextureManager::_brushes_path;
61 
62 TextureManager::TextureManager()
63 {
64  _hasLoadedTextures = false;
65  _pInstance = this;
66  _defaultTextureId = 0;
67 }
68 
69 TextureManager::~TextureManager()
70 {
71  if (!_brushesMap.empty()) {
72  _brushesMap.clear();
73  }
74  _pInstance = nullptr;
75 }
76 
78 {
79  if (_hasLoadedTextures) {
80  return;
81  }
82  loadStandardBrushes();
83  _hasLoadedTextures = true;
84 }
85 
86 unsigned TextureManager::getBrushTextureIndex(string name, Stroke::MediumType iType)
87 {
88  BrushTexture bt(name, iType);
89  brushesMap::iterator b = _brushesMap.find(bt);
90  if (b == _brushesMap.end()) {
91  unsigned texId = loadBrush(name, iType);
92  _brushesMap[bt] = texId;
93  return texId;
94  // XXX!
95  cerr << "brush file " << name << " not found" << endl;
96  return 0;
97  }
98 
99  return _brushesMap[bt];
100 }
101 
102 void TextureManager::Options::setPatternsPath(const string &path)
103 {
104  _patterns_path = path;
105 }
106 
107 string TextureManager::Options::getPatternsPath()
108 {
109  return _patterns_path;
110 }
111 
112 void TextureManager::Options::setBrushesPath(const string &path)
113 {
114  _brushes_path = path;
115 }
116 
117 string TextureManager::Options::getBrushesPath()
118 {
119  return _brushes_path;
120 }
121 
122 } /* namespace Freestyle */
Classes to render a stroke with OpenGL.
std::pair< string, Stroke::MediumType > BrushTexture
int load(istream &in, Vec3r &v)
Definition: ViewMapIO.cpp:61
inherits from class Rep
Definition: AppCanvas.cpp:32