Graphics: Remake DepthRender[Queue|Technique]

Former-commit-id: c4d8d4d28d02822273ebe7dca3e468ea156af674
This commit is contained in:
Lynix
2015-07-05 23:43:35 +02:00
parent 6870148314
commit 1f2e810927
4 changed files with 387 additions and 428 deletions

View File

@@ -18,10 +18,10 @@
#include <map>
#include <tuple>
class NAZARA_GRAPHICS_API NzDepthRenderQueue : public NzAbstractRenderQueue
class NAZARA_GRAPHICS_API NzDepthRenderQueue : public NzForwardRenderQueue
{
public:
NzDepthRenderQueue() = default;
NzDepthRenderQueue();
~NzDepthRenderQueue() = default;
void AddBillboard(const NzMaterial* material, const NzVector3f& position, const NzVector2f& size, const NzVector2f& sinCos = NzVector2f(0.f, 1.f), const NzColor& color = NzColor::White) override;
@@ -33,44 +33,16 @@ class NAZARA_GRAPHICS_API NzDepthRenderQueue : public NzAbstractRenderQueue
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const NzVector2f> sinCosPtr, NzSparsePtr<const float> alphaPtr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const NzColor> colorPtr = nullptr) override;
void AddBillboards(const NzMaterial* material, unsigned int count, NzSparsePtr<const NzVector3f> positionPtr, NzSparsePtr<const float> sizePtr, NzSparsePtr<const float> anglePtr, NzSparsePtr<const float> alphaPtr) override;
void AddDrawable(const NzDrawable* drawable) override;
void AddDirectionalLight(const DirectionalLight& light) override;
void AddMesh(const NzMaterial* material, const NzMeshData& meshData, const NzBoxf& meshAABB, const NzMatrix4f& transformMatrix) override;
void AddPointLight(const PointLight& light) override;
void AddSpotLight(const SpotLight& light) override;
void AddSprites(const NzMaterial* material, const NzVertexStruct_XYZ_Color_UV* vertices, unsigned int spriteCount, const NzTexture* overlay = nullptr) override;
void Clear(bool fully = false);
struct BillboardData
{
NzColor color;
NzVector3f center;
NzVector2f size;
NzVector2f sinCos;
};
struct MeshInstanceEntry
{
NazaraSlot(NzIndexBuffer, OnIndexBufferRelease, indexBufferReleaseSlot);
NazaraSlot(NzVertexBuffer, OnVertexBufferRelease, vertexBufferReleaseSlot);
std::vector<NzMatrix4f> instances;
};
struct SpriteChain_XYZ_Color_UV
{
const NzVertexStruct_XYZ_Color_UV* vertices;
unsigned int spriteCount;
};
std::map<NzMeshData, MeshInstanceEntry, NzForwardRenderQueue::MeshDataComparator> meshes;
std::vector<BillboardData> billboards;
std::vector<const NzDrawable*> otherDrawables;
std::vector<SpriteChain_XYZ_Color_UV> basicSprites;
private:
bool IsMaterialSuitable(const NzMaterial* material) const;
void OnIndexBufferInvalidation(const NzIndexBuffer* indexBuffer);
void OnVertexBufferInvalidation(const NzVertexBuffer* vertexBuffer);
NzMaterialRef m_baseMaterial;
};
#endif // NAZARA_DEPTHRENDERQUEUE_HPP

View File

@@ -12,7 +12,6 @@
#include <Nazara/Graphics/Config.hpp>
#include <Nazara/Graphics/DepthRenderQueue.hpp>
#include <Nazara/Graphics/Light.hpp>
#include <Nazara/Graphics/Material.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
@@ -32,22 +31,51 @@ class NAZARA_GRAPHICS_API NzDepthRenderTechnique : public NzAbstractRenderTechni
static void Uninitialize();
private:
struct ShaderUniforms;
void DrawBasicSprites(const NzSceneData& sceneData) const;
void DrawBillboards(const NzSceneData& sceneData) const;
void DrawOpaqueModels(const NzSceneData& sceneData) const;
const ShaderUniforms* GetShaderUniforms(const NzShader* shader) const;
void OnShaderInvalidated(const NzShader* shader) const;
struct LightIndex
{
nzLightType type;
float score;
unsigned int index;
};
struct ShaderUniforms
{
NazaraSlot(NzShader, OnShaderUniformInvalidated, shaderUniformInvalidatedSlot);
NazaraSlot(NzShader, OnShaderRelease, shaderReleaseSlot);
NzLightUniforms lightUniforms;
bool hasLightUniforms;
/// Moins coûteux en mémoire que de stocker un NzLightUniforms par index de lumière,
/// à voir si ça fonctionne chez tout le monde
int lightOffset; // "Distance" entre Lights[0].type et Lights[1].type
// Autre uniformes
int eyePosition;
int sceneAmbient;
int textureOverlay;
};
mutable std::unordered_map<const NzShader*, ShaderUniforms> m_shaderUniforms;
NzBuffer m_vertexBuffer;
mutable NzDepthRenderQueue m_renderQueue;
NzVertexBuffer m_billboardPointBuffer;
NzVertexBuffer m_spriteBuffer;
static NzIndexBuffer s_quadIndexBuffer;
static NzMaterialRef s_material;
static NzVertexBuffer s_quadVertexBuffer;
static NzVertexDeclaration s_billboardInstanceDeclaration;
static NzVertexDeclaration s_billboardVertexDeclaration;
};
#include <Nazara/Graphics/DepthRenderTechnique.inl>
#include <Nazara/Graphics/dEPTHRenderTechnique.inl>
#endif // NAZARA_DEPTHRENDERTECHNIQUE_HPP