Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreRenderable.h @ 148

Last change on this file since 148 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 20.0 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-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef __Renderable_H__
29#define __Renderable_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreCommon.h"
33
34#include "OgreRenderOperation.h"
35#include "OgreMatrix4.h"
36#include "OgreMaterial.h"
37#include "OgrePlane.h"
38#include "OgreGpuProgram.h"
39#include "OgreVector4.h"
40#include "OgreException.h"
41#include "OgreUserObjectBindings.h"
42#include "OgreHeaderPrefix.h"
43
44namespace Ogre {
45
46    /** \addtogroup Core
47    *  @{
48    */
49    /** \addtogroup Scene
50    *  @{
51    */
52    /** Abstract class defining the interface all renderable objects must implement.
53    @remarks
54        This interface abstracts renderable discrete objects which will be queued in the render pipeline,
55        grouped by material. Classes implementing this interface must be based on a single material, a single
56        world matrix (or a collection of world matrices which are blended by weights), and must be
57        renderable via a single render operation.
58    @par
59        Note that deciding whether to put these objects in the rendering pipeline is done from the more specific
60        classes e.g. entities. Only once it is decided that the specific class is to be rendered is the abstract version
61        created (could be more than one per visible object) and pushed onto the rendering queue.
62    */
63    class _OgreExport Renderable
64    {
65    public:
66        /** An internal class that should be used only by a render system for internal use
67        @remarks
68            This class was created so a render system can associate internal data to this class.
69            The need for this class started when the DX10 render system needed to save state objects.
70        */
71        class RenderSystemData {}; 
72    public:
73        Renderable() : mPolygonModeOverrideable(true), mUseIdentityProjection(false), mUseIdentityView(false), mRenderSystemData(NULL) {}
74        /** Virtual destructor needed as class has virtual methods. */
75        virtual ~Renderable() 
76        {
77            if (mRenderSystemData)
78            {
79                delete mRenderSystemData;
80                mRenderSystemData = NULL;
81            }
82        }
83        /** Retrieves a weak reference to the material this renderable object uses.
84        @remarks
85            Note that the Renderable also has the option to override the getTechnique method
86            to specify a particular Technique to use instead of the best one available.
87        */
88        virtual const MaterialPtr& getMaterial(void) const = 0;
89        /** Retrieves a pointer to the Material Technique this renderable object uses.
90        @remarks
91            This is to allow Renderables to use a chosen Technique if they wish, otherwise
92            they will use the best Technique available for the Material they are using.
93        */
94        virtual Technique* getTechnique(void) const { return getMaterial()->getBestTechnique(0, this); }
95        /** Gets the render operation required to send this object to the frame buffer.
96        */
97        virtual void getRenderOperation(RenderOperation& op) = 0;
98
99        /** Called just prior to the Renderable being rendered.
100        @remarks
101            OGRE is a queued renderer, so the actual render commands are executed
102            at a later time than the point at which an object is discovered to be
103            visible. This allows ordering & grouping of renders without the discovery
104            process having to be aware of it. It also means OGRE uses declarative
105            render information rather than immediate mode rendering - this is very useful
106            in that certain effects and processes can automatically be applied to
107            a wide range of scenes, but the downside is that special cases are
108            more difficult to handle, because there is not the declared state to
109            cope with it.
110        @par
111            This method allows a Renderable to do something special at the actual
112            point of rendering if it wishes to. When this method is called, all the
113            material render state as declared by this Renderable has already been set,
114            all that is left to do is to bind the buffers and perform the render.
115            The Renderable may modify render state itself if it wants to (and restore it in the
116            postRender call) before the automated render happens, or by returning
117            'false' from this method can actually suppress the automatic render
118            and perform one of its own.
119        @return
120            true if the automatic render should proceed, false to skip it on
121            the assumption that the Renderable has done it manually.
122        */
123        virtual bool preRender(SceneManager* sm, RenderSystem* rsys)
124                { (void)sm; (void)rsys; return true; }
125
126        /** Called immediately after the Renderable has been rendered.
127        */
128        virtual void postRender(SceneManager* sm, RenderSystem* rsys)
129                { (void)sm; (void)rsys; }
130
131        /** Gets the world transform matrix / matrices for this renderable object.
132        @remarks
133            If the object has any derived transforms, these are expected to be up to date as long as
134            all the SceneNode structures have been updated before this is called.
135        @par
136            This method will populate transform with 1 matrix if it does not use vertex blending. If it
137            does use vertex blending it will fill the passed in pointer with an array of matrices,
138            the length being the value returned from getNumWorldTransforms.
139        @note
140            Internal Ogre never supports non-affine matrix for world transform matrix/matrices,
141            the behavior is undefined if returns non-affine matrix here. @see Matrix4::isAffine.
142        */
143        virtual void getWorldTransforms(Matrix4* xform) const = 0;
144
145        /** Returns the number of world transform matrices this renderable requires.
146        @remarks
147            When a renderable uses vertex blending, it uses multiple world matrices instead of a single
148            one. Each vertex sent to the pipeline can reference one or more matrices in this list
149            with given weights.
150            If a renderable does not use vertex blending this method returns 1, which is the default for
151            simplicity.
152        */
153        virtual unsigned short getNumWorldTransforms(void) const { return 1; }
154
155        /** Sets whether or not to use an 'identity' projection.
156        @remarks
157            Usually Renderable objects will use a projection matrix as determined
158            by the active camera. However, if they want they can cancel this out
159            and use an identity projection, which effectively projects in 2D using
160            a {-1, 1} view space. Useful for overlay rendering. Normal renderables
161            need not change this. The default is false.
162        @see Renderable::getUseIdentityProjection
163        */
164        void setUseIdentityProjection(bool useIdentityProjection)
165        {
166            mUseIdentityProjection = useIdentityProjection;
167        }
168
169        /** Returns whether or not to use an 'identity' projection.
170        @remarks
171            Usually Renderable objects will use a projection matrix as determined
172            by the active camera. However, if they want they can cancel this out
173            and use an identity projection, which effectively projects in 2D using
174            a {-1, 1} view space. Useful for overlay rendering. Normal renderables
175            need not change this.
176        @see Renderable::setUseIdentityProjection
177        */
178        bool getUseIdentityProjection(void) const { return mUseIdentityProjection; }
179
180        /** Sets whether or not to use an 'identity' view.
181        @remarks
182            Usually Renderable objects will use a view matrix as determined
183            by the active camera. However, if they want they can cancel this out
184            and use an identity matrix, which means all geometry is assumed
185            to be relative to camera space already. Useful for overlay rendering.
186            Normal renderables need not change this. The default is false.
187        @see Renderable::getUseIdentityView
188        */
189        void setUseIdentityView(bool useIdentityView)
190        {
191            mUseIdentityView = useIdentityView;
192        }
193
194        /** Returns whether or not to use an 'identity' view.
195        @remarks
196            Usually Renderable objects will use a view matrix as determined
197            by the active camera. However, if they want they can cancel this out
198            and use an identity matrix, which means all geometry is assumed
199            to be relative to camera space already. Useful for overlay rendering.
200            Normal renderables need not change this.
201        @see Renderable::setUseIdentityView
202        */
203        bool getUseIdentityView(void) const { return mUseIdentityView; }
204
205        /** Returns the camera-relative squared depth of this renderable.
206        @remarks
207            Used to sort transparent objects. Squared depth is used rather than
208            actual depth to avoid having to perform a square root on the result.
209        */
210        virtual Real getSquaredViewDepth(const Camera* cam) const = 0;
211
212        /** Gets a list of lights, ordered relative to how close they are to this renderable.
213        @remarks
214            Directional lights, which have no position, will always be first on this list.
215        */
216        virtual const LightList& getLights(void) const = 0;
217
218        /** Method which reports whether this renderable would normally cast a
219            shadow.
220        @remarks
221            Subclasses should override this if they could have been used to
222            generate a shadow.
223        */
224        virtual bool getCastsShadows(void) const { return false; }
225
226        /** Sets a custom parameter for this Renderable, which may be used to
227            drive calculations for this specific Renderable, like GPU program parameters.
228        @remarks
229            Calling this method simply associates a numeric index with a 4-dimensional
230            value for this specific Renderable. This is most useful if the material
231            which this Renderable uses a vertex or fragment program, and has an
232            ACT_CUSTOM parameter entry. This parameter entry can refer to the
233            index you specify as part of this call, thereby mapping a custom
234            parameter for this renderable to a program parameter.
235        @param index The index with which to associate the value. Note that this
236            does not have to start at 0, and can include gaps. It also has no direct
237            correlation with a GPU program parameter index - the mapping between the
238            two is performed by the ACT_CUSTOM entry, if that is used.
239        @param value The value to associate.
240        */
241        void setCustomParameter(size_t index, const Vector4& value) 
242        {
243            mCustomParameters[index] = value;
244        }
245
246        /** Removes a custom value which is associated with this Renderable at the given index.
247        @param index Index of the parameter to remove.
248            @see setCustomParameter for full details.
249        */
250        void removeCustomParameter(size_t index)
251        {
252            mCustomParameters.erase(index);
253        }
254
255        /** Checks whether a custom value is associated with this Renderable at the given index.
256        @param index Index of the parameter to check for existence.
257            @see setCustomParameter for full details.
258        */
259        bool hasCustomParameter(size_t index) const
260        {
261            return mCustomParameters.find(index) != mCustomParameters.end();
262        }
263
264        /** Gets the custom value associated with this Renderable at the given index.
265        @param index Index of the parameter to retrieve.
266            @see setCustomParameter for full details.
267        */
268        const Vector4& getCustomParameter(size_t index) const
269        {
270            CustomParameterMap::const_iterator i = mCustomParameters.find(index);
271            if (i != mCustomParameters.end())
272            {
273                return i->second;
274            }
275            else
276            {
277                OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, 
278                    "Parameter at the given index was not found.",
279                    "Renderable::getCustomParameter");
280            }
281        }
282
283        /** Update a custom GpuProgramParameters constant which is derived from
284            information only this Renderable knows.
285        @remarks
286            This method allows a Renderable to map in a custom GPU program parameter
287            based on it's own data. This is represented by a GPU auto parameter
288            of ACT_CUSTOM, and to allow there to be more than one of these per
289            Renderable, the 'data' field on the auto parameter will identify
290            which parameter is being updated. The implementation of this method
291            must identify the parameter being updated, and call a 'setConstant'
292            method on the passed in GpuProgramParameters object, using the details
293            provided in the incoming auto constant setting to identify the index
294            at which to set the parameter.
295        @par
296            You do not need to override this method if you're using the standard
297            sets of data associated with the Renderable as provided by setCustomParameter
298            and getCustomParameter. By default, the implementation will map from the
299            value indexed by the 'constantEntry.data' parameter to a value previously
300            set by setCustomParameter. But custom Renderables are free to override
301            this if they want, in any case.
302        @param constantEntry The auto constant entry referring to the parameter
303            being updated
304        @param params The parameters object which this method should call to
305            set the updated parameters.
306        */
307        virtual void _updateCustomGpuParameter(
308            const GpuProgramParameters::AutoConstantEntry& constantEntry,
309            GpuProgramParameters* params) const
310        {
311            CustomParameterMap::const_iterator i = mCustomParameters.find(constantEntry.data);
312            if (i != mCustomParameters.end())
313            {
314                params->_writeRawConstant(constantEntry.physicalIndex, i->second, 
315                    constantEntry.elementCount);
316            }
317        }
318
319        /** Sets whether this renderable's chosen detail level can be
320            overridden (downgraded) by the camera setting.
321        @param override true means that a lower camera detail will override this
322            renderables detail level, false means it won't.
323        */
324        virtual void setPolygonModeOverrideable(bool override)
325        {
326            mPolygonModeOverrideable = override;
327        }
328
329        /** Gets whether this renderable's chosen detail level can be
330            overridden (downgraded) by the camera setting.
331        */
332        virtual bool getPolygonModeOverrideable(void) const
333        {
334            return mPolygonModeOverrideable;
335        }
336
337        /** @deprecated use UserObjectBindings::setUserAny via getUserObjectBindings() instead.
338            Sets any kind of user value on this object.
339        @remarks
340            This method allows you to associate any user value you like with
341            this Renderable. This can be a pointer back to one of your own
342            classes for instance.
343        */
344        OGRE_DEPRECATED virtual void setUserAny(const Any& anything) { getUserObjectBindings().setUserAny(anything); }
345
346        /** @deprecated use UserObjectBindings::getUserAny via getUserObjectBindings() instead.
347            Retrieves the custom user value associated with this object.
348        */
349        OGRE_DEPRECATED virtual const Any& getUserAny(void) const { return getUserObjectBindings().getUserAny(); }
350
351        /** Return an instance of user objects binding associated with this class.
352            You can use it to associate one or more custom objects with this class instance.
353        @see UserObjectBindings::setUserAny.
354        */
355        UserObjectBindings&     getUserObjectBindings() { return mUserObjectBindings; }
356
357        /** Return an instance of user objects binding associated with this class.
358            You can use it to associate one or more custom objects with this class instance.
359        @see UserObjectBindings::setUserAny.
360        */
361        const UserObjectBindings& getUserObjectBindings() const { return mUserObjectBindings; }
362
363
364        /** Visitor object that can be used to iterate over a collection of Renderable
365            instances abstractly.
366        @remarks
367            Different scene objects use Renderable differently; some will have a
368            single Renderable, others will have many. This visitor interface allows
369            classes using Renderable to expose a clean way for external code to
370            get access to the contained Renderable instance(s) that it will
371            eventually add to the render queue.
372        @par
373            To actually have this method called, you have to call a method on the
374            class containing the Renderable instances. One example is
375            MovableObject::visitRenderables.
376        */
377        class Visitor
378        {
379        public:
380            /** Virtual destructor needed as class has virtual methods. */
381            virtual ~Visitor() { }
382            /** Generic visitor method.
383            @param rend The Renderable instance being visited
384            @param lodIndex The LOD index to which this Renderable belongs. Some
385                objects support LOD and this will tell you whether the Renderable
386                you're looking at is from the top LOD (0) or otherwise
387            @param isDebug Whether this is a debug renderable or not.
388            @param pAny Optional pointer to some additional data that the class
389                calling the visitor may populate if it chooses to.
390            */
391            virtual void visit(Renderable* rend, ushort lodIndex, bool isDebug, 
392                Any* pAny = 0) = 0;
393        };
394
395        /** Gets RenderSystem private data
396        @remarks
397            This should only be used by a RenderSystem
398        */
399        virtual RenderSystemData * getRenderSystemData() const 
400        { 
401            return mRenderSystemData; 
402        }
403        /** Sets RenderSystem private data
404        @remarks
405            This should only be used by a RenderSystem
406        */
407        virtual void setRenderSystemData(RenderSystemData * val) const
408        { 
409            mRenderSystemData = val; 
410        }
411
412
413    protected:
414        typedef map<size_t, Vector4>::type CustomParameterMap;
415        CustomParameterMap mCustomParameters;
416        bool mPolygonModeOverrideable;
417        bool mUseIdentityProjection;
418        bool mUseIdentityView;
419        UserObjectBindings mUserObjectBindings;      /// User objects binding.
420        mutable RenderSystemData * mRenderSystemData;/// This should be used only by a render system for internal use
421    };
422
423    /** @} */
424    /** @} */
425
426} // namespace Ogre
427
428#include "OgreHeaderSuffix.h"
429
430#endif //__Renderable_H__
Note: See TracBrowser for help on using the repository browser.