Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/include/OgreRenderable.h @ 1

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