MercuryMesh.h

Go to the documentation of this file.
00001 #ifndef MERCURYMESH_H
00002 #define MERCURYMESH_H
00003 
00004 #include "MercuryObject.h"
00005 #include "MercuryVertex.h"
00006 
00007 class MercuryDisplay;
00008 class MercuryMeshManager;
00009 
00010 struct MercuryMeshCore
00011 {
00012     MercuryMeshCore();
00013     void CalculateVertexNormals();
00014     void ComputeBinormalsAndTangents();
00015     MVector< MercuryVertex > m_vertices;
00016     MVector< MercuryPoint > m_tangents;
00017     MVector< MercuryPoint > m_binormals;
00018     MVector< unsigned int > m_indices;
00019     unsigned char *         m_extras;
00020 
00021     MVPtr m_verticesVBO;
00022     MVPtr m_tangentVBO;
00023     MVPtr m_binormalVBO;
00024     MVPtr m_indicesVBO;
00025     MVPtr m_extrasVBO;
00026 
00027     bool m_useVBOs, m_VBOinited;
00028 
00029     bool m_bIsAnimated;
00030     DRAWTYPES m_drawType;
00031 
00032     int m_iMeshCount;
00033 };
00034 
00036 class MercuryMesh : public MercuryObject
00037 {
00038     friend class MercuryDisplay;
00039     friend class MercuryMeshManager;
00040 public:
00041     MercuryMesh();
00042     virtual ~MercuryMesh();
00043     virtual void Init();
00044 
00045     void CalculateVertexNormals() { core->CalculateVertexNormals(); }
00046 
00047     virtual void Draw();
00048 
00049     inline void SetNumVertices(unsigned int size) { core->m_vertices.resize(size); }
00050     inline MercuryVertex* GetVerticePtr() { return &core->m_vertices[0]; }
00051     inline const MercuryVertex* GetVerticePtr() const { return &core->m_vertices[0]; }
00052     inline unsigned int NumVertices() const { return core->m_vertices.size(); }
00053     inline void SetDrawType(DRAWTYPES type) { core->m_drawType = type; }
00054     inline DRAWTYPES GetDrawType() const { return core->m_drawType; }
00055 
00056     inline MercuryVertex* GetVertex(unsigned int x) { return &core->m_vertices[x]; }
00057     inline unsigned int* GetIndicesPtr() { return &core->m_indices[0]; }
00058     inline const unsigned int* GetIndicesPtr() const { return &core->m_indices[0]; }
00059     inline void SetNumIndices(unsigned int size) { core->m_indices.resize(size); }
00060     inline unsigned int NumIndices() const { return core->m_indices.size(); }
00061     inline void SetIndice(unsigned int position, unsigned int value) { core->m_indices[position] = value; }
00062 
00063     inline bool HasTangents() const { return core->m_tangents.size() > 0; }
00064     inline const MercuryPoint* GetTangentsPtr() const { return &core->m_tangents[0]; }
00065     inline bool HasBinormals() const { return core->m_binormals.size() > 0; }
00066     inline const MercuryPoint* GetBinormalsPtr() const { return &core->m_binormals[0]; }
00067     inline unsigned int NumTangents() const { return core->m_tangents.size(); }
00068     inline unsigned int NumBinormals() const { return core->m_binormals.size(); }
00069 
00070     inline MercuryVertex& operator[](unsigned int x) { return core->m_vertices[x]; }
00071     inline const MercuryVertex& operator[](unsigned int x) const { return core->m_vertices[x]; }
00072 
00073     inline void SetIsAnimated( bool bOn ) { core->m_bIsAnimated = bOn; }
00074     inline void ToggleUseVBOs( bool toggle) { core->m_useVBOs = toggle; }
00075     inline bool IsUseVBOs() const { return core->m_useVBOs; }
00076     inline bool IsVBOsInited() const { return core->m_VBOinited; }
00077     inline bool IsAnimated() { return core->m_bIsAnimated; }
00078     CLASS_RTTI( MercuryMesh, MercuryObject );
00079 
00080     void ComputeBinormalsAndTangents() { core->CalculateVertexNormals(); }
00081 
00082     inline void SetVerticesVBO(MVPtr vbo) { core->m_verticesVBO = vbo; }
00083     inline void SetTangentVBO(MVPtr vbo) { core->m_tangentVBO = vbo; }
00084     inline void SetBinormalVBO(MVPtr vbo) { core->m_binormalVBO = vbo; }
00085     inline void SetIndicesVBO(MVPtr vbo) { core->m_indicesVBO = vbo; }
00086 
00087     inline const MVPtr GetVerticesVBO() const { return core->m_verticesVBO; }
00088     inline const MVPtr GetTangentVBO() const { return core->m_tangentVBO; }
00089     inline const MVPtr GetBinormalVBO() const { return core->m_binormalVBO; }
00090     inline const MVPtr GetIndicesVBO() const { return core->m_indicesVBO; }
00091     MercuryMeshCore * GetCore() const{ return core; }
00092 
00093     void BuildVBO();
00094 private:
00095 
00096     MercuryMeshCore * core;
00097 };
00098 
00100 class MercuryMeshManager
00101 {
00102 public:
00104     bool RegMesh( MercuryMesh * pOut, const MString & sName, bool bCanCache );
00105 
00107     void UnregMesh( MercuryMesh * pIn );
00108 private:
00109     MHash< MercuryMeshCore * >  m_hAllMeshes;
00110 };
00111 
00112 extern MercuryMeshManager MESHMAN;
00113 
00114 #endif
00115 
00116 /* 
00117  * Copyright (c) 2006 Joshua Allen
00118  * All rights reserved.
00119  *
00120  * Redistribution and use in source and binary forms, with or
00121  * without modification, are permitted provided that the following
00122  * conditions are met:
00123  *  -   Redistributions of source code must retain the above
00124  *      copyright notice, this list of conditions and the following disclaimer.
00125  *  -   Redistributions in binary form must reproduce the above copyright
00126  *      notice, this list of conditions and the following disclaimer in
00127  *      the documentation and/or other materials provided with the distribution.
00128  *  -   Neither the name of the Mercury Engine nor the names of its
00129  *      contributors may be used to endorse or promote products derived from
00130  *      this software without specific prior written permission.
00131  *
00132  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00133  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00134  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00135  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00136  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00137  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00138  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00139  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00140  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00141  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00142  */

Hosted by SourceForge.net Logo