source: OGRE/trunk/ogrenew/OgreMain/src/OgrePatchMesh.cpp @ 657

Revision 657, 4.4 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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