public VertexBufferObjectMesh( Mesh mesh, UInt32 offset ) { this._offset = offset; this._indicesList = new Queue< UInt32 >(); this.hash = mesh.hash; foreach( UInt32 index in mesh.indices ) { this._indicesList.Enqueue( index + offset ); } }
public VertexBufferObjectMesh AddMesh( Mesh mesh, UInt32 renderableObjectIndex ) { VertexBufferObjectMesh existsMesh = this.MeshExists( mesh ); if( existsMesh != null ) { return existsMesh; } UInt32 offset = ( UInt32 ) this._verticesList.Count; foreach( var vertex in mesh.vertices ) { this._verticesList.Enqueue( vertex ); this._perVerticeData.Enqueue( new Vector4UInt32( renderableObjectIndex, 0, 0, 0 ) ); this._perVerticeData.Enqueue( new Vector4UInt32( renderableObjectIndex, 0, 0, 0 ) ); this._perVerticeData.Enqueue( new Vector4UInt32( renderableObjectIndex, 0, 0, 0 ) ); this._perVerticeData.Enqueue( new Vector4UInt32( renderableObjectIndex, 0, 0, 0 ) ); } foreach( var color in mesh.colors ) { this._colorsList.Enqueue( color ); } foreach( var normal in mesh.normals ) { this._normalsList.Enqueue( normal ); } foreach( var texCoord in mesh.texCoords ) { this._texCoordsList.Enqueue( new Vector4( texCoord.X, texCoord.Y, 0.0f, 0.0f ) ); } VertexBufferObjectMesh newVBOMesh = new VertexBufferObjectMesh( mesh, offset ); this._meshList.Add( newVBOMesh ); GL.BindBuffer( BufferTarget.ElementArrayBuffer, this._ibo ); GL.BufferData( BufferTarget.ElementArrayBuffer, ( IntPtr ) ( sizeof( uint ) * mesh.indices.Count ), newVBOMesh.indicesList.ToArray(), BufferUsageHint.StaticDraw ); GL.BindBuffer( BufferTarget.ArrayBuffer, this.descriptors[ VertexBufferObject.DESCRIPTOR_VERTEX ] ); GL.BufferData( BufferTarget.ArrayBuffer, ( IntPtr ) ( this._verticesList.Count * sizeof( float ) * 3 ), this._verticesList.ToArray(), BufferUsageHint.StaticDraw ); GL.BindBuffer( BufferTarget.ArrayBuffer, this.descriptors[ VertexBufferObject.DESCRIPTOR_COLOR ] ); GL.BufferData( BufferTarget.ArrayBuffer, ( IntPtr ) ( this._colorsList.Count * sizeof( float ) * 4 ), this._colorsList.ToArray(), BufferUsageHint.StaticDraw ); GL.BindBuffer( BufferTarget.ArrayBuffer, this.descriptors[ VertexBufferObject.DESCRIPTOR_INFO ] ); GL.BufferData( BufferTarget.ArrayBuffer, ( IntPtr ) ( this._perVerticeData.Count * sizeof( UInt32 ) * 4 ), this._perVerticeData.ToArray(), BufferUsageHint.StaticDraw ); GL.BindBuffer( BufferTarget.ArrayBuffer, this.descriptors[ VertexBufferObject.DESCRIPTOR_TEXCOORDS ] ); GL.BufferData( BufferTarget.ArrayBuffer, ( IntPtr ) ( this._texCoordsList.Count * sizeof( float ) * 4 ), this._texCoordsList.ToArray(), BufferUsageHint.StaticDraw ); GL.BindBuffer( BufferTarget.ArrayBuffer, this.descriptors[ VertexBufferObject.DESCRIPTOR_NORMALS ] ); GL.BufferData( BufferTarget.ArrayBuffer, ( IntPtr ) ( this._normalsList.Count * sizeof( float ) * 3 ), this._normalsList.ToArray(), BufferUsageHint.StaticDraw ); GL.BindBuffer( BufferTarget.ArrayBuffer, 0 ); return newVBOMesh; }
public VertexBufferObjectMesh MeshExists( Mesh mesh ) { foreach( VertexBufferObjectMesh thisMesh in this._meshList ) { if( thisMesh.hash == mesh.hash ) { return thisMesh; } } return null; }