source: OGRE/trunk/ogre_changes/OgreMain/include/OgreRenderSystem.h @ 657

Revision 657, 52.8 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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 __RenderSystem_H_
26#define __RenderSystem_H_
27
28// Precompiler options
29#include "OgrePrerequisites.h"
30
31#include "OgreString.h"
32
33#include "OgreTextureUnitState.h"
34#include "OgreCommon.h"
35
36#include "OgreRenderOperation.h"
37#include "OgreRenderSystemCapabilities.h"
38#include "OgreRenderTarget.h"
39#include "OgreRenderTexture.h"
40#include "OgreFrameListener.h"
41#include "OgreConfigOptionMap.h"
42#include "OgreGpuProgram.h"
43#include "OgrePlane.h"
44#include "OgreIteratorWrappers.h"
45
46namespace Ogre
47{
48    typedef std::map< String, RenderTarget * > RenderTargetMap;
49        typedef std::multimap<uchar, RenderTarget * > RenderTargetPriorityMap;
50
51    class TextureManager;
52    /// Enum describing the ways to generate texture coordinates
53    enum TexCoordCalcMethod
54    {
55        /// No calculated texture coordinates
56        TEXCALC_NONE,
57        /// Environment map based on vertex normals
58        TEXCALC_ENVIRONMENT_MAP,
59        /// Environment map based on vertex positions
60        TEXCALC_ENVIRONMENT_MAP_PLANAR,
61        TEXCALC_ENVIRONMENT_MAP_REFLECTION,
62        TEXCALC_ENVIRONMENT_MAP_NORMAL,
63        /// Projective texture
64        TEXCALC_PROJECTIVE_TEXTURE
65    };
66    /// Enum describing the various actions which can be taken onthe stencil buffer
67    enum StencilOperation
68    {
69        /// Leave the stencil buffer unchanged
70        SOP_KEEP,
71        /// Set the stencil value to zero
72        SOP_ZERO,
73        /// Set the stencil value to the reference value
74        SOP_REPLACE,
75        /// Increase the stencil value by 1, clamping at the maximum value
76        SOP_INCREMENT,
77        /// Decrease the stencil value by 1, clamping at 0
78        SOP_DECREMENT,
79        /// Increase the stencil value by 1, wrapping back to 0 when incrementing the maximum value
80        SOP_INCREMENT_WRAP,
81        /// Decrease the stencil value by 1, wrapping when decrementing 0
82        SOP_DECREMENT_WRAP,
83        /// Invert the bits of the stencil buffer
84        SOP_INVERT
85    };
86
87    /** Defines the frame buffers which can be cleared. */
88    enum FrameBufferType {
89        FBT_COLOUR  = 0x1,
90        FBT_DEPTH   = 0x2,
91        FBT_STENCIL = 0x4
92    };
93   
94    /** Defines the functionality of a 3D API
95        @remarks
96            The RenderSystem class provides a base interface
97            which abstracts the general functionality of the 3D API
98            e.g. Direct3D or OpenGL. Whilst a few of the general
99            methods have implementations, most of this class is
100            abstract, requiring a subclass based on a specific API
101            to be constructed to provide the full functionality.
102            Note there are 2 levels to the interface - one which
103            will be used often by the caller of the Ogre library,
104            and one which is at a lower level and will be used by the
105            other classes provided by Ogre. These lower level
106            methods are prefixed with '_' to differentiate them.
107            The advanced user of the library may use these lower
108            level methods to access the 3D API at a more fundamental
109            level (dealing direct with render states and rendering
110            primitives), but still benefitting from Ogre's abstraction
111            of exactly which 3D API is in use.
112        @author
113            Steven Streeting
114        @version
115            1.0
116     */
117    class _OgreExport RenderSystem
118    {
119    public:
120        /** Default Constructor.
121        */
122        RenderSystem();
123
124        /** Destructor.
125        */
126        virtual ~RenderSystem();
127
128        /** Returns the name of the rendering system.
129        */
130        virtual const String& getName(void) const = 0;
131
132        /** Returns the details of this API's configuration options
133            @remarks
134                Each render system must be able to inform the world
135                of what options must/can be specified for it's
136                operation.
137            @par
138                These are passed as strings for portability, but
139                grouped into a structure (_ConfigOption) which includes
140                both options and current value.
141            @par
142                Note that the settings returned from this call are
143                affected by the options that have been set so far,
144                since some options are interdependent.
145            @par
146                This routine is called automatically by the default
147                configuration dialogue produced by Root::showConfigDialog
148                or may be used by the caller for custom settings dialogs
149            @returns
150                A 'map' of options, i.e. a list of options which is also
151                indexed by option name.
152         */
153        virtual ConfigOptionMap& getConfigOptions(void) = 0;
154
155        /** Sets an option for this API
156            @remarks
157                Used to confirm the settings (normally chosen by the user) in
158                order to make the renderer able to initialise with the settings as required.
159                This may be video mode, D3D driver, full screen / windowed etc.
160                Called automatically by the default configuration
161                dialog, and by the restoration of saved settings.
162                These settings are stored and only activated when
163                RenderSystem::initialise or RenderSystem::reinitialise
164                are called.
165            @par
166                If using a custom configuration dialog, it is advised that the
167                caller calls RenderSystem::getConfigOptions
168                again, since some options can alter resulting from a selection.
169            @param
170                name The name of the option to alter.
171            @param
172                value The value to set the option to.
173         */
174        virtual void setConfigOption(const String &name, const String &value) = 0;
175
176                /** Create an object for performing hardware occlusion queries.
177                */
178                virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
179
180                /** Destroy a hardware occlusion query object.
181                */
182                virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
183
184        /** Validates the options set for the rendering system, returning a message if there are problems.
185            @note
186                If the returned string is empty, there are no problems.
187        */
188        virtual String validateConfigOptions(void) = 0;
189
190        /** Start up the renderer using the settings selected (Or the defaults if none have been selected).
191            @remarks
192                Called by Root::setRenderSystem. Shouldn't really be called
193                directly, although  this can be done if the app wants to.
194            @param
195                autoCreateWindow If true, creates a render window
196                automatically, based on settings chosen so far. This saves
197                an extra call to RenderSystem::createRenderWindow
198                for the main render window.
199            @par
200                If an application has more specific window requirements,
201                however (e.g. a level design app), it should specify false
202                for this parameter and do it manually.
203            @returns
204                A pointer to the automatically created window, if requested, otherwise null.
205        */
206        virtual RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
207
208        /** Restart the renderer (normally following a change in settings).
209        */
210        virtual void reinitialise(void) = 0;
211
212        /** Shutdown the renderer and cleanup resources.
213        */
214        virtual void shutdown(void);
215
216
217        /** Sets the colour & strength of the ambient (global directionless) light in the world.
218        */
219        virtual void setAmbientLight(float r, float g, float b) = 0;
220
221        /** Sets the type of light shading required (default = Gouraud).
222        */
223        virtual void setShadingType(ShadeOptions so) = 0;
224
225        /** Sets whether or not dynamic lighting is enabled.
226            @param
227                enabled If true, dynamic lighting is performed on geometry with normals supplied, geometry without
228                normals will not be displayed. If false, no lighting is applied and all geometry will be full brightness.
229        */
230        virtual void setLightingEnabled(bool enabled) = 0;
231
232        /** Sets whether or not W-buffers are enabled if they are avalible for this renderer.
233                        @param
234                                enabled If true and the renderer supports them W-buffers will be used.  If false
235                                W-buffers will not be used even if avalible.  W-buffers are enabled by default
236                                for 16bit depth buffers and disabled for all other depths.
237        */
238                void setWBufferEnabled(bool enabled);
239
240                /** Returns true if the renderer will try to use W-buffers when avalible.
241                */
242                bool getWBufferEnabled(void) const;
243
244                /** Creates a new rendering window.
245            @remarks
246                This method creates a new rendering window as specified
247                by the paramteters. The rendering system could be
248                responible for only a single window (e.g. in the case
249                of a game), or could be in charge of multiple ones (in the
250                case of a level editor). The option to create the window
251                as a child of another is therefore given.
252                This method will create an appropriate subclass of
253                RenderWindow depending on the API and platform implementation.
254            @par
255                After creation, this window can be retrieved using getRenderTarget().
256            @param
257                name The name of the window. Used in other methods
258                later like setRenderTarget and getRenderWindow.
259            @param
260                width The width of the new window.
261            @param
262                height The height of the new window.
263            @param
264                fullScreen Specify true to make the window full screen
265                without borders, title bar or menu bar.
266            @param
267                miscParams A NameValuePairList describing the other parameters for the new rendering window.
268                                        Options are case sensitive. Unrecognised parameters will be ignored silently.
269                                        These values might be platform dependent, but these are present for all platorms unless
270                                        indicated otherwise:
271                                **
272                                Key: "title"
273                                Description: The title of the window that will appear in the title bar
274                                Values: string
275                                Default: RenderTarget name
276                                **
277                                Key: "colourDepth"
278                                Description: Colour depth of the resulting rendering window; only applies if fullScreen
279                                        is set.
280                                Values: 16 or 32
281                                Default: desktop depth
282                                Notes: [W32 specific]
283                                **
284                                Key: "left"
285                                Description: screen x coordinate from left
286                                Values: positive integers
287                                Default: 'center window on screen'
288                                Notes: Ignored in case of full screen
289                                **
290                                Key: "top"
291                                Description: screen y coordinate from top
292                                Values: positive integers
293                                Default: 'center window on screen'
294                                Notes: Ignored in case of full screen
295                                **
296                                Key: "depthBuffer" [DX9 specific]
297                                Description: Use depth buffer
298                                Values: false or true
299                                Default: true
300                                **
301                                Key: "externalWindowHandle" [API specific]
302                                Description: External window handle, for embedding the OGRE context
303                                Values: positive integer for W32 (HWND handle)
304                                        poslong:posint:poslong (display*:screen:windowHandle) or
305                                        poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) for GLX
306                                Default: 0 (None)
307                                **
308                                Key: "parentWindowHandle" [API specific]
309                                Description: Parent window handle, for embedding the OGRE context
310                                Values: positive integer for W32 (HWND handle)
311                                        poslong:posint:poslong for GLX (display*:screen:windowHandle)
312                                Default: 0 (None)
313                                **
314                                Key: "FSAA"
315                                Description: Full screen antialiasing factor
316                                Values: 0,2,4,6,...
317                                Default: 0
318                                **
319                                Key: "displayFrequency"
320                                Description: Display frequency rate, for fullscreen mode
321                                Values: 60...?
322                                Default: Desktop vsync rate
323                                **
324                                Key: "vsync"
325                                Description: Synchronize buffer swaps to vsync
326                                Values: true, false
327                                Default: 0
328                                **
329                                Key: "border"
330                                Description: The type of window border (in windowed mode)
331                                Values: none, fixed, resize
332                                Default: resize
333                                **
334                                Key: "outerDimensions"
335                                Description: Whether the width/height is expressed as the size of the
336                                outer window, rather than the content area
337                                Values: true, false
338                                Default: false
339        */
340                virtual RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
341                        bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
342
343                /** Creates and registers a render texture object.
344                        @param name
345                                The name for the new render texture. Note that names must be unique.
346                        @param width
347                                The requested width for the render texture. See Remarks for more info.
348                        @param height
349                                The requested width for the render texture. See Remarks for more info.
350                        @param texType
351                                The type of texture; defaults to TEX_TYPE_2D
352                        @param internalFormat
353                                The internal format of the texture; defaults to PF_X8R8G8B8
354                        @param miscParams A NameValuePairList describing the other parameters for the new rendering window.
355                                        Unrecognised parameters will be ignored silently.
356                                        These values might be platform dependent, but these are present for all platorms unless
357                                        indicated otherwise:
358                                **
359                                Key: "FSAA"
360                                Description: Full screen antialiasing factor
361                                Values: 0,2,4,6,...
362                                Default: 0
363                                **
364                                Key: "depth"
365                                Description: Depth in case of render-to-texture TEX_3D
366                                Values: positive integers
367                        @returns
368                                On succes, a pointer to a new platform-dependernt, RenderTexture-derived
369                                class is returned. On failiure, NULL is returned.
370                        @remarks
371                                Because a render texture is basically a wrapper around a texture object,
372                                the width and height parameters of this method just hint the preferred
373                                size for the texture. Depending on the hardware driver or the underlying
374                                API, these values might change when the texture is created. The same applies
375                                to the internalFormat parameter.
376                */
377                virtual RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
378                        TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8,
379                        const NameValuePairList *miscParams = 0 ) = 0;
380
381        /** Destroys a render window */
382        virtual void destroyRenderWindow(const String& name);
383        /** Destroys a render texture */
384        virtual void destroyRenderTexture(const String& name);
385        /** Destroys a render target of any sort */
386        virtual void destroyRenderTarget(const String& name);
387
388        /** Attaches the passed render target to the render system.
389        */
390        virtual void attachRenderTarget( RenderTarget &target );
391        /** Returns a pointer to the render target with the passed name, or NULL if that
392            render target cannot be found.
393        */
394        virtual RenderTarget * getRenderTarget( const String &name );
395        /** Detaches the render target with the passed name from the render system and
396            returns a pointer to it.
397            @note
398                If the render target cannot be found, NULL is returned.
399        */
400        virtual RenderTarget * detachRenderTarget( const String &name );
401
402                /// Iterator over RenderTargets
403                typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator;
404
405                /** Returns a specialised MapIterator over all render targets attached to the RenderSystem. */
406                virtual RenderTargetIterator getRenderTargetIterator(void) {
407                        return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() );
408                }
409        /** Returns a description of an error code.
410        */
411        virtual String getErrorDescription(long errorNumber) const = 0;
412
413        /** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
414            @remarks
415                By default, all rendering windows wait for a vertical blank (when the CRT beam turns off briefly to move
416                from the bottom right of the screen back to the top left) before flipping the screen buffers. This ensures
417                that the image you see on the screen is steady. However it restricts the frame rate to the refresh rate of
418                the monitor, and can slow the frame rate down. You can speed this up by not waiting for the blank, but
419                this has the downside of introducing 'tearing' artefacts where part of the previous frame is still displayed
420                as the buffers are switched. Speed vs quality, you choose.
421            @note
422                Has NO effect on windowed mode render targets. Only affects fullscreen mode.
423            @param
424                enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
425        */
426        void setWaitForVerticalBlank(bool enabled);
427
428        /** Returns true if the system is synchronising frames with the monitor vertical blank.
429        */
430        bool getWaitForVerticalBlank(void) const;
431
432        // ------------------------------------------------------------------------
433        //                     Internal Rendering Access
434        // All methods below here are normally only called by other OGRE classes
435        // They can be called by library user if required
436        // ------------------------------------------------------------------------
437
438
439        /** Tells the rendersystem to use the attached set of lights (and no others)
440        up to the number specified (this allows the same list to be used with different
441        count limits) */
442        virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
443        /** Sets the world transform matrix. */
444        virtual void _setWorldMatrix(const Matrix4 &m) = 0;
445        /** Sets multiple world matrices (vertex blending). */
446        virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
447        /** Sets the view transform matrix */
448        virtual void _setViewMatrix(const Matrix4 &m) = 0;
449        /** Sets the projection transform matrix */
450        virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
451        /** Utility function for setting all the properties of a texture unit at once.
452            This method is also worth using over the individual texture unit settings because it
453            only sets those settings which are different from the current settings for this
454            unit, thus minimising render state changes.
455        */
456        virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
457        /** Turns off a texture unit. */
458        virtual void _disableTextureUnit(size_t texUnit);
459        /** Disables all texture units from the given unit upwards */
460        virtual void _disableTextureUnitsFrom(size_t texUnit);
461        /** Sets the surface properties to be used for future rendering.
462
463            This method sets the the properties of the surfaces of objects
464            to be rendered after it. In this context these surface properties
465            are the amount of each type of light the object reflects (determining
466            it's colour under different types of light), whether it emits light
467            itself, and how shiny it is. Textures are not dealt with here,
468            see the _setTetxure method for details.
469            This method is used by _setMaterial so does not need to be called
470            direct if that method is being used.
471
472            @param ambient The amount of ambient (sourceless and directionless)
473            light an object reflects. Affected by the colour/amount of ambient light in the scene.
474            @param diffuse The amount of light from directed sources that is
475            reflected (affected by colour/amount of point, directed and spot light sources)
476            @param specular The amount of specular light reflected. This is also
477            affected by directed light sources but represents the colour at the
478            highlights of the object.
479            @param emissive The colour of light emitted from the object. Note that
480            this will make an object seem brighter and not dependent on lights in
481            the scene, but it will not act as a light, so will not illuminate other
482            objects. Use a light attached to the same SceneNode as the object for this purpose.
483            @param shininess A value which only has an effect on specular highlights (so
484            specular must be non-black). The higher this value, the smaller and crisper the
485            specular highlights will be, imitating a more highly polished surface.
486            This value is not constrained to 0.0-1.0, in fact it is likely to
487            be more (10.0 gives a modest sheen to an object).
488            @param tracking A bit field that describes which of the ambient, diffuse, specular
489            and emissive colours follow the vertex colour of the primitive. When a bit in this field is set
490            its ColourValue is ignored. This is a combination of TVC_AMBIENT, TVC_DIFFUSE, TVC_SPECULAR(note that the shininess value is still
491            taken from shininess) and TVC_EMISSIVE. TVC_NONE means that there will be no material property
492            tracking the vertex colours.
493        */
494        virtual void _setSurfaceParams(const ColourValue &ambient,
495            const ColourValue &diffuse, const ColourValue &specular,
496            const ColourValue &emissive, Real shininess,
497            TrackVertexColourType tracking = TVC_NONE) = 0;
498        /**
499          Sets the status of a single texture stage.
500
501          Sets the details of a texture stage, to be used for all primitives
502          rendered afterwards. User processes would
503          not normally call this direct unless rendering
504          primitives themselves - the SubEntity class
505          is designed to manage materials for objects.
506          Note that this method is called by _setMaterial.
507
508          @param unit The index of the texture unit to modify. Multitexturing hardware
509          can support multiple units (see RenderSystemCapabilites::numTextureUnits)
510          @param enabled Boolean to turn the unit on/off
511          @param texname The name of the texture to use - this should have
512              already been loaded with TextureManager::load.
513         */
514        virtual void _setTexture(size_t unit, bool enabled, const String &texname) = 0;
515
516        /**
517          Sets the texture coordinate set to use for a texture unit.
518
519          Meant for use internally - not generally used directly by apps - the Material and TextureUnitState
520          classes let you manage textures far more easily.
521
522          @param unit Texture unit as above
523          @param index The index of the texture coordinate set to use.
524         */
525        virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
526
527        /**
528          Sets a method for automatically calculating texture coordinates for a stage.
529          Should not be used by apps - for use by Ogre only.
530          @param unit Texture unit as above
531          @param m Calculation method to use
532          @param frustum Optional Frustum param, only used for projective effects
533         */
534        virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
535            const Frustum* frustum = 0) = 0;
536
537        /** Sets the texture blend modes from a TextureUnitState record.
538            Meant for use internally only - apps should use the Material
539            and TextureUnitState classes.
540            @param unit Texture unit as above
541            @param bm Details of the blending mode
542        */
543        virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
544
545        /** Sets the filtering options for a given texture unit.
546        @param unit The texture unit to set the filtering options for
547        @param minFilter The filter used when a texture is reduced in size
548        @param magFilter The filter used when a texture is magnified
549        @param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
550        */
551        virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
552            FilterOptions magFilter, FilterOptions mipFilter);
553
554        /** Sets a single filter for a given texture unit.
555        @param unit The texture unit to set the filtering options for
556        @param ftype The filter type
557        @param filter The filter to be used
558        */
559        virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
560
561                /** Sets the maximal anisotropy for the specified texture unit.*/
562                virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
563
564                /** Sets the texture addressing mode for a texture unit.*/
565        virtual void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam) = 0;
566
567        /** Sets the texture coordinate transformation matrix for a texture unit.
568            @param unit Texture unit to affect
569            @param xform The 4x4 matrix
570        */
571        virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
572
573        /** Sets the global blending factors for combining subsequent renders with the existing frame contents.
574            The result of the blending operation is:</p>
575            <p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
576            Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
577            enumerated type.
578            @param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
579            @param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
580        */
581        virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor) = 0;
582
583        /** Sets the global alpha rejection approach for future renders.
584            By default images are rendered regardless of texture alpha. This method lets you change that.
585            @param func The comparison function which must pass for a pixel to be written.
586            @param val The value to compare each pixels alpha value to (0-255)
587        */
588        virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value) = 0;
589        /**
590         * Signifies the beginning of a frame, ie the start of rendering on a single viewport. Will occur
591         * several times per complete frame if multiple viewports exist.
592         */
593        virtual void _beginFrame(void) = 0;
594
595
596        /**
597         * Ends rendering of a frame to the current viewport.
598         */
599        virtual void _endFrame(void) = 0;
600        /**
601          Sets the provided viewport as the active one for future
602          rendering operations. This viewport is aware of it's own
603          camera and render target. Must be implemented by subclass.
604
605          @param target Pointer to the appropriate viewport.
606         */
607        virtual void _setViewport(Viewport *vp) = 0;
608        /** Get the current active viewport for rendering. */
609        virtual Viewport* _getViewport(void);
610
611        /** Sets the culling mode for the render system based on the 'vertex winding'.
612            A typical way for the rendering engine to cull triangles is based on the
613            'vertex winding' of triangles. Vertex winding refers to the direction in
614            which the vertices are passed or indexed to in the rendering operation as viewed
615            from the camera, and will wither be clockwise or anticlockwise (that's 'counterclockwise' for
616            you Americans out there ;) The default is CULL_CLOCKWISE i.e. that only triangles whose vertices
617            are passed/indexed in anticlockwise order are rendered - this is a common approach and is used in 3D studio models
618            for example. You can alter this culling mode if you wish but it is not advised unless you know what you are doing.
619            You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
620            winding is uncertain.
621        */
622        virtual void _setCullingMode(CullingMode mode) = 0;
623
624        virtual CullingMode _getCullingMode(void) const;
625
626        /** Sets the mode of operation for depth buffer tests from this point onwards.
627            Sometimes you may wish to alter the behaviour of the depth buffer to achieve
628            special effects. Because it's unlikely that you'll set these options for an entire frame,
629            but rather use them to tweak settings between rendering objects, this is an internal
630            method (indicated by the '_' prefix) which will be used by a SceneManager implementation
631            rather than directly from the client application.
632            If this method is never called the settings are automatically the same as the default parameters.
633            @param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
634                if the depth function test succeeds. If false, no test is performed and pixels are always written.
635            @param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
636                If false, the depth buffer is left unchanged even if a new pixel is written.
637            @param depthFunction Sets the function required for the depth test.
638        */
639        virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
640
641        /** Sets whether or not the depth buffer check is performed before a pixel write.
642            @param enabled If true, the depth buffer is tested for each pixel and the frame buffer is only updated
643                if the depth function test succeeds. If false, no test is performed and pixels are always written.
644        */
645        virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
646        /** Sets whether or not the depth buffer is updated after a pixel write.
647            @param enabled If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
648                If false, the depth buffer is left unchanged even if a new pixel is written.
649        */
650        virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
651        /** Sets the comparison function for the depth buffer check.
652            Advanced use only - allows you to choose the function applied to compare the depth values of
653            new and existing pixels in the depth buffer. Only an issue if the deoth buffer check is enabled
654            (see _setDepthBufferCheckEnabled)
655            @param  func The comparison between the new depth and the existing depth which must return true
656             for the new pixel to be written.
657        */
658        virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
659                /** Sets whether or not colour buffer writing is enabled, and for which channels.
660                @remarks
661                        For some advanced effects, you may wish to turn off the writing of certain colour
662                        channels, or even all of the colour channels so that only the depth buffer is updated
663                        in a rendering pass. However, the chances are that you really want to use this option
664                        through the Material class.
665                @param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
666                virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
667        /** Sets the depth bias, NB you should use the Material version of this.
668        @remarks
669            When polygons are coplanar, you can get problems with 'depth fighting' where
670            the pixels from the two polys compete for the same screen pixel. This is particularly
671            a problem for decals (polys attached to another surface to represent details such as
672            bulletholes etc.).
673        @par
674            A way to combat this problem is to use a depth bias to adjust the depth buffer value
675            used for the decal such that it is slightly higher than the true value, ensuring that
676            the decal appears on top.
677        @param bias The bias value, should be between 0 and 16.
678        */
679        virtual void _setDepthBias(ushort bias) = 0;
680        /** Sets the fogging mode for future geometry.
681            @param mode Set up the mode of fog as described in the FogMode enum, or set to FOG_NONE to turn off.
682            @param colour The colour of the fog. Either set this to the same as your viewport background colour,
683                or to blend in with a skydome or skybox.
684            @param expDensity The density of the fog in FOG_EXP or FOG_EXP2 mode, as a value between 0 and 1. The default is 1. i.e. completely opaque, lower values can mean
685                that fog never completely obscures the scene.
686            @param linearStart Distance at which linear fog starts to encroach. The distance must be passed
687                as a parametric value between 0 and 1, with 0 being the near clipping plane, and 1 being the far clipping plane. Only applicable if mode is FOG_LINEAR.
688            @param linearEnd Distance at which linear fog becomes completely opaque.The distance must be passed
689                as a parametric value between 0 and 1, with 0 being the near clipping plane, and 1 being the far clipping plane. Only applicable if mode is FOG_LINEAR.
690        */
691        virtual void _setFog(FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0) = 0;
692
693
694        /** The RenderSystem will keep a count of tris rendered, this resets the count. */
695        virtual void _beginGeometryCount(void);
696        /** Reports the number of tris rendered since the last _beginGeometryCount call. */
697        virtual unsigned int _getFaceCount(void) const;
698        /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */
699        virtual unsigned int _getVertexCount(void) const;
700
701        /** Generates a packed data version of the passed in ColourValue suitable for
702            use as with this RenderSystem.
703        @remarks
704            Since different render systems have different colour data formats (eg
705            RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
706        @param colour The colour to convert
707        @param pDest Pointer to location to put the result.
708        */
709        virtual void convertColourValue(const ColourValue& colour, uint32* pDest) = 0;
710
711        /** Builds a perspective projection matrix suitable for this render system.
712        @remarks
713            Because different APIs have different requirements (some incompatible) for the
714            projection matrix, this method allows each to implement their own correctly and pass
715            back a generic OGRE matrix for storage in the engine.
716        */
717        virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
718            Matrix4& dest, bool forGpuProgram = false) = 0;
719
720        /** Builds a perspective projection matrix for the case when frustum is
721            not centered around camera.
722        @remarks
723            Viewport coordinates are in camera coordinate frame, i.e. camera is
724            at the origin.
725        */
726        virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
727            Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
728        /** Builds an orthographic projection matrix suitable for this render system.
729        @remarks
730            Because different APIs have different requirements (some incompatible) for the
731            projection matrix, this method allows each to implement their own correctly and pass
732            back a generic OGRE matrix for storage in the engine.
733        */
734        virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
735            Matrix4& dest, bool forGpuProgram = false) = 0;
736
737                /** Update a perspective projection matrix to use 'oblique depth projection'.
738                @remarks
739                        This method can be used to change the nature of a perspective
740                        transform in order to make the near plane not perpendicular to the
741                        camera view direction, but to be at some different orientation.
742                        This can be useful for performing arbitrary clipping (e.g. to a
743                        reflection plane) which could otherwise only be done using user
744                        clip planes, which are more expensive, and not necessarily supported
745                        on all cards.
746                @param matrix The existing projection matrix. Note that this must be a
747                        perspective transform (not orthographic), and must not have already
748                        been altered by this method. The matrix will be altered in-place.
749                @param plane The plane which is to be used as the clipping plane. This
750                        plane must be in CAMERA (view) space.
751        @param forGpuProgram Is this for use with a Gpu program or fixed-function
752                */
753                virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
754            bool forGpuProgram) = 0;
755               
756        /** Sets how to rasterise triangles, as points, wireframe or solid polys. */
757        virtual void _setRasterisationMode(SceneDetailLevel level) = 0;
758
759        /** Turns stencil buffer checking on or off.
760        @remarks
761            Stencilling (masking off areas of the rendering target based on the stencil
762            buffer) canbe turned on or off using this method. By default, stencilling is
763            disabled.
764        */
765        virtual void setStencilCheckEnabled(bool enabled) = 0;
766        /** Determines if this system supports hardware accelerated stencil buffer.
767        @remarks
768            Note that the lack of this function doesn't mean you can't do stencilling, but
769            the stencilling operations will be provided in software, which will NOT be
770            fast.
771        @par
772            Generally hardware stencils are only supported in 32-bit colour modes, because
773            the stencil buffer shares the memory of the z-buffer, and in most cards the
774            z-buffer has to be the same depth as the colour buffer. This means that in 32-bit
775            mode, 24 bits of the z-buffer are depth and 8 bits are stencil. In 16-bit mode there
776            is no room for a stencil (although some cards support a 15:1 depth:stencil option,
777            this isn't useful for very much) so 8 bits of stencil are provided in software.
778            This can mean that if you use stencilling, your applications may be faster in
779            32-but colour than in 16-bit, which may seem odd to some people.
780        */
781        /*virtual bool hasHardwareStencil(void) = 0;*/
782
783        /** This method allows you to set all the stencil buffer parameters in one call.
784        @remarks
785            The stencil buffer is used to mask out pixels in the render target, allowing
786            you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
787            your batches of rendering is likely to ignore the stencil buffer,
788            update it with new values, or apply it to mask the output of the render.
789            The stencil test is:<PRE>
790            (Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)</PRE>
791            The result of this will cause one of 3 actions depending on whether the test fails,
792            succeeds but with the depth buffer check still failing, or succeeds with the
793            depth buffer check passing too.
794        @par
795            Unlike other render states, stencilling is left for the application to turn
796            on and off when it requires. This is because you are likely to want to change
797            parameters between batches of arbitrary objects and control the ordering yourself.
798            In order to batch things this way, you'll want to use OGRE's separate render queue
799            groups (see RenderQueue) and register a RenderQueueListener to get notifications
800            between batches.
801        @par
802            There are individual state change methods for each of the parameters set using
803            this method.
804            Note that the default values in this method represent the defaults at system
805            start up too.
806        @param func The comparison function applied.
807        @param refValue The reference value used in the comparison
808        @param mask The bitmask applied to both the stencil value and the reference value
809            before comparison
810        @param stencilFailOp The action to perform when the stencil check fails
811        @param depthFailOp The action to perform when the stencil check passes, but the
812            depth buffer check still fails
813        @param passOp The action to take when both the stencil and depth check pass.
814        @param twoSidedOperation If set to true, then if you render both back and front faces
815            (you'll have to turn off culling) then these parameters will apply for front faces,
816            and the inverse of them will happen for back faces (keep remains the same).
817        */
818        virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
819            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
820            StencilOperation stencilFailOp = SOP_KEEP,
821            StencilOperation depthFailOp = SOP_KEEP,
822            StencilOperation passOp = SOP_KEEP,
823            bool twoSidedOperation = false) = 0;
824
825
826
827                /** Sets the current vertex declaration, ie the source of vertex data. */
828                virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
829                /** Sets the current vertex buffer binding state. */
830                virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
831
832        /** Sets whether or not normals are to be automatically normalised.
833        @remarks
834            This is useful when, for example, you are scaling SceneNodes such that
835            normals may not be unit-length anymore. Note though that this has an
836            overhead so should not be turn on unless you really need it.
837        @par
838            You should not normally call this direct unless you are rendering
839            world geometry; set it on the Renderable because otherwise it will be
840            overridden by material settings.
841        */
842        virtual void setNormaliseNormals(bool normalise) = 0;
843
844        /**
845          Render something to the active viewport.
846
847          Low-level rendering interface to perform rendering
848          operations. Unlikely to be used directly by client
849          applications, since the SceneManager and various support
850          classes will be responsible for calling this method.
851          Can only be called between _beginScene and _endScene
852
853          @param op A rendering operation instance, which contains
854            details of the operation to be performed.
855         */
856        virtual void _render(const RenderOperation& op);
857
858                /** Gets the capabilities of the render system. */
859                const RenderSystemCapabilities* getCapabilities(void) const { return mCapabilities; }
860
861        /** Binds a given GpuProgram (but not the parameters).
862        @remarks Only one GpuProgram of each type can be bound at once, binding another
863        one will simply replace the exsiting one.
864        */
865        virtual void bindGpuProgram(GpuProgram* prg) = 0;
866
867        /** Bind Gpu program parameters. */
868        virtual void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) = 0;
869        /** Unbinds GpuPrograms of a given GpuProgramType.
870        @remarks
871            This returns the pipeline to fixed-function processing for this type.
872        */
873        virtual void unbindGpuProgram(GpuProgramType gptype) = 0;
874
875        /** sets the clipping region.
876        */
877        virtual void setClipPlanes(const PlaneList& clipPlanes) = 0;
878
879        /** Utility method for initialising all render targets attached to this rendering system. */
880        virtual void _initRenderTargets(void);
881
882        /** Utility method to notify all render targets that a camera has been removed,
883            incase they were referring to it as their viewer.
884        */
885        virtual void _notifyCameraRemoved(const Camera* cam);
886
887        /** Internal method for updating all render targets attached to this rendering system. */
888        virtual void _updateAllRenderTargets(void);
889
890        /** Set a clipping plane. */
891        virtual void setClipPlane (ushort index, const Plane &p);
892        /** Set a clipping plane. */
893        virtual void setClipPlane (ushort index, Real A, Real B, Real C, Real D) = 0;
894        /** Enable the clipping plane. */
895        virtual void enableClipPlane (ushort index, bool enable) = 0;
896
897        /** Sets whether or not vertex windings set should be inverted; this can be important
898            for rendering reflections. */
899        virtual void setInvertVertexWinding(bool invert);
900        /** Sets the 'scissor region' ie the region of the target in which rendering can take place.
901        @remarks
902            This method allows you to 'mask off' rendering in all but a given rectangular area
903            as identified by the parameters to this method.
904        @note
905            Not all systems support this method. Check the RenderSystemCapabilities for the
906            RSC_SCISSOR_TEST capability to see if it is supported.
907        @param enabled True to enable the scissor test, false to disable it.
908        @param left, top, right, bottom The location of the corners of the rectangle, expressed in
909            <i>pixels</i>.
910        */
911        virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
912            size_t right = 800, size_t bottom = 600) = 0;
913
914        /** Clears one or more frame buffers on the active render target.
915        @param buffers Combination of one or more elements of FrameBufferType
916            denoting which buffers are to be cleared
917        @param colour The colour to clear the colour buffer with, if enabled
918        @param depth The value to initialise the depth buffer with, if enabled
919        @param stencil The value to initialise the stencil buffer with, if enabled.
920        */
921        virtual void clearFrameBuffer(unsigned int buffers,
922            const ColourValue& colour = ColourValue::Black,
923            Real depth = 1.0f, unsigned short stencil = 0) = 0;
924        /** Returns the horizontal texel offset value required for mapping
925            texel origins to pixel origins in this rendersystem.
926        @remarks
927            Since rendersystems sometimes disagree on the origin of a texel,
928            mapping from texels to pixels can sometimes be problematic to
929            implement generically. This method allows you to retrieve the offset
930            required to map the origin of a texel to the origin of a pixel in
931            the horizontal direction.
932        */
933        virtual Real getHorizontalTexelOffset(void) = 0;
934        /** Returns the vertical texel offset value required for mapping
935        texel origins to pixel origins in this rendersystem.
936        @remarks
937        Since rendersystems sometimes disagree on the origin of a texel,
938        mapping from texels to pixels can sometimes be problematic to
939        implement generically. This method allows you to retrieve the offset
940        required to map the origin of a texel to the origin of a pixel in
941        the vertical direction.
942        */
943        virtual Real getVerticalTexelOffset(void) = 0;
944
945        /** Gets the minimum (closest) depth value to be used when rendering
946            using identity transforms.
947        @remarks
948            When using identity transforms you can manually set the depth
949            of a vertex; however the input values required differ per
950            rendersystem. This method lets you retrieve the correct value.
951        @see Renderable::useIdentityView, Renderable::useIdentityProjection
952        */
953        virtual Real getMinimumDepthInputValue(void) = 0;
954        /** Gets the maximum (farthest) depth value to be used when rendering
955            using identity transforms.
956        @remarks
957            When using identity transforms you can manually set the depth
958            of a vertex; however the input values required differ per
959            rendersystem. This method lets you retrieve the correct value.
960        @see Renderable::useIdentityView, Renderable::useIdentityProjection
961        */
962        virtual Real getMaximumDepthInputValue(void) = 0;
963
964                /** Defines a listener on the custom events that this render system
965                        can raise.
966                @see RenderSystem::addListener
967                */
968                class _OgreExport Listener
969                {
970                public:
971                        Listener() {}
972                        virtual ~Listener() {}
973
974                        /** A rendersystem-specific event occurred.
975                        @param eventName The name of the event which has occurred
976                        @param parameters A list of parameters that may belong to this event,
977                                may be null if there are no parameters
978                        */
979                        virtual void eventOccurred(const String& eventName,
980                                const NameValuePairList* parameters = 0) = 0;
981                };
982                /** Adds a listener to the custom events that this render system can raise.
983                @remarks
984                        Some render systems have quite specific, internally generated events
985                        that the application may wish to be notified of. Many applications
986                        don't have to worry about these events, and can just trust OGRE to
987                        handle them, but if you want to know, you can add a listener here.
988                @par
989                        Events are raised very generically by string name. Perhaps the most
990                        common example of a render system specific event is the loss and
991                        restoration of a device in DirectX; which OGRE deals with, but you
992                        may wish to know when it happens.
993                @see RenderSystem::getRenderSystemEvents
994                */
995                virtual void addListener(Listener* l);
996                /** Remove a listener to the custom events that this render system can raise.
997                */
998                virtual void removeListener(Listener* l);
999
1000                /** Gets a list of the rendersystem specific events that this rendersystem
1001                        can raise.
1002                @see RenderSystem::addListener
1003                */
1004                virtual const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
1005    protected:
1006
1007
1008        /** The render targets. */
1009        RenderTargetMap mRenderTargets;
1010                /** The render targets, ordered by priority. */
1011                RenderTargetPriorityMap mPrioritisedRenderTargets;
1012                /** The Active render target. */
1013                RenderTarget * mActiveRenderTarget;
1014
1015        // Texture manager
1016        // A concrete class of this will be created and
1017        // made available under the TextureManager singleton,
1018        // managed by the RenderSystem
1019        TextureManager* mTextureManager;
1020
1021        /// Used to store the capabilities of the graphics card
1022        RenderSystemCapabilities* mCapabilities;
1023
1024        // Active viewport (dest for future rendering operations)
1025        Viewport* mActiveViewport;
1026
1027        CullingMode mCullingMode;
1028
1029        bool mVSync;
1030                bool mWBuffer;
1031
1032        size_t mFaceCount;
1033        size_t mVertexCount;
1034
1035        /// Saved set of world matrices
1036        Matrix4 mWorldMatrices[256];
1037
1038                /// Saved manual colour blends
1039                ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
1040
1041        bool mInvertVertexWinding;
1042
1043                /// List of names of events this rendersystem may raise
1044                StringVector mEventNames;
1045
1046                /// Internal method for firing a rendersystem event
1047                virtual void fireEvent(const String& name, const NameValuePairList* params = 0);
1048
1049                typedef std::list<Listener*> ListenerList;
1050                ListenerList mEventListeners;
1051
1052                typedef std::list<HardwareOcclusionQuery*> HardwareOcclusionQueryList;
1053                HardwareOcclusionQueryList mHwOcclusionQueries;
1054
1055
1056    };
1057}
1058
1059#endif
Note: See TracBrowser for help on using the repository browser.