Commit cd359855 authored by Otto Naderer's avatar Otto Naderer

checkin 1.8.4

parent ee858ab3
// Copyright (C) 2008-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_DYNAMIC_MESHBUFFER_H_INCLUDED__
#define __C_DYNAMIC_MESHBUFFER_H_INCLUDED__
#include "IDynamicMeshBuffer.h"
#include "CVertexBuffer.h"
#include "CIndexBuffer.h"
namespace irr
{
namespace scene
{
class CDynamicMeshBuffer: public IDynamicMeshBuffer
{
public:
//! constructor
CDynamicMeshBuffer(video::E_VERTEX_TYPE vertexType, video::E_INDEX_TYPE indexType)
{
VertexBuffer=new CVertexBuffer(vertexType);
IndexBuffer=new CIndexBuffer(indexType);
}
//! destructor
virtual ~CDynamicMeshBuffer()
{
if (VertexBuffer)
VertexBuffer->drop();
if (IndexBuffer)
IndexBuffer->drop();
}
virtual IVertexBuffer& getVertexBuffer() const
{
return *VertexBuffer;
}
virtual IIndexBuffer& getIndexBuffer() const
{
return *IndexBuffer;
}
virtual void setVertexBuffer(IVertexBuffer *newVertexBuffer)
{
if (newVertexBuffer)
newVertexBuffer->grab();
if (VertexBuffer)
VertexBuffer->drop();
VertexBuffer=newVertexBuffer;
}
virtual void setIndexBuffer(IIndexBuffer *newIndexBuffer)
{
if (newIndexBuffer)
newIndexBuffer->grab();
if (IndexBuffer)
IndexBuffer->drop();
IndexBuffer=newIndexBuffer;
}
//! Get Material of this buffer.
virtual const video::SMaterial& getMaterial() const
{
return Material;
}
//! Get Material of this buffer.
virtual video::SMaterial& getMaterial()
{
return Material;
}
//! Get bounding box
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return BoundingBox;
}
//! Set bounding box
virtual void setBoundingBox( const core::aabbox3df& box)
{
BoundingBox = box;
}
//! Recalculate bounding box
virtual void recalculateBoundingBox()
{
if (!getVertexBuffer().size())
BoundingBox.reset(0,0,0);
else
{
BoundingBox.reset(getVertexBuffer()[0].Pos);
for (u32 i=1; i<getVertexBuffer().size(); ++i)
BoundingBox.addInternalPoint(getVertexBuffer()[i].Pos);
}
}
video::SMaterial Material;
core::aabbox3d<f32> BoundingBox;
private:
IVertexBuffer *VertexBuffer;
IIndexBuffer *IndexBuffer;
};
} // end namespace scene
} // end namespace irr
#endif
// Copyright (C) 2008-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_INDEX_BUFFER_H_INCLUDED__
#define __C_INDEX_BUFFER_H_INCLUDED__
#include "IIndexBuffer.h"
namespace irr
{
namespace scene
{
class CIndexBuffer : public IIndexBuffer
{
class IIndexList
{
public:
virtual ~IIndexList(){};
virtual u32 stride() const =0;
virtual u32 size() const =0;
virtual void push_back(const u32 &element) =0;
virtual u32 operator [](u32 index) const =0;
virtual u32 getLast() =0;
virtual void setValue(u32 index, u32 value) =0;
virtual void set_used(u32 usedNow) =0;
virtual void reallocate(u32 new_size) =0;
virtual u32 allocated_size() const =0;
virtual void* pointer() =0;
virtual video::E_INDEX_TYPE getType() const =0;
};
template <class T>
class CSpecificIndexList : public IIndexList
{
public:
core::array<T> Indices;
virtual u32 stride() const {return sizeof(T);}
virtual u32 size() const {return Indices.size();}
virtual void push_back(const u32 &element)
{
// push const ref due to compiler problem with gcc 4.6, big endian
Indices.push_back((const T&)element);
}
virtual u32 operator [](u32 index) const
{
return (u32)(Indices[index]);
}
virtual u32 getLast() {return (u32)Indices.getLast();}
virtual void setValue(u32 index, u32 value)
{
Indices[index]=(T)value;
}
virtual void set_used(u32 usedNow)
{
Indices.set_used(usedNow);
}
virtual void reallocate(u32 new_size)
{
Indices.reallocate(new_size);
}
virtual u32 allocated_size() const
{
return Indices.allocated_size();
}
virtual void* pointer() {return Indices.pointer();}
virtual video::E_INDEX_TYPE getType() const
{
if (sizeof(T)==sizeof(u16))
return video::EIT_16BIT;
else
return video::EIT_32BIT;
}
};
public:
IIndexList *Indices;
CIndexBuffer(video::E_INDEX_TYPE IndexType) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
{
setType(IndexType);
}
CIndexBuffer(const IIndexBuffer &IndexBufferCopy) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
{
setType(IndexBufferCopy.getType());
reallocate(IndexBufferCopy.size());
for (u32 n=0;n<IndexBufferCopy.size();++n)
push_back(IndexBufferCopy[n]);
}
virtual ~CIndexBuffer()
{
delete Indices;
}
//virtual void setType(video::E_INDEX_TYPE IndexType);
virtual void setType(video::E_INDEX_TYPE IndexType)
{
IIndexList *NewIndices=0;
switch (IndexType)
{
case video::EIT_16BIT:
{
NewIndices=new CSpecificIndexList<u16>;
break;
}
case video::EIT_32BIT:
{
NewIndices=new CSpecificIndexList<u32>;
break;
}
}
if (Indices)
{
NewIndices->reallocate( Indices->size() );
for(u32 n=0;n<Indices->size();++n)
NewIndices->push_back((*Indices)[n]);
delete Indices;
}
Indices=NewIndices;
}
virtual void* getData() {return Indices->pointer();}
virtual video::E_INDEX_TYPE getType() const {return Indices->getType();}
virtual u32 stride() const {return Indices->stride();}
virtual u32 size() const
{
return Indices->size();
}
virtual void push_back(const u32 &element)
{
Indices->push_back(element);
}
virtual u32 operator [](u32 index) const
{
return (*Indices)[index];
}
virtual u32 getLast()
{
return Indices->getLast();
}
virtual void setValue(u32 index, u32 value)
{
Indices->setValue(index, value);
}
virtual void set_used(u32 usedNow)
{
Indices->set_used(usedNow);
}
virtual void reallocate(u32 new_size)
{
Indices->reallocate(new_size);
}
virtual u32 allocated_size() const
{
return Indices->allocated_size();
}
virtual void* pointer()
{
return Indices->pointer();
}
//! get the current hardware mapping hint
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const
{
return MappingHint;
}
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
{
MappingHint=NewMappingHint;
}
//! flags the mesh as changed, reloads hardware buffers
virtual void setDirty()
{
++ChangedID;
}
//! Get the currently used ID for identification of changes.
/** This shouldn't be used for anything outside the VideoDriver. */
virtual u32 getChangedID() const {return ChangedID;}
E_HARDWARE_MAPPING MappingHint;
u32 ChangedID;
};
} // end namespace scene
} // end namespace irr
#endif
// 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 implementation of the IMeshBuffer interface
template <class T>
class CMeshBuffer : public IMeshBuffer
{
public:
//! Default constructor for empty meshbuffer
CMeshBuffer():ChangedID_Vertex(1),ChangedID_Index(1),MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER)
{
#ifdef _DEBUG
setDebugName("SMeshBuffer");
#endif
}
//! Get material of this meshbuffer
/** \return Material of this buffer */
virtual const video::SMaterial& getMaterial() const
{
return Material;
}
//! Get material of this meshbuffer
/** \return Material of this buffer */
virtual video::SMaterial& getMaterial()
{
return Material;
}
//! Get pointer to vertices
/** \return Pointer to vertices. */
virtual const void* getVertices() const
{
return Vertices.const_pointer();
}
//! Get pointer to vertices
/** \return Pointer to vertices. */
virtual void* getVertices()
{
return Vertices.pointer();
}
//! Get number of vertices
/** \return Number of vertices. */
virtual u32 getVertexCount() const
{
return Vertices.size();
}
//! Get type of index data which is stored in this meshbuffer.
/** \return Index type of this buffer. */
virtual video::E_INDEX_TYPE getIndexType() const
{
return video::EIT_16BIT;
}
//! Get pointer to indices
/** \return Pointer to indices. */
virtual const u16* getIndices() const
{
return Indices.const_pointer();
}
//! Get pointer to indices
/** \return Pointer to indices. */
virtual u16* getIndices()
{
return Indices.pointer();
}
//! Get number of indices
/** \return Number of indices. */
virtual u32 getIndexCount() const
{
return Indices.size();
}
//! Get the axis aligned bounding box
/** \return Axis aligned bounding box of this buffer. */
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return BoundingBox;
}
//! Set the axis aligned bounding box
/** \param box New axis aligned bounding box for this buffer. */
//! set user axis aligned bounding box
virtual void setBoundingBox(const core::aabbox3df& box)
{
BoundingBox = box;
}
//! Recalculate the bounding box.
/** should be called if the mesh changed. */
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);
}
}
//! Get type of vertex data stored in this buffer.
/** \return Type of vertex data. */
virtual video::E_VERTEX_TYPE getVertexType() const
{
return T().getType();
}
//! returns position of vertex i
virtual const core::vector3df& getPosition(u32 i) const
{
return Vertices[i].Pos;
}
//! returns position of vertex i
virtual core::vector3df& getPosition(u32 i)
{
return Vertices[i].Pos;
}
//! returns normal of vertex i
virtual const core::vector3df& getNormal(u32 i) const
{
return Vertices[i].Normal;
}
//! returns normal of vertex i
virtual core::vector3df& getNormal(u32 i)
{
return Vertices[i].Normal;
}
//! returns texture coord of vertex i
virtual const core::vector2df& getTCoords(u32 i) const
{
return Vertices[i].TCoords;
}
//! returns texture coord of vertex i
virtual core::vector2df& getTCoords(u32 i)
{
return Vertices[i].TCoords;
}
//! Append the vertices and indices to the current buffer
/** Only works for compatible types, i.e. either the same type
or the main buffer is of standard type. Otherwise, behavior is
undefined.
*/
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);
}
}
//! Append the meshbuffer to the current buffer
/** Only works for compatible types, i.e. either the same type
or the main buffer is of standard type. Otherwise, behavior is
undefined.
\param other Meshbuffer to be appended to this one.
*/
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());
*/
}
//! get the current hardware mapping hint
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
{
return MappingHint_Vertex;
}
//! get the current hardware mapping hint
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
{
return MappingHint_Index;
}
//! set the hardware mapping hint, for driver
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EB