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-2006 Torus Knot Software Ltd 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 00024 You may alternatively use this source under the terms of a specific version of 00025 the OGRE Unrestricted License provided you have obtained such a license from 00026 Torus Knot Software Ltd. 00027 ----------------------------------------------------------------------------- 00028 */ 00029 #ifndef __Renderable_H__ 00030 #define __Renderable_H__ 00031 00032 #include "OgrePrerequisites.h" 00033 #include "OgreCommon.h" 00034 00035 #include "OgreRenderOperation.h" 00036 #include "OgreMatrix4.h" 00037 #include "OgreMaterial.h" 00038 #include "OgrePlane.h" 00039 #include "OgreGpuProgram.h" 00040 #include "OgreVector4.h" 00041 #include "OgreException.h" 00042 #include "OgreAny.h" 00043 00044 namespace Ogre { 00045 00057 class _OgreExport Renderable 00058 { 00059 public: 00065 class RenderSystemData {}; 00066 public: 00067 Renderable() : mPolygonModeOverrideable(true), mUseIdentityProjection(false), mUseIdentityView(false), mRenderSystemData(NULL){} 00069 virtual ~Renderable() 00070 { 00071 if (mRenderSystemData) 00072 { 00073 delete mRenderSystemData; 00074 } 00075 } 00081 virtual const MaterialPtr& getMaterial(void) const = 0; 00087 virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(0, this); } 00090 virtual void getRenderOperation(RenderOperation& op) = 0; 00091 00116 virtual bool preRender(SceneManager* sm, RenderSystem* rsys) { return true; } 00119 virtual void postRender(SceneManager* sm, RenderSystem* rsys) {} 00120 00133 virtual void getWorldTransforms(Matrix4* xform) const = 0; 00134 00143 virtual unsigned short getNumWorldTransforms(void) const { return 1; } 00144 00154 void setUseIdentityProjection(bool useIdentityProjection) 00155 { 00156 mUseIdentityProjection = useIdentityProjection; 00157 } 00158 00168 bool getUseIdentityProjection(void) const { return mUseIdentityProjection; } 00169 00179 void setUseIdentityView(bool useIdentityView) 00180 { 00181 mUseIdentityView = useIdentityView; 00182 } 00183 00193 bool getUseIdentityView(void) const { return mUseIdentityView; } 00194 00200 virtual Real getSquaredViewDepth(const Camera* cam) const = 0; 00201 00206 virtual const LightList& getLights(void) const = 0; 00207 00214 virtual bool getCastsShadows(void) const { return false; } 00215 00231 void setCustomParameter(size_t index, const Vector4& value) 00232 { 00233 mCustomParameters[index] = value; 00234 } 00235 00240 const Vector4& getCustomParameter(size_t index) const 00241 { 00242 CustomParameterMap::const_iterator i = mCustomParameters.find(index); 00243 if (i != mCustomParameters.end()) 00244 { 00245 return i->second; 00246 } 00247 else 00248 { 00249 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 00250 "Parameter at the given index was not found.", 00251 "Renderable::getCustomParameter"); 00252 } 00253 } 00254 00279 virtual void _updateCustomGpuParameter( 00280 const GpuProgramParameters::AutoConstantEntry& constantEntry, 00281 GpuProgramParameters* params) const 00282 { 00283 CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data); 00284 if (i != mCustomParameters.end()) 00285 { 00286 params->_writeRawConstant(constantEntry.physicalIndex, i->second, 00287 constantEntry.elementCount); 00288 } 00289 } 00290 00296 virtual void setPolygonModeOverrideable(bool override) 00297 { 00298 mPolygonModeOverrideable = override; 00299 } 00300 00304 virtual bool getPolygonModeOverrideable(void) const 00305 { 00306 return mPolygonModeOverrideable; 00307 } 00308 00315 virtual void setUserAny(const Any& anything) { mUserAny = anything; } 00316 00319 virtual const Any& getUserAny(void) const { return mUserAny; } 00320 00334 class Visitor 00335 { 00336 public: 00338 virtual ~Visitor() { } 00348 virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug, 00349 Any* pAny = 0) = 0; 00350 }; 00351 00356 virtual RenderSystemData * getRenderSystemData() const 00357 { 00358 return mRenderSystemData; 00359 } 00364 virtual void setRenderSystemData(RenderSystemData * val) const 00365 { 00366 mRenderSystemData = val; 00367 } 00368 00369 00370 protected: 00371 typedef std::map<size_t, Vector4> CustomParameterMap; 00372 CustomParameterMap mCustomParameters; 00373 bool mPolygonModeOverrideable; 00374 bool mUseIdentityProjection; 00375 bool mUseIdentityView; 00376 Any mUserAny; 00377 mutable RenderSystemData * mRenderSystemData;// this should be used only by a render system for internal use 00378 }; 00379 00380 00381 00382 } 00383 00384 #endif //__Renderable_H__
Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Sep 27 22:02:25 2009