Patch 2793067: fix trunk with OGRE_THREAD_SUPPORT=1 on non-Windows platforms (don...
[ogre3d.git] / OgreMain / src / OgrePose.cpp
blob34e1aee988e7e1082ae6634371b74102ef195338
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/
7 Copyright (c) 2000-2005 The OGRE Team
8 Also see acknowledgements in Readme.html
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.
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.
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.
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 -----------------------------------------------------------------------------
29 #include "OgreStableHeaders.h"
30 #include "OgrePose.h"
31 #include "OgreHardwareBufferManager.h"
33 namespace Ogre {
34 //---------------------------------------------------------------------
35 Pose::Pose(ushort target, const String& name)
36 : mTarget(target), mName(name)
39 //---------------------------------------------------------------------
40 Pose::~Pose()
43 //---------------------------------------------------------------------
44 void Pose::addVertex(size_t index, const Vector3& offset)
46 mVertexOffsetMap[index] = offset;
47 mBuffer.setNull();
49 //---------------------------------------------------------------------
50 void Pose::removeVertex(size_t index)
52 VertexOffsetMap::iterator i = mVertexOffsetMap.find(index);
53 if (i != mVertexOffsetMap.end())
55 mVertexOffsetMap.erase(i);
56 mBuffer.setNull();
59 //---------------------------------------------------------------------
60 void Pose::clearVertexOffsets(void)
62 mVertexOffsetMap.clear();
63 mBuffer.setNull();
65 //---------------------------------------------------------------------
66 Pose::ConstVertexOffsetIterator
67 Pose::getVertexOffsetIterator(void) const
69 return ConstVertexOffsetIterator(mVertexOffsetMap.begin(), mVertexOffsetMap.end());
71 //---------------------------------------------------------------------
72 Pose::VertexOffsetIterator
73 Pose::getVertexOffsetIterator(void)
75 return VertexOffsetIterator(mVertexOffsetMap.begin(), mVertexOffsetMap.end());
77 //---------------------------------------------------------------------
78 const HardwareVertexBufferSharedPtr& Pose::_getHardwareVertexBuffer(size_t numVertices) const
80 if (mBuffer.isNull())
82 // Create buffer
83 mBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
84 VertexElement::getTypeSize(VET_FLOAT3),
85 numVertices, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
87 float* pFloat = static_cast<float*>(
88 mBuffer->lock(HardwareBuffer::HBL_DISCARD));
89 // initialise
90 memset(pFloat, 0, mBuffer->getSizeInBytes());
91 // Set each vertex
92 for (VertexOffsetMap::const_iterator i = mVertexOffsetMap.begin();
93 i != mVertexOffsetMap.end(); ++i)
95 float* pDst = pFloat + (3 * i->first);
96 *pDst++ = i->second.x;
97 *pDst++ = i->second.y;
98 *pDst++ = i->second.z;
100 mBuffer->unlock();
102 return mBuffer;
104 //---------------------------------------------------------------------
105 Pose* Pose::clone(void) const
107 Pose* newPose = OGRE_NEW Pose(mTarget, mName);
108 newPose->mVertexOffsetMap = mVertexOffsetMap;
109 // Allow buffer to recreate itself, contents may change anyway
110 return newPose;