2012-12-28 20:21:05 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Classes to render a stroke with OpenGL
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
#include "StrokeRenderer.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
#include "../geometry/GeomUtils.h"
|
2012-12-28 20:21:05 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
/**********************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* StrokeRenderer */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/**********************************/
|
|
|
|
|
|
|
|
|
|
TextureManager *StrokeRenderer::_textureManager = 0;
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
StrokeRenderer::StrokeRenderer()
|
|
|
|
|
{
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
StrokeRenderer::~StrokeRenderer()
|
|
|
|
|
{
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
bool StrokeRenderer::loadTextures()
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
_textureManager->load();
|
|
|
|
|
return true;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**********************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* TextureManager */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/**********************************/
|
|
|
|
|
|
2013-03-11 06:56:51 +00:00
|
|
|
TextureManager *TextureManager::_pInstance = 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
|
|
|
|
|
string TextureManager::_patterns_path;
|
|
|
|
|
|
|
|
|
|
string TextureManager::_brushes_path;
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
TextureManager::TextureManager()
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
_hasLoadedTextures = false;
|
|
|
|
|
_pInstance = this;
|
|
|
|
|
_defaultTextureId = 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
TextureManager::~TextureManager()
|
2008-04-30 15:41:54 +00:00
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!_brushesMap.empty()) {
|
2019-04-17 06:17:24 +02:00
|
|
|
_brushesMap.clear();
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
_pInstance = 0;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextureManager::load()
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_hasLoadedTextures) {
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
loadStandardBrushes();
|
|
|
|
|
_hasLoadedTextures = true;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned TextureManager::getBrushTextureIndex(string name, Stroke::MediumType loadingMode)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
BrushTexture bt(name, loadingMode);
|
|
|
|
|
brushesMap::iterator b = _brushesMap.find(bt);
|
|
|
|
|
if (b == _brushesMap.end()) {
|
|
|
|
|
unsigned texId = loadBrush(name, loadingMode);
|
|
|
|
|
_brushesMap[bt] = texId;
|
|
|
|
|
return texId;
|
|
|
|
|
// XXX!
|
|
|
|
|
cerr << "brush file " << name << " not found" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return _brushesMap[bt];
|
|
|
|
|
}
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void TextureManager::Options::setPatternsPath(const string &path)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
_patterns_path = path;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
string TextureManager::Options::getPatternsPath()
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return _patterns_path;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
void TextureManager::Options::setBrushesPath(const string &path)
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
_brushes_path = path;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
string TextureManager::Options::getBrushesPath()
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
return _brushes_path;
|
2008-04-30 15:41:54 +00:00
|
|
|
}
|
2013-04-09 00:46:49 +00:00
|
|
|
|
|
|
|
|
} /* namespace Freestyle */
|