Added ShaderManager (Experimental)

Former-commit-id: 327e373f2b932e31184e88c5f29bd5bd8fa3ba46
This commit is contained in:
Lynix
2013-07-15 00:23:04 +02:00
parent 68d5f9a8e6
commit 4352083c4b
23 changed files with 1367 additions and 955 deletions

View File

@@ -115,7 +115,9 @@ enum nzStreamOptionFlags
{
nzStreamOption_None = 0x0,
nzStreamOption_Text = 0x1
nzStreamOption_Text = 0x1,
nzStreamOption_Max = nzStreamOption_Text*2-1
};
enum nzTernary

View File

@@ -16,7 +16,6 @@ class NAZARA_API NzColorBackground : public NzAbstractBackground
{
public:
NzColorBackground(const NzColor& color = NzColor::Black);
~NzColorBackground();
void Draw(const NzScene* scene) const;
@@ -27,7 +26,7 @@ class NAZARA_API NzColorBackground : public NzAbstractBackground
private:
NzColor m_color;
NzShaderRef m_shader;
NzShaderConstRef m_shader;
};
#endif // NAZARA_COLORBACKGROUND_HPP

View File

@@ -39,7 +39,7 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
private:
void OnResourceDestroy(const NzResource* resource, int index);
struct MaterialComparator
struct ModelMaterialComparator
{
bool operator()(const NzMaterial* mat1, const NzMaterial* mat2);
};
@@ -55,6 +55,12 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
bool operator()(const NzSkeletalMesh* subMesh1, const NzSkeletalMesh* subMesh2);
};
struct StaticData
{
NzBoxf aabb;
NzMatrix4f transformMatrix;
};
struct StaticMeshComparator
{
bool operator()(const NzStaticMesh* subMesh1, const NzStaticMesh* subMesh2);
@@ -78,8 +84,8 @@ class NAZARA_API NzForwardRenderQueue : public NzAbstractRenderQueue, NzResource
};
typedef std::map<const NzSkeletalMesh*, std::vector<SkeletalData>, SkeletalMeshComparator> SkeletalMeshContainer;
typedef std::map<const NzStaticMesh*, std::vector<NzMatrix4f>, StaticMeshComparator> StaticMeshContainer;
typedef std::map<const NzMaterial*, std::pair<SkeletalMeshContainer, StaticMeshContainer>, MaterialComparator> MeshContainer;
typedef std::map<const NzStaticMesh*, std::vector<StaticData>, StaticMeshComparator> StaticMeshContainer;
typedef std::map<const NzMaterial*, std::pair<SkeletalMeshContainer, StaticMeshContainer>, ModelMaterialComparator> MeshContainer;
MeshContainer opaqueModels;
std::vector<std::pair<unsigned int, bool>> transparentsModels;

View File

@@ -23,7 +23,7 @@ class NAZARA_API NzLight : public NzSceneNode
void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override;
void Apply(const NzShader* shader, unsigned int lightUnit) const;
void Enable(const NzShader* shader, unsigned int lightUnit) const;
NzColor GetAmbientColor() const;
float GetAttenuation() const;
@@ -46,6 +46,8 @@ class NAZARA_API NzLight : public NzSceneNode
NzLight& operator=(const NzLight& light);
static void Disable(const NzShader* shader, unsigned int lightUnit);
private:
void Invalidate();
void Register();

View File

@@ -17,7 +17,6 @@ class NAZARA_API NzTextureBackground : public NzAbstractBackground
public:
NzTextureBackground();
NzTextureBackground(NzTexture* texture);
~NzTextureBackground();
void Draw(const NzScene* scene) const;
@@ -27,7 +26,7 @@ class NAZARA_API NzTextureBackground : public NzAbstractBackground
void SetTexture(NzTexture* texture);
private:
NzShaderRef m_shader;
NzShaderConstRef m_shader;
NzTextureRef m_texture;
};

View File

@@ -43,7 +43,7 @@
#include <Nazara/Renderer/RenderTexture.hpp>
#include <Nazara/Renderer/RenderWindow.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderBuilder.hpp>
#include <Nazara/Renderer/ShaderManager.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>

View File

@@ -94,9 +94,11 @@ enum nzRendererCap
enum nzRendererClearFlags
{
nzRendererClear_Color = 0x01,
nzRendererClear_Depth = 0x02,
nzRendererClear_Stencil = 0x04
nzRendererClear_Color = 0x1,
nzRendererClear_Depth = 0x2,
nzRendererClear_Stencil = 0x4,
nzRendererClear_Max = nzRendererClear_Stencil*2-1
};
enum nzRendererComparison
@@ -155,17 +157,11 @@ enum nzShaderFlags
{
nzShaderFlags_None = 0,
nzShaderFlags_AlphaMapping = 0x001,
nzShaderFlags_AlphaTest = 0x002,
nzShaderFlags_Deferred = 0x004,
nzShaderFlags_DiffuseMapping = 0x008,
nzShaderFlags_EmissiveMapping = 0x010,
nzShaderFlags_FlipUVs = 0x020,
nzShaderFlags_Instancing = 0x040,
nzShaderFlags_Lighting = 0x080,
nzShaderFlags_NormalMapping = 0x100,
nzShaderFlags_ParallaxMapping = 0x200,
nzShaderFlags_SpecularMapping = 0x400
//nzShaderFlags_Deferred = 0x1,
nzShaderFlags_FlipUVs = 0x1,
nzShaderFlags_Instancing = 0x2,
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
};
enum nzShaderLanguage
@@ -178,11 +174,19 @@ enum nzShaderLanguage
nzShaderLanguage_Max = nzShaderLanguage_GLSL
};
enum nzShaderTarget
{
nzShaderTarget_FullscreenQuad,
nzShaderTarget_Model,
nzShaderTarget_None,
nzShaderTarget_Max = nzShaderTarget_None
};
enum nzShaderUniform
{
nzShaderUniform_CameraPosition,
nzShaderUniform_InvTargetSize,
nzShaderUniform_LightCount,
nzShaderUniform_MaterialAlphaMap,
nzShaderUniform_MaterialAlphaThreshold,
nzShaderUniform_MaterialAmbient,

View File

@@ -57,7 +57,6 @@ class NAZARA_API NzMaterial : public NzResource
NzTexture* GetAlphaMap() const;
float GetAlphaThreshold() const;
NzColor GetAmbientColor() const;
const NzShader* GetCustomShader() const;
nzRendererComparison GetDepthFunc() const;
NzColor GetDiffuseColor() const;
NzTexture* GetDiffuseMap() const;
@@ -70,7 +69,7 @@ class NAZARA_API NzMaterial : public NzResource
NzTexture* GetHeightMap() const;
NzTexture* GetNormalMap() const;
const NzRenderStates& GetRenderStates() const;
nzUInt32 GetShaderFlags() const;
const NzShader* GetShader(nzShaderTarget target, nzUInt32 flags) const;
float GetShininess() const;
NzColor GetSpecularColor() const;
NzTexture* GetSpecularMap() const;
@@ -78,10 +77,15 @@ class NAZARA_API NzMaterial : public NzResource
const NzTextureSampler& GetSpecularSampler() const;
nzBlendFunc GetSrcBlend() const;
bool HasCustomShader() const;
bool HasAlphaMap() const;
bool HasDiffuseMap() const;
bool HasEmissiveMap() const;
bool HasHeightMap() const;
bool HasNormalMap() const;
bool HasSpecularMap() const;
bool IsEnabled(nzRendererParameter renderParameter) const;
bool IsAlphaTestEnabled() const;
bool IsEnabled(nzRendererParameter renderParameter) const;
bool IsLightingEnabled() const;
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
@@ -94,7 +98,6 @@ class NAZARA_API NzMaterial : public NzResource
void SetAlphaMap(NzTexture* map);
void SetAlphaThreshold(float alphaThreshold);
void SetAmbientColor(const NzColor& ambient);
void SetCustomShader(const NzShader* shader);
void SetDepthFunc(nzRendererComparison depthFunc);
void SetDiffuseColor(const NzColor& diffuse);
bool SetDiffuseMap(const NzString& texturePath);
@@ -110,6 +113,7 @@ class NAZARA_API NzMaterial : public NzResource
bool SetNormalMap(const NzString& texturePath);
void SetNormalMap(NzTexture* map);
void SetRenderStates(const NzRenderStates& states);
void SetShader(nzShaderTarget target, nzUInt32 flags, const NzShader* shader);
void SetShininess(float shininess);
void SetSpecularColor(const NzColor& specular);
bool SetSpecularMap(const NzString& texturePath);
@@ -123,19 +127,26 @@ class NAZARA_API NzMaterial : public NzResource
static NzMaterial* GetDefault();
private:
struct ShaderUnit
{
NzShaderConstRef shader;
bool custom = false;
};
void Copy(const NzMaterial& material);
void GenerateShader(nzShaderTarget target, nzUInt32 flags) const;
void InvalidateShaders(nzShaderTarget target);
static bool Initialize();
static void Uninitialize();
nzUInt32 m_shaderFlags;
NzColor m_ambientColor;
NzColor m_diffuseColor;
NzColor m_specularColor;
NzRenderStates m_states;
mutable ShaderUnit m_shaders[nzShaderTarget_Max+1][nzShaderFlags_Max+1];
NzTextureSampler m_diffuseSampler;
NzTextureSampler m_specularSampler;
mutable NzShaderConstRef m_customShader;
NzTextureRef m_alphaMap;
NzTextureRef m_diffuseMap;
NzTextureRef m_emissiveMap;

View File

@@ -1,28 +0,0 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADERBUILDER_HPP
#define NAZARA_SHADERBUILDER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Shader.hpp>
class NAZARA_API NzShaderBuilder
{
friend class NzRenderer;
public:
NzShaderBuilder() = delete;
~NzShaderBuilder() = delete;
static const NzShader* Get(nzUInt32 flags);
private:
static bool Initialize();
static void Uninitialize();
};
#endif // NAZARA_SHADERBUILDER_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADERMANAGER_HPP
#define NAZARA_SHADERMANAGER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderManagerParams.hpp>
class NAZARA_API NzShaderManager
{
friend class NzRenderer;
public:
NzShaderManager() = delete;
~NzShaderManager() = delete;
static const NzShader* Get(const NzShaderManagerParams& params);
private:
static NzString BuildFragmentCode(const NzShaderManagerParams& params);
static NzString BuildVertexCode(const NzShaderManagerParams& params);
static NzShader* GenerateShader(const NzShaderManagerParams& params);
static bool Initialize();
static void Uninitialize();
};
#endif // NAZARA_SHADERMANAGER_HPP

View File

@@ -0,0 +1,43 @@
// Copyright (C) 2013 Jérôme Leclercq
// This file is part of the "Nazara Engine - Renderer module"
// For conditions of distribution and use, see copyright notice in Config.hpp
#pragma once
#ifndef NAZARA_SHADERMANAGERPARAMS_HPP
#define NAZARA_SHADERMANAGERPARAMS_HPP
#include <Nazara/Renderer/Enums.hpp>
struct NzShaderManagerParams
{
struct FullscreenQuad
{
bool alphaMapping;
bool alphaTest;
bool diffuseMapping;
};
struct Model
{
bool alphaMapping;
bool alphaTest;
bool diffuseMapping;
bool emissiveMapping;
bool lighting;
bool normalMapping;
bool parallaxMapping;
bool specularMapping;
};
nzShaderTarget target;
nzUInt32 flags;
union
{
FullscreenQuad fullscreenQuad;
Model model;
};
};
#endif // NAZARA_SHADERMANAGERPARAMS_HPP

View File

@@ -268,7 +268,8 @@ enum nzWindowStyleFlags
nzWindowStyle_Resizable = 0x4,
nzWindowStyle_Titlebar = 0x8,
nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar
nzWindowStyle_Default = nzWindowStyle_Closable | nzWindowStyle_Resizable | nzWindowStyle_Titlebar,
nzWindowStyle_Max = nzWindowStyle_Titlebar*2-1
};
#endif // NAZARA_ENUMS_UTILITY_HPP