source: GTP/trunk/App/Demos/Geom/OgreStuff/include/OgreRenderable.h @ 1092

Revision 1092, 12.6 KB checked in by gumbau, 18 years ago (diff)

LodStrips? and LODTrees demos

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://ogre.sourceforge.net/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __Renderable_H__
26#define __Renderable_H__
27
28#include "OgrePrerequisites.h"
29#include "OgreCommon.h"
30
31#include "OgreRenderOperation.h"
32#include "OgreMatrix4.h"
33#include "OgreMaterial.h"
34#include "OgrePlane.h"
35#include "OgreGpuProgram.h"
36#include "OgreVector4.h"
37#include "OgreException.h"
38
39namespace Ogre {
40
41    /** Abstract class defining the interface all renderable objects must implement.
42        @remarks
43            This interface abstracts renderable discrete objects which will be queued in the render pipeline,
44            grouped by material. Classes implementing this interface must be based on a single material, a single
45            world matrix (or a collection of world matrices which are blended by weights), and must be
46            renderable via a single render operation.
47        @par
48            Note that deciding whether to put these objects in the rendering pipeline is done from the more specific
49            classes e.g. entities. Only once it is decided that the specific class is to be rendered is the abstract version
50            created (could be more than one per visible object) and pushed onto the rendering queue.
51    */
52    class _OgreExport Renderable
53    {
54    public:
55                Renderable() : mRenderDetailOverrideable(true) {}
56        /** Virtual destructor needed as class has virtual methods. */
57        virtual ~Renderable() { }
58        /** Retrieves a weak reference to the material this renderable object uses.
59        @remarks
60            Note that the Renderable also has the option to override the getTechnique method
61            to specify a particular Technique to use instead of the best one available.
62        */
63        virtual const MaterialPtr& getMaterial(void) const = 0;
64        /** Retrieves a pointer to the Material Technique this renderable object uses.
65        @remarks
66            This is to allow Renderables to use a chosen Technique if they wish, otherwise
67            they will use the best Technique available for the Material they are using.
68        */
69        virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(); }
70        /** Gets the render operation required to send this object to the frame buffer.
71        */
72        virtual void getRenderOperation(RenderOperation& op) = 0;
73        /** Gets the world transform matrix / matrices for this renderable object.
74            @remarks
75                If the object has any derived transforms, these are expected to be up to date as long as
76                all the SceneNode structures have been updated before this is called.
77            @par
78                This method will populate xform with 1 matrix if it does not use vertex blending. If it
79                does use vertex blending it will fill the passed in pointer with an array of matrices,
80                the length being the value returned from getNumWorldTransforms.
81        */
82        virtual void getWorldTransforms(Matrix4* xform) const = 0;
83        /** Gets the worldspace orientation of this renderable; this is used in order to
84            more efficiently update parameters to vertex & fragment programs, since inverting Quaterion
85            and Vector in order to derive object-space positions / directions for cameras and
86            lights is much more efficient than inverting a complete 4x4 matrix, and also
87            eliminates problems introduced by scaling. */
88        virtual const Quaternion& getWorldOrientation(void) const = 0;
89        /** Gets the worldspace orientation of this renderable; this is used in order to
90            more efficiently update parameters to vertex & fragment programs, since inverting Quaterion
91            and Vector in order to derive object-space positions / directions for cameras and
92            lights is much more efficient than inverting a complete 4x4 matrix, and also
93            eliminates problems introduced by scaling. */
94        virtual const Vector3& getWorldPosition(void) const = 0;
95
96        /** Returns the number of world transform matrices this renderable requires.
97        @remarks
98            When a renderable uses vertex blending, it uses multiple world matrices instead of a single
99            one. Each vertex sent to the pipeline can reference one or more matrices in this list
100            with given weights.
101            If a renderable does not use vertex blending this method returns 1, which is the default for
102            simplicity.
103        */
104        virtual unsigned short getNumWorldTransforms(void) const { return 1; }
105
106        /** Returns whether or not to use an 'identity' projection.
107        @remarks
108            Usually Renderable objects will use a projection matrix as determined
109            by the active camera. However, if they want they can cancel this out
110            and use an identity projection, which effectively projects in 2D using
111            a {-1, 1} view space. Useful for overlay rendering. Normal renderables need
112            not override this.
113        */
114        virtual bool useIdentityProjection(void) const { return false; }
115
116        /** Returns whether or not to use an 'identity' projection.
117        @remarks
118            Usually Renderable objects will use a view matrix as determined
119            by the active camera. However, if they want they can cancel this out
120            and use an identity matrix, which means all geometry is assumed
121            to be relative to camera space already. Useful for overlay rendering.
122            Normal renderables need not override this.
123        */
124        virtual bool useIdentityView(void) const { return false; }
125
126                /** Returns the camera-relative squared depth of this renderable.
127                @remarks
128                        Used to sort transparent objects. Squared depth is used rather than
129                        actual depth to avoid having to perform a square root on the result.
130                */
131                virtual Real getSquaredViewDepth(const Camera* cam) const = 0;
132
133        /** Returns the preferred rasterisation mode of this renderable.
134        */
135        virtual SceneDetailLevel getRenderDetail() const {return SDL_SOLID;}
136
137        /** Returns whether or not this Renderable wishes the hardware to normalise normals. */
138        virtual bool getNormaliseNormals(void) const { return false; }
139
140        /** Gets a list of lights, ordered relative to how close they are to this renderable.
141        @remarks
142            Directional lights, which have no position, will always be first on this list.
143        */
144        virtual const LightList& getLights(void) const = 0;
145
146        virtual const PlaneList& getClipPlanes() const { return msDummyPlaneList; };
147
148        /** Method which reports whether this renderable would normally cast a
149            shadow.
150        @remarks
151            Subclasses should override this if they could have been used to
152            generate a shadow.
153        */
154        virtual bool getCastsShadows(void) const { return false; }
155
156        /** Sets a custom parameter for this Renderable, which may be used to
157            drive calculations for this specific Renderable, like GPU program parameters.
158        @remarks
159            Calling this method simply associates a numeric index with a 4-dimensional
160            value for this specific Renderable. This is most useful if the material
161            which this Renderable uses a vertex or fragment program, and has an
162            ACT_CUSTOM parameter entry. This parameter entry can refer to the
163            index you specify as part of this call, thereby mapping a custom
164            parameter for this renderable to a program parameter.
165        @param index The index with which to associate the value. Note that this
166            does not have to start at 0, and can include gaps. It also has no direct
167            correlation with a GPU program parameter index - the mapping between the
168            two is performed by the ACT_CUSTOM entry, if that is used.
169        @param value The value to associate.
170        */
171        void setCustomParameter(size_t index, const Vector4& value)
172        {
173            mCustomParameters[index] = value;
174        }
175
176        /** Gets the custom value associated with this Renderable at the given index.
177        @param
178            @see setCustomParaemter for full details.
179        */
180        const Vector4& getCustomParameter(size_t index) const
181        {
182            CustomParameterMap::const_iterator i = mCustomParameters.find(index);
183            if (i != mCustomParameters.end())
184            {
185                return i->second;
186            }
187            else
188            {
189                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
190                    "Parameter at the given index was not found.",
191                    "Renderable::getCustomParameter");
192            }
193        }
194
195        /** Update a custom GpuProgramParameters constant which is derived from
196            information only this Renderable knows.
197        @remarks
198            This method allows a Renderable to map in a custom GPU program parameter
199            based on it's own data. This is represented by a GPU auto parameter
200            of ACT_CUSTOM, and to allow there to be more than one of these per
201            Renderable, the 'data' field on the auto parameter will identify
202            which parameter is being updated. The implementation of this method
203            must identify the parameter being updated, and call a 'setConstant'
204            method on the passed in GpuProgramParameters object, using the details
205            provided in the incoming auto constant setting to identify the index
206            at which to set the parameter.
207        @par
208            You do not need to override this method if you're using the standard
209            sets of data associated with the Renderable as provided by setCustomParameter
210            and getCustomParameter. By default, the implementation will map from the
211            value indexed by the 'constantEntry.data' parameter to a value previously
212            set by setCustomParameter. But custom Renderables are free to override
213            this if they want, in any case.
214        @param constantEntry The auto constant entry referring to the parameter
215            being updated
216        @param params The parameters object which this method should call to
217            set the updated parameters.
218        */
219        virtual void _updateCustomGpuParameter(
220            const GpuProgramParameters::AutoConstantEntry& constantEntry,
221            GpuProgramParameters* params) const
222        {
223            CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
224            if (i != mCustomParameters.end())
225            {
226                params->setConstant(constantEntry.index, i->second);
227            }
228        }
229
230                /** Sets whether this renderable's chosen detail level can be
231                        overridden (downgraded) by the camera setting.
232                @param override true means that a lower camera detail will override this
233                        renderables detail level, false means it won't.
234                */
235                virtual void setRenderDetailOverrideable(bool override)
236                {
237                        mRenderDetailOverrideable = override;
238                }
239
240                /** Gets whether this renderable's chosen detail level can be
241                        overridden (downgraded) by the camera setting.
242                */
243                virtual bool getRenderDetailOverrideable(void) const
244                {
245                        return mRenderDetailOverrideable;
246                }
247
248
249    protected:
250        static const PlaneList msDummyPlaneList;
251        typedef std::map<size_t, Vector4> CustomParameterMap;
252        CustomParameterMap mCustomParameters;
253                bool mRenderDetailOverrideable;
254    };
255
256
257
258}
259
260#endif //__Renderable_H__
Note: See TracBrowser for help on using the repository browser.