Loading...
Searching...
No Matches
CMeshBuffer.h
Go to the documentation of this file.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __T_MESH_BUFFER_H_INCLUDED__
#define __T_MESH_BUFFER_H_INCLUDED__
#include "irrArray.h"
#include "IMeshBuffer.h"
namespace irr
{
namespace scene
{
template <class T>
class CMeshBuffer : public IMeshBuffer
{
public:
CMeshBuffer():ChangedID_Vertex(1),ChangedID_Index(1),MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER)
{
#ifdef _DEBUG
setDebugName("SMeshBuffer");
#endif
}
virtual const video::SMaterial& getMaterial() const
{
return Material;
}
virtual video::SMaterial& getMaterial()
{
return Material;
}
virtual const void* getVertices() const
{
return Vertices.const_pointer();
}
virtual void* getVertices()
{
return Vertices.pointer();
}
virtual u32 getVertexCount() const
{
return Vertices.size();
}
virtual video::E_INDEX_TYPE getIndexType() const
{
return video::EIT_16BIT;
}
virtual const u16* getIndices() const
{
return Indices.const_pointer();
}
virtual u16* getIndices()
{
return Indices.pointer();
}
virtual u32 getIndexCount() const
{
return Indices.size();
}
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return BoundingBox;
}
virtual void setBoundingBox(const core::aabbox3df& box)
{
BoundingBox = box;
}
virtual void recalculateBoundingBox()
{
if (Vertices.empty())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(Vertices[0].Pos);
for (u32 i=1; i<Vertices.size(); ++i)
BoundingBox.addInternalPoint(Vertices[i].Pos);
}
}
virtual video::E_VERTEX_TYPE getVertexType() const
{
return T().getType();
}
virtual const core::vector3df& getPosition(u32 i) const
{
return Vertices[i].Pos;
}
virtual core::vector3df& getPosition(u32 i)
{
return Vertices[i].Pos;
}
virtual const core::vector3df& getNormal(u32 i) const
{
return Vertices[i].Normal;
}
virtual core::vector3df& getNormal(u32 i)
{
return Vertices[i].Normal;
}
virtual const core::vector2df& getTCoords(u32 i) const
{
return Vertices[i].TCoords;
}
virtual core::vector2df& getTCoords(u32 i)
{
return Vertices[i].TCoords;
}
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices)
{
if (vertices == getVertices())
return;
const u32 vertexCount = getVertexCount();
u32 i;
Vertices.reallocate(vertexCount+numVertices);
for (i=0; i<numVertices; ++i)
{
Vertices.push_back(reinterpret_cast<const T*>(vertices)[i]);
BoundingBox.addInternalPoint(reinterpret_cast<const T*>(vertices)[i].Pos);
}
Indices.reallocate(getIndexCount()+numIndices);
for (i=0; i<numIndices; ++i)
{
Indices.push_back(indices[i]+vertexCount);
}
}
virtual void append(const IMeshBuffer* const other)
{
/*
if (this==other)
return;
const u32 vertexCount = getVertexCount();
u32 i;
Vertices.reallocate(vertexCount+other->getVertexCount());
for (i=0; i<other->getVertexCount(); ++i)
{
Vertices.push_back(reinterpret_cast<const T*>(other->getVertices())[i]);
}
Indices.reallocate(getIndexCount()+other->getIndexCount());
for (i=0; i<other->getIndexCount(); ++i)
{
Indices.push_back(other->getIndices()[i]+vertexCount);
}
BoundingBox.addInternalBox(other->getBoundingBox());
*/
}
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
{
return MappingHint_Vertex;
}
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
{
return MappingHint_Index;
}
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX )
{
if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)
MappingHint_Vertex=NewMappingHint;
if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
MappingHint_Index=NewMappingHint;
}
virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX)
{
if (Buffer==EBT_VERTEX_AND_INDEX ||Buffer==EBT_VERTEX)
++ChangedID_Vertex;
if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)
++ChangedID_Index;
}
virtual u32 getChangedID_Vertex() const {return ChangedID_Vertex;}
virtual u32 getChangedID_Index() const {return ChangedID_Index;}
u32 ChangedID_Vertex;
u32 ChangedID_Index;
E_HARDWARE_MAPPING MappingHint_Vertex;
E_HARDWARE_MAPPING MappingHint_Index;
video::SMaterial Material;
core::array<T> Vertices;
core::array<u16> Indices;
core::aabbox3d<f32> BoundingBox;
};
typedef CMeshBuffer<video::S3DVertex> SMeshBuffer;
typedef CMeshBuffer<video::S3DVertex2TCoords> SMeshBufferLightMap;
typedef CMeshBuffer<video::S3DVertexTangents> SMeshBufferTangents;
} // end namespace scene
} // end namespace irr
#endif
IMeshBuffer.h
irr::IReferenceCounted::setDebugName
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition IReferenceCounted.h:153
irr::core::aabbox3d
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
irr::core::array
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.h:23
irr::scene::CMeshBuffer
Template implementation of the IMeshBuffer interface.
Definition CMeshBuffer.h:18
irr::scene::CMeshBuffer< video::S3DVertex >::MappingHint_Index
E_HARDWARE_MAPPING MappingHint_Index
Definition CMeshBuffer.h:278
irr::scene::CMeshBuffer::getBoundingBox
virtual const core::aabbox3d< f32 > & getBoundingBox() const
Get the axis aligned bounding box.
Definition CMeshBuffer.h:101
irr::scene::CMeshBuffer::getVertices
virtual void * getVertices()
Get pointer to vertices.
Definition CMeshBuffer.h:55
irr::scene::CMeshBuffer< video::S3DVertex >::Material
video::SMaterial Material
Definition CMeshBuffer.h:281
irr::scene::CMeshBuffer::getVertices
virtual const void * getVertices() const
Get pointer to vertices.
Definition CMeshBuffer.h:47
irr::scene::CMeshBuffer< video::S3DVertex >::ChangedID_Vertex
u32 ChangedID_Vertex
Definition CMeshBuffer.h:273
irr::scene::CMeshBuffer< video::S3DVertex >::Indices
core::array< u16 > Indices
Definition CMeshBuffer.h:285
irr::scene::CMeshBuffer::getVertexType
virtual video::E_VERTEX_TYPE getVertexType() const
Get type of vertex data stored in this buffer.
Definition CMeshBuffer.h:133
irr::scene::CMeshBuffer::getHardwareMappingHint_Index
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
get the current hardware mapping hint
Definition CMeshBuffer.h:241
irr::scene::CMeshBuffer< video::S3DVertex >::ChangedID_Index
u32 ChangedID_Index
Definition CMeshBuffer.h:274
irr::scene::CMeshBuffer::getPosition
virtual const core::vector3df & getPosition(u32 i) const
returns position of vertex i
Definition CMeshBuffer.h:139
irr::scene::CMeshBuffer::getNormal
virtual const core::vector3df & getNormal(u32 i) const
returns normal of vertex i
Definition CMeshBuffer.h:151
irr::scene::CMeshBuffer::getVertexCount
virtual u32 getVertexCount() const
Get number of vertices.
Definition CMeshBuffer.h:63
irr::scene::CMeshBuffer::getIndices
virtual const u16 * getIndices() const
Get pointer to indices.
Definition CMeshBuffer.h:77
irr::scene::CMeshBuffer::setDirty
virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX)
flags the mesh as changed, reloads hardware buffers
Definition CMeshBuffer.h:257
irr::scene::CMeshBuffer::getTCoords
virtual core::vector2df & getTCoords(u32 i)
returns texture coord of vertex i
Definition CMeshBuffer.h:169
irr::scene::CMeshBuffer< video::S3DVertex >::Vertices
core::array< video::S3DVertex > Vertices
Definition CMeshBuffer.h:283
irr::scene::CMeshBuffer::append
virtual void append(const void *const vertices, u32 numVertices, const u16 *const indices, u32 numIndices)
Append the vertices and indices to the current buffer.
Definition CMeshBuffer.h:180
irr::scene::CMeshBuffer::getMaterial
virtual video::SMaterial & getMaterial()
Get material of this meshbuffer.
Definition CMeshBuffer.h:39
irr::scene::CMeshBuffer::getChangedID_Vertex
virtual u32 getChangedID_Vertex() const
Get the currently used ID for identification of changes.
Definition CMeshBuffer.h:267
irr::scene::CMeshBuffer< video::S3DVertex >::BoundingBox
core::aabbox3d< f32 > BoundingBox
Definition CMeshBuffer.h:287
irr::scene::CMeshBuffer::getIndexType
virtual video::E_INDEX_TYPE getIndexType() const
Get type of index data which is stored in this meshbuffer.
Definition CMeshBuffer.h:70
irr::scene::CMeshBuffer::CMeshBuffer
CMeshBuffer()
Default constructor for empty meshbuffer.
Definition CMeshBuffer.h:21
irr::scene::CMeshBuffer::setHardwareMappingHint
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX)
set the hardware mapping hint, for driver
Definition CMeshBuffer.h:247
irr::scene::CMeshBuffer::recalculateBoundingBox
virtual void recalculateBoundingBox()
Recalculate the bounding box.
Definition CMeshBuffer.h:118
irr::scene::CMeshBuffer::setBoundingBox
virtual void setBoundingBox(const core::aabbox3df &box)
Set the axis aligned bounding box.
Definition CMeshBuffer.h:110
irr::scene::CMeshBuffer::getIndexCount
virtual u32 getIndexCount() const
Get number of indices.
Definition CMeshBuffer.h:93
irr::scene::CMeshBuffer::getIndices
virtual u16 * getIndices()
Get pointer to indices.
Definition CMeshBuffer.h:85
irr::scene::CMeshBuffer::getTCoords
virtual const core::vector2df & getTCoords(u32 i) const
returns texture coord of vertex i
Definition CMeshBuffer.h:163
irr::scene::CMeshBuffer::getHardwareMappingHint_Vertex
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
get the current hardware mapping hint
Definition CMeshBuffer.h:235
irr::scene::CMeshBuffer::getMaterial
virtual const video::SMaterial & getMaterial() const
Get material of this meshbuffer.
Definition CMeshBuffer.h:31
irr::scene::CMeshBuffer::getChangedID_Index
virtual u32 getChangedID_Index() const
Get the currently used ID for identification of changes.
Definition CMeshBuffer.h:271
irr::scene::CMeshBuffer::getNormal
virtual core::vector3df & getNormal(u32 i)
returns normal of vertex i
Definition CMeshBuffer.h:157
irr::scene::CMeshBuffer::getPosition
virtual core::vector3df & getPosition(u32 i)
returns position of vertex i
Definition CMeshBuffer.h:145
irr::scene::CMeshBuffer::append
virtual void append(const IMeshBuffer *const other)
Append the meshbuffer to the current buffer.
Definition CMeshBuffer.h:209
irr::scene::CMeshBuffer< video::S3DVertex >::MappingHint_Vertex
E_HARDWARE_MAPPING MappingHint_Vertex
Definition CMeshBuffer.h:277
irr::scene::IMeshBuffer
Struct for holding a mesh with a single material.
Definition IMeshBuffer.h:40
irr::video::SMaterial
Struct for holding parameters for a material renderer.
Definition SMaterial.h:227
irrArray.h
irr::core::vector3df
vector3d< f32 > vector3df
Typedef for a f32 3d vector.
Definition vector3d.h:445
irr::core::vector2df
vector2d< f32 > vector2df
Typedef for f32 2d vector.
Definition vector2d.h:323
irr::core::aabbox3df
aabbox3d< f32 > aabbox3df
Typedef for a f32 3d bounding box.
Definition aabbox3d.h:324
irr::scene
All scene management can be found in this namespace: Mesh loading, special scene nodes like octrees a...
Definition CDynamicMeshBuffer.h:16
irr::scene::SMeshBufferLightMap
CMeshBuffer< video::S3DVertex2TCoords > SMeshBufferLightMap
Meshbuffer with two texture coords per vertex, e.g. for lightmaps.
Definition CMeshBuffer.h:293
irr::scene::SMeshBuffer
CMeshBuffer< video::S3DVertex > SMeshBuffer
Standard meshbuffer.
Definition CMeshBuffer.h:291
irr::scene::E_BUFFER_TYPE
E_BUFFER_TYPE
Definition EHardwareBufferFlags.h:29
irr::scene::EBT_VERTEX_AND_INDEX
@ EBT_VERTEX_AND_INDEX
Change both vertex and index mapping to the same value.
Definition EHardwareBufferFlags.h:37
irr::scene::EBT_INDEX
@ EBT_INDEX
Change the index mapping.
Definition EHardwareBufferFlags.h:35
irr::scene::EBT_VERTEX
@ EBT_VERTEX
Change the vertex mapping.
Definition EHardwareBufferFlags.h:33
irr::scene::SMeshBufferTangents
CMeshBuffer< video::S3DVertexTangents > SMeshBufferTangents
Meshbuffer with vertices having tangents stored, e.g. for normal mapping.
Definition CMeshBuffer.h:295
irr::scene::E_HARDWARE_MAPPING
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.h:14
irr::scene::EHM_NEVER
@ EHM_NEVER
Don't store on the hardware.
Definition EHardwareBufferFlags.h:16
irr::video::E_VERTEX_TYPE
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.h:19
irr::video::E_INDEX_TYPE
E_INDEX_TYPE
Definition SVertexIndex.h:16
irr::video::EIT_16BIT
@ EIT_16BIT
Definition SVertexIndex.h:17
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
irr::u32
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.h:58
irr::u16
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.h:40
- Irrlicht Engine Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on for Irrlicht 3D Engine by Doxygen 1.15.0