Coverage Report

Created: 2026-08-29 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgrePatchMesh.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 "OgrePatchMesh.h"
30
31
namespace Ogre {
32
33
    //-----------------------------------------------------------------------
34
    PatchMesh::PatchMesh(ResourceManager* creator, const String& name, ResourceHandle handle,
35
        const String& group)
36
0
        : Mesh(creator, name, handle, group, false, 0), mDeclaration(0)
37
0
    {
38
0
    }
39
    //-----------------------------------------------------------------------
40
    void PatchMesh::define(void* controlPointBuffer, 
41
            VertexDeclaration *declaration, size_t width, size_t height,
42
            size_t uMaxSubdivisionLevel, size_t vMaxSubdivisionLevel,
43
            PatchSurface::VisibleSide visibleSide, HardwareBuffer::Usage vbUsage, 
44
            HardwareBuffer::Usage ibUsage,
45
            bool vbUseShadow, bool ibUseShadow) 
46
0
    {
47
0
        setVertexBufferPolicy(vbUsage, vbUseShadow);
48
0
        setIndexBufferPolicy(ibUsage, ibUseShadow);
49
50
        // Init patch builder
51
        // define the surface
52
        // NB clone the declaration to make it independent
53
0
        mDeclaration = declaration->clone();
54
0
        mSurface.defineSurface(controlPointBuffer, mDeclaration, width, height, 
55
0
            PatchSurface::PST_BEZIER, uMaxSubdivisionLevel, vMaxSubdivisionLevel, 
56
0
            visibleSide);
57
58
0
    }
59
    //-----------------------------------------------------------------------
60
    void PatchMesh::update(void* controlPointBuffer, size_t width, size_t height,
61
                           size_t uMaxSubdivisionLevel, size_t vMaxSubdivisionLevel,
62
                           PatchSurface::VisibleSide visibleSide)
63
0
    {
64
0
        mSurface.defineSurface(controlPointBuffer, mDeclaration, width, height, PatchSurface::PST_BEZIER, uMaxSubdivisionLevel, vMaxSubdivisionLevel, visibleSide);
65
0
        Ogre::SubMesh* sm = this->getSubMesh(0);
66
0
        Ogre::VertexData* vertex_data = sm->useSharedVertices ? this->sharedVertexData : sm->vertexData;
67
0
        const Ogre::VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
68
0
        Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
69
70
        // Build patch with new control points
71
0
        mSurface.build(vbuf, 0, sm->indexData->indexBuffer, 0);
72
0
    }
73
    //-----------------------------------------------------------------------
74
    void PatchMesh::setSubdivision(Real factor)
75
0
    {
76
0
        mSurface.setSubdivisionFactor(factor);
77
0
        SubMesh* sm = this->getSubMesh(0);
78
0
        sm->indexData->indexCount = mSurface.getCurrentIndexCount();
79
        
80
0
    }
81
    //-----------------------------------------------------------------------
82
    void PatchMesh::loadImpl(void)
83
0
    {
84
0
        SubMesh* sm = this->createSubMesh();
85
0
        sm->createVertexData();
86
87
        // Set up vertex buffer
88
0
        sm->vertexData->vertexStart = 0;
89
0
        sm->vertexData->vertexCount = mSurface.getRequiredVertexCount();
90
0
        sm->vertexData->vertexDeclaration = mDeclaration;
91
0
        HardwareVertexBufferSharedPtr vbuf = getHardwareBufferManager()->
92
0
            createVertexBuffer(
93
0
                mDeclaration->getVertexSize(0), 
94
0
                sm->vertexData->vertexCount, 
95
0
                getVertexBufferUsage(),
96
0
                isVertexBufferShadowed());
97
0
        sm->vertexData->vertexBufferBinding->setBinding(0, vbuf);
98
99
        // Set up index buffer
100
0
        sm->indexData->indexStart = 0;
101
0
        sm->indexData->indexCount = mSurface.getRequiredIndexCount();
102
0
        sm->indexData->indexBuffer = getHardwareBufferManager()->
103
0
            createIndexBuffer(
104
0
                HardwareIndexBuffer::IT_16BIT, // only 16-bit indexes supported, patches shouldn't be bigger than that
105
0
                sm->indexData->indexCount,
106
0
                getIndexBufferUsage(),
107
0
                isIndexBufferShadowed());
108
        
109
        // Build patch
110
0
        mSurface.build(vbuf, 0, sm->indexData->indexBuffer, 0);
111
112
        // Set bounds
113
0
        this->_setBounds(mSurface.getBounds(), true);
114
0
        this->_setBoundingSphereRadius(mSurface.getBoundingSphereRadius());
115
116
0
    }
117
118
}
119