Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cegui0.8_ogre1.9/src/libraries/tools/TextureGenerator.cc @ 11787

Last change on this file since 11787 was 11071, checked in by landauf, 9 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file
31    @brief Implementation of the TextureGenerator.
32*/
33
34#include "TextureGenerator.h"
35
36#include <OgreMaterialManager.h>
37#include <OgreTechnique.h>
38#include "util/Convert.h"
39#include "util/Math.h"
40
41#if _MSC_VER >= 1900
42#define STLSPEC constexpr
43#else
44#define STLSPEC inline
45#endif
46
47namespace std
48{
49    template <>
50    STLSPEC bool less<orxonox::ColourValue>::operator()(const orxonox::ColourValue& __x, const orxonox::ColourValue& __y) const
51    {
52        //MSVC14 needs this function to be constexpr, but doesn't support C++14's style
53        //Keep the old code around for superior readability
54        //if (__x.r == __y.r)
55        //{
56        //    if (__x.g == __y.g)
57        //    {
58        //        if (__x.b == __y.b)
59        //        {
60        //            return __x.a < __y.a;
61        //        }
62        //        return __x.b < __y.b;
63        //    }
64        //    return __x.g < __y.g;
65        //}
66        //return __x.r < __y.r;
67        return __x.r == __y.r ? __x.g == __y.g ? __x.b == __y.b ? __x.a < __y.a : __x.b < __y.b : __x.g < __y.g :  __x.r < __y.r;
68    }
69}
70
71namespace orxonox
72{
73    std::map<std::string, std::map<ColourValue, std::string>> TextureGenerator::materials_s;
74    unsigned int TextureGenerator::materialCount_s = 0;
75
76    /*static*/ const std::string& TextureGenerator::getMaterialName(const std::string& textureName, const ColourValue& colour)
77    {
78        std::map<ColourValue, std::string>& colourMap = materials_s[textureName];
79        std::map<ColourValue, std::string>::const_iterator it = colourMap.find(colour);
80
81        if (it == colourMap.end())
82        {
83            const std::string& materialName = textureName + "_Material_" + multi_cast<std::string>(materialCount_s++);
84            Ogre::MaterialPtr material = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().create(materialName, "General"));
85            material->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
86            Ogre::TextureUnitState* textureUnitState = material->getTechnique(0)->getPass(0)->createTextureUnitState();
87            textureUnitState->setTextureName(textureName);
88            textureUnitState->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, colour);
89            return (colourMap[colour] = materialName);
90        }
91        else
92        {
93            return it->second;
94        }
95    }
96}
Note: See TracBrowser for help on using the repository browser.