1 /* 2 ----------------------------------------------------------------------------- 3 This source file is part of OGRE 4 (Object-oriented Graphics Rendering Engine) 5 For the latest info, see http://www.ogre3d.org/ 6 7 Copyright (c) 2000-2014 Torus Knot Software Ltd 8 9 Permission is hereby granted, free of charge, to any person obtaining a copy 10 of this software and associated documentation files (the "Software"), to deal 11 in the Software without restriction, including without limitation the rights 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 copies of the Software, and to permit persons to whom the Software is 14 furnished to do so, subject to the following conditions: 15 16 The above copyright notice and this permission notice shall be included in 17 all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 THE SOFTWARE. 26 ----------------------------------------------------------------------------- 27 */ 28 29 /*************************************************************************** 30 OgreExternalTextureSource.cpp - 31 Implementation of texture controller class 32 33 ------------------- 34 date : Jan 1 2004 35 email : pjcast@yahoo.com 36 ***************************************************************************/ 37 38 #include "OgreStableHeaders.h" 39 #include "OgreExternalTextureSource.h" 40 41 namespace Ogre 42 { 43 //String interface commands for setting some basic commands 44 ExternalTextureSource::CmdInputFileName ExternalTextureSource::msCmdInputFile; 45 ExternalTextureSource::CmdFPS ExternalTextureSource::msCmdFramesPerSecond; 46 ExternalTextureSource::CmdPlayMode ExternalTextureSource::msCmdPlayMode; 47 ExternalTextureSource::CmdTecPassState ExternalTextureSource::msCmdTecPassState; 48 49 //---------------------------------------------------------------------------------------// 50 ExternalTextureSource()51 ExternalTextureSource::ExternalTextureSource() : mTechniqueLevel(0), mPassLevel(0), mStateLevel(0) 52 { 53 mInputFileName = "None"; 54 mDictionaryName = "NotAssigned"; 55 mUpdateEveryFrame = false; 56 mFramesPerSecond = 24; 57 mMode = TextureEffectPause; 58 } 59 60 //---------------------------------------------------------------------------------------// 61 addBaseParams()62 void ExternalTextureSource::addBaseParams() 63 { 64 if( mDictionaryName == "NotAssigned" ) 65 OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND, 66 "Plugin " + mPluginName + 67 " needs to override default mDictionaryName", 68 "ExternalTextureSource::addBaseParams"); 69 70 //Create Dictionary Here 71 if (createParamDictionary( mDictionaryName )) 72 { 73 ParamDictionary* dict = getParamDictionary(); 74 75 dict->addParameter(ParameterDef("filename", 76 "A source for the texture effect (only certain plugins require this)" 77 , PT_STRING), 78 &ExternalTextureSource::msCmdInputFile); 79 dict->addParameter(ParameterDef("frames_per_second", 80 "How fast should playback be (only certain plugins use this)" 81 , PT_INT), 82 &ExternalTextureSource::msCmdFramesPerSecond); 83 dict->addParameter(ParameterDef("play_mode", 84 "How the playback starts(only certain plugins use this)" 85 , PT_STRING), 86 &ExternalTextureSource::msCmdPlayMode); 87 dict->addParameter(ParameterDef("set_T_P_S", 88 "Set the technique, pass, and state level of this texture_unit (eg. 0 0 0 )" 89 , PT_STRING), 90 &ExternalTextureSource::msCmdTecPassState); 91 } 92 } 93 94 //---------------------------------------------------------------------------------------// 95 //*** String Interface Command Class Definitions *****************************************/ doGet(const void * target) const96 String ExternalTextureSource::CmdInputFileName::doGet(const void* target) const 97 { 98 return static_cast<const ExternalTextureSource*>(target)->getInputName(); 99 } doSet(void * target,const String & val)100 void ExternalTextureSource::CmdInputFileName::doSet(void* target, const String& val) 101 { 102 static_cast<ExternalTextureSource*>(target)->setInputName( val ); 103 } 104 105 //------------------------------------------------------------------------------// doGet(const void * target) const106 String ExternalTextureSource::CmdFPS::doGet(const void* target) const 107 { 108 return StringConverter::toString( 109 static_cast<const ExternalTextureSource*>(target)->getFPS() ); 110 } doSet(void * target,const String & val)111 void ExternalTextureSource::CmdFPS::doSet(void* target, const String& val) 112 { 113 static_cast<ExternalTextureSource*>(target)->setFPS(StringConverter::parseInt(val)); 114 } 115 //------------------------------------------------------------------------------// doGet(const void * target) const116 String ExternalTextureSource::CmdPlayMode::doGet(const void* target) const 117 { 118 eTexturePlayMode eMode = static_cast<const ExternalTextureSource*>(target)->getPlayMode(); 119 String val; 120 121 switch(eMode) 122 { 123 case TextureEffectPlay_ASAP: 124 val = "play"; 125 break; 126 case TextureEffectPlay_Looping: 127 val = "loop"; 128 break; 129 case TextureEffectPause: 130 val = "pause"; 131 break; 132 default: 133 val = "error"; 134 break; 135 } 136 137 return val; 138 } doSet(void * target,const String & val)139 void ExternalTextureSource::CmdPlayMode::doSet(void* target, const String& val) 140 { 141 eTexturePlayMode eMode = TextureEffectPause; 142 143 if( val == "play" ) 144 eMode = TextureEffectPlay_ASAP; 145 if( val == "loop" ) 146 eMode = TextureEffectPlay_Looping; 147 if( val == "pause" ) 148 eMode = TextureEffectPause; 149 150 static_cast<ExternalTextureSource*>(target)->setPlayMode( eMode ); 151 } 152 153 //------------------------------------------------------------------------------// doGet(const void * target) const154 String ExternalTextureSource::CmdTecPassState::doGet(const void* target) const 155 { 156 int t = 0, p = 0, s = 0; 157 158 static_cast<const ExternalTextureSource*>(target)->getTextureTecPassStateLevel(t, p, s); 159 160 String ret = StringConverter::toString( t ) + " " 161 + StringConverter::toString( p ) + " " 162 + StringConverter::toString( s ); 163 164 return ret; 165 } 166 doSet(void * target,const String & val)167 void ExternalTextureSource::CmdTecPassState::doSet(void* target, const String& val) 168 { 169 int t = 0, p = 0, s = 0; 170 171 StringVector vecparams = StringUtil::split(val, " \t"); 172 173 if( vecparams.size() == 3 ) 174 { 175 t = StringConverter::parseInt( vecparams[0] ); 176 p = StringConverter::parseInt( vecparams[1] ); 177 s = StringConverter::parseInt( vecparams[2] ); 178 } 179 else 180 { 181 LogManager::getSingleton().logMessage("Texture controller had problems extracting technique, pass, and state level... Default to 0, 0, 0", LML_CRITICAL); 182 t = p = s = 0; 183 } 184 185 static_cast<ExternalTextureSource*>(target)->setTextureTecPassStateLevel(t,p,s); 186 } 187 } 188 189