axmol/core/renderer/CCPass.h

189 lines
6.6 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2015-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
https://axis-project.github.io/
2019-11-23 20:27:39 +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:
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.
Ideas taken from:
- GamePlay3D: http://gameplay3d.org/
- OGRE3D: http://www.ogre3d.org/
- Qt3D: http://qt-project.org/
****************************************************************************/
#pragma once
#include <stdio.h>
#include "platform/CCPlatformMacros.h"
#include "renderer/CCRenderState.h"
#include "renderer/CCMeshCommand.h"
#include "renderer/CCGroupCommand.h"
#include "renderer/CCCallbackCommand.h"
NS_CC_BEGIN
class Technique;
class Node;
class VertexAttribBinding;
class MeshIndexData;
class RenderState;
namespace backend
{
2021-12-25 10:04:45 +08:00
class ProgramState;
class Buffer;
} // namespace backend
2019-11-23 20:27:39 +08:00
class CC_DLL Pass : public Ref
{
friend class Material;
friend class Technique;
friend class RenderState;
friend class VertexAttribBinding;
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
public:
/** Creates a Pass with a GLProgramState.
*/
static Pass* createWithProgramState(Technique* parent, backend::ProgramState* programState);
static Pass* create(Technique* parent);
/** Returns the ProgramState */
backend::ProgramState* getProgramState() const;
2021-12-25 10:04:45 +08:00
void draw(MeshCommand* meshCommand,
float globalZOrder,
backend::Buffer* vertexBuffer,
backend::Buffer* indexBuffer,
MeshCommand::PrimitiveType primitive,
MeshCommand::IndexFormat indexFormat,
unsigned int indexCount,
const Mat4& modelView);
2019-11-23 20:27:39 +08:00
/**
* Sets a vertex attribute binding for this pass.
*
* When a mesh binding is set, the VertexAttribBinding will be automatically
* bound when the bind() method is called for the pass.
*
* @param binding The VertexAttribBinding to set (or NULL to remove an existing binding).
*/
void setVertexAttribBinding(VertexAttribBinding* binding);
/**
* Returns the vertex attribute binding for this pass.
*
* @return The vertex attribute binding for this pass.
*/
VertexAttribBinding* getVertexAttributeBinding() const;
void setName(std::string_view name) { _name = name; }
std::string_view getName() const { return _name; }
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
inline RenderState::StateBlock& getStateBlock() { return _renderState._state; }
2019-11-23 20:27:39 +08:00
/**
* Returns a clone (deep-copy) of this instance */
Pass* clone() const;
2021-12-25 10:04:45 +08:00
void setTechnique(Technique* technique);
2019-11-23 20:27:39 +08:00
void updateMVPUniform(const Mat4& modelView);
void setUniformTexture(uint32_t slot, backend::TextureBackend*); // u_tex0
void setUniformNormTexture(uint32_t slot, backend::TextureBackend*); // u_tex0
2021-12-25 10:04:45 +08:00
void setUniformColor(const void*, size_t); // ucolor
void setUniformMatrixPalette(const void*, size_t); // u_matrixPalette
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void setUniformDirLightColor(const void*, size_t);
void setUniformDirLightDir(const void*, size_t);
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void setUniformPointLightColor(const void*, size_t);
void setUniformPointLightPosition(const void*, size_t);
void setUniformPointLightRangeInverse(const void*, size_t);
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void setUniformSpotLightColor(const void*, size_t);
void setUniformSpotLightPosition(const void*, size_t);
void setUniformSpotLightDir(const void*, size_t);
void setUniformSpotLightInnerAngleCos(const void*, size_t);
void setUniformSpotLightOuterAngleCos(const void*, size_t);
void setUniformSpotLightRangeInverse(const void*, size_t);
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
void setUniformAmbientLigthColor(const void*, size_t);
2019-11-23 20:27:39 +08:00
protected:
Pass();
~Pass();
bool init(Technique* parent);
2021-12-25 10:04:45 +08:00
bool initWithProgramState(Technique* parent, backend::ProgramState* glProgramState);
2019-11-23 20:27:39 +08:00
void setProgramState(backend::ProgramState* programState);
Node* getTarget() const;
2021-12-25 10:04:45 +08:00
VertexAttribBinding* _vertexAttribBinding = nullptr;
backend::ProgramState* _programState = nullptr;
Technique* _technique = nullptr;
bool _hashDirty = true;
RenderState _renderState;
std::string _name;
2019-11-23 20:27:39 +08:00
private:
void initUniformLocations();
2021-12-25 10:04:45 +08:00
void onBeforeVisitCmd(MeshCommand*);
void onAfterVisitCmd(MeshCommand*);
2019-11-23 20:27:39 +08:00
backend::UniformLocation _locMVPMatrix;
backend::UniformLocation _locMVMatrix;
backend::UniformLocation _locPMatrix;
backend::UniformLocation _locNormalMatrix;
backend::UniformLocation _locTexture; // u_tex0
2021-12-25 10:04:45 +08:00
backend::UniformLocation _locNormalTexture; // u_normalTex
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
backend::UniformLocation _locColor; // ucolor
backend::UniformLocation _locMatrixPalette; // u_matrixPalette
2019-11-23 20:27:39 +08:00
backend::UniformLocation _locDirLightColor;
backend::UniformLocation _locDirLightDir;
backend::UniformLocation _locPointLightColor;
backend::UniformLocation _locPointLightPosition;
backend::UniformLocation _locPointLightRangeInverse;
backend::UniformLocation _locSpotLightColor;
backend::UniformLocation _locSpotLightPosition;
backend::UniformLocation _locSpotLightDir;
backend::UniformLocation _locSpotLightInnerAngleCos;
backend::UniformLocation _locSpotLightOuterAngleCos;
backend::UniformLocation _locSpotLightRangeInverse;
backend::UniformLocation _locAmbientLigthColor;
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;
2019-11-23 20:27:39 +08:00
};
NS_CC_END