source: trunk/VUT/work/ogre_changes/OgreMain/include/OgreRenderSystem.h @ 150

Revision 150, 49.9 KB checked in by mattausch, 19 years ago (diff)

added item buffer functionality

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