Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# OgrePatchMesh.cpp

Go to the documentation of this file.

    00001 /*
    00002 -----------------------------------------------------------------------------
    00003 This source file is part of OGRE
    00004     (Object-oriented Graphics Rendering Engine)
    00005 For the latest info, see http://www.ogre3d.org/
    00006
    00007 Copyright © 2000-2002 The OGRE Team
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023 -----------------------------------------------------------------------------
    00024 */
    00025 #include "OgreStableHeaders.h"
    00026 #include "OgrePatchMesh.h"
    00027 #include "OgreSubMesh.h"
    00028 #include "OgreHardwareBufferManager.h"
    00029
    00030 namespace Ogre {
    00031
    00032     //-----------------------------------------------------------------------
    00033     PatchMesh::PatchMesh(const String& name, void* controlPointBuffer,
    00034             VertexDeclaration *declaration, size_t width, size_t height,
    00035             size_t uMaxSubdivisionLevel, size_t vMaxSubdivisionLevel,
    00036             PatchSurface::VisibleSide visibleSide, HardwareBuffer::Usage vbUsage,
    00037             HardwareBuffer::Usage ibUsage,
    00038             bool vbUseShadow, bool ibUseShadow) : Mesh(name)
    00039     {
    00040         mVertexBufferUsage = vbUsage;
    00041         mVertexBufferShadowBuffer = vbUseShadow;
    00042         mIndexBufferUsage = ibUsage;
    00043         mIndexBufferShadowBuffer = ibUseShadow;
    00044
    00045         // Init patch builder
    00046         // define the surface
    00047         // NB clone the declaration to make it independent
    00048         mDeclaration = declaration->clone();
    00049         mSurface.defineSurface(controlPointBuffer, mDeclaration, width, height,
    00050             PatchSurface::PST_BEZIER, uMaxSubdivisionLevel, vMaxSubdivisionLevel,
    00051             visibleSide);
    00052
    00053
    00054     }
    00055     //-----------------------------------------------------------------------
    00056     void PatchMesh::setSubdivision(Real factor)
    00057     {
    00058         mSurface.setSubdivisionFactor(factor);
    00059         SubMesh* sm = this->getSubMesh(0);
    00060         sm->indexData->indexCount = mSurface.getCurrentIndexCount();
    00061
    00062     }
    00063     //-----------------------------------------------------------------------
    00064     void PatchMesh::load(void)
    00065     {
    00066         SubMesh* sm = this->createSubMesh();
    00067         sm->vertexData = new VertexData();
    00068         sm->useSharedVertices = false;
    00069
    00070         // Set up vertex buffer
    00071         sm->vertexData->vertexStart = 0;
    00072         sm->vertexData->vertexCount = mSurface.getRequiredVertexCount();
    00073         sm->vertexData->vertexDeclaration = mDeclaration;
    00074         HardwareVertexBufferSharedPtr vbuf = HardwareBufferManager::getSingleton().
    00075             createVertexBuffer(
    00076                 mDeclaration->getVertexSize(0),
    00077                 sm->vertexData->vertexCount,
    00078                 mVertexBufferUsage,
    00079                 mVertexBufferShadowBuffer);
    00080         sm->vertexData->vertexBufferBinding->setBinding(0, vbuf);
    00081
    00082         // Set up index buffer
    00083         sm->indexData->indexStart = 0;
    00084         sm->indexData->indexCount = mSurface.getRequiredIndexCount();
    00085         sm->indexData->indexBuffer = HardwareBufferManager::getSingleton().
    00086             createIndexBuffer(
    00087                 HardwareIndexBuffer::IT_16BIT, // only 16-bit indexes supported, patches shouldn't be bigger than that
    00088                 sm->indexData->indexCount,
    00089                 mIndexBufferUsage,
    00090                 mIndexBufferShadowBuffer);
    00091
    00092         // Build patch
    00093         mSurface.build(vbuf, 0, sm->indexData->indexBuffer, 0);
    00094
    00095         // Set bounds
    00096         this->_setBounds(mSurface.getBounds(), true);
    00097         this->_setBoundingSphereRadius(mSurface.getBoundingSphereRadius());
    00098         mIsLoaded = true;
    00099
    00100     }
    00101
    00102 }
    00103

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:38 2004