//////////////////////////////////////////////////////////////////////////////////
// SPARK particle engine //
// Copyright (C) 2008-2011 //
// Julien Fryer -
julienfryer@gmail.com //
// Thibault Lescoat - info-tibo <at> orange <dot> fr //
// //
// This software is provided 'as-is', without any express or implied //
// warranty. In no event will the authors be held liable for any damages //
// arising from the use of this software. //
// //
// Permission is granted to anyone to use this software for any purpose, //
// including commercial applications, and to alter it and redistribute it //
// freely, subject to the following restrictions: //
// //
// 1. The origin of this software must not be misrepresented; you must not //
// claim that you wrote the original software. If you use this software //
// in a product, an acknowledgment in the product documentation would be //
// appreciated but is not required. //
// 2. Altered source versions must be plainly marked as such, and must not be //
// misrepresented as being the original software. //
// 3. This notice may not be removed or altered from any source distribution. //
//////////////////////////////////////////////////////////////////////////////////
#ifndef H_SPK_IRRBUFFER
#define H_SPK_IRRBUFFER
#include "Rendering/Irrlicht/SPK_IRR_DEF.h"
namespace SPK
{
namespace IRR
{
struct S3DVertexPSize : public irr::video::S3DVertex
{
//! default constructor
S3DVertexPSize() : irr::video::S3DVertex(),Psize(100) {}
//! constructor with two different texture coords, but no normal
S3DVertexPSize(irr::f32 x, irr::f32 y, irr::f32 z, irr::video::SColor c, irr::f32 tu, irr::f32 tv, irr::f32 tu2)
: S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), Psize(100) {}
//! constructor with two different texture coords, but no normal
S3DVertexPSize(const irr::core::vector3df& pos, irr::video::SColor color,
const irr::core::vector2d<irr::f32>& tcoords, const irr::f32 tcoords2)
: S3DVertex(pos, irr::core::vector3df(), color, tcoords), Psize(100) {}
//! constructor with all values
S3DVertexPSize(const irr::core::vector3df& pos, const irr::core::vector3df& normal, const irr::video::SColor& color,
const irr::core::vector2d<irr::f32>& tcoords, const irr::f32 tcoords2)
: S3DVertex(pos, normal, color, tcoords), Psize(100) {}
irr::f32 Psize;
};
class SPK_IRR_PREFIX IRRBuffer : public RenderBuffer
{
public :
IRRBuffer(irr::IrrlichtDevice* device,size_t nbParticles,size_t nbVerticesPerParticle,size_t nbIndicesPerParticle);
~IRRBuffer();
irr::video::E_INDEX_TYPE getIndiceType() const;
void positionAtStart();
void setNextIndex(int index);
void setNextVertex(const Vector3D& vertex);
void setNextColor(const Color& color);
void skipNextColors(size_t nb);
void setNextTexCoords(float u,float v);
void skipNextTexCoords(size_t nb);
irr::scene::CMeshBuffer<irr::video::S3DVertex>& getMeshBuffer();
const irr::scene::CMeshBuffer<irr::video::S3DVertex>& getMeshBuffer() const;
void setUsed(size_t nb);
private :
irr::scene::CMeshBuffer<irr::video::S3DVertex>* meshBuffer;
irr::IrrlichtDevice* device;
size_t nbParticles;
size_t nbVerticesPerParticle;
size_t nbIndicesPerParticle;
size_t currentIndexIndex;
size_t currentVertexIndex;
size_t currentColorIndex;
size_t currentTexCoordIndex;
};
inline irr::video::E_INDEX_TYPE IRRBuffer::getIndiceType() const
{
return nbParticles * nbVerticesPerParticle > 65536 ? irr::video::EIT_32BIT : irr::video::EIT_16BIT;
}
inline void IRRBuffer::positionAtStart()
{
currentIndexIndex = 0;
currentVertexIndex = 0;
currentColorIndex = 0;
currentTexCoordIndex = 0;
}
inline void IRRBuffer::setNextIndex(int index)
{
meshBuffer->getIndexBuffer()->setIndex(currentIndexIndex++,index);
}
inline void IRRBuffer::setNextVertex(const Vector3D& vertex)
{
((irr::video::S3DVertex*)meshBuffer->getVertexBuffer()->getVertices())[currentVertexIndex++].Pos.set(
vertex.x,
vertex.y,
vertex.z);
}
inline void IRRBuffer::setNextColor(const Color& color)
{
((irr::video::S3DVertex*)meshBuffer->getVertexBuffer()->getVertices())[currentColorIndex++].Color.set(color.getARGB());
}
inline void IRRBuffer::skipNextColors(size_t nb)
{
currentColorIndex += nb;
}
inline void IRRBuffer::setNextTexCoords(float u,float v)
{
((irr::video::S3DVertex*)meshBuffer->getVertexBuffer()->getVertices())[currentTexCoordIndex++].TCoords.set(u,v);
}
inline void IRRBuffer::skipNextTexCoords(size_t nb)
{
currentTexCoordIndex += nb;
}
inline irr::scene::CMeshBuffer<irr::video::S3DVertex>& IRRBuffer::getMeshBuffer()
{
return *meshBuffer;
}
inline const irr::scene::CMeshBuffer<irr::video::S3DVertex>& IRRBuffer::getMeshBuffer() const
{
return *meshBuffer;
}
}}
#endif