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

@@ -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