Coverage Report

Created: 2025-12-14 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgrePose.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 "OgrePose.h"
30
31
namespace Ogre {
32
    //---------------------------------------------------------------------
33
    Pose::Pose(ushort target, const String& name)
34
0
        : mTarget(target), mName(name)
35
0
    {
36
0
    }
37
    //---------------------------------------------------------------------
38
    void Pose::addVertex(uint32 index, const Vector3f& offset)
39
0
    {
40
0
        OgreAssert(mNormalsMap.empty(),
41
0
                   "Inconsistent calls to addVertex, must include normals always or never");
42
43
0
        if(offset.squaredLength() < 1e-6f)
44
0
        {
45
0
            return;
46
0
        }
47
48
0
        mVertexOffsetMap[index] = offset;
49
0
        mBuffer.reset();
50
0
    }
51
    //---------------------------------------------------------------------
52
    void Pose::addVertex(uint32 index, const Vector3f& offset, const Vector3f& normal)
53
0
    {
54
0
        OgreAssert(mVertexOffsetMap.empty() || !mNormalsMap.empty(),
55
0
                   "Inconsistent calls to addVertex, must include normals always or never");
56
57
0
        if(offset.squaredLength() < 1e-6f && normal.squaredLength() < 1e-6f)
58
0
        {
59
0
            return;
60
0
        }
61
62
0
        mVertexOffsetMap[index] = offset;
63
0
        mNormalsMap[index] = normal;
64
0
        mBuffer.reset();
65
0
    }
66
    //---------------------------------------------------------------------
67
    void Pose::removeVertex(uint32 index)
68
0
    {
69
0
        VertexOffsetMap::iterator i = mVertexOffsetMap.find(index);
70
0
        if (i != mVertexOffsetMap.end())
71
0
        {
72
0
            mVertexOffsetMap.erase(i);
73
0
            mBuffer.reset();
74
0
        }
75
0
        NormalsMap::iterator j = mNormalsMap.find(index);
76
0
        if (j != mNormalsMap.end())
77
0
        {
78
0
            mNormalsMap.erase(j);
79
0
        }
80
0
    }
81
    //---------------------------------------------------------------------
82
    void Pose::clearVertices(void)
83
0
    {
84
0
        mVertexOffsetMap.clear();
85
0
        mNormalsMap.clear();
86
0
        mBuffer.reset();
87
0
    }
88
    //---------------------------------------------------------------------
89
    Pose::ConstVertexOffsetIterator 
90
        Pose::getVertexOffsetIterator(void) const
91
0
    {
92
0
        return ConstVertexOffsetIterator(mVertexOffsetMap.begin(), mVertexOffsetMap.end());
93
0
    }
94
    //---------------------------------------------------------------------
95
    Pose::VertexOffsetIterator 
96
        Pose::getVertexOffsetIterator(void)
97
0
    {
98
0
        return VertexOffsetIterator(mVertexOffsetMap.begin(), mVertexOffsetMap.end());
99
0
    }
100
    //---------------------------------------------------------------------
101
    Pose::ConstNormalsIterator Pose::getNormalsIterator(void) const
102
0
    {
103
0
        return ConstNormalsIterator(mNormalsMap.begin(), mNormalsMap.end());
104
0
    }
105
    //---------------------------------------------------------------------
106
    Pose::NormalsIterator Pose::getNormalsIterator(void)
107
0
    {
108
0
        return NormalsIterator(mNormalsMap.begin(), mNormalsMap.end());
109
0
    }
110
    //---------------------------------------------------------------------
111
    const HardwareVertexBufferSharedPtr& Pose::_getHardwareVertexBuffer(const VertexData* origData) const
112
0
    {
113
0
        size_t numVertices = origData->vertexCount;
114
        
115
0
        if (!mBuffer)
116
0
        {
117
            // Create buffer
118
0
            size_t vertexSize = VertexElement::getTypeSize(VET_FLOAT3);
119
0
            bool normals = getIncludesNormals();
120
0
            if (normals)
121
0
                vertexSize += VertexElement::getTypeSize(VET_FLOAT3);
122
                
123
0
            mBuffer = HardwareBufferManager::getSingleton().createVertexBuffer(
124
0
                vertexSize, numVertices, HardwareBuffer::HBU_STATIC_WRITE_ONLY);
125
126
0
            HardwareBufferLockGuard bufLock(mBuffer, HardwareBuffer::HBL_DISCARD);
127
0
            float* pFloat = static_cast<float*>(bufLock.pData);
128
            // initialise - these will be the values used where no pose vertex is included
129
0
            memset(pFloat, 0, mBuffer->getSizeInBytes()); 
130
0
            if (normals)
131
0
            {
132
                // zeroes are fine for positions (deltas), but for normals we need the original
133
                // mesh normals, since delta normals don't work (re-normalisation would
134
                // always result in a blended normal even with full pose applied)
135
0
                const VertexElement* origNormElem = 
136
0
                    origData->vertexDeclaration->findElementBySemantic(VES_NORMAL, 0);
137
0
                assert(origNormElem);
138
                
139
0
                const HardwareVertexBufferSharedPtr& origBuffer = 
140
0
                    origData->vertexBufferBinding->getBuffer(origNormElem->getSource());
141
0
                HardwareBufferLockGuard origBufLock(origBuffer, HardwareBuffer::HBL_READ_ONLY);
142
0
                float* pDst = pFloat + 3;
143
0
                float* pSrc;
144
0
                origNormElem->baseVertexPointerToElement(origBufLock.pData, &pSrc);
145
0
                for (size_t v = 0; v < numVertices; ++v)
146
0
                {
147
0
                    memcpy(pDst, pSrc, sizeof(float)*3);
148
                    
149
0
                    pDst += 6;
150
0
                    pSrc = (float*)(((char*)pSrc) + origBuffer->getVertexSize());
151
0
                }
152
0
            }
153
            // Set each vertex
154
0
            VertexOffsetMap::const_iterator v = mVertexOffsetMap.begin();
155
0
            NormalsMap::const_iterator n = mNormalsMap.begin();
156
            
157
0
            size_t numFloatsPerVertex = normals ? 6: 3;
158
            
159
0
            while(v != mVertexOffsetMap.end())
160
0
            {
161
                // Remember, vertex maps are *sparse* so may have missing entries
162
                // This is why we skip
163
0
                float* pDst = pFloat + (numFloatsPerVertex * v->first);
164
0
                *pDst++ = v->second[0];
165
0
                *pDst++ = v->second[1];
166
0
                *pDst++ = v->second[2];
167
0
                ++v;
168
0
                if (normals)
169
0
                {
170
0
                    *pDst++ = n->second[0];
171
0
                    *pDst++ = n->second[1];
172
0
                    *pDst++ = n->second[2];
173
0
                    ++n;
174
0
                }
175
                
176
0
            }
177
0
        }
178
0
        return mBuffer;
179
0
    }
180
    //---------------------------------------------------------------------
181
    Pose* Pose::clone(void) const
182
0
    {
183
0
        Pose* newPose = OGRE_NEW Pose(mTarget, mName);
184
0
        newPose->mVertexOffsetMap = mVertexOffsetMap;
185
0
        newPose->mNormalsMap = mNormalsMap;
186
        // Allow buffer to recreate itself, contents may change anyway
187
0
        return newPose;
188
0
    }
189
190
}
191