Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre/OgreMain/src/OgrePatchMesh.cpp @ 48

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

=hoffentlich gehts jetzt

File size: 4.5 KB
Line 
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 "OgrePatchMesh.h"
31#include "OgreSubMesh.h"
32#include "OgreHardwareBufferManager.h"
33
34namespace Ogre {
35
36    //-----------------------------------------------------------------------
37    PatchMesh::PatchMesh(ResourceManager* creator, const String& name, ResourceHandle handle,
38        const String& group)
39        : Mesh(creator, name, handle, group, false, 0)
40    {
41    }
42    //-----------------------------------------------------------------------
43    void PatchMesh::define(void* controlPointBuffer, 
44            VertexDeclaration *declaration, size_t width, size_t height,
45            size_t uMaxSubdivisionLevel, size_t vMaxSubdivisionLevel,
46            PatchSurface::VisibleSide visibleSide, HardwareBuffer::Usage vbUsage, 
47            HardwareBuffer::Usage ibUsage,
48            bool vbUseShadow, bool ibUseShadow) 
49    {
50        mVertexBufferUsage = vbUsage;
51        mVertexBufferShadowBuffer = vbUseShadow;
52        mIndexBufferUsage = ibUsage;
53        mIndexBufferShadowBuffer = ibUseShadow;
54
55        // Init patch builder
56        // define the surface
57        // NB clone the declaration to make it independent
58        mDeclaration = declaration->clone();
59        mSurface.defineSurface(controlPointBuffer, mDeclaration, width, height, 
60            PatchSurface::PST_BEZIER, uMaxSubdivisionLevel, vMaxSubdivisionLevel, 
61            visibleSide);
62
63    }
64    //-----------------------------------------------------------------------
65    void PatchMesh::setSubdivision(Real factor)
66    {
67        mSurface.setSubdivisionFactor(factor);
68        SubMesh* sm = this->getSubMesh(0);
69        sm->indexData->indexCount = mSurface.getCurrentIndexCount();
70       
71    }
72    //-----------------------------------------------------------------------
73    void PatchMesh::loadImpl(void)
74    {
75        SubMesh* sm = this->createSubMesh();
76        sm->vertexData = new VertexData();
77        sm->useSharedVertices = false;
78
79        // Set up vertex buffer
80        sm->vertexData->vertexStart = 0;
81        sm->vertexData->vertexCount = mSurface.getRequiredVertexCount();
82        sm->vertexData->vertexDeclaration = mDeclaration;
83        HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().
84            createVertexBuffer(
85                mDeclaration->getVertexSize(0), 
86                sm->vertexData->vertexCount, 
87                mVertexBufferUsage, 
88                mVertexBufferShadowBuffer);
89        sm->vertexData->vertexBufferBinding->setBinding(0, vbuf);
90
91        // Set up index buffer
92        sm->indexData->indexStart = 0;
93        sm->indexData->indexCount = mSurface.getRequiredIndexCount();
94        sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().
95            createIndexBuffer(
96                HardwareIndexBuffer::IT_16BIT, // only 16-bit indexes supported, patches shouldn't be bigger than that
97                sm->indexData->indexCount,
98                mIndexBufferUsage, 
99                mIndexBufferShadowBuffer);
100       
101        // Build patch
102        mSurface.build(vbuf, 0, sm->indexData->indexBuffer, 0);
103
104        // Set bounds
105        this->_setBounds(mSurface.getBounds(), true);
106        this->_setBoundingSphereRadius(mSurface.getBoundingSphereRadius());
107
108    }
109
110}
111
Note: See TracBrowser for help on using the repository browser.