Coverage Report

Created: 2026-02-11 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/include/OgreRenderSystem.h
Line
Count
Source
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
(Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
#ifndef __RenderSystem_H_
29
#define __RenderSystem_H_
30
31
// Precompiler options
32
#include "OgrePrerequisites.h"
33
34
#include "OgreCommon.h"
35
#include "OgreBlendMode.h"
36
37
#include "OgreRenderSystemCapabilities.h"
38
#include "OgreConfigOptionMap.h"
39
#include "OgreGpuProgram.h"
40
#include "OgrePlane.h"
41
#include "OgreHardwareVertexBuffer.h"
42
#include "OgreHeaderPrefix.h"
43
44
namespace Ogre
45
{
46
    class Sampler;
47
    class TextureUnitState;
48
49
    /** \addtogroup Core
50
    *  @{
51
    */
52
    /** \addtogroup RenderSystem
53
    *  @{
54
    */
55
56
    typedef std::vector<DepthBuffer*> DepthBufferVec;
57
    typedef std::map< uint32, DepthBufferVec > DepthBufferMap;
58
    typedef std::map< String, RenderTarget * > RenderTargetMap;
59
    typedef std::multimap<uchar, RenderTarget * > RenderTargetPriorityMap;
60
61
    class TextureManager;
62
    /// Enum describing the ways to generate texture coordinates
63
    enum TexCoordCalcMethod : uint8
64
    {
65
        /// No calculated texture coordinates
66
        TEXCALC_NONE,
67
        /// 2D texture coordinates using spherical reflection mapping based on vertex normals.
68
        TEXCALC_ENVIRONMENT_MAP,
69
        /// 2D texture coordinates using view space position. Same as #TEXCALC_ENVIRONMENT_MAP on all backends.
70
        TEXCALC_ENVIRONMENT_MAP_PLANAR,
71
        /// 3D texture coordinates using the reflection vector.
72
        TEXCALC_ENVIRONMENT_MAP_REFLECTION,
73
        /// 3D texture coordinates using the normal vector.
74
        TEXCALC_ENVIRONMENT_MAP_NORMAL,
75
        /// Projective texture
76
        TEXCALC_PROJECTIVE_TEXTURE
77
    };
78
    /// Enum describing the various actions which can be taken on the stencil buffer
79
    enum StencilOperation
80
    {
81
        /// Leave the stencil buffer unchanged
82
        SOP_KEEP,
83
        /// Set the stencil value to zero
84
        SOP_ZERO,
85
        /// Set the stencil value to the reference value
86
        SOP_REPLACE,
87
        /// Increase the stencil value by 1, clamping at the maximum value
88
        SOP_INCREMENT,
89
        /// Decrease the stencil value by 1, clamping at 0
90
        SOP_DECREMENT,
91
        /// Increase the stencil value by 1, wrapping back to 0 when incrementing the maximum value
92
        SOP_INCREMENT_WRAP,
93
        /// Decrease the stencil value by 1, wrapping when decrementing 0
94
        SOP_DECREMENT_WRAP,
95
        /// Invert the bits of the stencil buffer
96
        SOP_INVERT
97
    };
98
99
    /** Describes the stencil buffer operation
100
101
    The stencil buffer is used to mask out pixels in the render target, allowing
102
    you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
103
    your batches of rendering is likely to ignore the stencil buffer,
104
    update it with new values, or apply it to mask the output of the render.
105
106
    The stencil test is:
107
    $$(referenceValue\\,\\&\\,compareMask)\\;compareOp\\;(stencilBuffer\\,\\&\\,compareMask)$$
108
109
    The result of this will cause one of 3 actions depending on whether
110
    1. the stencil test fails
111
    2. the stencil test succeeds but the depth buffer check fails
112
    3. both depth buffer check and stencil test pass
113
    */
114
    struct _OgreExport StencilState
115
    {
116
        /// Comparison operator for the stencil test
117
        CompareFunction compareOp;
118
        /// The action to perform when the stencil check fails
119
        StencilOperation stencilFailOp;
120
        /// The action to perform when the stencil check passes, but the depth buffer check fails
121
        StencilOperation depthFailOp;
122
        /// The action to take when both the stencil and depth check pass
123
        StencilOperation depthStencilPassOp;
124
125
        /// The reference value used in the stencil comparison
126
        uint32 referenceValue;
127
        ///  The bitmask applied to both the stencil value and the reference value before comparison
128
        uint32 compareMask;
129
        /** The bitmask the controls which bits from stencilRefValue will be written to stencil buffer
130
        (valid for operations such as #SOP_REPLACE) */
131
        uint32 writeMask;
132
133
        /// Turns stencil buffer checking on or off
134
        bool enabled : 1;
135
        /// Toggles two-sided stencil operation, which swaps increment and decrement for back-facing polygons.
136
        bool twoSidedOperation : 1;
137
138
        StencilState()
139
            : compareOp(CMPF_LESS_EQUAL), stencilFailOp(SOP_KEEP), depthFailOp(SOP_KEEP),
140
              depthStencilPassOp(SOP_KEEP), referenceValue(0), compareMask(0xFFFFFFFF),
141
              writeMask(0xFFFFFFFF), enabled(false), twoSidedOperation(false)
142
0
        {
143
0
        }
144
    };
145
146
    struct _OgreExport GlobalInstancingData
147
    {
148
        HardwareVertexBufferPtr vertexBuffer;
149
        VertexDeclaration* vertexDecl = nullptr;
150
        uint32 instanceCount = 1;
151
    };
152
153
    /** Defines the functionality of a 3D API
154
155
    The RenderSystem class provides a base interface
156
    which abstracts the general functionality of the 3D API
157
    e.g. Direct3D or OpenGL. Whilst a few of the general
158
    methods have implementations, most of this class is
159
    abstract, requiring a subclass based on a specific API
160
    to be constructed to provide the full functionality.
161
    Note there are 2 levels to the interface - one which
162
    will be used often by the caller of the Ogre library,
163
    and one which is at a lower level and will be used by the
164
    other classes provided by Ogre. These lower level
165
    methods are prefixed with '_' to differentiate them.
166
    The advanced user of the library may use these lower
167
    level methods to access the 3D API at a more fundamental
168
    level (dealing direct with render states and rendering
169
    primitives), but still benefiting from Ogre's abstraction
170
    of exactly which 3D API is in use.
171
    @author
172
    Steven Streeting
173
    */
174
    class _OgreExport RenderSystem : public RenderSysAlloc
175
    {
176
    public:
177
        /** Default Constructor.
178
        */
179
        RenderSystem();
180
181
        /** Destructor.
182
        */
183
        virtual ~RenderSystem();
184
185
        /** Returns the name of the rendering system.
186
        */
187
        virtual const String& getName(void) const = 0;
188
189
        /** Returns the details of this API's configuration options
190
191
        Each render system must be able to inform the world
192
        of what options must/can be specified for it's
193
        operation.
194
        @par
195
        These are passed as strings for portability, but
196
        grouped into a structure (ConfigOption) which includes
197
        both options and current value.
198
        @par
199
        Note that the settings returned from this call are
200
        affected by the options that have been set so far,
201
        since some options are interdependent.
202
        @par
203
        This routine is called automatically by the default
204
        configuration dialogue produced by Root::showConfigDialog
205
        or may be used by the caller for custom settings dialogs
206
        @return
207
        A 'map' of options, i.e. a list of options which is also
208
        indexed by option name.
209
        */
210
0
        const ConfigOptionMap& getConfigOptions() const { return mOptions; }
211
212
        /** Sets an option for this API
213
214
        Used to confirm the settings (normally chosen by the user) in
215
        order to make the renderer able to initialise with the settings as required.
216
        This may initialise the @ref RenderWindowDescription or set some RenderSystem
217
        specific parameters.
218
        Called automatically by the default configuration
219
        dialog, and by the restoration of saved settings.
220
        These settings are stored and only activated when
221
        @ref RenderSystem::_initialise or @ref RenderSystem::reinitialise
222
        are called.
223
224
        If using a custom configuration dialog, it is advised that the
225
        caller calls RenderSystem::getConfigOptions
226
        again, since some options can alter resulting from a selection.
227
228
        Common options:
229
230
        | Key |  Default | Description |
231
        |-----|---------------|---------|
232
        | Full Screen | false | Window full-screen flag |
233
        | VSync | true | "vsync" in  @ref _createRenderWindow |
234
        | VSync Interval | 1 | "vsyncInterval" in  @ref _createRenderWindow |
235
        | sRGB Gamma Conversion | false | "gamma" in  @ref _createRenderWindow  |
236
        | HDR Display | false | "hdrDisplay" in  @ref _createRenderWindow  |
237
        | FSAA | 0 | concatenation of "FSAA" and "FSAAHint" as in  @ref _createRenderWindow  |
238
        | Video Mode | - | Window resolution |
239
        | Display Frequency | - | "displayFrequency" in  @ref _createRenderWindow |
240
        | Content Scaling Factor | 1.0 | "contentScalingFactor" in  @ref _createRenderWindow |
241
        @param
242
        name The name of the option to alter.
243
        @param
244
        value The value to set the option to.
245
        */
246
        virtual void setConfigOption(const String &name, const String &value) = 0;
247
248
        /** get a RenderWindowDescription from the current ConfigOptionMap
249
         */
250
        RenderWindowDescription getRenderWindowDescription() const;
251
252
        /** Create an object for performing hardware occlusion queries. 
253
        */
254
        virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
255
256
        /** Destroy a hardware occlusion query object. 
257
        */
258
        virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
259
260
        /** Validates the options set for the rendering system, returning a message if there are problems.
261
        @note
262
        If the returned string is empty, there are no problems.
263
        */
264
0
        virtual String validateConfigOptions(void) { return BLANKSTRING; }
265
266
        /** Start up the renderer using the settings selected (Or the defaults if none have been selected).
267
268
        Called by Root::setRenderSystem. Shouldn't really be called
269
        directly, although  this can be done if the app wants to.
270
        */
271
        virtual void _initialise();
272
 
273
        /** Get a pointer to the current capabilities being used by the RenderSystem.
274
275
        The capabilities may be modified using this pointer, this will only have an effect
276
        before the RenderSystem has been initialised. It's intended use is to allow a
277
        listener of the RenderSystemCapabilitiesCreated event to customise the capabilities
278
        on the fly before the RenderSystem is initialised.
279
        */
280
0
        RenderSystemCapabilities* getMutableCapabilities(){ return mCurrentCapabilities; }
281
282
        /** Force the render system to use the special capabilities. Can only be called
283
        *    before the render system has been fully initializer (before createWindow is called) 
284
        *   @param
285
        *        capabilities has to be a subset of the real capabilities and the caller is 
286
        *        responsible for deallocating capabilities.
287
        */
288
        void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
289
290
        /** Restart the renderer (normally following a change in settings).
291
        */
292
        void reinitialise(void);
293
294
        /** Shutdown the renderer and cleanup resources.
295
        */
296
        virtual void shutdown(void);
297
298
        virtual const GpuProgramParametersPtr& getFixedFunctionParams(TrackVertexColourType tracking,
299
                                                                      FogMode fog)
300
0
        {
301
0
            return mFixedFunctionParams;
302
0
        }
303
304
        /// @deprecated migrate to getFixedFunctionParams ASAP. this is very slow now.
305
        OGRE_DEPRECATED void _setProjectionMatrix(Matrix4 m);
306
307
        /// @deprecated migrate to getFixedFunctionParams ASAP. this is very slow now.
308
        OGRE_DEPRECATED void _setViewMatrix(const Matrix4& m)
309
0
        {
310
0
            if (!mFixedFunctionParams) return;
311
0
            mFixedFunctionParams->setConstant(4, m);
312
0
            applyFixedFunctionParams(mFixedFunctionParams, GPV_GLOBAL);
313
0
        }
314
315
        /// @deprecated migrate to getFixedFunctionParams ASAP. this is very slow now.
316
        OGRE_DEPRECATED void _setWorldMatrix(const Matrix4& m)
317
0
        {
318
0
            if (!mFixedFunctionParams) return;
319
0
            mFixedFunctionParams->setConstant(0, m);
320
0
            applyFixedFunctionParams(mFixedFunctionParams, GPV_PER_OBJECT);
321
0
        }
322
323
        /// @deprecated migrate to getFixedFunctionParams ASAP. this is very slow now.
324
        OGRE_DEPRECATED void _setFog(FogMode f)
325
0
        {
326
0
            if (mFixedFunctionParams)
327
0
                getFixedFunctionParams(TVC_NONE, f);
328
0
        }
329
330
        /// @deprecated use setColourBlendState
331
        OGRE_DEPRECATED void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor,
332
                                               SceneBlendOperation op = SBO_ADD)
333
0
        {
334
0
            mCurrentBlend.sourceFactor = sourceFactor;
335
0
            mCurrentBlend.destFactor = destFactor;
336
0
            mCurrentBlend.sourceFactorAlpha = sourceFactor;
337
0
            mCurrentBlend.destFactorAlpha = destFactor;
338
0
            mCurrentBlend.operation = op;
339
0
            mCurrentBlend.alphaOperation = op;
340
0
            setColourBlendState(mCurrentBlend);
341
0
        }
342
343
0
        virtual void applyFixedFunctionParams(const GpuProgramParametersPtr& params, uint16 variabilityMask) {}
344
345
        /** Sets the type of light shading required (default = Gouraud).
346
        @deprecated only needed for fixed function APIs
347
        */
348
0
        virtual void setShadingType(ShadeOptions so) {}
349
350
        /** Sets whether or not dynamic lighting is enabled.
351
        @param
352
        enabled If true, dynamic lighting is performed on geometry with normals supplied, geometry without
353
        normals will not be displayed. If false, no lighting is applied and all geometry will be full brightness.
354
        @deprecated only needed for fixed function APIs
355
        */
356
0
        virtual void setLightingEnabled(bool enabled) {}
357
358
        /** Creates a new rendering window.
359
360
        This method creates a new rendering window as specified
361
        by the paramteters. The rendering system could be
362
        responible for only a single window (e.g. in the case
363
        of a game), or could be in charge of multiple ones (in the
364
        case of a level editor). The option to create the window
365
        as a child of another is therefore given.
366
        This method will create an appropriate subclass of
367
        RenderWindow depending on the API and platform implementation.
368
        @par
369
        After creation, this window can be retrieved using getRenderTarget().
370
        @param
371
        name The name of the window. Used in other methods
372
        later like setRenderTarget and getRenderTarget.
373
        @param
374
        width The width of the new window.
375
        @param
376
        height The height of the new window.
377
        @param
378
        fullScreen Specify true to make the window full screen
379
        without borders, title bar or menu bar.
380
        @param
381
        miscParams A NameValuePairList describing the other parameters for the new rendering window. 
382
        Options are case sensitive. Unrecognised parameters will be ignored silently.
383
        These values might be platform dependent, but these are present for all platforms unless
384
        indicated otherwise:
385
386
        | Key | Type / Values | Default | Description | Platform |
387
        |-----|---------------|---------|-------------|-------|
388
        | title | String | RenderTarget name | The title of the window that will appear in the title bar |  |
389
        | left | Positive integers | Centred | Screen x coordinate from left |  |
390
        | top | Positive integers | Centred | Screen y coordinate from left |  |
391
        | hidden | true, false | false | hide the created window | |
392
        | FSAA | Positive integer (usually 0, 2, 4, 8, 16) | 0 | Full screen antialiasing factor |  |
393
        | gamma | true, false | false | Enable hardware conversion from linear colour space to gamma colour space on rendering to the window. |  |
394
        | hdrDisplay | true, false | false | Enable hardware HDR display output if available. This enables rendering to 10bit or higher formats where supported by the hardware and OS. Note that this does not enable HDR rendering within the frame, only the final output conversion. |  |
395
        | vsync | true, false | false | Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate |  |
396
        | vsyncInterval | 1, 2, 3, 4 | 1 | If vsync is enabled, the minimum number of vertical blanks that should occur between renders. For example if vsync is enabled, the refresh rate is 60 and this is set to 2, then the frame rate will be locked at 30. |  |
397
        | Full Screen | true, false | false | Specify whether to create the window in full screen mode | |
398
        | border | none, fixed, resize | resize | The type of window border (in windowed mode) | Windows, OSX |
399
        | displayFrequency | Refresh rate in Hertz (e.g. 60, 75, 100) | Desktop vsync rate | Display frequency rate, for fullscreen mode |  |
400
        | externalWindowHandle | <ul><li>Win32: HWND as int<li>Linux: X11 Window as ulong<li>OSX: OgreGLView address as an integer. You can pass NSView or NSWindow too, but should perform OgreGLView callbacks into the Ogre manually<li>iOS: UIWindow address as an integer<li>Emscripten: canvas selector String ("#canvas")</ul> | 0 (none) | External window handle, for embedding the OGRE render in an existing window |  |
401
        | externalGLControl | true, false | false | Let the external window control OpenGL i.e. don't select a pixel format for the window, do not change v-sync and do not swap buffer. When set to true, the calling application is responsible of OpenGL initialization and buffer swapping. It should also create an OpenGL context for its own rendering, Ogre will create one for its use. Then the calling application must also enable Ogre OpenGL context before calling any Ogre function and restore its OpenGL context after these calls. | OpenGL |
402
        | externalWlDisplay | wl_display address as an integer | 0 (none) | Wayland display connection | Linux |
403
        | externalWlSurface | wl_surface address as an integer | 0 (none) | Wayland onscreen surface | Linux |
404
        | currentGLContext | true, false | false | Use an externally created GL context. (Must be current) | OpenGL |
405
        | currentEGLSurface | true, false | false | Use an externally created EGL surface. | Android |
406
        | minColourBufferSize | Positive integer (usually 16, 32) | 16 | Min total colour buffer size. See EGL_BUFFER_SIZE | OpenGL |
407
        | windowProc | WNDPROC | DefWindowProc | function that processes window messages | Win 32 |
408
        | colourDepth | 16, 32 | Desktop depth | Colour depth of the resulting rendering window; only applies if fullScreen | Win32 |
409
        | FSAAHint | %RenderSystem specific. Currently enables EQAA/ CSAA mode on D3D: if you want 4f8x (8x CSAA), set FSAA=4 and this to "f8" | Blank | FSAA mode hint | D3D |
410
        | outerDimensions | true, false | false | Whether the width/height is expressed as the size of the outer window, rather than the content area | Win32  |
411
        | monitorIndex | | -1 | | Win 32 |
412
        | monitorHandle | | 0 (none) | | Win 32 (OpenGL) |
413
        | enableDoubleClick | true, false | false | Enable the window to keep track and transmit double click messages. | Win32 |
414
        | useNVPerfHUD | true, false | false | Enable the use of nVidia NVPerfHUD | D3D |
415
        | depthBuffer | true, false | true | Use depth buffer | D3D |
416
        | NSOpenGLCPSurfaceOrder | -1 or 1 | 1 | [NSOpenGLCPSurfaceOrder](https://developer.apple.com/documentation/appkit/nsopenglcpsurfaceorder) | OSX |
417
        | contentScalingFactor | Positive Float | The default content scaling factor of the screen | On IOS specifies the CAEAGLLayer content scaling factor. This can be useful to limit the resolution of the OpenGL ES backing store. For example, the iPhone 4's native resolution is 960 x 640\. Windows are always 320 x 480, if you would like to limit the display to 720 x 480, specify 1.5 as the scaling factor. | OSX, iOS, Android |
418
        | externalViewHandle | UIView pointer as an integer | 0 | External view handle, for rendering OGRE render in an existing view | iOS |
419
        | externalViewControllerHandle | UIViewController pointer as an integer | 0 | External view controller handle, for embedding OGRE in an existing view controller | iOS |
420
        | externalSharegroup | EAGLSharegroup pointer as an integer | 0 | External sharegroup, used to shared GL resources between contexts | iOS |
421
        | CSAA | Positive integer (usually 0, 2, 4, 8, 16) | 0 | [Coverage sampling factor](https://www.khronos.org/registry/egl/extensions/NV/EGL_NV_coverage_sample.txt) | Android |
422
        | maxColourBufferSize | Positive integer (usually 16, 32) | 32 | Max EGL_BUFFER_SIZE | Android |
423
        | maxStencilBufferSize | Positive integer (usually 0, 8) | 0 | EGL_STENCIL_SIZE | Android |
424
        | maxDepthBufferSize | Positive integer (usually 0, 16, 24) | 16 | EGL_DEPTH_SIZE | Android |
425
        */
426
        virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height, 
427
            bool fullScreen, const NameValuePairList *miscParams = 0);
428
        
429
        /** Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
430
        at once. Surfaces can be bound and unbound at will.
431
        This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
432
        */
433
        virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0; 
434
435
        /** Destroys a render window */
436
        virtual void destroyRenderWindow(const String& name);
437
        /** Destroys a render texture */
438
        virtual void destroyRenderTexture(const String& name);
439
        /** Destroys a render target of any sort */
440
        virtual void destroyRenderTarget(const String& name);
441
442
        /** Attaches the passed render target to the render system.
443
        */
444
        void attachRenderTarget( RenderTarget &target );
445
        /** Returns a pointer to the render target with the passed name, or NULL if that
446
        render target cannot be found.
447
        */
448
        RenderTarget * getRenderTarget( const String &name );
449
        /** Detaches the render target with the passed name from the render system and
450
        returns a pointer to it.
451
        @note
452
        If the render target cannot be found, NULL is returned.
453
        */
454
        virtual RenderTarget * detachRenderTarget( const String &name );
455
456
        /// @deprecated use getSchemeInstancingData instead
457
        OGRE_DEPRECATED HardwareVertexBufferPtr getGlobalInstanceVertexBuffer() const
458
0
        {
459
0
            auto it = mSchemeInstancingData.find(_getDefaultViewportMaterialScheme());
460
0
            return it != mSchemeInstancingData.end() ? it->second.vertexBuffer : nullptr;
461
0
        }
462
        /// @deprecated use enableSchemeInstancing instead
463
        OGRE_DEPRECATED void setGlobalInstanceVertexBuffer(const HardwareVertexBufferPtr& val);
464
        /// @deprecated use getSchemeInstancingData instead
465
        OGRE_DEPRECATED VertexDeclaration* getGlobalInstanceVertexDeclaration() const
466
0
        {
467
0
            auto it = mSchemeInstancingData.find(_getDefaultViewportMaterialScheme());
468
0
            return it != mSchemeInstancingData.end() ? it->second.vertexDecl : nullptr;
469
0
        }
470
        /// @deprecated use enableSchemeInstancing instead
471
        OGRE_DEPRECATED void setGlobalInstanceVertexDeclaration(VertexDeclaration* val)
472
0
        {
473
0
            mSchemeInstancingData[_getDefaultViewportMaterialScheme()].vertexDecl = val;
474
0
        }
475
        /// @deprecated use getSchemeInstancingData instead
476
        OGRE_DEPRECATED uint32 getGlobalInstanceCount() const
477
0
        {
478
0
            auto it = mSchemeInstancingData.find(_getDefaultViewportMaterialScheme());
479
0
            return it != mSchemeInstancingData.end() ? it->second.instanceCount : 1;
480
0
        }
481
        /// @deprecated use enableSchemeInstancing instead
482
        OGRE_DEPRECATED void setGlobalInstanceCount(uint32 val)
483
0
        {
484
0
            mSchemeInstancingData[_getDefaultViewportMaterialScheme()].instanceCount = val;
485
0
        }
486
487
        /// Sets the global instance data for the given material scheme.
488
        void enableSchemeInstancing(const String& materialScheme, const HardwareVertexBufferPtr& buffer,
489
                                    VertexDeclaration* decl, uint32 instanceCount);
490
        /// Gets all data for the global scheme based instancing
491
        GlobalInstancingData getSchemeInstancingData(const String& materialScheme) const
492
0
        {
493
0
            auto it = mSchemeInstancingData.find(materialScheme);
494
0
            return it != mSchemeInstancingData.end() ? it->second : GlobalInstancingData();
495
0
        }
496
        /// disables instancing for the given material scheme
497
0
        void disableSchemeInstancing(const String& materialScheme) { mSchemeInstancingData.erase(materialScheme); }
498
499
        /** Retrieves an existing DepthBuffer or creates a new one suited for the given RenderTarget
500
            and sets it.
501
502
            RenderTarget's pool ID is respected. @see RenderTarget::setDepthBufferPool()
503
        */
504
        void setDepthBufferFor( RenderTarget *renderTarget );
505
506
        /**
507
         Returns if reverse Z-buffer is enabled.
508
509
         If you have large scenes and need big far clip distance but still want
510
         to draw objects closer (for example cockpit of a plane) you can enable
511
         reverse depth buffer so that the depth buffer precision is greater further away.
512
         This enables the OGRE_REVERSED_Z preprocessor define for shaders.
513
514
         @retval true If reverse Z-buffer is enabled.
515
         @retval false If reverse Z-buffer is disabled (default).
516
517
         @see setReverseDepthBuffer
518
         */
519
        bool isReverseDepthBufferEnabled() const;
520
521
        // ------------------------------------------------------------------------
522
        //                     Internal Rendering Access
523
        // All methods below here are normally only called by other OGRE classes
524
        // They can be called by library user if required
525
        // ------------------------------------------------------------------------
526
527
        /** Tells the rendersystem to use the attached set of lights (and no others) 
528
        up to the number specified (this allows the same list to be used with different
529
        count limits)
530
        @deprecated only needed for fixed function APIs
531
        */
532
0
        virtual void _useLights(unsigned short limit) {}
533
        /** Utility function for setting all the properties of a texture unit at once.
534
        This method is also worth using over the individual texture unit settings because it
535
        only sets those settings which are different from the current settings for this
536
        unit, thus minimising render state changes.
537
        */
538
        virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
539
        /// set the sampler settings for the given texture unit
540
        virtual void _setSampler(size_t texUnit, Sampler& s) = 0;
541
        /** Turns off a texture unit. */
542
        virtual void _disableTextureUnit(size_t texUnit);
543
        /** Disables all texture units from the given unit upwards */
544
        virtual void _disableTextureUnitsFrom(size_t texUnit);
545
546
        /** Sets whether or not rendering points using OT_POINT_LIST will 
547
        render point sprites (textured quads) or plain points.
548
        @param enabled True enables point sprites, false returns to normal
549
        point rendering.
550
        @deprecated only needed for fixed function APIs
551
        */  
552
0
        virtual void _setPointSpritesEnabled(bool enabled) {};
553
554
        /**
555
        @deprecated only needed for fixed function APIs
556
        */
557
0
        virtual void _setPointParameters(bool attenuationEnabled, Real minSize, Real maxSize) {}
558
559
        /**
560
         * Set the line width when drawing as RenderOperation::OT_LINE_LIST/ RenderOperation::OT_LINE_STRIP
561
         * @param width only value of 1.0 might be supported. Check for RSC_WIDE_LINES.
562
         */
563
0
        virtual void _setLineWidth(float width) {};
564
565
        /**
566
        Sets the texture to bind to a given texture unit.
567
568
        User processes would not normally call this direct unless rendering
569
        primitives themselves.
570
571
        @param unit The index of the texture unit to modify. Multitexturing 
572
        hardware can support multiple units (see 
573
        RenderSystemCapabilites::getNumTextureUnits)
574
        @param enabled Boolean to turn the unit on/off
575
        @param texPtr Pointer to the texture to use.
576
        */
577
        virtual void _setTexture(size_t unit, bool enabled, 
578
            const TexturePtr &texPtr) = 0;
579
580
        /**
581
        Sets the texture coordinate set to use for a texture unit.
582
583
        Meant for use internally - not generally used directly by apps - the Material and TextureUnitState
584
        classes let you manage textures far more easily.
585
586
        @param unit Texture unit as above
587
        @param index The index of the texture coordinate set to use.
588
        @deprecated only needed for fixed function APIs
589
        */
590
0
        virtual void _setTextureCoordSet(size_t unit, size_t index) {}
591
592
        /**
593
        Sets a method for automatically calculating texture coordinates for a stage.
594
        Should not be used by apps - for use by Ogre only.
595
        @param unit Texture unit as above
596
        @param m Calculation method to use
597
        @param frustum Optional Frustum param, only used for projective effects
598
        @deprecated only needed for fixed function APIs
599
        */
600
        virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m, 
601
0
            const Frustum* frustum = 0) {}
602
603
        /** Sets the texture blend modes from a TextureUnitState record.
604
        Meant for use internally only - apps should use the Material
605
        and TextureUnitState classes.
606
        @param unit Texture unit as above
607
        @param bm Details of the blending mode
608
        @deprecated only needed for fixed function APIs
609
        */
610
0
        virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) {}
611
612
        /** Sets the texture coordinate transformation matrix for a texture unit.
613
        @param unit Texture unit to affect
614
        @param xform The 4x4 matrix
615
        @deprecated only needed for fixed function APIs
616
        */
617
0
        virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) {}
618
619
        /// Sets the global blending factors for combining subsequent renders with the existing frame contents.
620
        virtual void setColourBlendState(const ColourBlendState& state) = 0;
621
622
        /// @deprecated use setColourBlendState
623
        OGRE_DEPRECATED void
624
        _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor,
625
                                  SceneBlendFactor sourceFactorAlpha, SceneBlendFactor destFactorAlpha,
626
                                  SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD)
627
0
        {
628
0
            mCurrentBlend.sourceFactor = sourceFactor;
629
0
            mCurrentBlend.destFactor = destFactor;
630
0
            mCurrentBlend.sourceFactorAlpha = sourceFactorAlpha;
631
0
            mCurrentBlend.destFactorAlpha = destFactorAlpha;
632
0
            mCurrentBlend.operation = op;
633
0
            mCurrentBlend.alphaOperation = alphaOp;
634
0
            setColourBlendState(mCurrentBlend);
635
0
        }
636
637
        /** Sets the global alpha rejection approach for future renders.
638
        By default images are rendered regardless of texture alpha. This method lets you change that.
639
        @param func The comparison function which must pass for a pixel to be written.
640
        @param value The value to compare each pixels alpha value to (0-255)
641
        @param alphaToCoverage Whether to enable alpha to coverage, if supported
642
        */
643
        virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
644
645
        /** Notify the rendersystem that it should adjust texture projection to be 
646
            relative to a different origin.
647
        */
648
        virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
649
650
        /** Creates a DepthBuffer that can be attached to the specified RenderTarget
651
652
            It doesn't attach anything, it just returns a pointer to a new DepthBuffer
653
            Caller is responsible for putting this buffer into the right pool, for
654
            attaching, and deleting it. Here's where API-specific magic happens.
655
            Don't call this directly unless you know what you're doing.
656
        */
657
        virtual DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ) = 0;
658
659
        /** Removes all depth buffers. Should be called on device lost and shutdown
660
661
            Advanced users can call this directly with bCleanManualBuffers=false to
662
            remove all depth buffers created for RTTs; when they think the pool has
663
            grown too big or they've used lots of depth buffers they don't need anymore,
664
            freeing GPU RAM.
665
        */
666
        void _cleanupDepthBuffers( bool bCleanManualBuffers=true );
667
668
        /**
669
        * Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
670
        * several times per complete frame if multiple viewports exist.
671
        */
672
        virtual void _beginFrame();
673
674
        /**
675
        * Ends rendering of a frame to the current viewport.
676
        */
677
        virtual void _endFrame(void) = 0;
678
        /**
679
        Sets the provided viewport as the active one for future
680
        rendering operations. This viewport is aware of it's own
681
        camera and render target. Must be implemented by subclass.
682
683
        @param vp Pointer to the appropriate viewport.
684
        */
685
        virtual void _setViewport(Viewport *vp) = 0;
686
        /** Get the current active viewport for rendering. */
687
        virtual Viewport* _getViewport(void);
688
689
        /** Sets the culling mode for the render system based on the 'vertex winding'.
690
        @copydetails Pass::setCullingMode
691
        */
692
        virtual void _setCullingMode(CullingMode mode) = 0;
693
694
        virtual CullingMode _getCullingMode(void) const;
695
696
        /** Sets the mode of operation for depth buffer tests from this point onwards.
697
        Sometimes you may wish to alter the behaviour of the depth buffer to achieve
698
        special effects. Because it's unlikely that you'll set these options for an entire frame,
699
        but rather use them to tweak settings between rendering objects, this is an internal
700
        method (indicated by the '_' prefix) which will be used by a SceneManager implementation
701
        rather than directly from the client application.
702
        If this method is never called the settings are automatically the same as the default parameters.
703
        @param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
704
        if the depth function test succeeds. If false, no test is performed and pixels are always written.
705
        @param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
706
        If false, the depth buffer is left unchanged even if a new pixel is written.
707
        @param depthFunction Sets the function required for the depth test.
708
        */
709
        virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
710
711
        /// @deprecated use setColourBlendState
712
        OGRE_DEPRECATED void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha)
713
0
        {
714
0
            mCurrentBlend.writeR = red;
715
0
            mCurrentBlend.writeG = green;
716
0
            mCurrentBlend.writeB = blue;
717
0
            mCurrentBlend.writeA = alpha;
718
0
            setColourBlendState(mCurrentBlend);
719
0
        }
720
        /** Sets the depth bias, NB you should use the Material version of this. 
721
722
        When polygons are coplanar, you can get problems with 'depth fighting' where
723
        the pixels from the two polys compete for the same screen pixel. This is particularly
724
        a problem for decals (polys attached to another surface to represent details such as
725
        bulletholes etc.).
726
        @par
727
        A way to combat this problem is to use a depth bias to adjust the depth buffer value
728
        used for the decal such that it is slightly higher than the true value, ensuring that
729
        the decal appears on top.
730
        @note
731
        The final bias value is a combination of a constant bias and a bias proportional
732
        to the maximum depth slope of the polygon being rendered. The final bias
733
        is constantBias + slopeScaleBias * maxslope. Slope scale biasing is
734
        generally preferable but is not available on older hardware.
735
        @param constantBias The constant bias value, expressed as a value in 
736
        homogeneous depth coordinates.
737
        @param slopeScaleBias The bias value which is factored by the maximum slope
738
        of the polygon, see the description above. This is not supported by all
739
        cards.
740
741
        */
742
        virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
743
744
        /**
745
         * Clamp depth values to near and far plane rather than discarding
746
         *
747
         * Useful for "shadow caster pancaking" or with shadow volumes
748
         */
749
0
        virtual void _setDepthClamp(bool enable) {}
750
751
        /** The RenderSystem will keep a count of tris rendered, this resets the count. */
752
        void _beginGeometryCount(void);
753
        /** Reports the number of tris rendered since the last _beginGeometryCount call. */
754
0
        unsigned int _getFaceCount(void) const { return static_cast<unsigned int>(mFaceCount); }
755
        /** Reports the number of batches rendered since the last _beginGeometryCount call. */
756
0
        unsigned int _getBatchCount(void) const { return static_cast<unsigned int>(mBatchCount); }
757
        /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */
758
0
        unsigned int _getVertexCount(void) const { return static_cast<unsigned int>(mVertexCount); }
759
760
        /// @deprecated use ColourValue::getAsBYTE()
761
        OGRE_DEPRECATED static void convertColourValue(const ColourValue& colour, uint32* pDest)
762
0
        {
763
0
            *pDest = colour.getAsBYTE();
764
0
        }
765
        /// @deprecated assume VET_UBYTE4_NORM
766
0
        OGRE_DEPRECATED static VertexElementType getColourVertexElementType(void) { return VET_UBYTE4_NORM; }
767
768
        /** Converts a uniform projection matrix to suitable for this render system.
769
770
        Because different APIs have different requirements (some incompatible) for the
771
        projection matrix, this method allows each to implement their own correctly and pass
772
        back a generic OGRE matrix for storage in the engine.
773
        */
774
        virtual void _convertProjectionMatrix(const Matrix4& matrix,
775
            Matrix4& dest, bool forGpuProgram = false) = 0;
776
777
        /** Sets how to rasterise triangles, as points, wireframe or solid polys. */
778
        virtual void _setPolygonMode(PolygonMode level) = 0;
779
780
        /** This method allows you to set all the stencil buffer parameters in one call.
781
782
        Unlike other render states, stencilling is left for the application to turn
783
        on and off when it requires. This is because you are likely to want to change
784
        parameters between batches of arbitrary objects and control the ordering yourself.
785
        In order to batch things this way, you'll want to use OGRE's Compositor stencil pass
786
        or separate render queue groups and register a RenderQueueListener to get notifications
787
        between batches.
788
789
        @see RenderQueue
790
        */
791
        virtual void setStencilState(const StencilState& state) = 0;
792
793
        /// @deprecated use setStencilState
794
        OGRE_DEPRECATED void setStencilCheckEnabled(bool enabled);
795
        /// @deprecated use setStencilState
796
        OGRE_DEPRECATED void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS, uint32 refValue = 0,
797
                                    uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
798
                                    StencilOperation stencilFailOp = SOP_KEEP,
799
                                    StencilOperation depthFailOp = SOP_KEEP,
800
                                    StencilOperation passOp = SOP_KEEP, bool twoSidedOperation = false);
801
802
        /** Sets whether or not normals are to be automatically normalised.
803
804
        This is useful when, for example, you are scaling SceneNodes such that
805
        normals may not be unit-length anymore. Note though that this has an
806
        overhead so should not be turn on unless you really need it.
807
        @par
808
        You should not normally call this direct unless you are rendering
809
        world geometry; set it on the Renderable because otherwise it will be
810
        overridden by material settings.
811
        @deprecated only needed for fixed function APIs
812
        */
813
0
        virtual void setNormaliseNormals(bool normalise) {}
814
815
        /**
816
        Render something to the active viewport.
817
818
        Low-level rendering interface to perform rendering
819
        operations. Unlikely to be used directly by client
820
        applications, since the SceneManager and various support
821
        classes will be responsible for calling this method.
822
        Can only be called between _beginScene and _endScene
823
824
        @param op A rendering operation instance, which contains
825
        details of the operation to be performed.
826
        */
827
        virtual void _render(const RenderOperation& op);
828
829
0
        virtual void _dispatchCompute(const Vector3i& workgroupDim) {}
830
831
        /** Gets the capabilities of the render system. */
832
0
        const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
833
834
835
        /** Returns the driver version.
836
        */
837
0
        const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
838
839
        /** Returns the default material scheme used by the render system.
840
            Systems that use the RTSS to emulate a fixed function pipeline 
841
            (e.g. OpenGL ES 2, GL3+, DX11) need to return
842
            the default material scheme of the RTSS ShaderGenerator.
843
         
844
            This is currently only used to set the default material scheme for
845
            viewports.  It is a necessary step on these render systems for
846
            render textures to be rendered into properly.
847
        */
848
        const String& _getDefaultViewportMaterialScheme(void) const;
849
850
        /** Binds a given GpuProgram (but not the parameters). 
851
        @remarks Only one GpuProgram of each type can be bound at once, binding another
852
        one will simply replace the existing one.
853
        */
854
        virtual void bindGpuProgram(GpuProgram* prg);
855
856
        /** Bind Gpu program parameters.
857
        @param gptype The type of program to bind the parameters to
858
        @param params The parameters to bind
859
        @param variabilityMask A mask of GpuParamVariability identifying which params need binding
860
        */
861
        virtual void bindGpuProgramParameters(GpuProgramType gptype, 
862
            const GpuProgramParametersPtr& params, uint16 variabilityMask) = 0;
863
864
        /** Unbinds GpuPrograms of a given GpuProgramType.
865
866
        This returns the pipeline to fixed-function processing for this type.
867
        */
868
        virtual void unbindGpuProgram(GpuProgramType gptype);
869
870
        /** Returns whether or not a Gpu program of the given type is currently bound. */
871
        bool isGpuProgramBound(GpuProgramType gptype);
872
873
        /**
874
         * Gets the native shading language version for this render system.
875
         * Formatted so that it can be used within a shading program. 
876
         * For example, OpenGL 3.2 would return 150, while 3.3 would return 330
877
         */
878
0
        uint16 getNativeShadingLanguageVersion() const { return mNativeShadingLanguageVersion; }
879
880
        /** Sets the user clipping region.
881
        @deprecated only needed for fixed function APIs
882
        */
883
        virtual void setClipPlanes(const PlaneList& clipPlanes);
884
885
        /** Utility method for initialising all render targets attached to this rendering system. */
886
        void _initRenderTargets(void);
887
888
        /** Utility method to notify all render targets that a camera has been removed, 
889
        in case they were referring to it as their viewer. 
890
        */
891
        void _notifyCameraRemoved(const Camera* cam);
892
893
        /** Internal method for updating all render targets attached to this rendering system. */
894
        virtual void _updateAllRenderTargets(bool swapBuffers = true);
895
        /** Internal method for swapping all the buffers on all render targets,
896
        if _updateAllRenderTargets was called with a 'false' parameter. */
897
        virtual void _swapAllRenderTargetBuffers();
898
899
        /** Sets whether or not vertex windings set should be inverted; this can be important
900
        for rendering reflections. */
901
        void setInvertVertexWinding(bool invert);
902
903
        /** Indicates whether or not the vertex windings set will be inverted for the current render (e.g. reflections)
904
        @see RenderSystem::setInvertVertexWinding
905
        */
906
        bool getInvertVertexWinding(void) const;
907
908
        /** Sets the 'scissor region' i.e. the region of the target in which rendering can take place.
909
910
        This method allows you to 'mask off' rendering in all but a given rectangular area
911
        as identified by the parameters to this method.
912
        @param enabled True to enable the scissor test, false to disable it.
913
        @param rect The location of the corners of the rectangle, expressed in
914
        <i>pixels</i>.
915
        */
916
        virtual void setScissorTest(bool enabled, const Rect& rect = Rect()) = 0;
917
        /// @deprecated
918
        OGRE_DEPRECATED void setScissorTest(bool enabled, uint32 left, uint32 top = 0,
919
                                            uint32 right = 800, uint32 bottom = 600)
920
0
        {
921
0
            setScissorTest(enabled, Rect(left, top, right, bottom));
922
0
        }
923
924
        /** Clears one or more frame buffers on the active render target. 
925
        @param buffers Combination of one or more elements of FrameBufferType
926
        denoting which buffers are to be cleared
927
        @param colour The colour to clear the colour buffer with, if enabled
928
        @param depth The value to initialise the depth buffer with, if enabled
929
        @param stencil The value to initialise the stencil buffer with, if enabled.
930
        */
931
        virtual void clearFrameBuffer(uint32 buffers, const ColourValue& colour = ColourValue::Black,
932
                                      float depth = 1.0f, uint16 stencil = 0) = 0;
933
        /** Returns the horizontal texel offset value required for mapping 
934
        texel origins to pixel origins in this rendersystem.
935
936
        Since rendersystems sometimes disagree on the origin of a texel, 
937
        mapping from texels to pixels can sometimes be problematic to 
938
        implement generically. This method allows you to retrieve the offset
939
        required to map the origin of a texel to the origin of a pixel in
940
        the horizontal direction.
941
        @note only non-zero with D3D9
942
        */
943
0
        virtual Real getHorizontalTexelOffset(void) { return 0.0f; }
944
        /** Returns the vertical texel offset value required for mapping 
945
        texel origins to pixel origins in this rendersystem.
946
947
        Since rendersystems sometimes disagree on the origin of a texel, 
948
        mapping from texels to pixels can sometimes be problematic to 
949
        implement generically. This method allows you to retrieve the offset
950
        required to map the origin of a texel to the origin of a pixel in
951
        the vertical direction.
952
        @note only non-zero with D3D9
953
        */
954
0
        virtual Real getVerticalTexelOffset(void) { return 0.0f; }
955
956
        /** Gets the minimum (closest) depth value to be used when rendering
957
        using identity transforms.
958
959
        When using identity transforms you can manually set the depth
960
        of a vertex; however the input values required differ per
961
        rendersystem. This method lets you retrieve the correct value.
962
        @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
963
        */
964
        virtual Real getMinimumDepthInputValue(void) = 0;
965
        /** Gets the maximum (farthest) depth value to be used when rendering
966
        using identity transforms.
967
968
        When using identity transforms you can manually set the depth
969
        of a vertex; however the input values required differ per
970
        rendersystem. This method lets you retrieve the correct value.
971
        @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
972
        */
973
        virtual Real getMaximumDepthInputValue(void) = 0;
974
        /** set the current multi pass count value.  This must be set prior to 
975
        calling _render() if multiple renderings of the same pass state are 
976
        required.
977
        @param count Number of times to render the current state.
978
        */
979
0
        virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
980
981
        /** Tell the render system whether to derive a depth bias on its own based on 
982
        the values passed to it in setCurrentPassIterationCount.
983
        The depth bias set will be baseValue + iteration * multiplier
984
        @param derive True to tell the RS to derive this automatically
985
        @param baseValue The base value to which the multiplier should be
986
        added
987
        @param multiplier The amount of depth bias to apply per iteration
988
        @param slopeScale The constant slope scale bias for completeness
989
        */
990
        void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
991
            float multiplier = 0.0f, float slopeScale = 0.0f)
992
0
        {
993
0
            mDerivedDepthBias = derive;
994
0
            mDerivedDepthBiasBase = baseValue;
995
0
            mDerivedDepthBiasMultiplier = multiplier;
996
0
            mDerivedDepthBiasSlopeScale = slopeScale;
997
0
        }
998
999
        /**
1000
         * Set current render target to target, enabling its device context if needed
1001
         */
1002
        virtual void _setRenderTarget(RenderTarget *target) = 0;
1003
1004
        /** Defines a listener on the custom events that this render system 
1005
        can raise.
1006
        @see RenderSystem::addListener
1007
        */
1008
        class _OgreExport Listener
1009
        {
1010
        public:
1011
0
            Listener() {}
1012
0
            virtual ~Listener() {}
1013
1014
            /** A rendersystem-specific event occurred.
1015
            @param eventName The name of the event which has occurred
1016
            @param parameters A list of parameters that may belong to this event,
1017
            may be null if there are no parameters
1018
            */
1019
            virtual void eventOccurred(const String& eventName, 
1020
                const NameValuePairList* parameters = 0) = 0;
1021
        };
1022
1023
        /** Sets shared listener.
1024
1025
        Shared listener could be set even if no render system is selected yet.
1026
        This listener will receive "RenderSystemChanged" event on each Root::setRenderSystem call.
1027
        */
1028
        static void setSharedListener(Listener* listener);
1029
        /** Retrieve a pointer to the current shared render system listener. */
1030
        static Listener* getSharedListener(void);
1031
1032
        /** Adds a listener to the custom events that this render system can raise.
1033
1034
        Some render systems have quite specific, internally generated events 
1035
        that the application may wish to be notified of. Many applications
1036
        don't have to worry about these events, and can just trust OGRE to 
1037
        handle them, but if you want to know, you can add a listener here.
1038
        @par
1039
        Events are raised very generically by string name. Perhaps the most 
1040
        common example of a render system specific event is the loss and 
1041
        restoration of a device in DirectX; which OGRE deals with, but you 
1042
        may wish to know when it happens. 
1043
        @see RenderSystem::getRenderSystemEvents
1044
        */
1045
        void addListener(Listener* l);
1046
        /** Remove a listener to the custom events that this render system can raise.
1047
        */
1048
        void removeListener(Listener* l);
1049
1050
        /** Gets a list of the rendersystem specific events that this rendersystem
1051
        can raise.
1052
        @see RenderSystem::addListener
1053
        */
1054
0
        const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
1055
1056
        /** Tell the rendersystem to perform any prep tasks it needs to directly
1057
        before other threads which might access the rendering API are registered.
1058
1059
        Call this from your main thread before starting your other threads.
1060
        @note
1061
        If you start your own threads, there is a specific startup sequence which
1062
        must be respected and requires synchronisation between the threads:
1063
1064
        @note
1065
        1. [Main thread] Call preExtraThreadsStarted()
1066
        2. [Main thread] Start other thread, wait
1067
        3. [Other thread] Call registerThread(), notify main thread & continue
1068
        4. [Main thread] Wake up & call postExtraThreadsStarted()
1069
1070
        @note
1071
        Once this init sequence is completed the threads are independent but
1072
        this startup sequence must be respected.
1073
        */
1074
0
        virtual void preExtraThreadsStarted() {}
1075
1076
        /** Tell the rendersystem to perform any tasks it needs to directly
1077
        after other threads which might access the rendering API are registered.
1078
        @see RenderSystem::preExtraThreadsStarted
1079
        */
1080
0
        virtual void postExtraThreadsStarted() {}
1081
1082
        /** Register the an additional thread which may make calls to rendersystem-related 
1083
        objects.
1084
1085
        This method should only be called by additional threads during their
1086
        initialisation. If they intend to use hardware rendering system resources 
1087
        they should call this method before doing anything related to the render system.
1088
        Some rendering APIs require a per-thread setup and this method will sort that
1089
        out. It is also necessary to call unregisterThread before the thread shuts down.
1090
        @note
1091
        This method takes no parameters - it must be called from the thread being
1092
        registered and that context is enough.
1093
        */
1094
0
        virtual void registerThread() {}
1095
1096
        /** Unregister an additional thread which may make calls to rendersystem-related objects.
1097
        @see RenderSystem::registerThread
1098
        */
1099
0
        virtual void unregisterThread() {}
1100
1101
        /**
1102
        * This marks the beginning of an event for GPU profiling.
1103
        */
1104
        virtual void beginProfileEvent( const String &eventName ) = 0;
1105
1106
        /**
1107
        * Ends the currently active GPU profiling event.
1108
        */
1109
        virtual void endProfileEvent( void ) = 0;
1110
1111
        /**
1112
        * Marks an instantaneous event for graphics profilers.  
1113
        * This is equivalent to calling @see beginProfileEvent and @see endProfileEvent back to back.
1114
        */
1115
        virtual void markProfileEvent( const String &event ) = 0;
1116
1117
        /** Gets a custom (maybe platform-specific) attribute.
1118
        @remarks This is a nasty way of satisfying any API's need to see platform-specific details.
1119
        @param name The name of the attribute.
1120
        @param pData Pointer to memory of the right kind of structure to receive the info.
1121
        */
1122
        virtual void getCustomAttribute(const String& name, void* pData);
1123
1124
    /**
1125
    * Sets the colour buffer that the render system will to draw. If the render system
1126
    * implementation or configuration does not support a particular value, then false will be
1127
    * returned and the current colour buffer value will not be modified.
1128
    *
1129
    * @param
1130
    *     colourBuffer Specifies the colour buffer that will be drawn into.
1131
    */
1132
0
    virtual bool setDrawBuffer(ColourBufferType colourBuffer) { return false; };
1133
1134
    protected:
1135
1136
        /** DepthBuffers to be attached to render targets */
1137
        DepthBufferMap  mDepthBufferPool;
1138
1139
        /** The render targets. */
1140
        RenderTargetMap mRenderTargets;
1141
        /** The render targets, ordered by priority. */
1142
        RenderTargetPriorityMap mPrioritisedRenderTargets;
1143
        /** The Active render target. */
1144
        RenderTarget * mActiveRenderTarget;
1145
1146
        /** The Active GPU programs and gpu program parameters*/
1147
        GpuProgramParametersPtr mActiveParameters[GPT_COUNT];
1148
1149
        // Texture manager
1150
        // A concrete class of this will be created and
1151
        // made available under the TextureManager singleton,
1152
        // managed by the RenderSystem
1153
        TextureManager* mTextureManager;
1154
1155
        // Active viewport (dest for future rendering operations)
1156
        Viewport* mActiveViewport;
1157
1158
        CullingMode mCullingMode;
1159
1160
        size_t mBatchCount;
1161
        size_t mFaceCount;
1162
        size_t mVertexCount;
1163
1164
        bool mInvertVertexWinding;
1165
        bool mIsReverseDepthBufferEnabled;
1166
1167
        /// Texture units from this upwards are disabled
1168
        size_t mDisabledTexUnitsFrom;
1169
1170
        /// number of times to render the current state
1171
        size_t mCurrentPassIterationCount;
1172
        size_t mCurrentPassIterationNum;
1173
        /// Whether to update the depth bias per render call
1174
        bool mDerivedDepthBias;
1175
        float mDerivedDepthBiasBase;
1176
        float mDerivedDepthBiasMultiplier;
1177
        float mDerivedDepthBiasSlopeScale;
1178
1179
        /** updates pass iteration rendering state including bound gpu program parameter
1180
        pass iteration auto constant entry
1181
        @return True if more iterations are required
1182
        */
1183
        bool updatePassIterationRenderState(void);
1184
1185
        /// List of names of events this rendersystem may raise
1186
        StringVector mEventNames;
1187
1188
        /// Internal method for firing a rendersystem event
1189
        void fireEvent(const String& name, const NameValuePairList* params = 0);
1190
1191
        typedef std::list<Listener*> ListenerList;
1192
        ListenerList mEventListeners;
1193
        static Listener* msSharedEventListener;
1194
1195
        typedef std::list<HardwareOcclusionQuery*> HardwareOcclusionQueryList;
1196
        HardwareOcclusionQueryList mHwOcclusionQueries;
1197
1198
        std::array<bool, GPT_COUNT> mProgramBound;
1199
1200
        // Recording user clip planes
1201
        PlaneList mClipPlanes;
1202
        // Indicator that we need to re-set the clip planes on next render call
1203
        bool mClipPlanesDirty;
1204
1205
        /// Used to store the capabilities of the graphics card
1206
        RenderSystemCapabilities* mRealCapabilities;
1207
        RenderSystemCapabilities* mCurrentCapabilities;
1208
        bool mUseCustomCapabilities;
1209
1210
        /// @deprecated only needed for fixed function APIs
1211
0
        virtual void setClipPlanesImpl(const PlaneList& clipPlanes) {}
1212
1213
        /** Query the real capabilities of the GPU and driver in the RenderSystem*/
1214
        virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
1215
1216
        /** Initialize the render system from the capabilities*/
1217
0
        virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* = NULL) {}
1218
1219
        DriverVersion mDriverVersion;
1220
        uint16 mNativeShadingLanguageVersion;
1221
1222
        bool mTexProjRelative;
1223
        Vector3 mTexProjRelativeOrigin;
1224
1225
        // Stored options
1226
        ConfigOptionMap mOptions;
1227
1228
        virtual void initConfigOptions();
1229
1230
        ColourBlendState mCurrentBlend;
1231
        GpuProgramParametersSharedPtr mFixedFunctionParams;
1232
1233
        void initFixedFunctionParams();
1234
        void setFFPLightParams(uint32 index, bool enabled);
1235
        bool flipFrontFace() const;
1236
        static CompareFunction reverseCompareFunction(CompareFunction func);
1237
1238
        const HardwareBufferPtr& updateDefaultUniformBuffer(GpuProgramType type, const ConstantList& params);
1239
    private:
1240
        StencilState mStencilState;
1241
1242
        /// buffers for default uniform blocks
1243
        HardwareBufferPtr mUniformBuffer[GPT_COUNT];
1244
1245
        /// a global vertex buffer for global instancing
1246
        std::map<String, GlobalInstancingData> mSchemeInstancingData;
1247
    };
1248
    /** @} */
1249
    /** @} */
1250
}
1251
1252
#include "OgreHeaderSuffix.h"
1253
1254
#endif