Big UberShader update

-Added GRAPHICS_MAX_LIGHTPERPASS macro
-Added glGetActiveUniform OpenGL function
-Added (Uber)ShaderLibrary
-Added (Uber)ShaderName parameter to models
-Changed uniform system
-Fixed Node copying
-Moved Material class to Graphics module
-Optimized lights
-Remade Shader class
-Renamed Node::Invalidate to Node::InvalidateNode
-Renamed ShaderProgram to Shader


Former-commit-id: 15f0cad52969e91a2442e7d750ba2dc412f3549d
This commit is contained in:
Lynix
2014-02-21 19:27:39 +01:00
parent 4ee2ceaef0
commit 86bdab9055
147 changed files with 2693 additions and 4135 deletions

View File

@@ -41,7 +41,4 @@
// Active les tests de sécurité basés sur le code (Conseillé pour le développement)
#define NAZARA_RENDERER_SAFE 1
// Le nombre maximum de lumières qu'un forward shader supportera
#define NAZARA_RENDERER_SHADER_MAX_LIGHTCOUNT 8
#endif // NAZARA_CONFIG_MODULENAME_HPP

View File

@@ -185,27 +185,6 @@ enum nzSamplerWrap
nzSamplerWrap_Max = nzSamplerWrap_Repeat
};
enum nzShaderFlags
{
nzShaderFlags_None = 0,
nzShaderFlags_Deferred = 0x1,
nzShaderFlags_FlipUVs = 0x2,
nzShaderFlags_Instancing = 0x4,
nzShaderFlags_Max = nzShaderFlags_Instancing*2-1
};
enum nzShaderLanguage
{
nzShaderLanguage_Unknown = -1,
nzShaderLanguage_Cg,
nzShaderLanguage_GLSL,
nzShaderLanguage_Max = nzShaderLanguage_GLSL
};
enum nzShaderTarget
{
nzShaderTarget_FullscreenQuad,
@@ -226,21 +205,9 @@ enum nzShaderUniform
nzShaderUniform_InvWorldMatrix,
nzShaderUniform_InvWorldViewMatrix,
nzShaderUniform_InvWorldViewProjMatrix,
nzShaderUniform_MaterialAlphaMap,
nzShaderUniform_MaterialAlphaThreshold,
nzShaderUniform_MaterialAmbient,
nzShaderUniform_MaterialDiffuse,
nzShaderUniform_MaterialDiffuseMap,
nzShaderUniform_MaterialEmissiveMap,
nzShaderUniform_MaterialHeightMap,
nzShaderUniform_MaterialNormalMap,
nzShaderUniform_MaterialShininess,
nzShaderUniform_MaterialSpecular,
nzShaderUniform_MaterialSpecularMap,
nzShaderUniform_ProjMatrix,
nzShaderUniform_SceneAmbient,
nzShaderUniform_TargetSize,
nzShaderUniform_VertexDepth,
nzShaderUniform_ViewMatrix,
nzShaderUniform_ViewProjMatrix,
nzShaderUniform_WorldMatrix,
@@ -250,13 +217,13 @@ enum nzShaderUniform
nzShaderUniform_Max = nzShaderUniform_WorldViewProjMatrix
};
enum nzShaderType
enum nzShaderStage
{
nzShaderType_Fragment,
nzShaderType_Geometry,
nzShaderType_Vertex,
nzShaderStage_Fragment,
nzShaderStage_Geometry,
nzShaderStage_Vertex,
nzShaderType_Max = nzShaderType_Vertex
nzShaderStage_Max = nzShaderStage_Vertex
};
enum nzStencilOperation

View File

@@ -1,166 +0,0 @@
// Copyright (C) 2014 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_MATERIAL_HPP
#define NAZARA_MATERIAL_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceLoader.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/RenderStates.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/Texture.hpp>
#include <Nazara/Renderer/TextureSampler.hpp>
struct NAZARA_API NzMaterialParams
{
bool loadAlphaMap = true;
bool loadDiffuseMap = true;
bool loadEmissiveMap = true;
bool loadHeightMap = true;
bool loadNormalMap = true;
bool loadSpecularMap = true;
bool IsValid() const;
};
class NzMaterial;
using NzMaterialConstRef = NzResourceRef<const NzMaterial>;
using NzMaterialLoader = NzResourceLoader<NzMaterial, NzMaterialParams>;
using NzMaterialRef = NzResourceRef<NzMaterial>;
class NAZARA_API NzMaterial : public NzResource
{
friend NzMaterialLoader;
friend class NzRenderer;
public:
NzMaterial();
NzMaterial(const NzMaterial& material);
NzMaterial(NzMaterial&& material);
~NzMaterial();
void Apply(const NzShaderProgram* program) const;
void Enable(nzRendererParameter renderParameter, bool enable);
void EnableAlphaTest(bool alphaTest);
void EnableLighting(bool lighting);
NzTexture* GetAlphaMap() const;
float GetAlphaThreshold() const;
NzColor GetAmbientColor() const;
nzRendererComparison GetDepthFunc() const;
NzColor GetDiffuseColor() const;
NzTexture* GetDiffuseMap() const;
NzTextureSampler& GetDiffuseSampler();
const NzTextureSampler& GetDiffuseSampler() const;
nzBlendFunc GetDstBlend() const;
NzTexture* GetEmissiveMap() const;
nzFaceSide GetFaceCulling() const;
nzFaceFilling GetFaceFilling() const;
NzTexture* GetHeightMap() const;
NzTexture* GetNormalMap() const;
const NzRenderStates& GetRenderStates() const;
const NzShaderProgram* GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const;
float GetShininess() const;
NzColor GetSpecularColor() const;
NzTexture* GetSpecularMap() const;
NzTextureSampler& GetSpecularSampler();
const NzTextureSampler& GetSpecularSampler() const;
nzBlendFunc GetSrcBlend() const;
bool HasAlphaMap() const;
bool HasCustomShaderProgram(nzShaderTarget target, nzUInt32 flags) const;
bool HasDiffuseMap() const;
bool HasEmissiveMap() const;
bool HasHeightMap() const;
bool HasNormalMap() const;
bool HasSpecularMap() const;
bool IsAlphaTestEnabled() const;
bool IsEnabled(nzRendererParameter renderParameter) const;
bool IsLightingEnabled() const;
bool LoadFromFile(const NzString& filePath, const NzMaterialParams& params = NzMaterialParams());
bool LoadFromMemory(const void* data, std::size_t size, const NzMaterialParams& params = NzMaterialParams());
bool LoadFromStream(NzInputStream& stream, const NzMaterialParams& params = NzMaterialParams());
void Reset();
bool SetAlphaMap(const NzString& texturePath);
void SetAlphaMap(NzTexture* map);
void SetAlphaThreshold(float alphaThreshold);
void SetAmbientColor(const NzColor& ambient);
void SetDepthFunc(nzRendererComparison depthFunc);
void SetDiffuseColor(const NzColor& diffuse);
bool SetDiffuseMap(const NzString& texturePath);
void SetDiffuseMap(NzTexture* map);
void SetDiffuseSampler(const NzTextureSampler& sampler);
void SetDstBlend(nzBlendFunc func);
bool SetEmissiveMap(const NzString& texturePath);
void SetEmissiveMap(NzTexture* map);
void SetFaceCulling(nzFaceSide faceSide);
void SetFaceFilling(nzFaceFilling filling);
bool SetHeightMap(const NzString& texturePath);
void SetHeightMap(NzTexture* map);
bool SetNormalMap(const NzString& texturePath);
void SetNormalMap(NzTexture* map);
void SetRenderStates(const NzRenderStates& states);
void SetShaderProgram(nzShaderTarget target, nzUInt32 flags, const NzShaderProgram* program);
void SetShininess(float shininess);
void SetSpecularColor(const NzColor& specular);
bool SetSpecularMap(const NzString& texturePath);
void SetSpecularMap(NzTexture* map);
void SetSpecularSampler(const NzTextureSampler& sampler);
void SetSrcBlend(nzBlendFunc func);
NzMaterial& operator=(const NzMaterial& material);
NzMaterial& operator=(NzMaterial&& material);
static NzMaterial* GetDefault();
private:
struct ProgramUnit
{
NzShaderProgramConstRef program;
bool custom = false;
};
void Copy(const NzMaterial& material);
void GenerateProgram(nzShaderTarget target, nzUInt32 flags) const;
void InvalidatePrograms(nzShaderTarget target);
static bool Initialize();
static void Uninitialize();
NzColor m_ambientColor;
NzColor m_diffuseColor;
NzColor m_specularColor;
NzRenderStates m_states;
mutable ProgramUnit m_programs[nzShaderTarget_Max+1][nzShaderFlags_Max+1];
NzTextureSampler m_diffuseSampler;
NzTextureSampler m_specularSampler;
NzTextureRef m_alphaMap;
NzTextureRef m_diffuseMap;
NzTextureRef m_emissiveMap;
NzTextureRef m_heightMap;
NzTextureRef m_normalMap;
NzTextureRef m_specularMap;
bool m_alphaTestEnabled;
bool m_lightingEnabled;
float m_alphaThreshold;
float m_shininess;
static NzMaterial* s_defaultMaterial;
static NzMaterialLoader::LoaderList s_loaders;
};
#endif // NAZARA_MATERIAL_HPP

View File

@@ -140,15 +140,15 @@ class NAZARA_API NzOpenGL
static GLenum RendererComparison[nzRendererComparison_Max+1];
static GLenum RendererParameter[nzRendererParameter_Max+1];
static GLenum SamplerWrapMode[nzSamplerWrap_Max+1];
static GLenum ShaderType[nzShaderType_Max+1];
static GLenum ShaderStage[nzShaderStage_Max+1];
static GLenum StencilOperation[nzStencilOperation_Max+1];
static GLenum TextureTarget[nzImageType_Max+1];
static GLenum TextureTargetBinding[nzImageType_Max+1];
static GLenum TextureTargetProxy[nzImageType_Max+1];
private:
static void OnContextDestruction(const NzContext* context);
static void OnContextChange(const NzContext* newContext);
static void OnContextDestruction(const NzContext* context);
};
NAZARA_API extern PFNGLACTIVETEXTUREPROC glActiveTexture;
@@ -221,6 +221,7 @@ NAZARA_API extern PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
NAZARA_API extern PFNGLGENSAMPLERSPROC glGenSamplers;
NAZARA_API extern PFNGLGENTEXTURESPROC glGenTextures;
NAZARA_API extern PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
NAZARA_API extern PFNGLGETACTIVEUNIFORMPROC glGetActiveUniform;
NAZARA_API extern PFNGLGETBOOLEANVPROC glGetBooleanv;
NAZARA_API extern PFNGLGETBUFFERPARAMETERIVPROC glGetBufferParameteriv;
NAZARA_API extern PFNGLGETDEBUGMESSAGELOGPROC glGetDebugMessageLog;

View File

@@ -21,15 +21,13 @@
class NzColor;
class NzContext;
class NzIndexBuffer;
class NzMaterial;
class NzRenderTarget;
class NzShaderProgram;
class NzShader;
class NzTexture;
class NzVertexBuffer;
class NAZARA_API NzRenderer
{
friend NzShaderProgram;
friend NzTexture;
public:
@@ -64,7 +62,7 @@ class NAZARA_API NzRenderer
static float GetPointSize();
static const NzRenderStates& GetRenderStates();
static NzRecti GetScissorRect();
static const NzShaderProgram* GetShaderProgram();
static const NzShader* GetShader();
static const NzRenderTarget* GetTarget();
static NzRecti GetViewport();
@@ -89,7 +87,7 @@ class NAZARA_API NzRenderer
static void SetPointSize(float size);
static void SetRenderStates(const NzRenderStates& states);
static void SetScissorRect(const NzRecti& rect);
static void SetShaderProgram(const NzShaderProgram* shader);
static void SetShader(const NzShader* shader);
static void SetStencilCompareFunction(nzRendererComparison compareFunc, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
static void SetStencilFailOperation(nzStencilOperation failOperation, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
static void SetStencilMask(nzUInt32 mask, nzFaceSide faceSide = nzFaceSide_FrontAndBack);
@@ -107,7 +105,7 @@ class NAZARA_API NzRenderer
private:
static void EnableInstancing(bool instancing);
static bool EnsureStateUpdate();
static void OnProgramReleased(const NzShaderProgram* program);
static void OnShaderReleased(const NzShader* shader);
static void OnTextureReleased(const NzTexture* texture);
static void UpdateMatrix(nzMatrixType type);

View File

@@ -0,0 +1,110 @@
// Copyright (C) 2014 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_SHADER_HPP
#define NAZARA_SHADER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Enums.hpp>
class NzShader;
class NzShaderStage;
using NzShaderConstRef = NzResourceRef<const NzShader>;
using NzShaderRef = NzResourceRef<NzShader>;
class NAZARA_API NzShader : public NzResource, NzNonCopyable
{
friend class NzRenderer;
public:
NzShader();
NzShader(NzShader&& shader);
~NzShader();
void AttachStage(nzShaderStage stage, const NzShaderStage& shaderStage);
bool AttachStageFromFile(nzShaderStage stage, const NzString& filePath);
bool AttachStageFromSource(nzShaderStage stage, const char* source, unsigned int length);
bool AttachStageFromSource(nzShaderStage stage, const NzString& source);
void Bind() const;
bool Create();
void Destroy();
NzByteArray GetBinary() const;
NzString GetLog() const;
NzString GetSourceCode(nzShaderStage stage) const;
int GetUniformLocation(const NzString& name) const;
int GetUniformLocation(nzShaderUniform shaderUniform) const;
bool HasStage(nzShaderStage stage) const;
bool IsBinaryRetrievable() const;
bool IsLinked() const;
bool IsValid() const;
bool Link();
bool LoadFromBinary(const void* buffer, unsigned int size);
bool LoadFromBinary(const NzByteArray& byteArray);
void SendBoolean(int location, bool value) const;
void SendColor(int location, const NzColor& color) const;
void SendDouble(int location, double value) const;
void SendDoubleArray(int location, const double* values, unsigned int count) const;
void SendFloat(int location, float value) const;
void SendFloatArray(int location, const float* values, unsigned int count) const;
void SendInteger(int location, int value) const;
void SendIntegerArray(int location, const int* values, unsigned int count) const;
void SendMatrix(int location, const NzMatrix4d& matrix) const;
void SendMatrix(int location, const NzMatrix4f& matrix) const;
void SendVector(int location, const NzVector2d& vector) const;
void SendVector(int location, const NzVector2f& vector) const;
void SendVector(int location, const NzVector2i& vector) const;
void SendVector(int location, const NzVector3d& vector) const;
void SendVector(int location, const NzVector3f& vector) const;
void SendVector(int location, const NzVector3i& vector) const;
void SendVector(int location, const NzVector4d& vector) const;
void SendVector(int location, const NzVector4f& vector) const;
void SendVector(int location, const NzVector4i& vector) const;
void SendVectorArray(int location, const NzVector2d* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector2f* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector2i* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector3d* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector3f* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector3i* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector4d* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector4f* vectors, unsigned int count) const;
void SendVectorArray(int location, const NzVector4i* vectors, unsigned int count) const;
// Fonctions OpenGL
unsigned int GetOpenGLID() const;
NzShader& operator=(NzShader&& shader);
static bool IsStageSupported(nzShaderStage stage);
private:
bool PostLinkage();
std::vector<unsigned int> m_attachedShaders[nzShaderStage_Max+1];
bool m_linked;
int m_uniformLocations[nzShaderUniform_Max+1];
unsigned int m_program;
};
#endif // NAZARA_SHADER_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2014 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_SHADERLIBRARY_HPP
#define NAZARA_SHADERLIBRARY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <unordered_map>
class NAZARA_API NzShaderLibrary
{
public:
NzShaderLibrary() = delete;
~NzShaderLibrary() = delete;
static NzShader* Get(const NzString& name);
static bool Has(const NzString& name);
static bool Initialize();
static void Register(const NzString& name, NzShader* shader);
static void Uninitialize();
static void Unregister(const NzString& name);
private:
static std::unordered_map<NzString, NzShaderRef> s_library;
};
#endif // NAZARA_SHADERLIBRARY_HPP

View File

@@ -1,109 +0,0 @@
// Copyright (C) 2014 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_SHADERPROGRAM_HPP
#define NAZARA_SHADERPROGRAM_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ByteArray.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Math/Matrix4.hpp>
#include <Nazara/Math/Vector2.hpp>
#include <Nazara/Math/Vector3.hpp>
#include <Nazara/Math/Vector4.hpp>
#include <Nazara/Renderer/Enums.hpp>
class NzShaderProgram;
using NzShaderProgramConstRef = NzResourceRef<const NzShaderProgram>;
using NzShaderProgramRef = NzResourceRef<NzShaderProgram>;
class NzAbstractShaderProgram;
class NzTexture;
class NAZARA_API NzShaderProgram : public NzResource, NzNonCopyable
{
friend class NzRenderer;
public:
NzShaderProgram();
NzShaderProgram(nzShaderLanguage language);
NzShaderProgram(NzShaderProgram&& shader);
~NzShaderProgram();
bool Create(nzShaderLanguage language);
bool Compile();
void Destroy();
NzByteArray GetBinary() const;
nzUInt32 GetFlags() const;
NzString GetLog() const;
nzShaderLanguage GetLanguage() const;
NzString GetSourceCode(nzShaderType type) const;
int GetUniformLocation(const NzString& name) const;
int GetUniformLocation(nzShaderUniform uniform) const;
bool HasUniform(const NzString& name) const;
bool IsBinaryRetrievable() const;
bool IsCompiled() const;
bool IsLoaded(nzShaderType type) const;
bool IsValid() const;
bool LoadFromBinary(const void* buffer, unsigned int size);
bool LoadFromBinary(const NzByteArray& byteArray);
bool LoadShader(nzShaderType type, const NzString& source);
bool LoadShaderFromFile(nzShaderType type, const NzString& filePath);
bool SendBoolean(int location, bool value) const;
bool SendColor(int location, const NzColor& color) const;
bool SendDouble(int location, double value) const;
bool SendDoubleArray(int location, const double* values, unsigned int count) const;
bool SendFloat(int location, float value) const;
bool SendFloatArray(int location, const float* values, unsigned int count) const;
bool SendInteger(int location, int value) const;
bool SendIntegerArray(int location, const int* values, unsigned int count) const;
bool SendMatrix(int location, const NzMatrix4d& matrix) const;
bool SendMatrix(int location, const NzMatrix4f& matrix) const;
bool SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit = nullptr) const;
bool SendVector(int location, const NzVector2d& vector) const;
bool SendVector(int location, const NzVector2f& vector) const;
bool SendVector(int location, const NzVector2i& vector) const;
bool SendVector(int location, const NzVector3d& vector) const;
bool SendVector(int location, const NzVector3f& vector) const;
bool SendVector(int location, const NzVector3i& vector) const;
bool SendVector(int location, const NzVector4d& vector) const;
bool SendVector(int location, const NzVector4f& vector) const;
bool SendVector(int location, const NzVector4i& vector) const;
bool SendVectorArray(int location, const NzVector2d* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector2f* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector2i* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector3d* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector3f* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector3i* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector4d* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector4f* vectors, unsigned int count) const;
bool SendVectorArray(int location, const NzVector4i* vectors, unsigned int count) const;
void SetFlags(nzUInt32 flags);
NzShaderProgram& operator=(NzShaderProgram&& shader);
static bool IsLanguageSupported(nzShaderLanguage language);
static bool IsShaderTypeSupported(nzShaderType type);
private:
nzUInt32 m_flags;
NzAbstractShaderProgram* m_impl;
bool m_compiled;
};
#endif // NAZARA_SHADERPROGRAM_HPP

View File

@@ -1,33 +0,0 @@
// Copyright (C) 2014 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_SHADERPROGRAMMANAGER_HPP
#define NAZARA_SHADERPROGRAMMANAGER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/ShaderProgramManagerParams.hpp>
class NAZARA_API NzShaderProgramManager
{
friend class NzRenderer;
public:
NzShaderProgramManager() = delete;
~NzShaderProgramManager() = delete;
static const NzShaderProgram* Get(const NzShaderProgramManagerParams& params);
private:
static NzString BuildFragmentCode(const NzShaderProgramManagerParams& params);
static NzString BuildVertexCode(const NzShaderProgramManagerParams& params);
static NzShaderProgram* GenerateProgram(const NzShaderProgramManagerParams& params);
static bool Initialize();
static void Uninitialize();
};
#endif // NAZARA_SHADERPROGRAMMANAGER_HPP

View File

@@ -1,51 +0,0 @@
// Copyright (C) 2014 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_SHADERPROGRAMMANAGERPARAMS_HPP
#define NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP
#include <Nazara/Renderer/Enums.hpp>
struct NzShaderProgramManagerParams
{
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;
};
struct Sprite
{
bool alphaMapping;
bool alphaTest;
bool diffuseMapping;
};
nzShaderTarget target;
nzUInt32 flags;
union
{
FullscreenQuad fullscreenQuad;
Model model;
Sprite sprite;
};
};
#endif // NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP

View File

@@ -0,0 +1,51 @@
// Copyright (C) 2014 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_SHADERSTAGE_HPP
#define NAZARA_SHADERSTAGE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/NonCopyable.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Renderer/Enums.hpp>
class NAZARA_API NzShaderStage : NzNonCopyable
{
public:
NzShaderStage();
NzShaderStage(nzShaderStage stage);
NzShaderStage(NzShaderStage&& stage);
~NzShaderStage();
bool Compile();
bool Create(nzShaderStage stage);
void Destroy();
NzString GetLog() const;
NzString GetSource() const;
bool IsCompiled() const;
bool IsValid() const;
void SetSource(const char* source, unsigned int length);
void SetSource(const NzString& source);
bool SetSourceFromFile(const NzString& filePath);
NzShaderStage& operator=(NzShaderStage&& shader);
// Fonctions OpenGL
unsigned int GetOpenGLID() const;
static bool IsSupported(nzShaderStage stage);
private:
nzShaderStage m_stage;
bool m_compiled;
unsigned int m_id;
};
#endif // NAZARA_SHADERSTAGE_HPP

View File

@@ -0,0 +1,31 @@
// Copyright (C) 2014 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_UBERSHADER_HPP
#define NAZARA_UBERSHADER_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/ParameterList.hpp>
#include <Nazara/Core/Resource.hpp>
#include <Nazara/Core/ResourceRef.hpp>
#include <Nazara/Renderer/UberShaderInstance.hpp>
#include <unordered_map>
class NzUberShader;
using NzUberShaderConstRef = NzResourceRef<const NzUberShader>;
using NzUberShaderRef = NzResourceRef<NzUberShader>;
class NAZARA_API NzUberShader : public NzResource
{
public:
NzUberShader() = default;
virtual ~NzUberShader();
virtual NzUberShaderInstance* Get(const NzParameterList& parameters) const = 0;
};
#endif // NAZARA_UBERSHADER_HPP

View File

@@ -0,0 +1,27 @@
// Copyright (C) 2014 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_UBERSHADERINSTANCE_HPP
#define NAZARA_UBERSHADERINSTANCE_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Shader.hpp>
class NAZARA_API NzUberShaderInstance
{
public:
NzUberShaderInstance(const NzShader* shader);
virtual ~NzUberShaderInstance();
virtual bool Activate() const = 0;
const NzShader* GetShader() const;
protected:
NzShaderConstRef m_shader;
};
#endif // NAZARA_UBERSHADERINSTANCE_HPP

View File

@@ -0,0 +1,22 @@
// Copyright (C) 2014 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_UBERSHADERINSTANCEPREPROCESSOR_HPP
#define NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/UberShaderInstance.hpp>
class NAZARA_API NzUberShaderInstancePreprocessor : public NzUberShaderInstance
{
public:
NzUberShaderInstancePreprocessor(const NzShader* shader);
virtual ~NzUberShaderInstancePreprocessor();
bool Activate() const;
};
#endif // NAZARA_UBERSHADERINSTANCEPREPROCESSOR_HPP

View File

@@ -0,0 +1,33 @@
// Copyright (C) 2014 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_UBERSHADERLIBRARY_HPP
#define NAZARA_UBERSHADERLIBRARY_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Core/String.hpp>
#include <Nazara/Renderer/UberShader.hpp>
#include <unordered_map>
class NAZARA_API NzUberShaderLibrary
{
public:
NzUberShaderLibrary() = delete;
~NzUberShaderLibrary() = delete;
static NzUberShader* Get(const NzString& name);
static bool Has(const NzString& name);
static bool Initialize();
static void Register(const NzString& name, NzUberShader* uberShader);
static void Uninitialize();
static void Unregister(const NzString& name);
private:
static std::unordered_map<NzString, NzUberShaderRef> s_library;
};
#endif // NAZARA_UBERSHADERLIBRARY_HPP

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2014 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_UBERSHADERPREPROCESSOR_HPP
#define NAZARA_UBERSHADERPREPROCESSOR_HPP
#include <Nazara/Prerequesites.hpp>
#include <Nazara/Renderer/Enums.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderStage.hpp>
#include <Nazara/Renderer/UberShader.hpp>
#include <Nazara/Renderer/UberShaderInstancePreprocessor.hpp>
#include <unordered_map>
class NAZARA_API NzUberShaderPreprocessor : public NzUberShader
{
public:
NzUberShaderPreprocessor() = default;
~NzUberShaderPreprocessor() = default;
NzUberShaderInstance* Get(const NzParameterList& parameters) const;
void SetShader(nzShaderStage stage, const NzString& source, const NzString& flags);
bool SetShaderFromFile(nzShaderStage stage, const NzString& filePath, const NzString& flags);
static bool IsSupported();
private:
struct Shader
{
mutable std::unordered_map<nzUInt32, NzShaderStage> cache;
std::unordered_map<NzString, nzUInt32> flags;
NzString source;
bool present = false;
};
mutable std::unordered_map<nzUInt32, NzUberShaderInstancePreprocessor> m_cache;
std::unordered_map<NzString, nzUInt32> m_flags;
Shader m_shaders[nzShaderStage_Max+1];
};
#endif // NAZARA_UBERSHADERPREPROCESSOR_HPP