Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgreDefaultHardwareBufferManager.cpp @ 10

Last change on this file since 10 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

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