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

Revision 316, 50.0 KB checked in by mattausch, 19 years ago (diff)

queries are realized as templates

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                                Key: "border"
322                                Description: The type of window border (in windowed mode)
323                                Values: none, fixed, resize
324                                Default: resize
325                                **
326                                Key: "outerDimensions"
327                                Description: Whether the width/height is expressed as the size of the
328                                outer window, rather than the content area
329                                Values: true, false
330                                Default: false
331        */
332                virtual RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height,
333                        bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
334
335                /** Creates and registers a render texture object.
336                        @param name
337                                The name for the new render texture. Note that names must be unique.
338                        @param width
339                                The requested width for the render texture. See Remarks for more info.
340                        @param height
341                                The requested width for the render texture. See Remarks for more info.
342                        @param texType
343                                The type of texture; defaults to TEX_TYPE_2D
344                        @param internalFormat
345                                The internal format of the texture; defaults to PF_X8R8G8B8
346                        @param miscParams A NameValuePairList describing the other parameters for the new rendering window.
347                                        Unrecognised parameters will be ignored silently.
348                                        These values might be platform dependent, but these are present for all platorms unless
349                                        indicated otherwise:
350                                **
351                                Key: "FSAA"
352                                Description: Full screen antialiasing factor
353                                Values: 0,2,4,6,...
354                                Default: 0
355                                **
356                                Key: "depth"
357                                Description: Depth in case of render-to-texture TEX_3D
358                                Values: positive integers
359                        @returns
360                                On succes, a pointer to a new platform-dependernt, RenderTexture-derived
361                                class is returned. On failiure, NULL is returned.
362                        @remarks
363                                Because a render texture is basically a wrapper around a texture object,
364                                the width and height parameters of this method just hint the preferred
365                                size for the texture. Depending on the hardware driver or the underlying
366                                API, these values might change when the texture is created. The same applies
367                                to the internalFormat parameter.
368                */
369                virtual RenderTexture * createRenderTexture( const String & name, unsigned int width, unsigned int height,
370                        TextureType texType = TEX_TYPE_2D, PixelFormat internalFormat = PF_X8R8G8B8,
371                        const NameValuePairList *miscParams = 0 ) = 0;
372
373        /** Destroys a render window */
374        virtual void destroyRenderWindow(const String& name);
375        /** Destroys a render texture */
376        virtual void destroyRenderTexture(const String& name);
377        /** Destroys a render target of any sort */
378        virtual void destroyRenderTarget(const String& name);
379
380        /** Attaches the passed render target to the render system.
381        */
382        virtual void attachRenderTarget( RenderTarget &target );
383        /** Returns a pointer to the render target with the passed name, or NULL if that
384            render target cannot be found.
385        */
386        virtual RenderTarget * getRenderTarget( const String &name );
387        /** Detaches the render target with the passed name from the render system and
388            returns a pointer to it.
389            @note
390                If the render target cannot be found, NULL is returned.
391        */
392        virtual RenderTarget * detachRenderTarget( const String &name );
393
394        /** Returns a description of an error code.
395        */
396        virtual String getErrorDescription(long errorNumber) const = 0;
397
398        /** Defines whether or now fullscreen render windows wait for the vertical blank before flipping buffers.
399            @remarks
400                By default, all rendering windows wait for a vertical blank (when the CRT beam turns off briefly to move
401                from the bottom right of the screen back to the top left) before flipping the screen buffers. This ensures
402                that the image you see on the screen is steady. However it restricts the frame rate to the refresh rate of
403                the monitor, and can slow the frame rate down. You can speed this up by not waiting for the blank, but
404                this has the downside of introducing 'tearing' artefacts where part of the previous frame is still displayed
405                as the buffers are switched. Speed vs quality, you choose.
406            @note
407                Has NO effect on windowed mode render targets. Only affects fullscreen mode.
408            @param
409                enabled If true, the system waits for vertical blanks - quality over speed. If false it doesn't - speed over quality.
410        */
411        void setWaitForVerticalBlank(bool enabled);
412
413        /** Returns true if the system is synchronising frames with the monitor vertical blank.
414        */
415        bool getWaitForVerticalBlank(void) const;
416
417        // ------------------------------------------------------------------------
418        //                     Internal Rendering Access
419        // All methods below here are normally only called by other OGRE classes
420        // They can be called by library user if required
421        // ------------------------------------------------------------------------
422
423
424        /** Tells the rendersystem to use the attached set of lights (and no others)
425        up to the number specified (this allows the same list to be used with different
426        count limits) */
427        virtual void _useLights(const LightList& lights, unsigned short limit) = 0;
428        /** Sets the world transform matrix. */
429        virtual void _setWorldMatrix(const Matrix4 &m) = 0;
430        /** Sets multiple world matrices (vertex blending). */
431        virtual void _setWorldMatrices(const Matrix4* m, unsigned short count);
432        /** Sets the view transform matrix */
433        virtual void _setViewMatrix(const Matrix4 &m) = 0;
434        /** Sets the projection transform matrix */
435        virtual void _setProjectionMatrix(const Matrix4 &m) = 0;
436        /** Utility function for setting all the properties of a texture unit at once.
437            This method is also worth using over the individual texture unit settings because it
438            only sets those settings which are different from the current settings for this
439            unit, thus minimising render state changes.
440        */
441        virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
442        /** Turns off a texture unit. */
443        virtual void _disableTextureUnit(size_t texUnit);
444        /** Disables all texture units from the given unit upwards */
445        virtual void _disableTextureUnitsFrom(size_t texUnit);
446        /** Sets the surface properties to be used for future rendering.
447
448            This method sets the the properties of the surfaces of objects
449            to be rendered after it. In this context these surface properties
450            are the amount of each type of light the object reflects (determining
451            it's colour under different types of light), whether it emits light
452            itself, and how shiny it is. Textures are not dealt with here,
453            see the _setTetxure method for details.
454            This method is used by _setMaterial so does not need to be called
455            direct if that method is being used.
456
457            @param ambient The amount of ambient (sourceless and directionless)
458            light an object reflects. Affected by the colour/amount of ambient light in the scene.
459            @param diffuse The amount of light from directed sources that is
460            reflected (affected by colour/amount of point, directed and spot light sources)
461            @param specular The amount of specular light reflected. This is also
462            affected by directed light sources but represents the colour at the
463            highlights of the object.
464            @param emissive The colour of light emitted from the object. Note that
465            this will make an object seem brighter and not dependent on lights in
466            the scene, but it will not act as a light, so will not illuminate other
467            objects. Use a light attached to the same SceneNode as the object for this purpose.
468            @param shininess A value which only has an effect on specular highlights (so
469            specular must be non-black). The higher this value, the smaller and crisper the
470            specular highlights will be, imitating a more highly polished surface.
471            This value is not constrained to 0.0-1.0, in fact it is likely to
472            be more (10.0 gives a modest sheen to an object).
473            @param tracking A bit field that describes which of the ambient, diffuse, specular
474            and emissive colours follow the vertex colour of the primitive. When a bit in this field is set
475            its ColourValue is ignored. This is a combination of TVC_AMBIENT, TVC_DIFFUSE, TVC_SPECULAR(note that the shininess value is still
476            taken from shininess) and TVC_EMISSIVE. TVC_NONE means that there will be no material property
477            tracking the vertex colours.
478        */
479        virtual void _setSurfaceParams(const ColourValue &ambient,
480            const ColourValue &diffuse, const ColourValue &specular,
481            const ColourValue &emissive, Real shininess,
482            TrackVertexColourType tracking = TVC_NONE) = 0;
483        /**
484          Sets the status of a single texture stage.
485
486          Sets the details of a texture stage, to be used for all primitives
487          rendered afterwards. User processes would
488          not normally call this direct unless rendering
489          primitives themselves - the SubEntity class
490          is designed to manage materials for objects.
491          Note that this method is called by _setMaterial.
492
493          @param unit The index of the texture unit to modify. Multitexturing hardware
494          can support multiple units (see RenderSystemCapabilites::numTextureUnits)
495          @param enabled Boolean to turn the unit on/off
496          @param texname The name of the texture to use - this should have
497              already been loaded with TextureManager::load.
498         */
499        virtual void _setTexture(size_t unit, bool enabled, const String &texname) = 0;
500
501        /**
502          Sets the texture coordinate set to use for a texture unit.
503
504          Meant for use internally - not generally used directly by apps - the Material and TextureUnitState
505          classes let you manage textures far more easily.
506
507          @param unit Texture unit as above
508          @param index The index of the texture coordinate set to use.
509         */
510        virtual void _setTextureCoordSet(size_t unit, size_t index) = 0;
511
512        /**
513          Sets a method for automatically calculating texture coordinates for a stage.
514          Should not be used by apps - for use by Ogre only.
515          @param unit Texture unit as above
516          @param m Calculation method to use
517          @param frustum Optional Frustum param, only used for projective effects
518         */
519        virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
520            const Frustum* frustum = 0) = 0;
521
522        /** Sets the texture blend modes from a TextureUnitState record.
523            Meant for use internally only - apps should use the Material
524            and TextureUnitState classes.
525            @param unit Texture unit as above
526            @param bm Details of the blending mode
527        */
528        virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) = 0;
529
530        /** Sets the filtering options for a given texture unit.
531        @param unit The texture unit to set the filtering options for
532        @param minFilter The filter used when a texture is reduced in size
533        @param magFilter The filter used when a texture is magnified
534        @param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
535        */
536        virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
537            FilterOptions magFilter, FilterOptions mipFilter);
538
539        /** Sets a single filter for a given texture unit.
540        @param unit The texture unit to set the filtering options for
541        @param ftype The filter type
542        @param filter The filter to be used
543        */
544        virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
545
546                /** Sets the maximal anisotropy for the specified texture unit.*/
547                virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
548
549                /** Sets the texture addressing mode for a texture unit.*/
550        virtual void _setTextureAddressingMode(size_t unit, TextureUnitState::TextureAddressingMode tam) = 0;
551
552        /** Sets the texture coordinate transformation matrix for a texture unit.
553            @param unit Texture unit to affect
554            @param xform The 4x4 matrix
555        */
556        virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) = 0;
557
558        /** Sets the global blending factors for combining subsequent renders with the existing frame contents.
559            The result of the blending operation is:</p>
560            <p align="center">final = (texture * sourceFactor) + (pixel * destFactor)</p>
561            Each of the factors is specified as one of a number of options, as specified in the SceneBlendFactor
562            enumerated type.
563            @param sourceFactor The source factor in the above calculation, i.e. multiplied by the texture colour components.
564            @param destFactor The destination factor in the above calculation, i.e. multiplied by the pixel colour components.
565        */
566        virtual void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor) = 0;
567
568        /** Sets the global alpha rejection approach for future renders.
569            By default images are rendered regardless of texture alpha. This method lets you change that.
570            @param func The comparison function which must pass for a pixel to be written.
571            @param val The value to compare each pixels alpha value to (0-255)
572        */
573        virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value) = 0;
574        /**
575         * Signifies the beginning of a frame, ie the start of rendering on a single viewport. Will occur
576         * several times per complete frame if multiple viewports exist.
577         */
578        virtual void _beginFrame(void) = 0;
579
580
581        /**
582         * Ends rendering of a frame to the current viewport.
583         */
584        virtual void _endFrame(void) = 0;
585        /**
586          Sets the provided viewport as the active one for future
587          rendering operations. This viewport is aware of it's own
588          camera and render target. Must be implemented by subclass.
589
590          @param target Pointer to the appropriate viewport.
591         */
592        virtual void _setViewport(Viewport *vp) = 0;
593        /** Get the current active viewport for rendering. */
594        virtual Viewport* _getViewport(void);
595
596        /** Sets the culling mode for the render system based on the 'vertex winding'.
597            A typical way for the rendering engine to cull triangles is based on the
598            'vertex winding' of triangles. Vertex winding refers to the direction in
599            which the vertices are passed or indexed to in the rendering operation as viewed
600            from the camera, and will wither be clockwise or anticlockwise (that's 'counterclockwise' for
601            you Americans out there ;) The default is CULL_CLOCKWISE i.e. that only triangles whose vertices
602            are passed/indexed in anticlockwise order are rendered - this is a common approach and is used in 3D studio models
603            for example. You can alter this culling mode if you wish but it is not advised unless you know what you are doing.
604            You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
605            winding is uncertain.
606        */
607        virtual void _setCullingMode(CullingMode mode) = 0;
608
609        virtual CullingMode _getCullingMode(void) const;
610
611        /** Sets the mode of operation for depth buffer tests from this point onwards.
612            Sometimes you may wish to alter the behaviour of the depth buffer to achieve
613            special effects. Because it's unlikely that you'll set these options for an entire frame,
614            but rather use them to tweak settings between rendering objects, this is an internal
615            method (indicated by the '_' prefix) which will be used by a SceneManager implementation
616            rather than directly from the client application.
617            If this method is never called the settings are automatically the same as the default parameters.
618            @param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
619                if the depth function test succeeds. If false, no test is performed and pixels are always written.
620            @param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
621                If false, the depth buffer is left unchanged even if a new pixel is written.
622            @param depthFunction Sets the function required for the depth test.
623        */
624        virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
625
626        /** Sets whether or not the depth buffer check is performed before a pixel write.
627            @param enabled If true, the depth buffer is tested for each pixel and the frame buffer is only updated
628                if the depth function test succeeds. If false, no test is performed and pixels are always written.
629        */
630        virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
631        /** Sets whether or not the depth buffer is updated after a pixel write.
632            @param enabled If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
633                If false, the depth buffer is left unchanged even if a new pixel is written.
634        */
635        virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
636        /** Sets the comparison function for the depth buffer check.
637            Advanced use only - allows you to choose the function applied to compare the depth values of
638            new and existing pixels in the depth buffer. Only an issue if the deoth buffer check is enabled
639            (see _setDepthBufferCheckEnabled)
640            @param  func The comparison between the new depth and the existing depth which must return true
641             for the new pixel to be written.
642        */
643        virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
644                /** Sets whether or not colour buffer writing is enabled, and for which channels.
645                @remarks
646                        For some advanced effects, you may wish to turn off the writing of certain colour
647                        channels, or even all of the colour channels so that only the depth buffer is updated
648                        in a rendering pass. However, the chances are that you really want to use this option
649                        through the Material class.
650                @param red, green, blue, alpha Whether writing is enabled for each of the 4 colour channels. */
651                virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
652        /** Sets the depth bias, NB you should use the Material version of this.
653        @remarks
654            When polygons are coplanar, you can get problems with 'depth fighting' where
655            the pixels from the two polys compete for the same screen pixel. This is particularly
656            a problem for decals (polys attached to another surface to represent details such as
657            bulletholes etc.).
658        @par
659            A way to combat this problem is to use a depth bias to adjust the depth buffer value
660            used for the decal such that it is slightly higher than the true value, ensuring that
661            the decal appears on top.
662        @param bias The bias value, should be between 0 and 16.
663        */
664        virtual void _setDepthBias(ushort bias) = 0;
665        /** Sets the fogging mode for future geometry.
666            @param mode Set up the mode of fog as described in the FogMode enum, or set to FOG_NONE to turn off.
667            @param colour The colour of the fog. Either set this to the same as your viewport background colour,
668                or to blend in with a skydome or skybox.
669            @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
670                that fog never completely obscures the scene.
671            @param linearStart Distance at which linear fog starts to encroach. The distance must be passed
672                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.
673            @param linearEnd Distance at which linear fog becomes completely opaque.The distance must be passed
674                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.
675        */
676        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;
677
678
679        /** The RenderSystem will keep a count of tris rendered, this resets the count. */
680        virtual void _beginGeometryCount(void);
681        /** Reports the number of tris rendered since the last _beginGeometryCount call. */
682        virtual unsigned int _getFaceCount(void) const;
683        /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */
684        virtual unsigned int _getVertexCount(void) const;
685
686        /** Generates a packed data version of the passed in ColourValue suitable for
687            use as with this RenderSystem.
688        @remarks
689            Since different render systems have different colour data formats (eg
690            RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
691        @param colour The colour to convert
692        @param pDest Pointer to location to put the result.
693        */
694        virtual void convertColourValue(const ColourValue& colour, uint32* pDest) = 0;
695
696        /** Builds a perspective projection matrix suitable for this render system.
697        @remarks
698            Because different APIs have different requirements (some incompatible) for the
699            projection matrix, this method allows each to implement their own correctly and pass
700            back a generic OGRE matrix for storage in the engine.
701        */
702        virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
703            Matrix4& dest, bool forGpuProgram = false) = 0;
704
705        /** Builds a perspective projection matrix for the case when frustum is
706            not centered around camera.
707        @remarks
708            Viewport coordinates are in camera coordinate frame, i.e. camera is
709            at the origin.
710        */
711        virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
712            Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
713        /** Builds an orthographic projection matrix suitable for this render system.
714        @remarks
715            Because different APIs have different requirements (some incompatible) for the
716            projection matrix, this method allows each to implement their own correctly and pass
717            back a generic OGRE matrix for storage in the engine.
718        */
719        virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
720            Matrix4& dest, bool forGpuProgram = false) = 0;
721
722                /** Update a perspective projection matrix to use 'oblique depth projection'.
723                @remarks
724                        This method can be used to change the nature of a perspective
725                        transform in order to make the near plane not perpendicular to the
726                        camera view direction, but to be at some different orientation.
727                        This can be useful for performing arbitrary clipping (e.g. to a
728                        reflection plane) which could otherwise only be done using user
729                        clip planes, which are more expensive, and not necessarily supported
730                        on all cards.
731                @param matrix The existing projection matrix. Note that this must be a
732                        perspective transform (not orthographic), and must not have already
733                        been altered by this method. The matrix will be altered in-place.
734                @param plane The plane which is to be used as the clipping plane. This
735                        plane must be in CAMERA (view) space.
736        @param forGpuProgram Is this for use with a Gpu program or fixed-function
737                */
738                virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
739            bool forGpuProgram) = 0;
740               
741        /** Sets how to rasterise triangles, as points, wireframe or solid polys. */
742        virtual void _setRasterisationMode(SceneDetailLevel level) = 0;
743
744        /** Turns stencil buffer checking on or off.
745        @remarks
746            Stencilling (masking off areas of the rendering target based on the stencil
747            buffer) canbe turned on or off using this method. By default, stencilling is
748            disabled.
749        */
750        virtual void setStencilCheckEnabled(bool enabled) = 0;
751        /** Determines if this system supports hardware accelerated stencil buffer.
752        @remarks
753            Note that the lack of this function doesn't mean you can't do stencilling, but
754            the stencilling operations will be provided in software, which will NOT be
755            fast.
756        @par
757            Generally hardware stencils are only supported in 32-bit colour modes, because
758            the stencil buffer shares the memory of the z-buffer, and in most cards the
759            z-buffer has to be the same depth as the colour buffer. This means that in 32-bit
760            mode, 24 bits of the z-buffer are depth and 8 bits are stencil. In 16-bit mode there
761            is no room for a stencil (although some cards support a 15:1 depth:stencil option,
762            this isn't useful for very much) so 8 bits of stencil are provided in software.
763            This can mean that if you use stencilling, your applications may be faster in
764            32-but colour than in 16-bit, which may seem odd to some people.
765        */
766        /*virtual bool hasHardwareStencil(void) = 0;*/
767
768        /** This method allows you to set all the stencil buffer parameters in one call.
769        @remarks
770            The stencil buffer is used to mask out pixels in the render target, allowing
771            you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
772            your batches of rendering is likely to ignore the stencil buffer,
773            update it with new values, or apply it to mask the output of the render.
774            The stencil test is:<PRE>
775            (Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)</PRE>
776            The result of this will cause one of 3 actions depending on whether the test fails,
777            succeeds but with the depth buffer check still failing, or succeeds with the
778            depth buffer check passing too.
779        @par
780            Unlike other render states, stencilling is left for the application to turn
781            on and off when it requires. This is because you are likely to want to change
782            parameters between batches of arbitrary objects and control the ordering yourself.
783            In order to batch things this way, you'll want to use OGRE's separate render queue
784            groups (see RenderQueue) and register a RenderQueueListener to get notifications
785            between batches.
786        @par
787            There are individual state change methods for each of the parameters set using
788            this method.
789            Note that the default values in this method represent the defaults at system
790            start up too.
791        @param func The comparison function applied.
792        @param refValue The reference value used in the comparison
793        @param mask The bitmask applied to both the stencil value and the reference value
794            before comparison
795        @param stencilFailOp The action to perform when the stencil check fails
796        @param depthFailOp The action to perform when the stencil check passes, but the
797            depth buffer check still fails
798        @param passOp The action to take when both the stencil and depth check pass.
799        @param twoSidedOperation If set to true, then if you render both back and front faces
800            (you'll have to turn off culling) then these parameters will apply for front faces,
801            and the inverse of them will happen for back faces (keep remains the same).
802        */
803        virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
804            uint32 refValue = 0, uint32 mask = 0xFFFFFFFF,
805            StencilOperation stencilFailOp = SOP_KEEP,
806            StencilOperation depthFailOp = SOP_KEEP,
807            StencilOperation passOp = SOP_KEEP,
808            bool twoSidedOperation = false) = 0;
809
810
811
812                /** Sets the current vertex declaration, ie the source of vertex data. */
813                virtual void setVertexDeclaration(VertexDeclaration* decl) = 0;
814                /** Sets the current vertex buffer binding state. */
815                virtual void setVertexBufferBinding(VertexBufferBinding* binding) = 0;
816
817        /** Sets whether or not normals are to be automatically normalised.
818        @remarks
819            This is useful when, for example, you are scaling SceneNodes such that
820            normals may not be unit-length anymore. Note though that this has an
821            overhead so should not be turn on unless you really need it.
822        @par
823            You should not normally call this direct unless you are rendering
824            world geometry; set it on the Renderable because otherwise it will be
825            overridden by material settings.
826        */
827        virtual void setNormaliseNormals(bool normalise) = 0;
828
829        /**
830          Render something to the active viewport.
831
832          Low-level rendering interface to perform rendering
833          operations. Unlikely to be used directly by client
834          applications, since the SceneManager and various support
835          classes will be responsible for calling this method.
836          Can only be called between _beginScene and _endScene
837
838          @param op A rendering operation instance, which contains
839            details of the operation to be performed.
840         */
841        virtual void _render(const RenderOperation& op);
842
843                /** Gets the capabilities of the render system. */
844                const RenderSystemCapabilities* getCapabilities(void) const { return mCapabilities; }
845
846        /** Binds a given GpuProgram (but not the parameters).
847        @remarks Only one GpuProgram of each type can be bound at once, binding another
848        one will simply replace the exsiting one.
849        */
850        virtual void bindGpuProgram(GpuProgram* prg) = 0;
851
852        /** Bind Gpu program parameters. */
853        virtual void bindGpuProgramParameters(GpuProgramType gptype, GpuProgramParametersSharedPtr params) = 0;
854        /** Unbinds GpuPrograms of a given GpuProgramType.
855        @remarks
856            This returns the pipeline to fixed-function processing for this type.
857        */
858        virtual void unbindGpuProgram(GpuProgramType gptype) = 0;
859
860        /** sets the clipping region.
861        */
862        virtual void setClipPlanes(const PlaneList& clipPlanes) = 0;
863
864        /** Utility method for initialising all render targets attached to this rendering system. */
865        virtual void _initRenderTargets(void);
866
867        /** Utility method to notify all render targets that a camera has been removed,
868            incase they were referring to it as their viewer.
869        */
870        virtual void _notifyCameraRemoved(const Camera* cam);
871
872        /** Internal method for updating all render targets attached to this rendering system. */
873        virtual void _updateAllRenderTargets(void);
874
875        /** Set a clipping plane. */
876        virtual void setClipPlane (ushort index, const Plane &p);
877        /** Set a clipping plane. */
878        virtual void setClipPlane (ushort index, Real A, Real B, Real C, Real D) = 0;
879        /** Enable the clipping plane. */
880        virtual void enableClipPlane (ushort index, bool enable) = 0;
881
882        /** Sets whether or not vertex windings set should be inverted; this can be important
883            for rendering reflections. */
884        virtual void setInvertVertexWinding(bool invert);
885        /** Sets the 'scissor region' ie the region of the target in which rendering can take place.
886        @remarks
887            This method allows you to 'mask off' rendering in all but a given rectangular area
888            as identified by the parameters to this method.
889        @note
890            Not all systems support this method. Check the RenderSystemCapabilities for the
891            RSC_SCISSOR_TEST capability to see if it is supported.
892        @param enabled True to enable the scissor test, false to disable it.
893        @param left, top, right, bottom The location of the corners of the rectangle, expressed in
894            <i>pixels</i>.
895        */
896        virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
897            size_t right = 800, size_t bottom = 600) = 0;
898
899        /** Clears one or more frame buffers on the active render target.
900        @param buffers Combination of one or more elements of FrameBufferType
901            denoting which buffers are to be cleared
902        @param colour The colour to clear the colour buffer with, if enabled
903        @param depth The value to initialise the depth buffer with, if enabled
904        @param stencil The value to initialise the stencil buffer with, if enabled.
905        */
906        virtual void clearFrameBuffer(unsigned int buffers,
907            const ColourValue& colour = ColourValue::Black,
908            Real depth = 1.0f, unsigned short stencil = 0) = 0;
909        /** Returns the horizontal texel offset value required for mapping
910            texel origins to pixel origins in this rendersystem.
911        @remarks
912            Since rendersystems sometimes disagree on the origin of a texel,
913            mapping from texels to pixels can sometimes be problematic to
914            implement generically. This method allows you to retrieve the offset
915            required to map the origin of a texel to the origin of a pixel in
916            the horizontal direction.
917        */
918        virtual Real getHorizontalTexelOffset(void) = 0;
919        /** Returns the vertical texel offset value required for mapping
920        texel origins to pixel origins in this rendersystem.
921        @remarks
922        Since rendersystems sometimes disagree on the origin of a texel,
923        mapping from texels to pixels can sometimes be problematic to
924        implement generically. This method allows you to retrieve the offset
925        required to map the origin of a texel to the origin of a pixel in
926        the vertical direction.
927        */
928        virtual Real getVerticalTexelOffset(void) = 0;
929
930        /** Gets the minimum (closest) depth value to be used when rendering
931            using identity transforms.
932        @remarks
933            When using identity transforms you can manually set the depth
934            of a vertex; however the input values required differ per
935            rendersystem. This method lets you retrieve the correct value.
936        @see Renderable::useIdentityView, Renderable::useIdentityProjection
937        */
938        virtual Real getMinimumDepthInputValue(void) = 0;
939        /** Gets the maximum (farthest) depth value to be used when rendering
940            using identity transforms.
941        @remarks
942            When using identity transforms you can manually set the depth
943            of a vertex; however the input values required differ per
944            rendersystem. This method lets you retrieve the correct value.
945        @see Renderable::useIdentityView, Renderable::useIdentityProjection
946        */
947        virtual Real getMaximumDepthInputValue(void) = 0;
948
949    protected:
950
951
952        /** The render targets. */
953        RenderTargetMap mRenderTargets;
954                /** The render targets, ordered by priority. */
955                RenderTargetPriorityMap mPrioritisedRenderTargets;
956                /** The Active render target. */
957                RenderTarget * mActiveRenderTarget;
958
959        // Texture manager
960        // A concrete class of this will be created and
961        // made available under the TextureManager singleton,
962        // managed by the RenderSystem
963        TextureManager* mTextureManager;
964
965        /// Used to store the capabilities of the graphics card
966        RenderSystemCapabilities* mCapabilities;
967
968        // Active viewport (dest for future rendering operations)
969        Viewport* mActiveViewport;
970
971        CullingMode mCullingMode;
972
973        bool mVSync;
974                bool mWBuffer;
975
976        size_t mFaceCount;
977        size_t mVertexCount;
978
979        /// Saved set of world matrices
980        Matrix4 mWorldMatrices[256];
981
982                /// Saved manual colour blends
983                ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
984
985        bool mInvertVertexWinding;
986    };
987}
988
989#endif
Note: See TracBrowser for help on using the repository browser.