[148] | 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-2013 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 __HardwareBufferManager__ |
---|
| 29 | #define __HardwareBufferManager__ |
---|
| 30 | |
---|
| 31 | // Precompiler options |
---|
| 32 | #include "OgrePrerequisites.h" |
---|
| 33 | |
---|
| 34 | #include "OgreSingleton.h" |
---|
| 35 | #include "OgreHardwareCounterBuffer.h" |
---|
| 36 | #include "OgreHardwareIndexBuffer.h" |
---|
| 37 | #include "OgreHardwareUniformBuffer.h" |
---|
| 38 | #include "OgreHardwareVertexBuffer.h" |
---|
| 39 | #include "OgreRenderToVertexBuffer.h" |
---|
| 40 | #include "OgreHeaderPrefix.h" |
---|
| 41 | |
---|
| 42 | namespace Ogre { |
---|
| 43 | /** \addtogroup Core |
---|
| 44 | * @{ |
---|
| 45 | */ |
---|
| 46 | /** \addtogroup RenderSystem |
---|
| 47 | * @{ |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | /** Abstract interface representing a 'licensee' of a hardware buffer copy. |
---|
| 51 | @remarks |
---|
| 52 | Often it's useful to have temporary buffers which are used for working |
---|
| 53 | but are not necessarily needed permanently. However, creating and |
---|
| 54 | destroying buffers is expensive, so we need a way to share these |
---|
| 55 | working areas, especially those based on existing fixed buffers. |
---|
| 56 | This class represents a licensee of one of those temporary buffers, |
---|
| 57 | and must be implemented by any user of a temporary buffer if they |
---|
| 58 | wish to be notified when the license is expired. |
---|
| 59 | */ |
---|
| 60 | class _OgreExport HardwareBufferLicensee |
---|
| 61 | { |
---|
| 62 | public: |
---|
| 63 | virtual ~HardwareBufferLicensee() { } |
---|
| 64 | /** This method is called when the buffer license is expired and is about |
---|
| 65 | to be returned to the shared pool. |
---|
| 66 | */ |
---|
| 67 | virtual void licenseExpired(HardwareBuffer* buffer) = 0; |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | /** Structure for recording the use of temporary blend buffers. */ |
---|
| 71 | class _OgreExport TempBlendedBufferInfo : public HardwareBufferLicensee, public BufferAlloc |
---|
| 72 | { |
---|
| 73 | private: |
---|
| 74 | // Pre-blended |
---|
| 75 | HardwareVertexBufferSharedPtr srcPositionBuffer; |
---|
| 76 | HardwareVertexBufferSharedPtr srcNormalBuffer; |
---|
| 77 | // Post-blended |
---|
| 78 | HardwareVertexBufferSharedPtr destPositionBuffer; |
---|
| 79 | HardwareVertexBufferSharedPtr destNormalBuffer; |
---|
| 80 | /// Both positions and normals are contained in the same buffer. |
---|
| 81 | bool posNormalShareBuffer; |
---|
| 82 | unsigned short posBindIndex; |
---|
| 83 | unsigned short normBindIndex; |
---|
| 84 | bool bindPositions; |
---|
| 85 | bool bindNormals; |
---|
| 86 | |
---|
| 87 | public: |
---|
| 88 | ~TempBlendedBufferInfo(void); |
---|
| 89 | /// Utility method, extract info from the given VertexData. |
---|
| 90 | void extractFrom(const VertexData* sourceData); |
---|
| 91 | /// Utility method, checks out temporary copies of src into dest. |
---|
| 92 | void checkoutTempCopies(bool positions = true, bool normals = true); |
---|
| 93 | /// Utility method, binds dest copies into a given VertexData struct. |
---|
| 94 | void bindTempCopies(VertexData* targetData, bool suppressHardwareUpload); |
---|
| 95 | /** Overridden member from HardwareBufferLicensee. */ |
---|
| 96 | void licenseExpired(HardwareBuffer* buffer); |
---|
| 97 | /** Detect currently have buffer copies checked out and touch it. */ |
---|
| 98 | bool buffersCheckedOut(bool positions = true, bool normals = true) const; |
---|
| 99 | }; |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | /** Base definition of a hardware buffer manager. |
---|
| 103 | @remarks |
---|
| 104 | This class is deliberately not a Singleton, so that multiple types can |
---|
| 105 | exist at once. The Singleton is wrapped via the Decorator pattern |
---|
| 106 | in HardwareBufferManager, below. Each concrete implementation should |
---|
| 107 | provide a subclass of HardwareBufferManagerBase, which does the actual |
---|
| 108 | work, and also a very simple subclass of HardwareBufferManager which |
---|
| 109 | simply constructs the instance of the HardwareBufferManagerBase subclass |
---|
| 110 | and passes it to the HardwareBufferManager superclass as a delegate. |
---|
| 111 | This subclass must also delete the implementation instance it creates. |
---|
| 112 | */ |
---|
| 113 | class _OgreExport HardwareBufferManagerBase : public BufferAlloc |
---|
| 114 | { |
---|
| 115 | friend class HardwareVertexBufferSharedPtr; |
---|
| 116 | friend class HardwareIndexBufferSharedPtr; |
---|
| 117 | protected: |
---|
| 118 | /** WARNING: The following two members should place before all other members. |
---|
| 119 | Members destruct order is very important here, because destructing other |
---|
| 120 | members will cause notify back to this class, and then will access to this |
---|
| 121 | two members. |
---|
| 122 | */ |
---|
| 123 | typedef set<HardwareVertexBuffer*>::type VertexBufferList; |
---|
| 124 | typedef set<HardwareIndexBuffer*>::type IndexBufferList; |
---|
| 125 | typedef set<HardwareUniformBuffer*>::type UniformBufferList; |
---|
| 126 | typedef set<HardwareCounterBuffer*>::type CounterBufferList; |
---|
| 127 | VertexBufferList mVertexBuffers; |
---|
| 128 | IndexBufferList mIndexBuffers; |
---|
| 129 | UniformBufferList mUniformBuffers; |
---|
| 130 | CounterBufferList mCounterBuffers; |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | typedef set<VertexDeclaration*>::type VertexDeclarationList; |
---|
| 134 | typedef set<VertexBufferBinding*>::type VertexBufferBindingList; |
---|
| 135 | VertexDeclarationList mVertexDeclarations; |
---|
| 136 | VertexBufferBindingList mVertexBufferBindings; |
---|
| 137 | |
---|
| 138 | // Mutexes |
---|
| 139 | OGRE_MUTEX(mVertexBuffersMutex); |
---|
| 140 | OGRE_MUTEX(mIndexBuffersMutex); |
---|
| 141 | OGRE_MUTEX(mUniformBuffersMutex); |
---|
| 142 | OGRE_MUTEX(mCounterBuffersMutex); |
---|
| 143 | OGRE_MUTEX(mVertexDeclarationsMutex); |
---|
| 144 | OGRE_MUTEX(mVertexBufferBindingsMutex); |
---|
| 145 | |
---|
| 146 | /// Internal method for destroys all vertex declarations. |
---|
| 147 | virtual void destroyAllDeclarations(void); |
---|
| 148 | /// Internal method for destroys all vertex buffer bindings. |
---|
| 149 | virtual void destroyAllBindings(void); |
---|
| 150 | |
---|
| 151 | /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs. |
---|
| 152 | virtual VertexDeclaration* createVertexDeclarationImpl(void); |
---|
| 153 | /// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs. |
---|
| 154 | virtual void destroyVertexDeclarationImpl(VertexDeclaration* decl); |
---|
| 155 | |
---|
| 156 | /// Internal method for creates a new VertexBufferBinding, may be overridden by certain rendering APIs. |
---|
| 157 | virtual VertexBufferBinding* createVertexBufferBindingImpl(void); |
---|
| 158 | /// Internal method for destroys a VertexBufferBinding, may be overridden by certain rendering APIs. |
---|
| 159 | virtual void destroyVertexBufferBindingImpl(VertexBufferBinding* binding); |
---|
| 160 | |
---|
| 161 | public: |
---|
| 162 | |
---|
| 163 | enum BufferLicenseType |
---|
| 164 | { |
---|
| 165 | /// Licensee will only release buffer when it says so. |
---|
| 166 | BLT_MANUAL_RELEASE, |
---|
| 167 | /// Licensee can have license revoked. |
---|
| 168 | BLT_AUTOMATIC_RELEASE |
---|
| 169 | }; |
---|
| 170 | |
---|
| 171 | protected: |
---|
| 172 | /** Struct holding details of a license to use a temporary shared buffer. */ |
---|
| 173 | class _OgrePrivate VertexBufferLicense |
---|
| 174 | { |
---|
| 175 | public: |
---|
| 176 | HardwareVertexBuffer* originalBufferPtr; |
---|
| 177 | BufferLicenseType licenseType; |
---|
| 178 | size_t expiredDelay; |
---|
| 179 | HardwareVertexBufferSharedPtr buffer; |
---|
| 180 | HardwareBufferLicensee* licensee; |
---|
| 181 | VertexBufferLicense( |
---|
| 182 | HardwareVertexBuffer* orig, |
---|
| 183 | BufferLicenseType ltype, |
---|
| 184 | size_t delay, |
---|
| 185 | HardwareVertexBufferSharedPtr buf, |
---|
| 186 | HardwareBufferLicensee* lic) |
---|
| 187 | : originalBufferPtr(orig) |
---|
| 188 | , licenseType(ltype) |
---|
| 189 | , expiredDelay(delay) |
---|
| 190 | , buffer(buf) |
---|
| 191 | , licensee(lic) |
---|
| 192 | {} |
---|
| 193 | |
---|
| 194 | }; |
---|
| 195 | |
---|
| 196 | /// Map from original buffer to temporary buffers. |
---|
| 197 | typedef multimap<HardwareVertexBuffer*, HardwareVertexBufferSharedPtr>::type FreeTemporaryVertexBufferMap; |
---|
| 198 | /// Map of current available temp buffers. |
---|
| 199 | FreeTemporaryVertexBufferMap mFreeTempVertexBufferMap; |
---|
| 200 | /// Map from temporary buffer to details of a license. |
---|
| 201 | typedef map<HardwareVertexBuffer*, VertexBufferLicense>::type TemporaryVertexBufferLicenseMap; |
---|
| 202 | /// Map of currently licensed temporary buffers. |
---|
| 203 | TemporaryVertexBufferLicenseMap mTempVertexBufferLicenses; |
---|
| 204 | /// Number of frames elapsed since temporary buffers utilization was above half the available. |
---|
| 205 | size_t mUnderUsedFrameCount; |
---|
| 206 | /// Number of frames to wait before free unused temporary buffers. |
---|
| 207 | static const size_t UNDER_USED_FRAME_THRESHOLD; |
---|
| 208 | /// Frame delay for BLT_AUTOMATIC_RELEASE temporary buffers. |
---|
| 209 | static const size_t EXPIRED_DELAY_FRAME_THRESHOLD; |
---|
| 210 | // Mutexes |
---|
| 211 | OGRE_MUTEX(mTempBuffersMutex); |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | /// Creates a new buffer as a copy of the source, does not copy data. |
---|
| 215 | virtual HardwareVertexBufferSharedPtr makeBufferCopy( |
---|
| 216 | const HardwareVertexBufferSharedPtr& source, |
---|
| 217 | HardwareBuffer::Usage usage, bool useShadowBuffer); |
---|
| 218 | |
---|
| 219 | public: |
---|
| 220 | HardwareBufferManagerBase(); |
---|
| 221 | virtual ~HardwareBufferManagerBase(); |
---|
| 222 | /** Create a hardware vertex buffer. |
---|
| 223 | @remarks |
---|
| 224 | This method creates a new vertex buffer; this will act as a source of geometry |
---|
| 225 | data for rendering objects. Note that because the meaning of the contents of |
---|
| 226 | the vertex buffer depends on the usage, this method does not specify a |
---|
| 227 | vertex format; the user of this buffer can actually insert whatever data |
---|
| 228 | they wish, in any format. However, in order to use this with a RenderOperation, |
---|
| 229 | the data in this vertex buffer will have to be associated with a semantic element |
---|
| 230 | of the rendering pipeline, e.g. a position, or texture coordinates. This is done |
---|
| 231 | using the VertexDeclaration class, which itself contains VertexElement structures |
---|
| 232 | referring to the source data. |
---|
| 233 | @remarks Note that because vertex buffers can be shared, they are reference |
---|
| 234 | counted so you do not need to worry about destroying themm this will be done |
---|
| 235 | automatically. |
---|
| 236 | @param vertexSize |
---|
| 237 | The size in bytes of each vertex in this buffer; you must calculate |
---|
| 238 | this based on the kind of data you expect to populate this buffer with. |
---|
| 239 | @param numVerts |
---|
| 240 | The number of vertices in this buffer. |
---|
| 241 | @param usage |
---|
| 242 | One or more members of the HardwareBuffer::Usage enumeration; you are |
---|
| 243 | strongly advised to use HBU_STATIC_WRITE_ONLY wherever possible, if you need to |
---|
| 244 | update regularly, consider HBU_DYNAMIC_WRITE_ONLY and useShadowBuffer=true. |
---|
| 245 | @param useShadowBuffer |
---|
| 246 | If set to @c true, this buffer will be 'shadowed' by one stored in |
---|
| 247 | system memory rather than GPU or AGP memory. You should set this flag if you intend |
---|
| 248 | to read data back from the vertex buffer, because reading data from a buffer |
---|
| 249 | in the GPU or AGP memory is very expensive, and is in fact impossible if you |
---|
| 250 | specify HBU_WRITE_ONLY for the main buffer. If you use this option, all |
---|
| 251 | reads and writes will be done to the shadow buffer, and the shadow buffer will |
---|
| 252 | be synchronised with the real buffer at an appropriate time. |
---|
| 253 | */ |
---|
| 254 | virtual HardwareVertexBufferSharedPtr |
---|
| 255 | createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage, |
---|
| 256 | bool useShadowBuffer = false) = 0; |
---|
| 257 | /** Create a hardware index buffer. |
---|
| 258 | @remarks Note that because buffers can be shared, they are reference |
---|
| 259 | counted so you do not need to worry about destroying them this will be done |
---|
| 260 | automatically. |
---|
| 261 | @param itype |
---|
| 262 | The type in index, either 16- or 32-bit, depending on how many vertices |
---|
| 263 | you need to be able to address |
---|
| 264 | @param numIndexes |
---|
| 265 | The number of indexes in the buffer |
---|
| 266 | @param usage |
---|
| 267 | One or more members of the HardwareBuffer::Usage enumeration. |
---|
| 268 | @param useShadowBuffer |
---|
| 269 | If set to @c true, this buffer will be 'shadowed' by one stored in |
---|
| 270 | system memory rather than GPU or AGP memory. You should set this flag if you intend |
---|
| 271 | to read data back from the index buffer, because reading data from a buffer |
---|
| 272 | in the GPU or AGP memory is very expensive, and is in fact impossible if you |
---|
| 273 | specify HBU_WRITE_ONLY for the main buffer. If you use this option, all |
---|
| 274 | reads and writes will be done to the shadow buffer, and the shadow buffer will |
---|
| 275 | be synchronised with the real buffer at an appropriate time. |
---|
| 276 | */ |
---|
| 277 | virtual HardwareIndexBufferSharedPtr |
---|
| 278 | createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes, |
---|
| 279 | HardwareBuffer::Usage usage, bool useShadowBuffer = false) = 0; |
---|
| 280 | |
---|
| 281 | /** Create a render to vertex buffer. |
---|
| 282 | @remarks The parameters (such as vertex size etc) are determined later |
---|
| 283 | and are allocated when needed. |
---|
| 284 | */ |
---|
| 285 | virtual RenderToVertexBufferSharedPtr createRenderToVertexBuffer() = 0; |
---|
| 286 | |
---|
| 287 | /** |
---|
| 288 | * Create uniform buffer. This type of buffer allows the upload of shader constants once, |
---|
| 289 | * and sharing between shader stages or even shaders from another materials. |
---|
| 290 | * The update shall be triggered by GpuProgramParameters, if is dirty |
---|
| 291 | */ |
---|
| 292 | virtual HardwareUniformBufferSharedPtr createUniformBuffer(size_t sizeBytes, |
---|
| 293 | HardwareBuffer::Usage usage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, |
---|
| 294 | bool useShadowBuffer = false, const String& name = "") = 0; |
---|
| 295 | |
---|
| 296 | /** |
---|
| 297 | * Create counter buffer. |
---|
| 298 | * The update shall be triggered by GpuProgramParameters, if is dirty |
---|
| 299 | */ |
---|
| 300 | virtual HardwareCounterBufferSharedPtr createCounterBuffer(size_t sizeBytes, |
---|
| 301 | HardwareBuffer::Usage usage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, |
---|
| 302 | bool useShadowBuffer = false, const String& name = "") = 0; |
---|
| 303 | |
---|
| 304 | /** Creates a new vertex declaration. */ |
---|
| 305 | virtual VertexDeclaration* createVertexDeclaration(void); |
---|
| 306 | /** Destroys a vertex declaration. */ |
---|
| 307 | virtual void destroyVertexDeclaration(VertexDeclaration* decl); |
---|
| 308 | |
---|
| 309 | /** Creates a new VertexBufferBinding. */ |
---|
| 310 | virtual VertexBufferBinding* createVertexBufferBinding(void); |
---|
| 311 | /** Destroys a VertexBufferBinding. */ |
---|
| 312 | virtual void destroyVertexBufferBinding(VertexBufferBinding* binding); |
---|
| 313 | |
---|
| 314 | /** Registers a vertex buffer as a copy of another. |
---|
| 315 | @remarks |
---|
| 316 | This is useful for registering an existing buffer as a temporary buffer |
---|
| 317 | which can be allocated just like a copy. |
---|
| 318 | */ |
---|
| 319 | virtual void registerVertexBufferSourceAndCopy( |
---|
| 320 | const HardwareVertexBufferSharedPtr& sourceBuffer, |
---|
| 321 | const HardwareVertexBufferSharedPtr& copy); |
---|
| 322 | |
---|
| 323 | /** Allocates a copy of a given vertex buffer. |
---|
| 324 | @remarks |
---|
| 325 | This method allocates a temporary copy of an existing vertex buffer. |
---|
| 326 | This buffer is subsequently stored and can be made available for |
---|
| 327 | other purposes later without incurring the cost of construction / |
---|
| 328 | destruction. |
---|
| 329 | @param sourceBuffer |
---|
| 330 | The source buffer to use as a copy. |
---|
| 331 | @param licenseType |
---|
| 332 | The type of license required on this buffer - automatic |
---|
| 333 | release causes this class to release licenses every frame so that |
---|
| 334 | they can be reallocated anew. |
---|
| 335 | @param licensee |
---|
| 336 | Pointer back to the class requesting the copy, which must |
---|
| 337 | implement HardwareBufferLicense in order to be notified when the license |
---|
| 338 | expires. |
---|
| 339 | @param copyData |
---|
| 340 | If @c true, the current data is copied as well as the |
---|
| 341 | structure of the buffer/ |
---|
| 342 | */ |
---|
| 343 | virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy( |
---|
| 344 | const HardwareVertexBufferSharedPtr& sourceBuffer, |
---|
| 345 | BufferLicenseType licenseType, |
---|
| 346 | HardwareBufferLicensee* licensee, |
---|
| 347 | bool copyData = false); |
---|
| 348 | |
---|
| 349 | /** Manually release a vertex buffer copy for others to subsequently use. |
---|
| 350 | @remarks |
---|
| 351 | Only required if the original call to allocateVertexBufferCopy |
---|
| 352 | included a licenseType of BLT_MANUAL_RELEASE. |
---|
| 353 | @param bufferCopy |
---|
| 354 | The buffer copy. The caller is expected to delete |
---|
| 355 | or at least no longer use this reference, since another user may |
---|
| 356 | well begin to modify the contents of the buffer. |
---|
| 357 | */ |
---|
| 358 | virtual void releaseVertexBufferCopy( |
---|
| 359 | const HardwareVertexBufferSharedPtr& bufferCopy); |
---|
| 360 | |
---|
| 361 | /** Tell engine that the vertex buffer copy intent to reuse. |
---|
| 362 | @remarks |
---|
| 363 | Ogre internal keep an expired delay counter of BLT_AUTOMATIC_RELEASE |
---|
| 364 | buffers, when the counter count down to zero, it'll release for other |
---|
| 365 | purposes later. But you can use this function to reset the counter to |
---|
| 366 | the internal configured value, keep the buffer not get released for |
---|
| 367 | some frames. |
---|
| 368 | @param bufferCopy |
---|
| 369 | The buffer copy. The caller is expected to keep this |
---|
| 370 | buffer copy for use. |
---|
| 371 | */ |
---|
| 372 | virtual void touchVertexBufferCopy(const HardwareVertexBufferSharedPtr& bufferCopy); |
---|
| 373 | |
---|
| 374 | /** Free all unused vertex buffer copies. |
---|
| 375 | @remarks |
---|
| 376 | This method free all temporary vertex buffers that not in used. |
---|
| 377 | In normally, temporary vertex buffers are subsequently stored and can |
---|
| 378 | be made available for other purposes later without incurring the cost |
---|
| 379 | of construction / destruction. But in some cases you want to free them |
---|
| 380 | to save hardware memory (e.g. application was runs in a long time, you |
---|
| 381 | might free temporary buffers periodically to avoid memory overload). |
---|
| 382 | */ |
---|
| 383 | virtual void _freeUnusedBufferCopies(void); |
---|
| 384 | |
---|
| 385 | /** Internal method for releasing all temporary buffers which have been |
---|
| 386 | allocated using BLT_AUTOMATIC_RELEASE; is called by OGRE. |
---|
| 387 | @param forceFreeUnused |
---|
| 388 | If @c true, free all unused temporary buffers. |
---|
| 389 | If @c false, auto detect and free all unused temporary buffers based on |
---|
| 390 | temporary buffers utilization. |
---|
| 391 | */ |
---|
| 392 | virtual void _releaseBufferCopies(bool forceFreeUnused = false); |
---|
| 393 | |
---|
| 394 | /** Internal method that forces the release of copies of a given buffer. |
---|
| 395 | @remarks |
---|
| 396 | This usually means that the buffer which the copies are based on has |
---|
| 397 | been changed in some fundamental way, and the owner of the original |
---|
| 398 | wishes to make that known so that new copies will reflect the |
---|
| 399 | changes. |
---|
| 400 | @param sourceBuffer |
---|
| 401 | The source buffer as a shared pointer. Any buffer copies created |
---|
| 402 | from the source buffer are deleted. |
---|
| 403 | */ |
---|
| 404 | virtual void _forceReleaseBufferCopies(const HardwareVertexBufferSharedPtr& sourceBuffer); |
---|
| 405 | |
---|
| 406 | /** Internal method that forces the release of copies of a given buffer. |
---|
| 407 | @remarks |
---|
| 408 | This usually means that the buffer which the copies are based on has |
---|
| 409 | been changed in some fundamental way, and the owner of the original |
---|
| 410 | wishes to make that known so that new copies will reflect the |
---|
| 411 | changes. |
---|
| 412 | @param sourceBuffer |
---|
| 413 | The source buffer as a pointer. Any buffer copies created from |
---|
| 414 | the source buffer are deleted. |
---|
| 415 | */ |
---|
| 416 | virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer); |
---|
| 417 | |
---|
| 418 | /// Notification that a hardware vertex buffer has been destroyed. |
---|
| 419 | void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf); |
---|
| 420 | /// Notification that a hardware index buffer has been destroyed. |
---|
| 421 | void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf); |
---|
| 422 | /// Notification that at hardware uniform buffer has been destroyed |
---|
| 423 | void _notifyUniformBufferDestroyed(HardwareUniformBuffer* buf); |
---|
| 424 | /// Notification that at hardware counter buffer has been destroyed |
---|
| 425 | void _notifyCounterBufferDestroyed(HardwareCounterBuffer* buf); |
---|
| 426 | }; |
---|
| 427 | |
---|
| 428 | /** Singleton wrapper for hardware buffer manager. */ |
---|
| 429 | class _OgreExport HardwareBufferManager : public HardwareBufferManagerBase, public Singleton<HardwareBufferManager> |
---|
| 430 | { |
---|
| 431 | friend class HardwareVertexBufferSharedPtr; |
---|
| 432 | friend class HardwareIndexBufferSharedPtr; |
---|
| 433 | protected: |
---|
| 434 | HardwareBufferManagerBase* mImpl; |
---|
| 435 | public: |
---|
| 436 | HardwareBufferManager(HardwareBufferManagerBase* imp); |
---|
| 437 | ~HardwareBufferManager(); |
---|
| 438 | |
---|
| 439 | /** @copydoc HardwareBufferManagerBase::createVertexBuffer */ |
---|
| 440 | HardwareVertexBufferSharedPtr |
---|
| 441 | createVertexBuffer(size_t vertexSize, size_t numVerts, HardwareBuffer::Usage usage, |
---|
| 442 | bool useShadowBuffer = false) |
---|
| 443 | { |
---|
| 444 | return mImpl->createVertexBuffer(vertexSize, numVerts, usage, useShadowBuffer); |
---|
| 445 | } |
---|
| 446 | /** @copydoc HardwareBufferManagerBase::createIndexBuffer */ |
---|
| 447 | HardwareIndexBufferSharedPtr |
---|
| 448 | createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes, |
---|
| 449 | HardwareBuffer::Usage usage, bool useShadowBuffer = false) |
---|
| 450 | { |
---|
| 451 | return mImpl->createIndexBuffer(itype, numIndexes, usage, useShadowBuffer); |
---|
| 452 | } |
---|
| 453 | |
---|
| 454 | /** @copydoc HardwareBufferManagerBase::createRenderToVertexBuffer */ |
---|
| 455 | RenderToVertexBufferSharedPtr createRenderToVertexBuffer() |
---|
| 456 | { |
---|
| 457 | return mImpl->createRenderToVertexBuffer(); |
---|
| 458 | } |
---|
| 459 | |
---|
| 460 | /** @copydoc HardwareBufferManagerBase::createUniformBuffer */ |
---|
| 461 | HardwareUniformBufferSharedPtr |
---|
| 462 | createUniformBuffer(size_t sizeBytes, HardwareBuffer::Usage usage, bool useShadowBuffer, const String& name = "") |
---|
| 463 | { |
---|
| 464 | return mImpl->createUniformBuffer(sizeBytes, usage, useShadowBuffer, name); |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | /** @copydoc HardwareBufferManagerBase::createCounterBuffer */ |
---|
| 468 | HardwareCounterBufferSharedPtr |
---|
| 469 | createCounterBuffer(size_t sizeBytes, HardwareBuffer::Usage usage, bool useShadowBuffer, const String& name = "") |
---|
| 470 | { |
---|
| 471 | return mImpl->createCounterBuffer(sizeBytes, usage, useShadowBuffer, name); |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /** @copydoc HardwareBufferManagerInterface::createVertexDeclaration */ |
---|
| 475 | virtual VertexDeclaration* createVertexDeclaration(void) |
---|
| 476 | { |
---|
| 477 | return mImpl->createVertexDeclaration(); |
---|
| 478 | } |
---|
| 479 | /** @copydoc HardwareBufferManagerBase::destroyVertexDeclaration */ |
---|
| 480 | virtual void destroyVertexDeclaration(VertexDeclaration* decl) |
---|
| 481 | { |
---|
| 482 | mImpl->destroyVertexDeclaration(decl); |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | /** @copydoc HardwareBufferManagerBase::createVertexBufferBinding */ |
---|
| 486 | virtual VertexBufferBinding* createVertexBufferBinding(void) |
---|
| 487 | { |
---|
| 488 | return mImpl->createVertexBufferBinding(); |
---|
| 489 | } |
---|
| 490 | /** @copydoc HardwareBufferManagerBase::destroyVertexBufferBinding */ |
---|
| 491 | virtual void destroyVertexBufferBinding(VertexBufferBinding* binding) |
---|
| 492 | { |
---|
| 493 | mImpl->destroyVertexBufferBinding(binding); |
---|
| 494 | } |
---|
| 495 | /** @copydoc HardwareBufferManagerBase::registerVertexBufferSourceAndCopy */ |
---|
| 496 | virtual void registerVertexBufferSourceAndCopy( |
---|
| 497 | const HardwareVertexBufferSharedPtr& sourceBuffer, |
---|
| 498 | const HardwareVertexBufferSharedPtr& copy) |
---|
| 499 | { |
---|
| 500 | mImpl->registerVertexBufferSourceAndCopy(sourceBuffer, copy); |
---|
| 501 | } |
---|
| 502 | /** @copydoc HardwareBufferManagerBase::allocateVertexBufferCopy */ |
---|
| 503 | virtual HardwareVertexBufferSharedPtr allocateVertexBufferCopy( |
---|
| 504 | const HardwareVertexBufferSharedPtr& sourceBuffer, |
---|
| 505 | BufferLicenseType licenseType, |
---|
| 506 | HardwareBufferLicensee* licensee, |
---|
| 507 | bool copyData = false) |
---|
| 508 | { |
---|
| 509 | return mImpl->allocateVertexBufferCopy(sourceBuffer, licenseType, licensee, copyData); |
---|
| 510 | } |
---|
| 511 | /** @copydoc HardwareBufferManagerBase::releaseVertexBufferCopy */ |
---|
| 512 | virtual void releaseVertexBufferCopy( |
---|
| 513 | const HardwareVertexBufferSharedPtr& bufferCopy) |
---|
| 514 | { |
---|
| 515 | mImpl->releaseVertexBufferCopy(bufferCopy); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | /** @copydoc HardwareBufferManagerBase::touchVertexBufferCopy */ |
---|
| 519 | virtual void touchVertexBufferCopy( |
---|
| 520 | const HardwareVertexBufferSharedPtr& bufferCopy) |
---|
| 521 | { |
---|
| 522 | mImpl->touchVertexBufferCopy(bufferCopy); |
---|
| 523 | } |
---|
| 524 | |
---|
| 525 | /** @copydoc HardwareBufferManagerBase::_freeUnusedBufferCopies */ |
---|
| 526 | virtual void _freeUnusedBufferCopies(void) |
---|
| 527 | { |
---|
| 528 | mImpl->_freeUnusedBufferCopies(); |
---|
| 529 | } |
---|
| 530 | /** @copydoc HardwareBufferManagerBase::_releaseBufferCopies */ |
---|
| 531 | virtual void _releaseBufferCopies(bool forceFreeUnused = false) |
---|
| 532 | { |
---|
| 533 | mImpl->_releaseBufferCopies(forceFreeUnused); |
---|
| 534 | } |
---|
| 535 | /** @copydoc HardwareBufferManagerBase::_forceReleaseBufferCopies */ |
---|
| 536 | virtual void _forceReleaseBufferCopies( |
---|
| 537 | const HardwareVertexBufferSharedPtr& sourceBuffer) |
---|
| 538 | { |
---|
| 539 | mImpl->_forceReleaseBufferCopies(sourceBuffer); |
---|
| 540 | } |
---|
| 541 | /** @copydoc HardwareBufferManagerBase::_forceReleaseBufferCopies */ |
---|
| 542 | virtual void _forceReleaseBufferCopies(HardwareVertexBuffer* sourceBuffer) |
---|
| 543 | { |
---|
| 544 | mImpl->_forceReleaseBufferCopies(sourceBuffer); |
---|
| 545 | } |
---|
| 546 | /** @copydoc HardwareBufferManagerBase::_notifyVertexBufferDestroyed */ |
---|
| 547 | void _notifyVertexBufferDestroyed(HardwareVertexBuffer* buf) |
---|
| 548 | { |
---|
| 549 | mImpl->_notifyVertexBufferDestroyed(buf); |
---|
| 550 | } |
---|
| 551 | /** @copydoc HardwareBufferManagerBase::_notifyIndexBufferDestroyed */ |
---|
| 552 | void _notifyIndexBufferDestroyed(HardwareIndexBuffer* buf) |
---|
| 553 | { |
---|
| 554 | mImpl->_notifyIndexBufferDestroyed(buf); |
---|
| 555 | } |
---|
| 556 | /** @copydoc HardwareBufferManagerInterface::_notifyUniformBufferDestroyed */ |
---|
| 557 | void _notifyUniformBufferDestroyed(HardwareUniformBuffer* buf) |
---|
| 558 | { |
---|
| 559 | mImpl->_notifyUniformBufferDestroyed(buf); |
---|
| 560 | } |
---|
| 561 | /** @copydoc HardwareBufferManagerInterface::_notifyCounterBufferDestroyed */ |
---|
| 562 | void _notifyConterBufferDestroyed(HardwareCounterBuffer* buf) |
---|
| 563 | { |
---|
| 564 | mImpl->_notifyCounterBufferDestroyed(buf); |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | /** Override standard Singleton retrieval. |
---|
| 568 | @remarks |
---|
| 569 | Why do we do this? Well, it's because the Singleton |
---|
| 570 | implementation is in a .h file, which means it gets compiled |
---|
| 571 | into anybody who includes it. This is needed for the |
---|
| 572 | Singleton template to work, but we actually only want it |
---|
| 573 | compiled into the implementation of the class based on the |
---|
| 574 | Singleton, not all of them. If we don't change this, we get |
---|
| 575 | link errors when trying to use the Singleton-based class from |
---|
| 576 | an outside dll. |
---|
| 577 | @par |
---|
| 578 | This method just delegates to the template version anyway, |
---|
| 579 | but the implementation stays in this single compilation unit, |
---|
| 580 | preventing link errors. |
---|
| 581 | */ |
---|
| 582 | static HardwareBufferManager& getSingleton(void); |
---|
| 583 | /** Override standard Singleton retrieval. |
---|
| 584 | @remarks |
---|
| 585 | Why do we do this? Well, it's because the Singleton |
---|
| 586 | implementation is in a .h file, which means it gets compiled |
---|
| 587 | into anybody who includes it. This is needed for the |
---|
| 588 | Singleton template to work, but we actually only want it |
---|
| 589 | compiled into the implementation of the class based on the |
---|
| 590 | Singleton, not all of them. If we don't change this, we get |
---|
| 591 | link errors when trying to use the Singleton-based class from |
---|
| 592 | an outside dll. |
---|
| 593 | @par |
---|
| 594 | This method just delegates to the template version anyway, |
---|
| 595 | but the implementation stays in this single compilation unit, |
---|
| 596 | preventing link errors. |
---|
| 597 | */ |
---|
| 598 | static HardwareBufferManager* getSingletonPtr(void); |
---|
| 599 | |
---|
| 600 | }; |
---|
| 601 | |
---|
| 602 | /** @} */ |
---|
| 603 | /** @} */ |
---|
| 604 | } // namespace Ogre |
---|
| 605 | |
---|
| 606 | #include "OgreHeaderSuffix.h" |
---|
| 607 | |
---|
| 608 | #endif // __HardwareBufferManager__ |
---|
| 609 | |
---|