00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org 00006 00007 Copyright (c) 2000-2012 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 #ifndef __Renderable_H__ 00029 #define __Renderable_H__ 00030 00031 #include "OgrePrerequisites.h" 00032 #include "OgreCommon.h" 00033 00034 #include "OgreRenderOperation.h" 00035 #include "OgreMatrix4.h" 00036 #include "OgreMaterial.h" 00037 #include "OgrePlane.h" 00038 #include "OgreGpuProgram.h" 00039 #include "OgreVector4.h" 00040 #include "OgreException.h" 00041 #include "OgreUserObjectBindings.h" 00042 00043 namespace Ogre { 00044 00062 class _OgreExport Renderable 00063 { 00064 public: 00070 class RenderSystemData {}; 00071 public: 00072 Renderable() : mPolygonModeOverrideable(true), mUseIdentityProjection(false), mUseIdentityView(false), mRenderSystemData(NULL) {} 00074 virtual ~Renderable() 00075 { 00076 if (mRenderSystemData) 00077 { 00078 delete mRenderSystemData; 00079 mRenderSystemData = NULL; 00080 } 00081 } 00087 virtual const MaterialPtr& getMaterial(void) const = 0; 00093 virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(0, this); } 00096 virtual void getRenderOperation(RenderOperation& op) = 0; 00097 00122 virtual bool preRender(SceneManager* sm, RenderSystem* rsys) 00123 { (void)sm; (void)rsys; return true; } 00124 00127 virtual void postRender(SceneManager* sm, RenderSystem* rsys) 00128 { (void)sm; (void)rsys; } 00129 00142 virtual void getWorldTransforms(Matrix4* xform) const = 0; 00143 00152 virtual unsigned short getNumWorldTransforms(void) const { return 1; } 00153 00163 void setUseIdentityProjection(bool useIdentityProjection) 00164 { 00165 mUseIdentityProjection = useIdentityProjection; 00166 } 00167 00177 bool getUseIdentityProjection(void) const { return mUseIdentityProjection; } 00178 00188 void setUseIdentityView(bool useIdentityView) 00189 { 00190 mUseIdentityView = useIdentityView; 00191 } 00192 00202 bool getUseIdentityView(void) const { return mUseIdentityView; } 00203 00209 virtual Real getSquaredViewDepth(const Camera* cam) const = 0; 00210 00215 virtual const LightList& getLights(void) const = 0; 00216 00223 virtual bool getCastsShadows(void) const { return false; } 00224 00240 void setCustomParameter(size_t index, const Vector4& value) 00241 { 00242 mCustomParameters[index] = value; 00243 } 00244 00249 void removeCustomParameter(size_t index) 00250 { 00251 mCustomParameters.erase(index); 00252 } 00253 00258 bool hasCustomParameter(size_t index) const 00259 { 00260 return mCustomParameters.find(index) != mCustomParameters.end(); 00261 } 00262 00267 const Vector4& getCustomParameter(size_t index) const 00268 { 00269 CustomParameterMap::const_iterator i = mCustomParameters.find(index); 00270 if (i != mCustomParameters.end()) 00271 { 00272 return i->second; 00273 } 00274 else 00275 { 00276 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00277 "Parameter at the given index was not found.", 00278 "Renderable::getCustomParameter"); 00279 } 00280 } 00281 00306 virtual void _updateCustomGpuParameter( 00307 const GpuProgramParameters::AutoConstantEntry& constantEntry, 00308 GpuProgramParameters* params) const 00309 { 00310 CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data); 00311 if (i != mCustomParameters.end()) 00312 { 00313 params->_writeRawConstant(constantEntry.physicalIndex, i->second, 00314 constantEntry.elementCount); 00315 } 00316 } 00317 00323 virtual void setPolygonModeOverrideable(bool override) 00324 { 00325 mPolygonModeOverrideable = override; 00326 } 00327 00331 virtual bool getPolygonModeOverrideable(void) const 00332 { 00333 return mPolygonModeOverrideable; 00334 } 00335 00343 virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); } 00344 00348 virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); } 00349 00354 UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; } 00355 00360 const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; } 00361 00362 00376 class Visitor 00377 { 00378 public: 00380 virtual ~Visitor() { } 00390 virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug, 00391 Any* pAny = 0) = 0; 00392 }; 00393 00398 virtual RenderSystemData * getRenderSystemData() const 00399 { 00400 return mRenderSystemData; 00401 } 00406 virtual void setRenderSystemData(RenderSystemData * val) const 00407 { 00408 mRenderSystemData = val; 00409 } 00410 00411 00412 protected: 00413 typedef map<size_t, Vector4>::type CustomParameterMap; 00414 CustomParameterMap mCustomParameters; 00415 bool mPolygonModeOverrideable; 00416 bool mUseIdentityProjection; 00417 bool mUseIdentityView; 00418 UserObjectBindings mUserObjectBindings; 00419 mutable RenderSystemData * mRenderSystemData; 00420 }; 00421 00426 } 00427 00428 #endif //__Renderable_H__
Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Fri May 25 23:36:25 2012