/src/ogre/OgreMain/src/OgreDefaultHardwareBufferManager.cpp
Line | Count | Source |
1 | | /* |
2 | | ----------------------------------------------------------------------------- |
3 | | This source file is part of OGRE |
4 | | (Object-oriented Graphics Rendering Engine) |
5 | | For the latest info, see http://www.ogre3d.org/ |
6 | | |
7 | | Copyright (c) 2000-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #include "OgreStableHeaders.h" |
29 | | #include "OgreDefaultHardwareBufferManager.h" |
30 | | |
31 | | namespace Ogre { |
32 | | |
33 | | DefaultHardwareBuffer::DefaultHardwareBuffer(size_t sizeInBytes) |
34 | 0 | : HardwareBuffer(HBU_CPU_ONLY, false) // always software, never shadowed |
35 | 0 | { |
36 | 0 | mSizeInBytes = sizeInBytes; |
37 | | // Allocate aligned memory for better SIMD processing friendly. |
38 | 0 | mData = (uchar*)AlignedMemory::allocate(mSizeInBytes); |
39 | 0 | } |
40 | | //----------------------------------------------------------------------- |
41 | | DefaultHardwareBuffer::~DefaultHardwareBuffer() |
42 | 0 | { |
43 | 0 | AlignedMemory::deallocate(mData); |
44 | 0 | } |
45 | | //----------------------------------------------------------------------- |
46 | | void* DefaultHardwareBuffer::lockImpl(size_t offset, size_t length, LockOptions options) |
47 | 0 | { |
48 | | // Only for use internally, no 'locking' as such |
49 | 0 | return mData + offset; |
50 | 0 | } |
51 | | //----------------------------------------------------------------------- |
52 | | void DefaultHardwareBuffer::unlockImpl(void) |
53 | 0 | { |
54 | | // Nothing to do |
55 | 0 | } |
56 | | //----------------------------------------------------------------------- |
57 | | void DefaultHardwareBuffer::readData(size_t offset, size_t length, void* pDest) |
58 | 0 | { |
59 | 0 | assert((offset + length) <= mSizeInBytes); |
60 | 0 | memcpy(pDest, mData + offset, length); |
61 | 0 | } |
62 | | //----------------------------------------------------------------------- |
63 | | void DefaultHardwareBuffer::writeData(size_t offset, size_t length, const void* pSource, |
64 | | bool discardWholeBuffer) |
65 | 0 | { |
66 | 0 | assert((offset + length) <= mSizeInBytes); |
67 | | // ignore discard, memory is not guaranteed to be zeroised |
68 | 0 | memcpy(mData + offset, pSource, length); |
69 | 0 | } |
70 | | //----------------------------------------------------------------------- |
71 | | DefaultHardwareBufferManagerBase::DefaultHardwareBufferManagerBase() |
72 | 0 | { |
73 | 0 | } |
74 | | //----------------------------------------------------------------------- |
75 | | DefaultHardwareBufferManagerBase::~DefaultHardwareBufferManagerBase() |
76 | 0 | { |
77 | 0 | destroyAllDeclarations(); |
78 | 0 | destroyAllBindings(); |
79 | 0 | } |
80 | | //----------------------------------------------------------------------- |
81 | | HardwareVertexBufferSharedPtr |
82 | | DefaultHardwareBufferManagerBase::createVertexBuffer(size_t vertexSize, |
83 | | size_t numVerts, HardwareBuffer::Usage usage, bool useShadowBuffer) |
84 | 0 | { |
85 | 0 | return std::make_shared<HardwareVertexBuffer>(this, vertexSize, numVerts, |
86 | 0 | new DefaultHardwareBuffer(vertexSize * numVerts)); |
87 | 0 | } |
88 | | //----------------------------------------------------------------------- |
89 | | HardwareIndexBufferSharedPtr |
90 | | DefaultHardwareBufferManagerBase::createIndexBuffer(HardwareIndexBuffer::IndexType itype, |
91 | | size_t numIndexes, HardwareBuffer::Usage usage, bool useShadowBuffer) |
92 | 0 | { |
93 | 0 | return std::make_shared<HardwareIndexBuffer>( |
94 | 0 | this, itype, numIndexes, |
95 | 0 | new DefaultHardwareBuffer(HardwareIndexBuffer::indexSize(itype) * numIndexes)); |
96 | 0 | } |
97 | | } |