Skip to content

Commit

Permalink
#102 Update for cpu buffer compute
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Oct 9, 2020
1 parent 1a0491e commit bfc96e8
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ namespace Skylicht
OrientationUp(0.0f, 1.0f, 0.0f)
{
m_particleSystem = new CParticleSystem();
m_bufferSystem = new CParticleBufferSystem();

m_instancingSystem = new CParticleInstancingSystem();
m_cpuBufferSystem = new CParticleCPUBufferSystem();

m_instancing = new CParticleInstancing();
m_cpuBuffer = new CParticleCPUBuffer();
}

CGroup::~CGroup()
Expand All @@ -62,9 +65,12 @@ namespace Skylicht
m_interpolators.clear();

delete m_particleSystem;
delete m_bufferSystem;

delete m_instancingSystem;
delete m_cpuBufferSystem;

delete m_instancing;
delete m_cpuBuffer;
}

IRenderer* CGroup::setRenderer(IRenderer *r)
Expand Down Expand Up @@ -140,8 +146,13 @@ namespace Skylicht
}

// update instancing buffer
if (visible == true)
m_bufferSystem->update(particles, numParticles, this, dt);
if (visible == true && m_renderer != NULL)
{
if (m_renderer->useInstancing() == true)
m_instancingSystem->update(particles, numParticles, this, dt);
else
m_cpuBufferSystem->update(particles, numParticles, this, dt);
}

bornParticle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ This file is part of the "Skylicht Engine".
#include "Systems/ISystem.h"

#include "Systems/CParticleSystem.h"
#include "Systems/CParticleBufferSystem.h"
#include "Systems/CParticleInstancingSystem.h"
#include "Systems/CParticleCPUBufferSystem.h"

#include "CParticleInstancing.h"
#include "CParticleCPUBuffer.h"

#include "CModel.h"

namespace Skylicht
Expand Down Expand Up @@ -107,10 +110,14 @@ namespace Skylicht
std::vector<CInterpolator*> m_interpolators;

CParticleSystem *m_particleSystem;
CParticleBufferSystem *m_bufferSystem;

CParticleInstancingSystem *m_instancingSystem;
CParticleCPUBufferSystem *m_cpuBufferSystem;

IRenderer* m_renderer;

CParticleInstancing *m_instancing;
CParticleCPUBuffer *m_cpuBuffer;

std::vector<IParticleCallback*> m_callback;

Expand Down Expand Up @@ -253,6 +260,11 @@ namespace Skylicht
return m_instancing;
}

CParticleCPUBuffer* getParticleBuffer()
{
return m_cpuBuffer;
}

inline u32 getCurrentParticleCount()
{
return m_particles.size();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "Material/Shader/CShaderManager.h"
#include "CParticleCPUBuffer.h"

namespace Skylicht
{
namespace Particle
{
CParticleCPUBuffer::CParticleCPUBuffer()
{
m_meshBuffer = new CMeshBuffer<video::S3DVertex>(getVideoDriver()->getVertexDescriptor(video::EVT_STANDARD), video::EIT_32BIT);
m_meshBuffer->setHardwareMappingHint(EHM_STREAM);
}

CParticleCPUBuffer::~CParticleCPUBuffer()
{
m_meshBuffer->drop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

namespace Skylicht
{
namespace Particle
{
class CParticleCPUBuffer
{
protected:
IMeshBuffer* m_meshBuffer;

public:
CParticleCPUBuffer();

virtual ~CParticleCPUBuffer();

inline IMeshBuffer* getMeshBuffer()
{
return m_meshBuffer;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace Skylicht
ERenderer m_type;
CMaterial *m_material;

bool m_useInstancing;

public:
float SizeX;
float SizeY;
Expand All @@ -53,7 +55,8 @@ namespace Skylicht
m_material(NULL),
SizeX(1.0f),
SizeY(1.0f),
SizeZ(1.0f)
SizeZ(1.0f),
m_useInstancing(true)
{

}
Expand All @@ -73,6 +76,11 @@ namespace Skylicht
return m_material;
}

bool useInstancing()
{
return m_useInstancing;
}

virtual void getParticleBuffer(IMeshBuffer *buffer) = 0;

virtual u32 getTotalFrames()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CParticleCPUBufferSystem.h"

#include "ParticleSystem/Particles/CParticle.h"
#include "ParticleSystem/Particles/CGroup.h"

#include "ParticleSystem/Particles/Renderers/CQuadRenderer.h"

namespace Skylicht
{
namespace Particle
{
CParticleCPUBufferSystem::CParticleCPUBufferSystem()
{

}

CParticleCPUBufferSystem::~CParticleCPUBufferSystem()
{

}

void CParticleCPUBufferSystem::update(CParticle *particles, int num, CGroup *group, float dt)
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ namespace Skylicht
{
namespace Particle
{
class CParticleBufferSystem : public ISystem
class CParticleCPUBufferSystem : public ISystem
{
public:
CParticleBufferSystem();
CParticleCPUBufferSystem();

virtual ~CParticleBufferSystem();
virtual ~CParticleCPUBufferSystem();

virtual void update(CParticle *particles, int num, CGroup *group, float dt);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This file is part of the "Skylicht Engine".
*/

#include "pch.h"
#include "CParticleBufferSystem.h"
#include "CParticleInstancingSystem.h"

#include "ParticleSystem/Particles/CParticle.h"
#include "ParticleSystem/Particles/CGroup.h"
Expand All @@ -34,17 +34,17 @@ namespace Skylicht
{
namespace Particle
{
CParticleBufferSystem::CParticleBufferSystem()
CParticleInstancingSystem::CParticleInstancingSystem()
{

}

CParticleBufferSystem::~CParticleBufferSystem()
CParticleInstancingSystem::~CParticleInstancingSystem()
{

}

void CParticleBufferSystem::update(CParticle *particles, int num, CGroup *group, float dt)
void CParticleInstancingSystem::update(CParticle *particles, int num, CGroup *group, float dt)
{
CVertexBuffer<SParticleInstance>* buffer = group->getIntancing()->getInstanceBuffer();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
!@
MIT License
Copyright (c) 2020 Skylicht Technology CO., LTD
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "ISystem.h"

namespace Skylicht
{
namespace Particle
{
class CParticleInstancingSystem : public ISystem
{
public:
CParticleInstancingSystem();

virtual ~CParticleInstancingSystem();

virtual void update(CParticle *particles, int num, CGroup *group, float dt);
};
}
}

0 comments on commit bfc96e8

Please sign in to comment.