# OgreRenderable.h

Go to the documentation of this file.

    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-2009 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         const Vector4& getCustomParameter(size_t index) const
    00250         {
    00251             CustomParameterMap::const_iterator i = mCustomParameters.find(index);
    00252             if (i != mCustomParameters.end())
    00253             {
    00254                 return i->second;
    00255             }
    00256             else
    00257             {
    00258                 OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
    00259                     "Parameter at the given index was not found.",
    00260                     "Renderable::getCustomParameter");
    00261             }
    00262         }
    00263
    00288         virtual void _updateCustomGpuParameter(
    00289             const GpuProgramParameters::AutoConstantEntry& constantEntry,
    00290             GpuProgramParameters* params) const
    00291         {
    00292             CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
    00293             if (i != mCustomParameters.end())
    00294             {
    00295                 params->_writeRawConstant(constantEntry.physicalIndex, i->second,
    00296                     constantEntry.elementCount);
    00297             }
    00298         }
    00299
    00305         virtual void setPolygonModeOverrideable(bool override)
    00306         {
    00307             mPolygonModeOverrideable = override;
    00308         }
    00309
    00313         virtual bool getPolygonModeOverrideable(void) const
    00314         {
    00315             return mPolygonModeOverrideable;
    00316         }
    00317
    00325         virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
    00326
    00330         virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
    00331
    00336         UserObjectBindings& getUserObjectBindings() { return mUserObjectBindings; }
    00337
    00342         const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
    00343
    00344
    00358         class Visitor
    00359         {
    00360         public:
    00362             virtual ~Visitor() { }
    00372             virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug,
    00373                 Any* pAny = 0) = 0;
    00374         };
    00375
    00380         virtual RenderSystemData * getRenderSystemData() const
    00381         {
    00382             return mRenderSystemData;
    00383         }
    00388         virtual void setRenderSystemData(RenderSystemData * val) const
    00389         {
    00390             mRenderSystemData = val;
    00391         }
    00392
    00393
    00394     protected:
    00395         typedef map<size_t, Vector4>::type CustomParameterMap;
    00396         CustomParameterMap mCustomParameters;
    00397         bool mPolygonModeOverrideable;
    00398         bool mUseIdentityProjection;
    00399         bool mUseIdentityView;
    00400         UserObjectBindings mUserObjectBindings;      // User objects binding.
    00401         mutable RenderSystemData * mRenderSystemData;// this should be used only by a render system for internal use
    00402     };
    00403
    00408 }
    00409
    00410 #endif //__Renderable_H__

Copyright © 2008 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Sun May 8 2011 20:28:08