axmol/extensions/Particle3D/CCParticle3DRender.h

164 lines
5.0 KiB
C
Raw Normal View History

2015-02-11 18:14:22 +08:00
/****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
https://axis-project.github.io/
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
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:
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
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.
****************************************************************************/
#pragma once
2015-02-11 18:14:22 +08:00
#include <vector>
#include "renderer/CCRenderState.h"
#include "renderer/backend/Types.h"
2019-03-07 17:30:11 +08:00
#include "renderer/CCMeshCommand.h"
#include "renderer/CCCallbackCommand.h"
#include "renderer/backend/Buffer.h"
2015-02-11 18:14:22 +08:00
#include "base/CCRef.h"
#include "math/CCMath.h"
2020-10-07 00:15:11 +08:00
#include "ExtensionExport.h"
2015-02-11 18:14:22 +08:00
NS_AX_BEGIN
2015-02-11 18:14:22 +08:00
class ParticleSystem3D;
class Renderer;
class MeshCommand;
class MeshRenderer;
2015-02-11 18:14:22 +08:00
class GLProgramState;
class IndexBuffer;
class VertexBuffer;
class Texture2D;
/**
* 3d particle render
*/
2020-10-07 00:15:11 +08:00
class CC_EX_DLL Particle3DRender : public Ref
2015-02-11 18:14:22 +08:00
{
2015-03-02 13:07:32 +08:00
friend class ParticleSystem3D;
2015-02-11 18:14:22 +08:00
2021-12-25 10:04:45 +08:00
public:
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) = 0;
2015-02-11 18:14:22 +08:00
/** Perform activities when a Renderer is started.
2021-12-25 10:04:45 +08:00
*/
2015-03-02 17:47:26 +08:00
virtual void notifyStart();
2015-02-11 18:14:22 +08:00
/** Perform activities when a Renderer is stopped.
2021-12-25 10:04:45 +08:00
*/
2015-03-02 17:47:26 +08:00
virtual void notifyStop();
2015-02-11 18:14:22 +08:00
/** Notify that the Particle System is rescaled.
2021-12-25 10:04:45 +08:00
*/
2015-02-11 18:14:22 +08:00
virtual void notifyRescaled(const Vec3& scale);
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
void setVisible(bool isVisible) { _isVisible = isVisible; }
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
bool isVisible() const { return _isVisible; }
void setDepthTest(bool isDepthTest);
void setDepthWrite(bool isDepthWrite);
void setBlendFunc(const BlendFunc& blendFunc);
2021-12-25 10:04:45 +08:00
void copyAttributesTo(Particle3DRender* render);
2021-12-25 10:04:45 +08:00
virtual void reset() {}
Particle3DRender();
virtual ~Particle3DRender();
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
protected:
2021-12-25 10:04:45 +08:00
ParticleSystem3D* _particleSystem;
RenderState::StateBlock _stateBlock;
2021-12-25 10:04:45 +08:00
bool _isVisible;
2015-02-11 18:14:22 +08:00
Vec3 _rendererScale;
bool _depthTest;
bool _depthWrite;
};
// particle render for quad
2020-10-07 00:15:11 +08:00
class CC_EX_DLL Particle3DQuadRender : public Particle3DRender
2015-02-11 18:14:22 +08:00
{
public:
2021-12-26 23:26:34 +08:00
static Particle3DQuadRender* create(std::string_view texFile = "");
2015-02-11 18:14:22 +08:00
2021-12-25 10:04:45 +08:00
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) override;
virtual void reset() override;
Particle3DQuadRender();
2015-02-11 18:14:22 +08:00
virtual ~Particle3DQuadRender();
protected:
2021-12-26 23:26:34 +08:00
bool initQuadRender(std::string_view texFile);
void onBeforeDraw();
void onAfterDraw();
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
protected:
2021-12-25 10:04:45 +08:00
MeshCommand _meshCommand;
2022-06-24 14:18:48 +08:00
//CallbackCommand _beforeCommand;
//CallbackCommand _afterCommand;
2021-12-25 10:04:45 +08:00
Texture2D* _texture = nullptr;
backend::ProgramState* _programState = nullptr;
backend::Buffer* _indexBuffer = nullptr; // index buffer
backend::Buffer* _vertexBuffer = nullptr; // vertex buffer
2015-02-11 18:14:22 +08:00
struct posuvcolor
{
Vec3 position;
Vec2 uv;
Vec4 color;
};
2021-12-25 10:04:45 +08:00
std::vector<posuvcolor> _posuvcolors; // vertex data
std::vector<uint16_t> _indexData; // index data
std::string _texFile;
2021-12-25 10:04:45 +08:00
backend::UniformLocation _locColor;
backend::UniformLocation _locTexture;
backend::UniformLocation _locPMatrix;
2021-12-25 10:04:45 +08:00
// renderer state cache variables
bool _rendererDepthTestEnabled = true;
backend::CompareFunction _rendererDepthCmpFunc = backend::CompareFunction::LESS;
backend::CullMode _rendererCullMode = backend::CullMode::BACK;
backend::Winding _rendererWinding = backend::Winding::COUNTER_CLOCK_WISE;
bool _rendererDepthWrite = false;
2015-02-11 18:14:22 +08:00
};
// particle renderer using MeshRenderer
2020-10-07 00:15:11 +08:00
class CC_EX_DLL Particle3DModelRender : public Particle3DRender
2015-02-11 18:14:22 +08:00
{
public:
2021-12-26 23:26:34 +08:00
static Particle3DModelRender* create(std::string_view modelFile, std::string_view texFile = "");
2015-02-11 18:14:22 +08:00
2021-12-25 10:04:45 +08:00
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) override;
virtual void reset() override;
Particle3DModelRender();
2015-02-11 18:14:22 +08:00
virtual ~Particle3DModelRender();
2021-12-25 10:04:45 +08:00
2015-02-11 18:14:22 +08:00
protected:
std::vector<MeshRenderer*> _meshList;
2015-02-11 18:14:22 +08:00
std::string _modelFile;
std::string _texFile;
Vec3 _meshSize;
2015-02-11 18:14:22 +08:00
};
NS_AX_END