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 "OgreTextureUnitState.h"
35 #include "OgreCommon.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     /** \addtogroup Core
47     *  @{
48     */
49     /** \addtogroup RenderSystem
50     *  @{
51     */
52 
53     typedef std::vector<DepthBuffer*> DepthBufferVec;
54     typedef std::map< uint16, DepthBufferVec > DepthBufferMap;
55     typedef std::map< String, RenderTarget * > RenderTargetMap;
56     typedef std::multimap<uchar, RenderTarget * > RenderTargetPriorityMap;
57 
58     class TextureManager;
59     /// Enum describing the ways to generate texture coordinates
60     enum TexCoordCalcMethod
61     {
62         /// No calculated texture coordinates
63         TEXCALC_NONE,
64         /// Environment map based on vertex normals
65         TEXCALC_ENVIRONMENT_MAP,
66         /// Environment map based on vertex positions
67         TEXCALC_ENVIRONMENT_MAP_PLANAR,
68         TEXCALC_ENVIRONMENT_MAP_REFLECTION,
69         TEXCALC_ENVIRONMENT_MAP_NORMAL,
70         /// Projective texture
71         TEXCALC_PROJECTIVE_TEXTURE
72     };
73     /// Enum describing the various actions which can be taken on the stencil buffer
74     enum StencilOperation
75     {
76         /// Leave the stencil buffer unchanged
77         SOP_KEEP,
78         /// Set the stencil value to zero
79         SOP_ZERO,
80         /// Set the stencil value to the reference value
81         SOP_REPLACE,
82         /// Increase the stencil value by 1, clamping at the maximum value
83         SOP_INCREMENT,
84         /// Decrease the stencil value by 1, clamping at 0
85         SOP_DECREMENT,
86         /// Increase the stencil value by 1, wrapping back to 0 when incrementing the maximum value
87         SOP_INCREMENT_WRAP,
88         /// Decrease the stencil value by 1, wrapping when decrementing 0
89         SOP_DECREMENT_WRAP,
90         /// Invert the bits of the stencil buffer
91         SOP_INVERT
92     };
93 
94 
95     /** Defines the functionality of a 3D API
96     @remarks
97     The RenderSystem class provides a base interface
98     which abstracts the general functionality of the 3D API
99     e.g. Direct3D or OpenGL. Whilst a few of the general
100     methods have implementations, most of this class is
101     abstract, requiring a subclass based on a specific API
102     to be constructed to provide the full functionality.
103     Note there are 2 levels to the interface - one which
104     will be used often by the caller of the Ogre library,
105     and one which is at a lower level and will be used by the
106     other classes provided by Ogre. These lower level
107     methods are prefixed with '_' to differentiate them.
108     The advanced user of the library may use these lower
109     level methods to access the 3D API at a more fundamental
110     level (dealing direct with render states and rendering
111     primitives), but still benefiting from Ogre's abstraction
112     of exactly which 3D API is in use.
113     @author
114     Steven Streeting
115     @version
116     1.0
117     */
118     class _OgreExport RenderSystem : public RenderSysAlloc
119     {
120     public:
121         /** Default Constructor.
122         */
123         RenderSystem();
124 
125         /** Destructor.
126         */
127         virtual ~RenderSystem();
128 
129         /** Returns the name of the rendering system.
130         */
131         virtual const String& getName(void) const = 0;
132 
133         /** Returns the details of this API's configuration options
134         @remarks
135         Each render system must be able to inform the world
136         of what options must/can be specified for it's
137         operation.
138         @par
139         These are passed as strings for portability, but
140         grouped into a structure (_ConfigOption) which includes
141         both options and current value.
142         @par
143         Note that the settings returned from this call are
144         affected by the options that have been set so far,
145         since some options are interdependent.
146         @par
147         This routine is called automatically by the default
148         configuration dialogue produced by Root::showConfigDialog
149         or may be used by the caller for custom settings dialogs
150         @return
151         A 'map' of options, i.e. a list of options which is also
152         indexed by option name.
153         */
getConfigOptions()154         ConfigOptionMap& getConfigOptions() { return mOptions; }
155 
156         /** Sets an option for this API
157         @remarks
158         Used to confirm the settings (normally chosen by the user) in
159         order to make the renderer able to initialise with the settings as required.
160         This may be video mode, D3D driver, full screen / windowed etc.
161         Called automatically by the default configuration
162         dialog, and by the restoration of saved settings.
163         These settings are stored and only activated when
164         RenderSystem::initialise or RenderSystem::reinitialise
165         are called.
166         @par
167         If using a custom configuration dialog, it is advised that the
168         caller calls RenderSystem::getConfigOptions
169         again, since some options can alter resulting from a selection.
170         @param
171         name The name of the option to alter.
172         @param
173         value The value to set the option to.
174         */
175         virtual void setConfigOption(const String &name, const String &value) = 0;
176 
177         /** Create an object for performing hardware occlusion queries.
178         */
179         virtual HardwareOcclusionQuery* createHardwareOcclusionQuery(void) = 0;
180 
181         /** Destroy a hardware occlusion query object.
182         */
183         virtual void destroyHardwareOcclusionQuery(HardwareOcclusionQuery *hq);
184 
185         /** Validates the options set for the rendering system, returning a message if there are problems.
186         @note
187         If the returned string is empty, there are no problems.
188         */
189         virtual String validateConfigOptions(void) = 0;
190 
191         /** Start up the renderer using the settings selected (Or the defaults if none have been selected).
192         @remarks
193         Called by Root::setRenderSystem. Shouldn't really be called
194         directly, although  this can be done if the app wants to.
195         @param
196         autoCreateWindow If true, creates a render window
197         automatically, based on settings chosen so far. This saves
198         an extra call to _createRenderWindow
199         for the main render window.
200         @param
201         windowTitle Sets the app window title
202         @return
203         A pointer to the automatically created window, if requested, otherwise null.
204         */
205         virtual RenderWindow* _initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window");
206 
207         /**
208         Returns whether under the current render system buffers marked as TU_STATIC can be locked for update
209         @remarks
210         Needed in the implementation of DirectX9 with DirectX9Ex driver
211         */
isStaticBufferLockable()212         virtual bool isStaticBufferLockable() const { return true; }
213 
214         /** Query the real capabilities of the GPU and driver in the RenderSystem*/
215         virtual RenderSystemCapabilities* createRenderSystemCapabilities() const = 0;
216 
217         /** Get a pointer to the current capabilities being used by the RenderSystem.
218         @remarks
219         The capabilities may be modified using this pointer, this will only have an effect
220         before the RenderSystem has been initialised. It's intended use is to allow a
221         listener of the RenderSystemCapabilitiesCreated event to customise the capabilities
222         on the fly before the RenderSystem is initialised.
223         */
getMutableCapabilities()224         RenderSystemCapabilities* getMutableCapabilities(){ return mCurrentCapabilities; }
225 
226         /** Force the render system to use the special capabilities. Can only be called
227         *    before the render system has been fully initializer (before createWindow is called)
228         *   @param
229         *        capabilities has to be a subset of the real capabilities and the caller is
230         *        responsible for deallocating capabilities.
231         */
232         void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
233 
234         /** Restart the renderer (normally following a change in settings).
235         */
236         virtual void reinitialise(void) = 0;
237 
238         /** Shutdown the renderer and cleanup resources.
239         */
240         virtual void shutdown(void);
241 
242 
243         /** Sets the colour & strength of the ambient (global directionless) light in the world.
244         @deprecated only needed for fixed function APIs
245         */
setAmbientLight(float r,float g,float b)246         virtual void setAmbientLight(float r, float g, float b) {}
247 
248         /// @overload
setAmbientLight(const ColourValue & c)249         void setAmbientLight(const ColourValue& c) { setAmbientLight(c.r, c.g, c.b); }
250 
251         /** Sets the type of light shading required (default = Gouraud).
252         @deprecated only needed for fixed function APIs
253         */
setShadingType(ShadeOptions so)254         virtual void setShadingType(ShadeOptions so) {}
255 
256         /** Sets whether or not dynamic lighting is enabled.
257         @param
258         enabled If true, dynamic lighting is performed on geometry with normals supplied, geometry without
259         normals will not be displayed. If false, no lighting is applied and all geometry will be full brightness.
260         @deprecated only needed for fixed function APIs
261         */
setLightingEnabled(bool enabled)262         virtual void setLightingEnabled(bool enabled) {}
263 
264         /// @deprecated use RSC_WBUFFER
265         OGRE_DEPRECATED void setWBufferEnabled(bool enabled);
266 
267         /// @deprecated use RSC_WBUFFER
268         OGRE_DEPRECATED bool getWBufferEnabled(void) const;
269 
270         /** Creates a new rendering window.
271         @remarks
272         This method creates a new rendering window as specified
273         by the paramteters. The rendering system could be
274         responible for only a single window (e.g. in the case
275         of a game), or could be in charge of multiple ones (in the
276         case of a level editor). The option to create the window
277         as a child of another is therefore given.
278         This method will create an appropriate subclass of
279         RenderWindow depending on the API and platform implementation.
280         @par
281         After creation, this window can be retrieved using getRenderTarget().
282         @param
283         name The name of the window. Used in other methods
284         later like setRenderTarget and getRenderTarget.
285         @param
286         width The width of the new window.
287         @param
288         height The height of the new window.
289         @param
290         fullScreen Specify true to make the window full screen
291         without borders, title bar or menu bar.
292         @param
293         miscParams A NameValuePairList describing the other parameters for the new rendering window.
294         Options are case sensitive. Unrecognised parameters will be ignored silently.
295         These values might be platform dependent, but these are present for all platforms unless
296         indicated otherwise:
297         | Key | Type / Values | Default | Description | Notes |
298         |-----|---------------|---------|-------------|-------|
299         | title | Any string | RenderTarget name | The title of the window that will appear in the title bar |  |
300         | left | Positive integers | Centred | Screen x coordinate from left |  |
301         | top | Positive integers | Centred | Screen y coordinate from left |  |
302         | border | none, fixed, resize | resize | The type of window border (in windowed mode) |  |
303         | hidden | true, false | false | hide the created window | |
304         | FSAA | Positive integer (usually 0, 2, 4, 8, 16) | 0 | Full screen antialiasing factor |  |
305         | gamma | true, false | false | Enable hardware conversion from linear colour space to gamma colour space on rendering to the window. |  |
306         | vsync | true, false | false | Synchronize buffer swaps to monitor vsync, eliminating tearing at the expense of a fixed frame rate |  |
307         | 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. |  |
308         | Full Screen | true, false | false | Specify whether to create the window in full screen mode | |
309         | displayFrequency | Refresh rate in Hertz (e.g. 60, 75, 100) | Desktop vsync rate | Display frequency rate, for fullscreen mode |  |
310         | parentWindowHandle | <ul><li>Win32: HWND as integer<li>GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*) | 0 (none) | Parent window handle, for embedding the OGRE in a child of an external window |  |
311         | externalWindowHandle | <ul><li>Win32: HWND as integer<li>GLX: poslong:posint:poslong (display*:screen:windowHandle) or poslong:posint:poslong:poslong (display*:screen:windowHandle:XVisualInfo*)<li>OS X Cocoa: OgreGLView address as an integer. You can pass NSView or NSWindow too, but should perform OgreGLView callbacks into the Ogre manually.<li>OS X Carbon: WindowRef as an integer<li>iOS: UIWindow address as an integer</ul> | 0 (none) | External window handle, for embedding the OGRE render in an existing window |  |
312         | 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 Specific |
313         | currentGLContext | true, false | false | Use an externally created GL context. (Must be current) | OpenGL Specific |
314         | minColourBufferSize | Positive integer (usually 16, 32) | 16 | Min total colour buffer size. See EGL_BUFFER_SIZE | OpenGL Specific |
315         | windowProc | WNDPROC | DefWindowProc | function that processes window messages | Win 32 Specific |
316         | colourDepth | 16, 32 | Desktop depth | Colour depth of the resulting rendering window; only applies if fullScreen | Win32 Specific |
317         | FSAAHint | Depends on RenderSystem and hardware. Currently supports:"Quality": on systems that have an option to prefer higher AA quality over speed, use it | Blank | Full screen antialiasing hint | Win32 Specific |
318         | outerDimensions | true, false | false | Whether the width/height is expressed as the size of the outer window, rather than the content area | Win32 Specific  |
319         | monitorIndex | | -1 | | Win 32 Specific |
320         | monitorHandle | | 0 (none) | | Win 32 Specific (OpenGL) |
321         | enableDoubleClick | true, false | false | Enable the window to keep track and transmit double click messages. | Win32 Specific |
322         | useNVPerfHUD | true, false | false | Enable the use of nVidia NVPerfHUD | DirectX Specific |
323         | depthBuffer | true, false | true | Use depth buffer | DirectX9 Specific |
324         | NSOpenGLCPSurfaceOrder | -1 or 1 | 1 | [NSOpenGLCPSurfaceOrder](https://developer.apple.com/documentation/appkit/nsopenglcpsurfaceorder) | Mac OS X Specific |
325         | contentScalingFactor | Positive Float greater than 1.0 | The default content scaling factor of the screen | On IOS specifies the CAEAGLLayer content scaling factor. Only supported on iOS 4 or greater. 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. | iOS / Android Specific |
326         | externalViewHandle | UIView pointer as an integer | 0 | External view handle, for rendering OGRE render in an existing view | iOS Specific |
327         | externalViewControllerHandle | UIViewController pointer as an integer | 0 | External view controller handle, for embedding OGRE in an existing view controller | iOS Specific |
328         | externalSharegroup | EAGLSharegroup pointer as an integer | 0 | External sharegroup, used to shared GL resources between contexts | iOS Specific |
329         | MSAA | Positive integer (usually 0, 2, 4, 8, 16) | 0 | Full screen antialiasing factor | Android Specific |
330         | 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 Specific |
331         | maxColourBufferSize | Positive integer (usually 16, 32) | 32 | Max EGL_BUFFER_SIZE | Android Specific |
332         | maxStencilBufferSize | Positive integer (usually 0, 8) | 0 | EGL_STENCIL_SIZE | Android Specific |
333         | maxDepthBufferSize | Positive integer (usually 0, 16, 24) | 16 | EGL_DEPTH_SIZE | Android Specific |
334         */
335         virtual RenderWindow* _createRenderWindow(const String &name, unsigned int width, unsigned int height,
336             bool fullScreen, const NameValuePairList *miscParams = 0) = 0;
337 
338         /** Creates multiple rendering windows.
339         @param
340         renderWindowDescriptions Array of structures containing the descriptions of each render window.
341         The structure's members are the same as the parameters of _createRenderWindow:
342         * name
343         * width
344         * height
345         * fullScreen
346         * miscParams
347         See _createRenderWindow for details about each member.
348         @param
349         createdWindows This array will hold the created render windows.
350         @return
351         true on success.
352         */
353         virtual bool _createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
354             RenderWindowList& createdWindows);
355 
356 
357         /** Create a MultiRenderTarget, which is a render target that renders to multiple RenderTextures
358         at once. Surfaces can be bound and unbound at will.
359         This fails if mCapabilities->getNumMultiRenderTargets() is smaller than 2.
360         */
361         virtual MultiRenderTarget * createMultiRenderTarget(const String & name) = 0;
362 
363         /** Destroys a render window */
364         virtual void destroyRenderWindow(const String& name);
365         /** Destroys a render texture */
366         virtual void destroyRenderTexture(const String& name);
367         /** Destroys a render target of any sort */
368         virtual void destroyRenderTarget(const String& name);
369 
370         /** Attaches the passed render target to the render system.
371         */
372         void attachRenderTarget( RenderTarget &target );
373         /** Returns a pointer to the render target with the passed name, or NULL if that
374         render target cannot be found.
375         */
376         RenderTarget * getRenderTarget( const String &name );
377         /** Detaches the render target with the passed name from the render system and
378         returns a pointer to it.
379         @note
380         If the render target cannot be found, NULL is returned.
381         */
382         virtual RenderTarget * detachRenderTarget( const String &name );
383 
384         /// Iterator over RenderTargets
385         typedef MapIterator<Ogre::RenderTargetMap> RenderTargetIterator;
386 
387         /** Returns a specialised MapIterator over all render targets attached to the RenderSystem. */
getRenderTargetIterator(void)388         RenderTargetIterator getRenderTargetIterator(void) {
389             return RenderTargetIterator( mRenderTargets.begin(), mRenderTargets.end() );
390         }
391         /** Returns the global instance vertex buffer.
392         */
393         HardwareVertexBufferSharedPtr getGlobalInstanceVertexBuffer() const;
394         /** Sets the global instance vertex buffer.
395         */
396         void setGlobalInstanceVertexBuffer(const HardwareVertexBufferSharedPtr &val);
397         /** Gets vertex declaration for the global vertex buffer for the global instancing
398         */
399         VertexDeclaration* getGlobalInstanceVertexBufferVertexDeclaration() const;
400         /** Sets vertex declaration for the global vertex buffer for the global instancing
401         */
402         void setGlobalInstanceVertexBufferVertexDeclaration( VertexDeclaration* val);
403         /** Gets the global number of instances.
404         */
405         size_t getGlobalNumberOfInstances() const;
406         /** Sets the global number of instances.
407         */
408         void setGlobalNumberOfInstances(const size_t val);
409 
410         /** Retrieves an existing DepthBuffer or creates a new one suited for the given RenderTarget
411             and sets it.
412             @remarks
413                 RenderTarget's pool ID is respected. @see RenderTarget::setDepthBufferPool()
414         */
415         void setDepthBufferFor( RenderTarget *renderTarget );
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         @deprecated only needed for fixed function APIs
428         */
_useLights(const LightList & lights,unsigned short limit)429         virtual void _useLights(const LightList& lights, unsigned short limit) {}
430         /** Are fixed-function lights provided in view space? Affects optimisation.
431         */
areFixedFunctionLightsInViewSpace()432         virtual bool areFixedFunctionLightsInViewSpace() const { return false; }
433         /** Sets the world transform matrix.
434          * @deprecated only needed for fixed function APIs */
_setWorldMatrix(const Matrix4 & m)435         virtual void _setWorldMatrix(const Matrix4 &m) {}
436         /** Sets the view transform matrix
437          * @deprecated only needed for fixed function APIs */
_setViewMatrix(const Matrix4 & m)438         virtual void _setViewMatrix(const Matrix4 &m) {}
439         /** Sets the projection transform matrix
440          * @deprecated only needed for fixed function APIs*/
_setProjectionMatrix(const Matrix4 & m)441         virtual void _setProjectionMatrix(const Matrix4 &m) {}
442         /** Utility function for setting all the properties of a texture unit at once.
443         This method is also worth using over the individual texture unit settings because it
444         only sets those settings which are different from the current settings for this
445         unit, thus minimising render state changes.
446         */
447         virtual void _setTextureUnitSettings(size_t texUnit, TextureUnitState& tl);
448         /// set the sampler settings for the given texture unit
449         virtual void _setSampler(size_t texUnit, Sampler& s) = 0;
_setBindingType(TextureUnitState::BindingType bindigType)450         OGRE_DEPRECATED virtual void _setBindingType(TextureUnitState::BindingType bindigType) {}
451         /** Turns off a texture unit. */
452         virtual void _disableTextureUnit(size_t texUnit);
453         /** Disables all texture units from the given unit upwards */
454         virtual void _disableTextureUnitsFrom(size_t texUnit);
455         /** Sets the surface properties to be used for future rendering.
456 
457         This method sets the the properties of the surfaces of objects
458         to be rendered after it. In this context these surface properties
459         are the amount of each type of light the object reflects (determining
460         it's colour under different types of light), whether it emits light
461         itself, and how shiny it is. Textures are not dealt with here,
462         see the _setTetxure method for details.
463         This method is used by _setMaterial so does not need to be called
464         direct if that method is being used.
465 
466         @param ambient The amount of ambient (sourceless and directionless)
467         light an object reflects. Affected by the colour/amount of ambient light in the scene.
468         @param diffuse The amount of light from directed sources that is
469         reflected (affected by colour/amount of point, directed and spot light sources)
470         @param specular The amount of specular light reflected. This is also
471         affected by directed light sources but represents the colour at the
472         highlights of the object.
473         @param emissive The colour of light emitted from the object. Note that
474         this will make an object seem brighter and not dependent on lights in
475         the scene, but it will not act as a light, so will not illuminate other
476         objects. Use a light attached to the same SceneNode as the object for this purpose.
477         @param shininess A value which only has an effect on specular highlights (so
478         specular must be non-black). The higher this value, the smaller and crisper the
479         specular highlights will be, imitating a more highly polished surface.
480         This value is not constrained to 0.0-1.0, in fact it is likely to
481         be more (10.0 gives a modest sheen to an object).
482         @param tracking A bit field that describes which of the ambient, diffuse, specular
483         and emissive colours follow the vertex colour of the primitive. When a bit in this field is set
484         its ColourValue is ignored. This is a combination of TVC_AMBIENT, TVC_DIFFUSE, TVC_SPECULAR(note that the shininess value is still
485         taken from shininess) and TVC_EMISSIVE. TVC_NONE means that there will be no material property
486         tracking the vertex colours.
487         @deprecated only needed for fixed function APIs
488         */
489         virtual void _setSurfaceParams(const ColourValue &ambient,
490             const ColourValue &diffuse, const ColourValue &specular,
491             const ColourValue &emissive, Real shininess,
492             TrackVertexColourType tracking = TVC_NONE) {}
493 
494         /** Sets whether or not rendering points using OT_POINT_LIST will
495         render point sprites (textured quads) or plain points.
496         @param enabled True enables point sprites, false returns to normal
497         point rendering.
498         @deprecated only needed for fixed function APIs
499         */
_setPointSpritesEnabled(bool enabled)500         virtual void _setPointSpritesEnabled(bool enabled) {};
501 
502         /** Sets the size of points and how they are attenuated with distance.
503         @remarks
504         When performing point rendering or point sprite rendering,
505         point size can be attenuated with distance. The equation for
506         doing this is attenuation = 1 / (constant + linear * dist + quadratic * d^2) .
507         @par
508         For example, to disable distance attenuation (constant screensize)
509         you would set constant to 1, and linear and quadratic to 0. A
510         standard perspective attenuation would be 0, 1, 0 respectively.
511         @deprecated only needed for fixed function APIs
512         */
_setPointParameters(Real size,bool attenuationEnabled,Real constant,Real linear,Real quadratic,Real minSize,Real maxSize)513         virtual void _setPointParameters(Real size, bool attenuationEnabled,
514             Real constant, Real linear, Real quadratic, Real minSize, Real maxSize) {};
515 
516         /**
517          * Set the line width when drawing as RenderOperation::OT_LINE_LIST/ RenderOperation::OT_LINE_STRIP
518          * @param width only value of 1.0 might be supported. Check for RSC_WIDE_LINES.
519          */
_setLineWidth(float width)520         virtual void _setLineWidth(float width) {};
521 
522         /**
523         Sets the texture to bind to a given texture unit.
524 
525         User processes would not normally call this direct unless rendering
526         primitives themselves.
527 
528         @param unit The index of the texture unit to modify. Multitexturing
529         hardware can support multiple units (see
530         RenderSystemCapabilites::getNumTextureUnits)
531         @param enabled Boolean to turn the unit on/off
532         @param texPtr Pointer to the texture to use.
533         */
534         virtual void _setTexture(size_t unit, bool enabled,
535             const TexturePtr &texPtr) = 0;
536 
537         /** Binds a texture to a vertex, geometry, compute, tesselation hull
538         or tessellation domain sampler.
539         @remarks
540         Not all rendersystems support separate vertex samplers. For those that
541         do, you can set a texture for them, separate to the regular texture
542         samplers, using this method. For those that don't, you should use the
543         regular texture samplers which are shared between the vertex and
544         fragment units; calling this method will throw an exception.
545         @deprecated only needed for D3D9
546         */
547         virtual void _setVertexTexture(size_t unit, const TexturePtr& tex);
548 
549         /**
550         Sets the texture coordinate set to use for a texture unit.
551 
552         Meant for use internally - not generally used directly by apps - the Material and TextureUnitState
553         classes let you manage textures far more easily.
554 
555         @param unit Texture unit as above
556         @param index The index of the texture coordinate set to use.
557         @deprecated only needed for fixed function APIs
558         */
_setTextureCoordSet(size_t unit,size_t index)559         virtual void _setTextureCoordSet(size_t unit, size_t index) {}
560 
561         /**
562         Sets a method for automatically calculating texture coordinates for a stage.
563         Should not be used by apps - for use by Ogre only.
564         @param unit Texture unit as above
565         @param m Calculation method to use
566         @param frustum Optional Frustum param, only used for projective effects
567         @deprecated only needed for fixed function APIs
568         */
569         virtual void _setTextureCoordCalculation(size_t unit, TexCoordCalcMethod m,
570             const Frustum* frustum = 0) {}
571 
572         /** Sets the texture blend modes from a TextureUnitState record.
573         Meant for use internally only - apps should use the Material
574         and TextureUnitState classes.
575         @param unit Texture unit as above
576         @param bm Details of the blending mode
577         @deprecated only needed for fixed function APIs
578         */
_setTextureBlendMode(size_t unit,const LayerBlendModeEx & bm)579         virtual void _setTextureBlendMode(size_t unit, const LayerBlendModeEx& bm) {}
580 
581         /** Sets a single filter for a given texture unit.
582         @param unit The texture unit to set the filtering options for
583         @param ftype The filter type
584         @param filter The filter to be used
585         */
586         virtual void _setTextureUnitFiltering(size_t unit, FilterType ftype, FilterOptions filter) = 0;
587 
588         /** @overload
589         @param unit The texture unit to set the filtering options for
590         @param minFilter The filter used when a texture is reduced in size
591         @param magFilter The filter used when a texture is magnified
592         @param mipFilter The filter used between mipmap levels, FO_NONE disables mipmapping
593         */
594         virtual void _setTextureUnitFiltering(size_t unit, FilterOptions minFilter,
595             FilterOptions magFilter, FilterOptions mipFilter);
596 
597         /** Sets whether the compare func is enabled or not for this texture unit
598         @param unit The texture unit to set the filtering options for
599         @param compare The state (enabled/disabled)
600         */
601         virtual void _setTextureUnitCompareEnabled(size_t unit, bool compare) = 0;
602 
603 
604         /** Sets the compare function to use for a given texture unit
605         @param unit The texture unit to set the filtering options for
606         @param function The comparison function
607         */
608         virtual void _setTextureUnitCompareFunction(size_t unit, CompareFunction function) = 0;
609 
610 
611         /** Sets the maximal anisotropy for the specified texture unit.*/
612         virtual void _setTextureLayerAnisotropy(size_t unit, unsigned int maxAnisotropy) = 0;
613 
614         /** Sets the texture addressing mode for a texture unit.*/
615         virtual void _setTextureAddressingMode(size_t unit, const Sampler::UVWAddressingMode& uvw) = 0;
616 
617         /** Sets the texture border colour for a texture unit.*/
618         virtual void _setTextureBorderColour(size_t unit, const ColourValue& colour) = 0;
619 
620         /** Sets the mipmap bias value for a given texture unit.
621         @remarks
622         This allows you to adjust the mipmap calculation up or down for a
623         given texture unit. Negative values force a larger mipmap to be used,
624         positive values force a smaller mipmap to be used. Units are in numbers
625         of levels, so +1 forces the mipmaps to one smaller level.
626         @note Only does something if render system has capability RSC_MIPMAP_LOD_BIAS.
627         */
628         virtual void _setTextureMipmapBias(size_t unit, float bias) = 0;
629 
630         /** Sets the texture coordinate transformation matrix for a texture unit.
631         @param unit Texture unit to affect
632         @param xform The 4x4 matrix
633         @deprecated only needed for fixed function APIs
634         */
_setTextureMatrix(size_t unit,const Matrix4 & xform)635         virtual void _setTextureMatrix(size_t unit, const Matrix4& xform) {}
636 
637         /// Sets the global blending factors for combining subsequent renders with the existing frame contents.
setColourBlendState(const ColourBlendState & state)638         virtual void setColourBlendState(const ColourBlendState& state)
639         {
640             _setSeparateSceneBlending(state.sourceFactor, state.destFactor, state.sourceFactorAlpha,
641                                       state.destFactorAlpha, state.operation, state.alphaOperation);
642             _setColourBufferWriteEnabled(state.writeR, state.writeG, state.writeB, state.writeA);
643         }
644 
645         /// @deprecated use setColourBlendState
646         OGRE_DEPRECATED void _setSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendOperation op = SBO_ADD)
647         {
648             _setSeparateSceneBlending(sourceFactor, destFactor, sourceFactor, destFactor, op, op);
649         }
650 
651         /// @deprecated use setColourBlendState
652         virtual void _setSeparateSceneBlending(SceneBlendFactor sourceFactor, SceneBlendFactor destFactor, SceneBlendFactor sourceFactorAlpha,
653             SceneBlendFactor destFactorAlpha, SceneBlendOperation op = SBO_ADD, SceneBlendOperation alphaOp = SBO_ADD) = 0;
654 
655         /** Sets the global alpha rejection approach for future renders.
656         By default images are rendered regardless of texture alpha. This method lets you change that.
657         @param func The comparison function which must pass for a pixel to be written.
658         @param value The value to compare each pixels alpha value to (0-255)
659         @param alphaToCoverage Whether to enable alpha to coverage, if supported
660         */
661         virtual void _setAlphaRejectSettings(CompareFunction func, unsigned char value, bool alphaToCoverage) = 0;
662 
663         /** Notify the rendersystem that it should adjust texture projection to be
664             relative to a different origin.
665         */
666         virtual void _setTextureProjectionRelativeTo(bool enabled, const Vector3& pos);
667 
668         /** Creates a DepthBuffer that can be attached to the specified RenderTarget
669             @remarks
670                 It doesn't attach anything, it just returns a pointer to a new DepthBuffer
671                 Caller is responsible for putting this buffer into the right pool, for
672                 attaching, and deleting it. Here's where API-specific magic happens.
673                 Don't call this directly unless you know what you're doing.
674         */
675         virtual DepthBuffer* _createDepthBufferFor( RenderTarget *renderTarget ) = 0;
676 
677         /** Removes all depth buffers. Should be called on device lost and shutdown
678             @remarks
679                 Advanced users can call this directly with bCleanManualBuffers=false to
680                 remove all depth buffers created for RTTs; when they think the pool has
681                 grown too big or they've used lots of depth buffers they don't need anymore,
682                 freeing GPU RAM.
683         */
684         void _cleanupDepthBuffers( bool bCleanManualBuffers=true );
685 
686         /**
687         * Signifies the beginning of a frame, i.e. the start of rendering on a single viewport. Will occur
688         * several times per complete frame if multiple viewports exist.
689         */
690         virtual void _beginFrame(void) = 0;
691 
692         /// Dummy structure for render system contexts - implementing RenderSystems can extend
693         /// as needed
694         struct RenderSystemContext { };
695         /**
696         * Pause rendering for a frame. This has to be called after _beginFrame and before _endFrame.
697         * Will usually be called by the SceneManager, don't use this manually unless you know what
698         * you are doing.
699         */
700         virtual RenderSystemContext* _pauseFrame(void);
701         /**
702         * Resume rendering for a frame. This has to be called after a _pauseFrame call
703         * Will usually be called by the SceneManager, don't use this manually unless you know what
704         * you are doing.
705         * @param context the render system context, as returned by _pauseFrame
706         */
707         virtual void _resumeFrame(RenderSystemContext* context);
708 
709         /**
710         * Ends rendering of a frame to the current viewport.
711         */
712         virtual void _endFrame(void) = 0;
713         /**
714         Sets the provided viewport as the active one for future
715         rendering operations. This viewport is aware of it's own
716         camera and render target. Must be implemented by subclass.
717 
718         @param vp Pointer to the appropriate viewport.
719         */
720         virtual void _setViewport(Viewport *vp) = 0;
721         /** Get the current active viewport for rendering. */
722         virtual Viewport* _getViewport(void);
723 
724         /** Sets the culling mode for the render system based on the 'vertex winding'.
725         A typical way for the rendering engine to cull triangles is based on the
726         'vertex winding' of triangles. Vertex winding refers to the direction in
727         which the vertices are passed or indexed to in the rendering operation as viewed
728         from the camera, and will wither be clockwise or anticlockwise (that's 'counterclockwise' for
729         you Americans out there ;) The default is CULL_CLOCKWISE i.e. that only triangles whose vertices
730         are passed/indexed in anticlockwise order are rendered - this is a common approach and is used in 3D studio models
731         for example. You can alter this culling mode if you wish but it is not advised unless you know what you are doing.
732         You may wish to use the CULL_NONE option for mesh data that you cull yourself where the vertex
733         winding is uncertain.
734         */
735         virtual void _setCullingMode(CullingMode mode) = 0;
736 
737         virtual CullingMode _getCullingMode(void) const;
738 
739         /** Sets the mode of operation for depth buffer tests from this point onwards.
740         Sometimes you may wish to alter the behaviour of the depth buffer to achieve
741         special effects. Because it's unlikely that you'll set these options for an entire frame,
742         but rather use them to tweak settings between rendering objects, this is an internal
743         method (indicated by the '_' prefix) which will be used by a SceneManager implementation
744         rather than directly from the client application.
745         If this method is never called the settings are automatically the same as the default parameters.
746         @param depthTest If true, the depth buffer is tested for each pixel and the frame buffer is only updated
747         if the depth function test succeeds. If false, no test is performed and pixels are always written.
748         @param depthWrite If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
749         If false, the depth buffer is left unchanged even if a new pixel is written.
750         @param depthFunction Sets the function required for the depth test.
751         */
752         virtual void _setDepthBufferParams(bool depthTest = true, bool depthWrite = true, CompareFunction depthFunction = CMPF_LESS_EQUAL) = 0;
753 
754         /** Sets whether or not the depth buffer check is performed before a pixel write.
755         @param enabled If true, the depth buffer is tested for each pixel and the frame buffer is only updated
756         if the depth function test succeeds. If false, no test is performed and pixels are always written.
757         */
758         virtual void _setDepthBufferCheckEnabled(bool enabled = true) = 0;
759         /** Sets whether or not the depth buffer is updated after a pixel write.
760         @param enabled If true, the depth buffer is updated with the depth of the new pixel if the depth test succeeds.
761         If false, the depth buffer is left unchanged even if a new pixel is written.
762         */
763         virtual void _setDepthBufferWriteEnabled(bool enabled = true) = 0;
764         /** Sets the comparison function for the depth buffer check.
765         Advanced use only - allows you to choose the function applied to compare the depth values of
766         new and existing pixels in the depth buffer. Only an issue if the deoth buffer check is enabled
767         (see _setDepthBufferCheckEnabled)
768         @param  func The comparison between the new depth and the existing depth which must return true
769         for the new pixel to be written.
770         */
771         virtual void _setDepthBufferFunction(CompareFunction func = CMPF_LESS_EQUAL) = 0;
772         /// @deprecated use setColourBlendState
773         virtual void _setColourBufferWriteEnabled(bool red, bool green, bool blue, bool alpha) = 0;
774         /** Sets the depth bias, NB you should use the Material version of this.
775         @remarks
776         When polygons are coplanar, you can get problems with 'depth fighting' where
777         the pixels from the two polys compete for the same screen pixel. This is particularly
778         a problem for decals (polys attached to another surface to represent details such as
779         bulletholes etc.).
780         @par
781         A way to combat this problem is to use a depth bias to adjust the depth buffer value
782         used for the decal such that it is slightly higher than the true value, ensuring that
783         the decal appears on top.
784         @note
785         The final bias value is a combination of a constant bias and a bias proportional
786         to the maximum depth slope of the polygon being rendered. The final bias
787         is constantBias + slopeScaleBias * maxslope. Slope scale biasing is
788         generally preferable but is not available on older hardware.
789         @param constantBias The constant bias value, expressed as a value in
790         homogeneous depth coordinates.
791         @param slopeScaleBias The bias value which is factored by the maximum slope
792         of the polygon, see the description above. This is not supported by all
793         cards.
794 
795         */
796         virtual void _setDepthBias(float constantBias, float slopeScaleBias = 0.0f) = 0;
797         /** Sets the fogging mode for future geometry.
798         @param mode Set up the mode of fog as described in the FogMode enum, or set to FOG_NONE to turn off.
799         @param colour The colour of the fog. Either set this to the same as your viewport background colour,
800         or to blend in with a skydome or skybox.
801         @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
802         that fog never completely obscures the scene.
803         @param linearStart Distance at which linear fog starts to encroach. The distance must be passed
804         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.
805         @param linearEnd Distance at which linear fog becomes completely opaque.The distance must be passed
806         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.
807         @deprecated only needed for fixed function APIs
808         */
809         virtual void _setFog(FogMode mode = FOG_NONE, const ColourValue& colour = ColourValue::White, Real expDensity = 1.0, Real linearStart = 0.0, Real linearEnd = 1.0) {}
810 
811 
812         /** The RenderSystem will keep a count of tris rendered, this resets the count. */
813         virtual void _beginGeometryCount(void);
814         /** Reports the number of tris rendered since the last _beginGeometryCount call. */
815         virtual unsigned int _getFaceCount(void) const;
816         /** Reports the number of batches rendered since the last _beginGeometryCount call. */
817         virtual unsigned int _getBatchCount(void) const;
818         /** Reports the number of vertices passed to the renderer since the last _beginGeometryCount call. */
819         virtual unsigned int _getVertexCount(void) const;
820 
821         /** Generates a packed data version of the passed in ColourValue suitable for
822         use as with this RenderSystem.
823         @remarks
824         Since different render systems have different colour data formats (eg
825         RGBA for GL, ARGB for D3D) this method allows you to use 1 method for all.
826         @param colour The colour to convert
827         @param pDest Pointer to location to put the result.
828         */
829         void convertColourValue(const ColourValue& colour, uint32* pDest);
830         /** Get the native VertexElementType for a compact 32-bit colour value
831         for this rendersystem.
832         */
833         virtual VertexElementType getColourVertexElementType(void) const = 0;
834 
835         /** Converts a uniform projection matrix to suitable for this render system.
836         @remarks
837         Because different APIs have different requirements (some incompatible) for the
838         projection matrix, this method allows each to implement their own correctly and pass
839         back a generic OGRE matrix for storage in the engine.
840         */
841         virtual void _convertProjectionMatrix(const Matrix4& matrix,
842             Matrix4& dest, bool forGpuProgram = false) = 0;
843 
844         /// @deprecated use Frustum::getProjectionMatrixRS
845         OGRE_DEPRECATED virtual void _makeProjectionMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
846             Matrix4& dest, bool forGpuProgram = false) = 0;
847         /// @deprecated use Frustum::getProjectionMatrixRS
848         OGRE_DEPRECATED virtual void _makeProjectionMatrix(Real left, Real right, Real bottom, Real top,
849             Real nearPlane, Real farPlane, Matrix4& dest, bool forGpuProgram = false) = 0;
850         /// @deprecated use Frustum::getProjectionMatrixRS
851         OGRE_DEPRECATED virtual void _makeOrthoMatrix(const Radian& fovy, Real aspect, Real nearPlane, Real farPlane,
852             Matrix4& dest, bool forGpuProgram = false) = 0;
853         /// @deprecated use Frustum::getProjectionMatrixRS
854         OGRE_DEPRECATED virtual void _applyObliqueDepthProjection(Matrix4& matrix, const Plane& plane,
855             bool forGpuProgram) = 0;
856 
857         /** Sets how to rasterise triangles, as points, wireframe or solid polys. */
858         virtual void _setPolygonMode(PolygonMode level) = 0;
859 
860         /** Turns stencil buffer checking on or off.
861         @remarks
862         Stencilling (masking off areas of the rendering target based on the stencil
863         buffer) can be turned on or off using this method. By default, stencilling is
864         disabled.
865         */
866         virtual void setStencilCheckEnabled(bool enabled) = 0;
867 
868         /** This method allows you to set all the stencil buffer parameters in one call.
869         @remarks
870         The stencil buffer is used to mask out pixels in the render target, allowing
871         you to do effects like mirrors, cut-outs, stencil shadows and more. Each of
872         your batches of rendering is likely to ignore the stencil buffer,
873         update it with new values, or apply it to mask the output of the render.
874         The stencil test is:<PRE>
875         (Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)</PRE>
876         The result of this will cause one of 3 actions depending on whether the test fails,
877         succeeds but with the depth buffer check still failing, or succeeds with the
878         depth buffer check passing too.
879         @par
880         Unlike other render states, stencilling is left for the application to turn
881         on and off when it requires. This is because you are likely to want to change
882         parameters between batches of arbitrary objects and control the ordering yourself.
883         In order to batch things this way, you'll want to use OGRE's separate render queue
884         groups (see RenderQueue) and register a RenderQueueListener to get notifications
885         between batches.
886         @par
887         There are individual state change methods for each of the parameters set using
888         this method.
889         Note that the default values in this method represent the defaults at system
890         start up too.
891         @param func The comparison function applied.
892         @param refValue The reference value used in the comparison
893         @param compareMask The bitmask applied to both the stencil value and the reference value
894         before comparison
895         @param writeMask The bitmask the controls which bits from refValue will be written to
896         stencil buffer (valid for operations such as SOP_REPLACE).
897         the stencil
898         @param stencilFailOp The action to perform when the stencil check fails
899         @param depthFailOp The action to perform when the stencil check passes, but the
900         depth buffer check still fails
901         @param passOp The action to take when both the stencil and depth check pass.
902         @param twoSidedOperation If set to true, then if you render both back and front faces
903         (you'll have to turn off culling) then these parameters will apply for front faces,
904         and the inverse of them will happen for back faces (keep remains the same).
905         @param readBackAsTexture D3D11 specific
906         */
907         virtual void setStencilBufferParams(CompareFunction func = CMPF_ALWAYS_PASS,
908             uint32 refValue = 0, uint32 compareMask = 0xFFFFFFFF, uint32 writeMask = 0xFFFFFFFF,
909             StencilOperation stencilFailOp = SOP_KEEP,
910             StencilOperation depthFailOp = SOP_KEEP,
911             StencilOperation passOp = SOP_KEEP,
912             bool twoSidedOperation = false,
913             bool readBackAsTexture = false) = 0;
914 
915         /** Sets whether or not normals are to be automatically normalised.
916         @remarks
917         This is useful when, for example, you are scaling SceneNodes such that
918         normals may not be unit-length anymore. Note though that this has an
919         overhead so should not be turn on unless you really need it.
920         @par
921         You should not normally call this direct unless you are rendering
922         world geometry; set it on the Renderable because otherwise it will be
923         overridden by material settings.
924         @deprecated only needed for fixed function APIs
925         */
setNormaliseNormals(bool normalise)926         virtual void setNormaliseNormals(bool normalise) {}
927 
928         /**
929         Render something to the active viewport.
930 
931         Low-level rendering interface to perform rendering
932         operations. Unlikely to be used directly by client
933         applications, since the SceneManager and various support
934         classes will be responsible for calling this method.
935         Can only be called between _beginScene and _endScene
936 
937         @param op A rendering operation instance, which contains
938         details of the operation to be performed.
939         */
940         virtual void _render(const RenderOperation& op);
941 
_dispatchCompute(const Vector3i & workgroupDim)942         virtual void _dispatchCompute(const Vector3i& workgroupDim) {}
943 
944         /** Gets the capabilities of the render system. */
getCapabilities(void)945         const RenderSystemCapabilities* getCapabilities(void) const { return mCurrentCapabilities; }
946 
947 
948         /** Returns the driver version.
949         */
getDriverVersion(void)950         const DriverVersion& getDriverVersion(void) const { return mDriverVersion; }
951 
952         /** Returns the default material scheme used by the render system.
953             Systems that use the RTSS to emulate a fixed function pipeline
954             (e.g. OpenGL ES 2, GL3+, DX11) need to return
955             the default material scheme of the RTSS ShaderGenerator.
956 
957             This is currently only used to set the default material scheme for
958             viewports.  It is a necessary step on these render systems for
959             render textures to be rendered into properly.
960         */
961         const String& _getDefaultViewportMaterialScheme(void) const;
962 
963         /** Binds a given GpuProgram (but not the parameters).
964         @remarks Only one GpuProgram of each type can be bound at once, binding another
965         one will simply replace the existing one.
966         */
967         virtual void bindGpuProgram(GpuProgram* prg);
968 
969         /** Bind Gpu program parameters.
970         @param gptype The type of program to bind the parameters to
971         @param params The parameters to bind
972         @param variabilityMask A mask of GpuParamVariability identifying which params need binding
973         */
974         virtual void bindGpuProgramParameters(GpuProgramType gptype,
975             const GpuProgramParametersPtr& params, uint16 variabilityMask) = 0;
976 
977         /** Only binds Gpu program parameters used for passes that have more than one iteration rendering
978         */
979         virtual void bindGpuProgramPassIterationParameters(GpuProgramType gptype) = 0;
980         /** Unbinds GpuPrograms of a given GpuProgramType.
981         @remarks
982         This returns the pipeline to fixed-function processing for this type.
983         */
984         virtual void unbindGpuProgram(GpuProgramType gptype);
985 
986         /** Returns whether or not a Gpu program of the given type is currently bound. */
987         bool isGpuProgramBound(GpuProgramType gptype);
988 
989         /**
990          * Gets the native shading language version for this render system.
991          * Formatted so that it can be used within a shading program.
992          * For example, OpenGL 3.2 would return 150, while 3.3 would return 330
993          */
getNativeShadingLanguageVersion()994         uint16 getNativeShadingLanguageVersion() const { return mNativeShadingLanguageVersion; }
995 
996         /** Sets the user clipping region.
997         @deprecated only needed for fixed function APIs
998         */
999         virtual void setClipPlanes(const PlaneList& clipPlanes);
1000 
1001         /// @deprecated use setClipPlanes
1002         OGRE_DEPRECATED void addClipPlane (const Plane &p);
1003 
1004         /// @deprecated use setClipPlanes
1005         OGRE_DEPRECATED void resetClipPlanes();
1006 
1007         /** Utility method for initialising all render targets attached to this rendering system. */
1008         void _initRenderTargets(void);
1009 
1010         /** Utility method to notify all render targets that a camera has been removed,
1011         in case they were referring to it as their viewer.
1012         */
1013         void _notifyCameraRemoved(const Camera* cam);
1014 
1015         /** Internal method for updating all render targets attached to this rendering system. */
1016         virtual void _updateAllRenderTargets(bool swapBuffers = true);
1017         /** Internal method for swapping all the buffers on all render targets,
1018         if _updateAllRenderTargets was called with a 'false' parameter. */
1019         virtual void _swapAllRenderTargetBuffers();
1020 
1021         /** Sets whether or not vertex windings set should be inverted; this can be important
1022         for rendering reflections. */
1023         void setInvertVertexWinding(bool invert);
1024 
1025         /** Indicates whether or not the vertex windings set will be inverted for the current render (e.g. reflections)
1026         @see RenderSystem::setInvertVertexWinding
1027         */
1028         bool getInvertVertexWinding(void) const;
1029 
1030         /** Sets the 'scissor region' i.e. the region of the target in which rendering can take place.
1031         @remarks
1032         This method allows you to 'mask off' rendering in all but a given rectangular area
1033         as identified by the parameters to this method.
1034         @note
1035         Not all systems support this method. Check the RenderSystemCapabilities for the
1036         RSC_SCISSOR_TEST capability to see if it is supported.
1037         @param enabled True to enable the scissor test, false to disable it.
1038         @param left, top, right, bottom The location of the corners of the rectangle, expressed in
1039         <i>pixels</i>.
1040         */
1041         virtual void setScissorTest(bool enabled, size_t left = 0, size_t top = 0,
1042             size_t right = 800, size_t bottom = 600) = 0;
1043 
1044         /** Clears one or more frame buffers on the active render target.
1045         @param buffers Combination of one or more elements of FrameBufferType
1046         denoting which buffers are to be cleared
1047         @param colour The colour to clear the colour buffer with, if enabled
1048         @param depth The value to initialise the depth buffer with, if enabled
1049         @param stencil The value to initialise the stencil buffer with, if enabled.
1050         */
1051         virtual void clearFrameBuffer(unsigned int buffers,
1052             const ColourValue& colour = ColourValue::Black,
1053             Real depth = 1.0f, unsigned short stencil = 0) = 0;
1054         /** Returns the horizontal texel offset value required for mapping
1055         texel origins to pixel origins in this rendersystem.
1056         @remarks
1057         Since rendersystems sometimes disagree on the origin of a texel,
1058         mapping from texels to pixels can sometimes be problematic to
1059         implement generically. This method allows you to retrieve the offset
1060         required to map the origin of a texel to the origin of a pixel in
1061         the horizontal direction.
1062         */
1063         virtual Real getHorizontalTexelOffset(void) = 0;
1064         /** Returns the vertical texel offset value required for mapping
1065         texel origins to pixel origins in this rendersystem.
1066         @remarks
1067         Since rendersystems sometimes disagree on the origin of a texel,
1068         mapping from texels to pixels can sometimes be problematic to
1069         implement generically. This method allows you to retrieve the offset
1070         required to map the origin of a texel to the origin of a pixel in
1071         the vertical direction.
1072         */
1073         virtual Real getVerticalTexelOffset(void) = 0;
1074 
1075         /** Gets the minimum (closest) depth value to be used when rendering
1076         using identity transforms.
1077         @remarks
1078         When using identity transforms you can manually set the depth
1079         of a vertex; however the input values required differ per
1080         rendersystem. This method lets you retrieve the correct value.
1081         @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
1082         */
1083         virtual Real getMinimumDepthInputValue(void) = 0;
1084         /** Gets the maximum (farthest) depth value to be used when rendering
1085         using identity transforms.
1086         @remarks
1087         When using identity transforms you can manually set the depth
1088         of a vertex; however the input values required differ per
1089         rendersystem. This method lets you retrieve the correct value.
1090         @see Renderable::getUseIdentityView, Renderable::getUseIdentityProjection
1091         */
1092         virtual Real getMaximumDepthInputValue(void) = 0;
1093         /** set the current multi pass count value.  This must be set prior to
1094         calling _render() if multiple renderings of the same pass state are
1095         required.
1096         @param count Number of times to render the current state.
1097         */
setCurrentPassIterationCount(const size_t count)1098         virtual void setCurrentPassIterationCount(const size_t count) { mCurrentPassIterationCount = count; }
1099 
1100         /** Tell the render system whether to derive a depth bias on its own based on
1101         the values passed to it in setCurrentPassIterationCount.
1102         The depth bias set will be baseValue + iteration * multiplier
1103         @param derive True to tell the RS to derive this automatically
1104         @param baseValue The base value to which the multiplier should be
1105         added
1106         @param multiplier The amount of depth bias to apply per iteration
1107         @param slopeScale The constant slope scale bias for completeness
1108         */
1109         void setDeriveDepthBias(bool derive, float baseValue = 0.0f,
1110             float multiplier = 0.0f, float slopeScale = 0.0f)
1111         {
1112             mDerivedDepthBias = derive;
1113             mDerivedDepthBiasBase = baseValue;
1114             mDerivedDepthBiasMultiplier = multiplier;
1115             mDerivedDepthBiasSlopeScale = slopeScale;
1116         }
1117 
1118         /**
1119          * Set current render target to target, enabling its device context if needed
1120          */
1121         virtual void _setRenderTarget(RenderTarget *target) = 0;
1122 
1123         /** Defines a listener on the custom events that this render system
1124         can raise.
1125         @see RenderSystem::addListener
1126         */
1127         class _OgreExport Listener
1128         {
1129         public:
Listener()1130             Listener() {}
~Listener()1131             virtual ~Listener() {}
1132 
1133             /** A rendersystem-specific event occurred.
1134             @param eventName The name of the event which has occurred
1135             @param parameters A list of parameters that may belong to this event,
1136             may be null if there are no parameters
1137             */
1138             virtual void eventOccurred(const String& eventName,
1139                 const NameValuePairList* parameters = 0) = 0;
1140         };
1141 
1142         /** Sets shared listener.
1143         @remarks
1144         Shared listener could be set even if no render system is selected yet.
1145         This listener will receive "RenderSystemChanged" event on each Root::setRenderSystem call.
1146         */
1147         static void setSharedListener(Listener* listener);
1148         /** Retrieve a pointer to the current shared render system listener. */
1149         static Listener* getSharedListener(void);
1150 
1151         /** Adds a listener to the custom events that this render system can raise.
1152         @remarks
1153         Some render systems have quite specific, internally generated events
1154         that the application may wish to be notified of. Many applications
1155         don't have to worry about these events, and can just trust OGRE to
1156         handle them, but if you want to know, you can add a listener here.
1157         @par
1158         Events are raised very generically by string name. Perhaps the most
1159         common example of a render system specific event is the loss and
1160         restoration of a device in DirectX; which OGRE deals with, but you
1161         may wish to know when it happens.
1162         @see RenderSystem::getRenderSystemEvents
1163         */
1164         void addListener(Listener* l);
1165         /** Remove a listener to the custom events that this render system can raise.
1166         */
1167         void removeListener(Listener* l);
1168 
1169         /** Gets a list of the rendersystem specific events that this rendersystem
1170         can raise.
1171         @see RenderSystem::addListener
1172         */
getRenderSystemEvents(void)1173         const StringVector& getRenderSystemEvents(void) const { return mEventNames; }
1174 
1175         /** Tell the rendersystem to perform any prep tasks it needs to directly
1176         before other threads which might access the rendering API are registered.
1177         @remarks
1178         Call this from your main thread before starting your other threads.
1179         @note
1180         If you start your own threads, there is a specific startup sequence which
1181         must be respected and requires synchronisation between the threads:
1182 
1183         @note
1184         1. [Main thread] Call preExtraThreadsStarted()
1185         2. [Main thread] Start other thread, wait
1186         3. [Other thread] Call registerThread(), notify main thread & continue
1187         4. [Main thread] Wake up & call postExtraThreadsStarted()
1188 
1189         @note
1190         Once this init sequence is completed the threads are independent but
1191         this startup sequence must be respected.
1192         */
1193         virtual void preExtraThreadsStarted() = 0;
1194 
1195         /** Tell the rendersystem to perform any tasks it needs to directly
1196         after other threads which might access the rendering API are registered.
1197         @see RenderSystem::preExtraThreadsStarted
1198         */
1199         virtual void postExtraThreadsStarted() = 0;
1200 
1201         /** Register the an additional thread which may make calls to rendersystem-related
1202         objects.
1203         @remarks
1204         This method should only be called by additional threads during their
1205         initialisation. If they intend to use hardware rendering system resources
1206         they should call this method before doing anything related to the render system.
1207         Some rendering APIs require a per-thread setup and this method will sort that
1208         out. It is also necessary to call unregisterThread before the thread shuts down.
1209         @note
1210         This method takes no parameters - it must be called from the thread being
1211         registered and that context is enough.
1212         */
1213         virtual void registerThread() = 0;
1214 
1215         /** Unregister an additional thread which may make calls to rendersystem-related objects.
1216         @see RenderSystem::registerThread
1217         */
1218         virtual void unregisterThread() = 0;
1219 
1220         /**
1221         * Gets the number of display monitors.
1222         @see Root::getDisplayMonitorCount
1223         */
1224         virtual unsigned int getDisplayMonitorCount() const = 0;
1225 
1226         /**
1227         * This marks the beginning of an event for GPU profiling.
1228         */
1229         virtual void beginProfileEvent( const String &eventName ) = 0;
1230 
1231         /**
1232         * Ends the currently active GPU profiling event.
1233         */
1234         virtual void endProfileEvent( void ) = 0;
1235 
1236         /**
1237         * Marks an instantaneous event for graphics profilers.
1238         * This is equivalent to calling @see beginProfileEvent and @see endProfileEvent back to back.
1239         */
1240         virtual void markProfileEvent( const String &event ) = 0;
1241 
1242         /** Determines if the system has anisotropic mip map filter support
1243         */
1244         virtual bool hasAnisotropicMipMapFilter() const = 0;
1245 
1246         /** Gets a custom (maybe platform-specific) attribute.
1247         @remarks This is a nasty way of satisfying any API's need to see platform-specific details.
1248         @param name The name of the attribute.
1249         @param pData Pointer to memory of the right kind of structure to receive the info.
1250         */
1251         virtual void getCustomAttribute(const String& name, void* pData);
1252 
1253 		/**
1254 		* Sets the colour buffer that the render system will to draw. If the render system
1255 		* implementation or configuration does not support a particular value, then false will be
1256 		* returned and the current colour buffer value will not be modified.
1257 		*
1258 		* @param
1259 		*     colourBuffer Specifies the colour buffer that will be drawn into.
1260 		*/
setDrawBuffer(ColourBufferType colourBuffer)1261 		virtual bool setDrawBuffer(ColourBufferType colourBuffer) { return false; };
1262 
1263     protected:
1264 
1265         /** DepthBuffers to be attached to render targets */
1266         DepthBufferMap  mDepthBufferPool;
1267 
1268         /** The render targets. */
1269         RenderTargetMap mRenderTargets;
1270         /** The render targets, ordered by priority. */
1271         RenderTargetPriorityMap mPrioritisedRenderTargets;
1272         /** The Active render target. */
1273         RenderTarget * mActiveRenderTarget;
1274 
1275         /** The Active GPU programs and gpu program parameters*/
1276         GpuProgramParametersSharedPtr mActiveVertexGpuProgramParameters;
1277         GpuProgramParametersSharedPtr mActiveGeometryGpuProgramParameters;
1278         GpuProgramParametersSharedPtr mActiveFragmentGpuProgramParameters;
1279         GpuProgramParametersSharedPtr mActiveTessellationHullGpuProgramParameters;
1280         GpuProgramParametersSharedPtr mActiveTessellationDomainGpuProgramParameters;
1281         GpuProgramParametersSharedPtr mActiveComputeGpuProgramParameters;
1282 
1283         // Texture manager
1284         // A concrete class of this will be created and
1285         // made available under the TextureManager singleton,
1286         // managed by the RenderSystem
1287         TextureManager* mTextureManager;
1288 
1289         // Active viewport (dest for future rendering operations)
1290         Viewport* mActiveViewport;
1291 
1292         CullingMode mCullingMode;
1293 
1294         size_t mBatchCount;
1295         size_t mFaceCount;
1296         size_t mVertexCount;
1297 
1298         /// Saved manual colour blends
1299         ColourValue mManualBlendColours[OGRE_MAX_TEXTURE_LAYERS][2];
1300 
1301         bool mInvertVertexWinding;
1302 
1303         /// Texture units from this upwards are disabled
1304         size_t mDisabledTexUnitsFrom;
1305 
1306         /// number of times to render the current state
1307         size_t mCurrentPassIterationCount;
1308         size_t mCurrentPassIterationNum;
1309         /// Whether to update the depth bias per render call
1310         bool mDerivedDepthBias;
1311         float mDerivedDepthBiasBase;
1312         float mDerivedDepthBiasMultiplier;
1313         float mDerivedDepthBiasSlopeScale;
1314 
1315         /// a global vertex buffer for global instancing
1316         HardwareVertexBufferSharedPtr mGlobalInstanceVertexBuffer;
1317         /// a vertex declaration for the global vertex buffer for the global instancing
1318         VertexDeclaration* mGlobalInstanceVertexBufferVertexDeclaration;
1319         /// the number of global instances (this number will be multiply by the render op instance number)
1320         size_t mGlobalNumberOfInstances;
1321 
1322         /** updates pass iteration rendering state including bound gpu program parameter
1323         pass iteration auto constant entry
1324         @return True if more iterations are required
1325         */
1326         bool updatePassIterationRenderState(void);
1327 
1328         /// List of names of events this rendersystem may raise
1329         StringVector mEventNames;
1330 
1331         /// Internal method for firing a rendersystem event
1332         void fireEvent(const String& name, const NameValuePairList* params = 0);
1333 
1334         typedef std::list<Listener*> ListenerList;
1335         ListenerList mEventListeners;
1336         static Listener* msSharedEventListener;
1337 
1338         typedef std::list<HardwareOcclusionQuery*> HardwareOcclusionQueryList;
1339         HardwareOcclusionQueryList mHwOcclusionQueries;
1340 
1341         bool mVertexProgramBound;
1342         bool mGeometryProgramBound;
1343         bool mFragmentProgramBound;
1344         bool mTessellationHullProgramBound;
1345         bool mTessellationDomainProgramBound;
1346         bool mComputeProgramBound;
1347 
1348         // Recording user clip planes
1349         PlaneList mClipPlanes;
1350         // Indicator that we need to re-set the clip planes on next render call
1351         bool mClipPlanesDirty;
1352 
1353         /// Used to store the capabilities of the graphics card
1354         RenderSystemCapabilities* mRealCapabilities;
1355         RenderSystemCapabilities* mCurrentCapabilities;
1356         bool mUseCustomCapabilities;
1357 
1358         /// @deprecated only needed for fixed function APIs
setClipPlanesImpl(const PlaneList & clipPlanes)1359         virtual void setClipPlanesImpl(const PlaneList& clipPlanes) {}
1360 
1361         /** Initialize the render system from the capabilities*/
1362         virtual void initialiseFromRenderSystemCapabilities(RenderSystemCapabilities* caps, RenderTarget* primary) = 0;
1363 
1364 
1365         DriverVersion mDriverVersion;
1366         uint16 mNativeShadingLanguageVersion;
1367 
1368         bool mTexProjRelative;
1369         Vector3 mTexProjRelativeOrigin;
1370 
1371         // Stored options
1372         ConfigOptionMap mOptions;
1373 
1374         virtual void initConfigOptions();
1375     };
1376     /** @} */
1377     /** @} */
1378 }
1379 
1380 #include "OgreHeaderSuffix.h"
1381 
1382 #endif
1383