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