Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
ParticleEmitter.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_PARTICLE_EMITTER_H_
34#define DVD_PARTICLE_EMITTER_H_
35
36#include "ParticleSource.h"
37#include "ParticleUpdater.h"
39
42namespace Divide {
43
44class Texture;
46
49{
50 public:
51 explicit ParticleEmitter( const ResourceDescriptor<ParticleEmitter>& descriptor );
52 ~ParticleEmitter() override;
53
54 void prepareRender(SceneGraphNode* sgn,
55 RenderingComponent& rComp,
56 RenderPackage& pkg,
57 GFX::MemoryBarrierCommand& postDrawMemCmd,
58 RenderStagePass renderStagePass,
59 const CameraSnapshot& cameraSnapshot,
60 bool refreshData) override;
61
62
64 void enableEmitter(const bool state) noexcept { _enabled = state; }
65
66 void setDrawImpostor(const bool state) noexcept { _drawImpostor = state; }
67
68 [[nodiscard]] bool initData(const std::shared_ptr<ParticleData>& particleData);
69
71 bool load( PlatformContext& context ) override;
72 bool unload() override;
73
74 void addUpdater(const std::shared_ptr<ParticleUpdater>& updater) {
75 _updaters.push_back(updater);
76 }
77
78 void addSource(const std::shared_ptr<ParticleSource>& source) {
79 _sources.push_back(source);
80 }
81
82 [[nodiscard]] U32 getAliveParticleCount() const noexcept;
83
84 protected:
85
87 void sceneUpdate(U64 deltaTimeUS,
88 SceneGraphNode* sgn,
89 SceneState& sceneState) override;
90
91 void buildDrawCommands(SceneGraphNode* sgn, GenericDrawCommandContainer& cmdsOut) override;
92
93 [[nodiscard]] GenericVertexData& getDataBuffer(RenderStage stage, PlayerIndex idx);
94
95 private:
96 static constexpr U8 s_MaxPlayerBuffers = 4;
97
98 std::shared_ptr<ParticleData> _particles;
99
102
104 bool _enabled = false;
106 bool _drawImpostor = false;
107
108 using BuffersPerStage = std::array<GenericVertexData_ptr, to_base(RenderStage::COUNT)>;
109 using BuffersPerPlayer = std::array<BuffersPerStage, s_MaxPlayerBuffers>;
110 BuffersPerPlayer _particleGPUBuffers{};
111 std::array<bool, to_base(RenderStage::COUNT)> _buffersDirty{};
112
113 Task* _bufferUpdate = nullptr;
114 Task* _bbUpdate = nullptr;
115};
116
118
119} // namespace Divide
120
121#endif //DVD_PARTICLE_EMITTER_H_
#define TYPEDEF_SMART_POINTERS_FOR_TYPE(T)
#define FWD_DECLARE_MANAGED_CLASS(T)
#define DEFINE_NODE_TYPE(Name, Enum)
Definition: SceneNodeFwd.h:120
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool load() override
bool unload() override
uint8_t U8
eastl::vector< Type > vector
Definition: Vector.h:42
eastl::fixed_vector< GenericDrawCommand, 1, true > GenericDrawCommandContainer
uint32_t U32
uint64_t U64
constexpr auto to_base(const Type value) -> Type