nux-0.9.48

NuxGraphics/GLVertexResourceManager.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef GLVERTEXRESOURCEMANAGER_H
00024 #define GLVERTEXRESOURCEMANAGER_H
00025 
00026 #include "GLResourceManager.h"
00027 #include "IOpenGLVertexBuffer.h"
00028 #include "IOpenGLIndexBuffer.h"
00029 #include "IOpenGLVertexDeclaration.h"
00030 
00031 namespace nux
00032 {
00033 
00034   class NMeshObject;
00035 
00036   class NVertexBuffer: public ResourceData
00037   {
00038     NUX_DECLARE_OBJECT_TYPE (NVertexBuffer, ResourceData);
00039 
00040   public:
00041     NVertexBuffer();
00042     virtual ~NVertexBuffer();
00043     NVertexBuffer (int Size, int Stride);
00045     NVertexBuffer (const NVertexBuffer &);
00047     NVertexBuffer &operator = (const NVertexBuffer &);
00048 
00049     void Allocate (int Size, int Stride);
00050     int GetSize() const;
00051     int GetStride() const;
00052     int GetNumElement() const;
00053     const t_u8 *GetPtrRawData() const;
00054     t_u8 *GetPtrRawData();
00055 
00056   public:
00057     std::vector<t_u8> _Data;
00058     int _Stride;
00059   };
00060 
00061   class NIndexBuffer: public ResourceData
00062   {
00063     NUX_DECLARE_OBJECT_TYPE (NIndexBuffer, ResourceData);
00064 
00065     // NIndexBuffer is very similar to NVertexBuffer except that vertex indices
00066     // are not inter-mixed with other vertex data. So the Stride here should be 2 bytes or 4 bytes.
00067   public:
00068     NIndexBuffer();
00069     virtual ~NIndexBuffer();
00070     NIndexBuffer (int Size, int Stride);
00072     NIndexBuffer (const NIndexBuffer &);
00074     NIndexBuffer &operator = (const NIndexBuffer &);
00075 
00076     void Allocate (int Size, int Stride);
00077     int GetSize() const;
00078     int GetStride() const;
00079     int GetNumElement() const;
00080     const t_u8 *GetPtrRawData() const;
00081     t_u8 *GetPtrRawData();
00082 
00083   public:
00084     std::vector<t_u8> _Data;
00085     int _Stride;
00086   };
00087 
00088   class NVertexDeclaration: public ResourceData
00089   {
00090     NUX_DECLARE_OBJECT_TYPE (NVertexDeclaration, ResourceData);
00091 
00092   public:
00093     NVertexDeclaration();
00094     ~NVertexDeclaration();
00095     void AddVertexComponent (VERTEXELEMENT);
00096     std::vector<VERTEXELEMENT> m_Declaration;
00097   };
00098 
00099   class NGLVertexBuffer: public CachedResourceData
00100   {
00101     NUX_DECLARE_OBJECT_TYPE (NGLVertexBuffer, CachedResourceData);
00102 
00103   public:
00104     NGLVertexBuffer (NResourceSet *ResourceManager, NVertexBuffer *VertexData);
00105     ~NGLVertexBuffer ();
00106 
00107     ObjectPtr<IOpenGLVertexBuffer>      m_VtxBuffer;
00108 
00109     bool UpdateResource (ResourceData *Resource);
00110   private:
00111     void LoadVertexData (NVertexBuffer *VertexData);
00112     int _Size;
00113     int _Stride;
00114   };
00115 
00116   class NGLIndexBuffer: public CachedResourceData
00117   {
00118     NUX_DECLARE_OBJECT_TYPE (NGLIndexBuffer, CachedResourceData);
00119   public:
00120     NGLIndexBuffer (NResourceSet *ResourceManager, NIndexBuffer *Resource);
00121     ~NGLIndexBuffer();
00122 
00123     ObjectPtr<IOpenGLIndexBuffer>       m_IdxBuffer;
00124 
00125     bool UpdateResource (ResourceData *Resource);
00126   private:
00127     void LoadIndexData (NIndexBuffer *VertexData);
00128     int _Size;
00129     int _Stride;
00130   };
00131 
00132   class NGLVertexDeclaration: public CachedResourceData
00133   {
00134     NUX_DECLARE_OBJECT_TYPE (NGLVertexDeclaration, CachedResourceData);
00135   public:
00136     NGLVertexDeclaration (NResourceSet *ResourceManager, NVertexDeclaration *Resource);
00137     ~NGLVertexDeclaration();
00138 
00139     bool UpdateResource (ResourceData *Resource);
00140     ObjectPtr< IOpenGLVertexDeclaration > m_VtxDeclaration;
00141   };
00142 
00143   class NMeshComponent
00144   {
00145   public:
00146     NMeshComponent();
00147     NMeshComponent (const NMeshComponent &);
00148     NMeshComponent (int StreamIndex/*ObjectPtr<NVertexBuffer> VtxBuffer*/, int Offset, ATTRIB_DECL_TYPE Type);
00149 
00150     NMeshComponent &operator = (const NMeshComponent &);
00151 
00152     virtual ~NMeshComponent();
00153 
00154     int GetStreamIndex() const;
00155 //     int GetStride();
00156     int GetOffset();
00157   private:
00158     ATTRIB_DECL_TYPE _Type;
00159     int _StreamIndex;
00160     int _Offset;
00161   };
00162 
00163   class NMesh: public ResourceData
00164   {
00165     NUX_DECLARE_OBJECT_TYPE (NStaticMesh, ResourceData);
00166 
00167     NMesh();
00168     virtual ~NMesh();
00169   };
00170 
00171   class NStaticMesh: public NMesh
00172   {
00173     NUX_DECLARE_OBJECT_TYPE (NStaticMesh, NMesh);
00174   public:
00175     NStaticMesh (NMeshObject *Object);
00176     ~NStaticMesh();
00177 
00178     int GetNumStreams() const;
00179 
00180     std::vector< NVertexBuffer * > m_pVertexStreamArray; // up to 8 stream of buffers on most GPU
00181     NIndexBuffer *m_pIndex;
00182     NVertexDeclaration *m_pVertexDeclaration;
00183   };
00184 
00185   class NGLStaticMesh: public CachedResourceData
00186   {
00187     NUX_DECLARE_OBJECT_TYPE (NGLStaticMesh, CachedResourceData);
00188   public:
00189     NGLStaticMesh (NResourceSet *ResourceManager, NStaticMesh *);
00190     ~NGLStaticMesh ();
00191     bool UpdateResource (ResourceData *Resource);
00192 
00193     std::vector< ObjectPtr<NGLVertexBuffer> > m_VertexBufferArray;
00194     ObjectPtr<NGLIndexBuffer> m_Index;
00195     ObjectPtr<NGLVertexDeclaration> m_VertexDeclaration;
00196   };
00197 
00198 }
00199 
00200 #endif // GLVERTEXRESOURCEMANAGER_H