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-2006 Torus Knot Software Ltd |
---|
8 | Also see acknowledgements in Readme.html |
---|
9 | |
---|
10 | This program is free software you can redistribute it and/or modify it under |
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software |
---|
12 | Foundation either version 2 of the License, or (at your option) any later |
---|
13 | version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
16 | ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU Lesser General Public License along with |
---|
20 | this program if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
22 | http://www.gnu.org/copyleft/lesser.txt. |
---|
23 | |
---|
24 | You may alternatively use this source under the terms of a specific version of |
---|
25 | the OGRE Unrestricted License provided you have obtained such a license from |
---|
26 | Torus Knot Software Ltd. |
---|
27 | ----------------------------------------------------------------------------- |
---|
28 | */ |
---|
29 | #include "OgreGLDefaultHardwareBufferManager.h" |
---|
30 | #include "OgreAlignedAllocator.h" |
---|
31 | |
---|
32 | namespace Ogre { |
---|
33 | |
---|
34 | GLDefaultHardwareVertexBuffer::GLDefaultHardwareVertexBuffer(size_t vertexSize, size_t numVertices, |
---|
35 | HardwareBuffer::Usage usage) |
---|
36 | : HardwareVertexBuffer(vertexSize, numVertices, usage, true, false) // always software, never shadowed |
---|
37 | { |
---|
38 | mpData = static_cast<unsigned char*>(AlignedMemory::allocate(mSizeInBytes)); |
---|
39 | } |
---|
40 | //----------------------------------------------------------------------- |
---|
41 | GLDefaultHardwareVertexBuffer::~GLDefaultHardwareVertexBuffer() |
---|
42 | { |
---|
43 | AlignedMemory::deallocate(mpData); |
---|
44 | } |
---|
45 | //----------------------------------------------------------------------- |
---|
46 | void* GLDefaultHardwareVertexBuffer::lockImpl(size_t offset, size_t length, LockOptions options) |
---|
47 | { |
---|
48 | // Only for use internally, no 'locking' as such |
---|
49 | return mpData + offset; |
---|
50 | } |
---|
51 | //----------------------------------------------------------------------- |
---|
52 | void GLDefaultHardwareVertexBuffer::unlockImpl(void) |
---|
53 | { |
---|
54 | // Nothing to do |
---|
55 | } |
---|
56 | //----------------------------------------------------------------------- |
---|
57 | void* GLDefaultHardwareVertexBuffer::lock(size_t offset, size_t length, LockOptions options) |
---|
58 | { |
---|
59 | mIsLocked = true; |
---|
60 | return mpData + offset; |
---|
61 | } |
---|
62 | //----------------------------------------------------------------------- |
---|
63 | void GLDefaultHardwareVertexBuffer::unlock(void) |
---|
64 | { |
---|
65 | mIsLocked = false; |
---|
66 | // Nothing to do |
---|
67 | } |
---|
68 | //----------------------------------------------------------------------- |
---|
69 | void GLDefaultHardwareVertexBuffer::readData(size_t offset, size_t length, void* pDest) |
---|
70 | { |
---|
71 | assert((offset + length) <= mSizeInBytes); |
---|
72 | memcpy(pDest, mpData + offset, length); |
---|
73 | } |
---|
74 | //----------------------------------------------------------------------- |
---|
75 | void GLDefaultHardwareVertexBuffer::writeData(size_t offset, size_t length, const void* pSource, |
---|
76 | bool discardWholeBuffer) |
---|
77 | { |
---|
78 | assert((offset + length) <= mSizeInBytes); |
---|
79 | // ignore discard, memory is not guaranteed to be zeroised |
---|
80 | memcpy(mpData + offset, pSource, length); |
---|
81 | |
---|
82 | } |
---|
83 | //----------------------------------------------------------------------- |
---|
84 | |
---|
85 | GLDefaultHardwareIndexBuffer::GLDefaultHardwareIndexBuffer(IndexType idxType, |
---|
86 | size_t numIndexes, HardwareBuffer::Usage usage) |
---|
87 | : HardwareIndexBuffer(idxType, numIndexes, usage, true, false) // always software, never shadowed |
---|
88 | { |
---|
89 | mpData = new unsigned char[mSizeInBytes]; |
---|
90 | } |
---|
91 | //----------------------------------------------------------------------- |
---|
92 | GLDefaultHardwareIndexBuffer::~GLDefaultHardwareIndexBuffer() |
---|
93 | { |
---|
94 | delete [] mpData; |
---|
95 | } |
---|
96 | //----------------------------------------------------------------------- |
---|
97 | void* GLDefaultHardwareIndexBuffer::lockImpl(size_t offset, size_t length, LockOptions options) |
---|
98 | { |
---|
99 | // Only for use internally, no 'locking' as such |
---|
100 | return mpData + offset; |
---|
101 | } |
---|
102 | //----------------------------------------------------------------------- |
---|
103 | void GLDefaultHardwareIndexBuffer::unlockImpl(void) |
---|
104 | { |
---|
105 | // Nothing to do |
---|
106 | } |
---|
107 | //----------------------------------------------------------------------- |
---|
108 | void* GLDefaultHardwareIndexBuffer::lock(size_t offset, size_t length, LockOptions options) |
---|
109 | { |
---|
110 | mIsLocked = true; |
---|
111 | return mpData + offset; |
---|
112 | } |
---|
113 | //----------------------------------------------------------------------- |
---|
114 | void GLDefaultHardwareIndexBuffer::unlock(void) |
---|
115 | { |
---|
116 | mIsLocked = false; |
---|
117 | // Nothing to do |
---|
118 | } |
---|
119 | //----------------------------------------------------------------------- |
---|
120 | void GLDefaultHardwareIndexBuffer::readData(size_t offset, size_t length, void* pDest) |
---|
121 | { |
---|
122 | assert((offset + length) <= mSizeInBytes); |
---|
123 | memcpy(pDest, mpData + offset, length); |
---|
124 | } |
---|
125 | //----------------------------------------------------------------------- |
---|
126 | void GLDefaultHardwareIndexBuffer::writeData(size_t offset, size_t length, const void* pSource, |
---|
127 | bool discardWholeBuffer) |
---|
128 | { |
---|
129 | assert((offset + length) <= mSizeInBytes); |
---|
130 | // ignore discard, memory is not guaranteed to be zeroised |
---|
131 | memcpy(mpData + offset, pSource, length); |
---|
132 | |
---|
133 | } |
---|
134 | //----------------------------------------------------------------------- |
---|
135 | |
---|
136 | |
---|
137 | //----------------------------------------------------------------------- |
---|
138 | GLDefaultHardwareBufferManager::GLDefaultHardwareBufferManager() |
---|
139 | { |
---|
140 | } |
---|
141 | //----------------------------------------------------------------------- |
---|
142 | GLDefaultHardwareBufferManager::~GLDefaultHardwareBufferManager() |
---|
143 | { |
---|
144 | destroyAllDeclarations(); |
---|
145 | destroyAllBindings(); |
---|
146 | } |
---|
147 | //----------------------------------------------------------------------- |
---|
148 | HardwareVertexBufferSharedPtr |
---|
149 | GLDefaultHardwareBufferManager::createVertexBuffer(size_t vertexSize, |
---|
150 | size_t numVerts, HardwareBuffer::Usage usage, bool useShadowBuffer) |
---|
151 | { |
---|
152 | return HardwareVertexBufferSharedPtr( |
---|
153 | new GLDefaultHardwareVertexBuffer(vertexSize, numVerts, usage)); |
---|
154 | } |
---|
155 | //----------------------------------------------------------------------- |
---|
156 | HardwareIndexBufferSharedPtr |
---|
157 | GLDefaultHardwareBufferManager::createIndexBuffer(HardwareIndexBuffer::IndexType itype, |
---|
158 | size_t numIndexes, HardwareBuffer::Usage usage, bool useShadowBuffer) |
---|
159 | { |
---|
160 | return HardwareIndexBufferSharedPtr( |
---|
161 | new GLDefaultHardwareIndexBuffer(itype, numIndexes, usage) ); |
---|
162 | } |
---|
163 | } |
---|