diff --git a/include/Nazara/Graphics/ColorBackground.hpp b/include/Nazara/Graphics/ColorBackground.hpp index 71e8891f8..bcb4468ff 100644 --- a/include/Nazara/Graphics/ColorBackground.hpp +++ b/include/Nazara/Graphics/ColorBackground.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include class NAZARA_API NzColorBackground : public NzAbstractBackground { @@ -26,7 +26,7 @@ class NAZARA_API NzColorBackground : public NzAbstractBackground private: NzColor m_color; - NzShaderConstRef m_shader; + NzShaderProgramConstRef m_program; }; #endif // NAZARA_COLORBACKGROUND_HPP diff --git a/include/Nazara/Graphics/Light.hpp b/include/Nazara/Graphics/Light.hpp index 5da646872..f0ba6a909 100644 --- a/include/Nazara/Graphics/Light.hpp +++ b/include/Nazara/Graphics/Light.hpp @@ -12,7 +12,7 @@ #include #include -class NzShader; +class NzShaderProgram; class NAZARA_API NzLight : public NzSceneNode { @@ -23,7 +23,7 @@ class NAZARA_API NzLight : public NzSceneNode void AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const override; - void Enable(const NzShader* shader, unsigned int lightUnit) const; + void Enable(const NzShaderProgram* program, unsigned int lightUnit) const; NzColor GetAmbientColor() const; float GetAttenuation() const; @@ -46,7 +46,7 @@ class NAZARA_API NzLight : public NzSceneNode NzLight& operator=(const NzLight& light); - static void Disable(const NzShader* shader, unsigned int lightUnit); + static void Disable(const NzShaderProgram* program, unsigned int lightUnit); private: void Invalidate(); diff --git a/include/Nazara/Graphics/SkyboxBackground.hpp b/include/Nazara/Graphics/SkyboxBackground.hpp index 5e02e58b4..3e63178f8 100644 --- a/include/Nazara/Graphics/SkyboxBackground.hpp +++ b/include/Nazara/Graphics/SkyboxBackground.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include #include @@ -35,7 +35,7 @@ class NAZARA_API NzSkyboxBackground : public NzAbstractBackground NzTextureRef m_texture; NzTextureSampler m_sampler; NzIndexBufferRef m_indexBuffer; - NzShaderRef m_shader; + NzShaderProgramRef m_program; NzVertexBufferRef m_vertexBuffer; }; diff --git a/include/Nazara/Graphics/TextureBackground.hpp b/include/Nazara/Graphics/TextureBackground.hpp index 17d5f86c3..f703b024c 100644 --- a/include/Nazara/Graphics/TextureBackground.hpp +++ b/include/Nazara/Graphics/TextureBackground.hpp @@ -9,7 +9,7 @@ #include #include -#include +#include #include class NAZARA_API NzTextureBackground : public NzAbstractBackground @@ -26,7 +26,7 @@ class NAZARA_API NzTextureBackground : public NzAbstractBackground void SetTexture(NzTexture* texture); private: - NzShaderConstRef m_shader; + NzShaderProgramConstRef m_program; NzTextureRef m_texture; }; diff --git a/include/Nazara/Renderer.hpp b/include/Nazara/Renderer.hpp index f227e2600..2c9cb8354 100644 --- a/include/Nazara/Renderer.hpp +++ b/include/Nazara/Renderer.hpp @@ -42,8 +42,8 @@ #include #include #include -#include -#include +#include +#include #include #include diff --git a/include/Nazara/Renderer/Material.hpp b/include/Nazara/Renderer/Material.hpp index fda3ec1bc..492b66d7f 100644 --- a/include/Nazara/Renderer/Material.hpp +++ b/include/Nazara/Renderer/Material.hpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -48,7 +48,7 @@ class NAZARA_API NzMaterial : public NzResource NzMaterial(NzMaterial&& material); ~NzMaterial() = default; - void Apply(const NzShader* shader) const; + void Apply(const NzShaderProgram* program) const; void Enable(nzRendererParameter renderParameter, bool enable); void EnableAlphaTest(bool alphaTest); @@ -69,7 +69,7 @@ class NAZARA_API NzMaterial : public NzResource NzTexture* GetHeightMap() const; NzTexture* GetNormalMap() const; const NzRenderStates& GetRenderStates() const; - const NzShader* GetShader(nzShaderTarget target, nzUInt32 flags) const; + const NzShaderProgram* GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const; float GetShininess() const; NzColor GetSpecularColor() const; NzTexture* GetSpecularMap() const; @@ -113,7 +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 SetShaderProgram(nzShaderTarget target, nzUInt32 flags, const NzShaderProgram* program); void SetShininess(float shininess); void SetSpecularColor(const NzColor& specular); bool SetSpecularMap(const NzString& texturePath); @@ -127,15 +127,15 @@ class NAZARA_API NzMaterial : public NzResource static NzMaterial* GetDefault(); private: - struct ShaderUnit + struct ProgramUnit { - NzShaderConstRef shader; + NzShaderProgramConstRef program; bool custom = false; }; void Copy(const NzMaterial& material); - void GenerateShader(nzShaderTarget target, nzUInt32 flags) const; - void InvalidateShaders(nzShaderTarget target); + void GenerateProgram(nzShaderTarget target, nzUInt32 flags) const; + void InvalidatePrograms(nzShaderTarget target); static bool Initialize(); static void Uninitialize(); @@ -144,7 +144,7 @@ class NAZARA_API NzMaterial : public NzResource NzColor m_diffuseColor; NzColor m_specularColor; NzRenderStates m_states; - mutable ShaderUnit m_shaders[nzShaderTarget_Max+1][nzShaderFlags_Max+1]; + mutable ProgramUnit m_programs[nzShaderTarget_Max+1][nzShaderFlags_Max+1]; NzTextureSampler m_diffuseSampler; NzTextureSampler m_specularSampler; NzTextureRef m_alphaMap; diff --git a/include/Nazara/Renderer/Renderer.hpp b/include/Nazara/Renderer/Renderer.hpp index 470337066..856175598 100644 --- a/include/Nazara/Renderer/Renderer.hpp +++ b/include/Nazara/Renderer/Renderer.hpp @@ -22,7 +22,7 @@ class NzContext; class NzIndexBuffer; class NzMaterial; class NzRenderTarget; -class NzShader; +class NzShaderProgram; class NzVertexBuffer; class NAZARA_API NzRenderer @@ -52,7 +52,7 @@ class NAZARA_API NzRenderer static float GetPointSize(); static const NzRenderStates& GetRenderStates(); static NzRectui GetScissorRect(); - static const NzShader* GetShader(); + static const NzShaderProgram* GetShaderProgram(); static const NzRenderTarget* GetTarget(); static NzRectui GetViewport(); @@ -79,7 +79,7 @@ class NAZARA_API NzRenderer static void SetPointSize(float size); static void SetRenderStates(const NzRenderStates& states); static void SetScissorRect(const NzRectui& viewport); - static void SetShader(const NzShader* shader); + static void SetShaderProgram(const NzShaderProgram* shader); static void SetStencilCompareFunction(nzRendererComparison compareFunc); static void SetStencilFailOperation(nzStencilOperation failOperation); static void SetStencilMask(nzUInt32 mask); diff --git a/include/Nazara/Renderer/ShaderManager.hpp b/include/Nazara/Renderer/ShaderManager.hpp deleted file mode 100644 index e4adae798..000000000 --- a/include/Nazara/Renderer/ShaderManager.hpp +++ /dev/null @@ -1,33 +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_SHADERMANAGER_HPP -#define NAZARA_SHADERMANAGER_HPP - -#include -#include -#include - -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 diff --git a/include/Nazara/Renderer/Shader.hpp b/include/Nazara/Renderer/ShaderProgram.hpp similarity index 74% rename from include/Nazara/Renderer/Shader.hpp rename to include/Nazara/Renderer/ShaderProgram.hpp index 5ade91d74..828d4d4ea 100644 --- a/include/Nazara/Renderer/Shader.hpp +++ b/include/Nazara/Renderer/ShaderProgram.hpp @@ -4,8 +4,8 @@ #pragma once -#ifndef NAZARA_SHADER_HPP -#define NAZARA_SHADER_HPP +#ifndef NAZARA_SHADERPROGRAM_HPP +#define NAZARA_SHADERPROGRAM_HPP #include #include @@ -20,23 +20,23 @@ #include #include -class NzShader; +class NzShaderProgram; -using NzShaderConstRef = NzResourceRef; -using NzShaderRef = NzResourceRef; +using NzShaderProgramConstRef = NzResourceRef; +using NzShaderProgramRef = NzResourceRef; -class NzAbstractShader; +class NzAbstractShaderProgram; class NzTexture; -class NAZARA_API NzShader : public NzResource, NzNonCopyable +class NAZARA_API NzShaderProgram : public NzResource, NzNonCopyable { friend class NzRenderer; public: - NzShader(); - NzShader(nzShaderLanguage language); - NzShader(NzShader&& shader); - ~NzShader(); + NzShaderProgram(); + NzShaderProgram(nzShaderLanguage language); + NzShaderProgram(NzShaderProgram&& shader); + ~NzShaderProgram(); bool Create(nzShaderLanguage language); bool Compile(); @@ -58,8 +58,8 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable bool IsLoaded(nzShaderType type) const; bool IsValid() const; - bool Load(nzShaderType type, const NzString& source); - bool LoadFromFile(nzShaderType type, const NzString& source); + bool LoadShader(nzShaderType type, const NzString& source); + bool LoadShaderFromFile(nzShaderType type, const NzString& source); bool SendBoolean(int location, bool value) const; bool SendColor(int location, const NzColor& color) const; @@ -78,15 +78,15 @@ class NAZARA_API NzShader : public NzResource, NzNonCopyable void SetFlags(nzUInt32 flags); - NzShader& operator=(NzShader&& shader); + NzShaderProgram& operator=(NzShaderProgram&& shader); static bool IsLanguageSupported(nzShaderLanguage language); - static bool IsTypeSupported(nzShaderType type); + static bool IsShaderTypeSupported(nzShaderType type); private: nzUInt32 m_flags; - NzAbstractShader* m_impl; + NzAbstractShaderProgram* m_impl; bool m_compiled; }; -#endif // NAZARA_SHADER_HPP +#endif // NAZARA_SHADERPROGRAM_HPP diff --git a/include/Nazara/Renderer/ShaderProgramManager.hpp b/include/Nazara/Renderer/ShaderProgramManager.hpp new file mode 100644 index 000000000..2f9431186 --- /dev/null +++ b/include/Nazara/Renderer/ShaderProgramManager.hpp @@ -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_SHADERPROGRAMMANAGER_HPP +#define NAZARA_SHADERPROGRAMMANAGER_HPP + +#include +#include +#include + +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 diff --git a/include/Nazara/Renderer/ShaderManagerParams.hpp b/include/Nazara/Renderer/ShaderProgramManagerParams.hpp similarity index 78% rename from include/Nazara/Renderer/ShaderManagerParams.hpp rename to include/Nazara/Renderer/ShaderProgramManagerParams.hpp index e31a1e750..e0b0214e8 100644 --- a/include/Nazara/Renderer/ShaderManagerParams.hpp +++ b/include/Nazara/Renderer/ShaderProgramManagerParams.hpp @@ -4,12 +4,12 @@ #pragma once -#ifndef NAZARA_SHADERMANAGERPARAMS_HPP -#define NAZARA_SHADERMANAGERPARAMS_HPP +#ifndef NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP +#define NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP #include -struct NzShaderManagerParams +struct NzShaderProgramManagerParams { struct FullscreenQuad { @@ -40,4 +40,4 @@ struct NzShaderManagerParams }; }; -#endif // NAZARA_SHADERMANAGERPARAMS_HPP +#endif // NAZARA_SHADERPROGRAMMANAGERPARAMS_HPP diff --git a/include/Nazara/Renderer/Texture.hpp b/include/Nazara/Renderer/Texture.hpp index f69f11ffe..5920e9e70 100644 --- a/include/Nazara/Renderer/Texture.hpp +++ b/include/Nazara/Renderer/Texture.hpp @@ -27,7 +27,6 @@ struct NzTextureImpl; class NAZARA_API NzTexture : public NzResource, NzNonCopyable { friend NzRenderTexture; - friend class NzShader; public: NzTexture() = default; diff --git a/src/Nazara/Graphics/ColorBackground.cpp b/src/Nazara/Graphics/ColorBackground.cpp index 9997d9c99..fa2775e95 100644 --- a/src/Nazara/Graphics/ColorBackground.cpp +++ b/src/Nazara/Graphics/ColorBackground.cpp @@ -4,21 +4,21 @@ #include #include -#include +#include #include #include NzColorBackground::NzColorBackground(const NzColor& color) : m_color(color) { - NzShaderManagerParams params; + NzShaderProgramManagerParams params; params.target = nzShaderTarget_FullscreenQuad; params.flags = 0; params.fullscreenQuad.alphaMapping = false; params.fullscreenQuad.alphaTest = false; params.fullscreenQuad.diffuseMapping = false; - m_shader = NzShaderManager::Get(params); + m_program = NzShaderProgramManager::Get(params); } void NzColorBackground::Draw(const NzScene* scene) const @@ -27,10 +27,10 @@ void NzColorBackground::Draw(const NzScene* scene) const static NzRenderStates states; - m_shader->SendColor(m_shader->GetUniformLocation(nzShaderUniform_MaterialDiffuse), m_color); + m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), m_color); NzRenderer::SetRenderStates(states); - NzRenderer::SetShader(m_shader); + NzRenderer::SetShaderProgram(m_program); NzRenderer::DrawFullscreenQuad(); } diff --git a/src/Nazara/Graphics/ForwardRenderQueue.cpp b/src/Nazara/Graphics/ForwardRenderQueue.cpp index df6f9c3bc..53e00c3b2 100644 --- a/src/Nazara/Graphics/ForwardRenderQueue.cpp +++ b/src/Nazara/Graphics/ForwardRenderQueue.cpp @@ -269,11 +269,11 @@ bool NzForwardRenderQueue::ModelMaterialComparator::operator()(const NzMaterial* ///TODO: Comparaison des shaders for (unsigned int i = 0; i <= nzShaderFlags_Max; ++i) { - const NzShader* shader1 = mat1->GetShader(nzShaderTarget_Model, i); - const NzShader* shader2 = mat2->GetShader(nzShaderTarget_Model, i); + const NzShaderProgram* program1 = mat1->GetShaderProgram(nzShaderTarget_Model, i); + const NzShaderProgram* program2 = mat2->GetShaderProgram(nzShaderTarget_Model, i); - if (shader1 != shader2) - return shader1 < shader2; + if (program1 != program2) + return program1 < program2; } const NzTexture* diffuseMap1 = mat1->GetDiffuseMap(); diff --git a/src/Nazara/Graphics/ForwardRenderTechnique.cpp b/src/Nazara/Graphics/ForwardRenderTechnique.cpp index 85ece8ba5..d875ac3a5 100644 --- a/src/Nazara/Graphics/ForwardRenderTechnique.cpp +++ b/src/Nazara/Graphics/ForwardRenderTechnique.cpp @@ -138,7 +138,7 @@ void NzForwardRenderTechnique::Draw(const NzScene* scene) LightManager lightManager; const NzCamera* camera = scene->GetActiveCamera(); - const NzShader* lastShader = nullptr; + const NzShaderProgram* lastProgram = nullptr; // Rendu des modèles opaques for (auto& matIt : m_renderQueue.opaqueModels) @@ -150,30 +150,30 @@ void NzForwardRenderTechnique::Draw(const NzScene* scene) { const NzMaterial* material = matIt.first; - // On commence par récupérer le shader du matériau - const NzShader* shader = material->GetShader(nzShaderTarget_Model, 0); + // On commence par récupérer le programme du matériau + const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, 0); unsigned int lightCount = 0; - // Les uniformes sont conservées au sein du shader, inutile de les renvoyer tant que le shader reste le même - if (shader != lastShader) + // Les uniformes sont conservées au sein d'un programme, inutile de les renvoyer tant qu'il ne change pas + if (program != lastProgram) { - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); // Couleur ambiante de la scène - shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor()); + program->SendColor(program->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor()); // Position de la caméra - shader->SendVector(shader->GetUniformLocation(nzShaderUniform_CameraPosition), camera->GetPosition()); + program->SendVector(program->GetUniformLocation(nzShaderUniform_CameraPosition), camera->GetPosition()); // On envoie les lumières directionnelles s'il y a (Les mêmes pour tous) lightCount = m_renderQueue.directionnalLights.size(); for (unsigned int i = 0; i < lightCount; ++i) - m_renderQueue.directionnalLights[i]->Enable(shader, i); + m_renderQueue.directionnalLights[i]->Enable(program, i); - lastShader = shader; + lastProgram = program; } - material->Apply(shader); + material->Apply(program); // Meshs squelettiques /*if (!skeletalContainer.empty()) @@ -223,11 +223,11 @@ void NzForwardRenderTechnique::Draw(const NzScene* scene) count -= lightCount; for (unsigned int i = 0; i < count; ++i) - lightManager.GetLight(i)->Enable(shader, lightCount++); + lightManager.GetLight(i)->Enable(program, lightCount++); } for (unsigned int i = lightCount; i < 3; ++i) ///TODO: Constante sur le nombre maximum de lumières - NzLight::Disable(shader, i); + NzLight::Disable(program, i); NzRenderer::SetMatrix(nzMatrixType_World, data.transformMatrix); drawFunc(mesh->GetPrimitiveMode(), 0, indexCount); @@ -246,29 +246,29 @@ void NzForwardRenderTechnique::Draw(const NzScene* scene) m_renderQueue.transparentSkeletalModels[pair.first].material; // On commence par récupérer le shader du matériau - const NzShader* shader = material->GetShader(nzShaderTarget_Model, 0); + const NzShaderProgram* program = material->GetShaderProgram(nzShaderTarget_Model, 0); unsigned int lightCount = 0; // Les uniformes sont conservées au sein du shader, inutile de les renvoyer tant que le shader reste le même - if (shader != lastShader) + if (program != lastProgram) { - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); // Couleur ambiante de la scène - shader->SendColor(shader->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor()); + program->SendColor(program->GetUniformLocation(nzShaderUniform_SceneAmbient), scene->GetAmbientColor()); // Position de la caméra - shader->SendVector(shader->GetUniformLocation(nzShaderUniform_CameraPosition), camera->GetPosition()); + program->SendVector(program->GetUniformLocation(nzShaderUniform_CameraPosition), camera->GetPosition()); // On envoie les lumières directionnelles s'il y a (Les mêmes pour tous) lightCount = m_renderQueue.directionnalLights.size(); for (unsigned int i = 0; i < lightCount; ++i) - m_renderQueue.directionnalLights[i]->Enable(shader, i); + m_renderQueue.directionnalLights[i]->Enable(program, i); - lastShader = shader; + lastProgram = program; } - material->Apply(shader); + material->Apply(program); // Mesh if (pair.second) @@ -306,11 +306,11 @@ void NzForwardRenderTechnique::Draw(const NzScene* scene) count -= lightCount; for (unsigned int i = 0; i < count; ++i) - lightManager.GetLight(i)->Enable(shader, lightCount++); + lightManager.GetLight(i)->Enable(program, lightCount++); } for (unsigned int i = lightCount; i < 3; ++i) ///TODO: Constante sur le nombre maximum de lumières - NzLight::Disable(shader, i); + NzLight::Disable(program, i); NzRenderer::SetMatrix(nzMatrixType_World, matrix); drawFunc(mesh->GetPrimitiveMode(), 0, indexCount); diff --git a/src/Nazara/Graphics/Light.cpp b/src/Nazara/Graphics/Light.cpp index 327ce1fc5..5a959a797 100644 --- a/src/Nazara/Graphics/Light.cpp +++ b/src/Nazara/Graphics/Light.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include @@ -38,7 +38,7 @@ void NzLight::AddToRenderQueue(NzAbstractRenderQueue* renderQueue) const renderQueue->AddLight(this); } -void NzLight::Enable(const NzShader* shader, unsigned int lightUnit) const +void NzLight::Enable(const NzShaderProgram* program, unsigned int lightUnit) const { /* struct Light @@ -67,17 +67,17 @@ void NzLight::Enable(const NzShader* shader, unsigned int lightUnit) const */ ///TODO: Optimiser - int typeLocation = shader->GetUniformLocation("Lights[0].type"); - int ambientLocation = shader->GetUniformLocation("Lights[0].ambient"); - int diffuseLocation = shader->GetUniformLocation("Lights[0].diffuse"); - int specularLocation = shader->GetUniformLocation("Lights[0].specular"); - int parameters1Location = shader->GetUniformLocation("Lights[0].parameters1"); - int parameters2Location = shader->GetUniformLocation("Lights[0].parameters2"); - int parameters3Location = shader->GetUniformLocation("Lights[0].parameters3"); + int typeLocation = program->GetUniformLocation("Lights[0].type"); + int ambientLocation = program->GetUniformLocation("Lights[0].ambient"); + int diffuseLocation = program->GetUniformLocation("Lights[0].diffuse"); + int specularLocation = program->GetUniformLocation("Lights[0].specular"); + int parameters1Location = program->GetUniformLocation("Lights[0].parameters1"); + int parameters2Location = program->GetUniformLocation("Lights[0].parameters2"); + int parameters3Location = program->GetUniformLocation("Lights[0].parameters3"); if (lightUnit > 0) { - int type2Location = shader->GetUniformLocation("Lights[1].type"); + int type2Location = program->GetUniformLocation("Lights[1].type"); int offset = lightUnit * (type2Location - typeLocation); // type2Location - typeLocation donne la taille de la structure // On applique cet offset @@ -90,10 +90,10 @@ void NzLight::Enable(const NzShader* shader, unsigned int lightUnit) const parameters3Location += offset; } - shader->SendInteger(typeLocation, m_type); - shader->SendColor(ambientLocation, m_ambientColor); - shader->SendColor(diffuseLocation, m_diffuseColor); - shader->SendColor(specularLocation, m_specularColor); + program->SendInteger(typeLocation, m_type); + program->SendColor(ambientLocation, m_ambientColor); + program->SendColor(diffuseLocation, m_diffuseColor); + program->SendColor(specularLocation, m_specularColor); if (!m_derivedUpdated) UpdateDerived(); @@ -101,18 +101,18 @@ void NzLight::Enable(const NzShader* shader, unsigned int lightUnit) const switch (m_type) { case nzLightType_Directional: - shader->SendVector(parameters1Location, NzVector4f(m_derivedRotation * NzVector3f::Forward())); + program->SendVector(parameters1Location, NzVector4f(m_derivedRotation * NzVector3f::Forward())); break; case nzLightType_Point: - shader->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation)); - shader->SendVector(parameters2Location, NzVector4f(1.f/m_radius, 0.f, 0.f, 0.f)); + program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation)); + program->SendVector(parameters2Location, NzVector4f(1.f/m_radius, 0.f, 0.f, 0.f)); break; case nzLightType_Spot: - shader->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation)); - shader->SendVector(parameters2Location, NzVector4f(m_derivedRotation * NzVector3f::Forward(), 1.f/m_radius)); - shader->SendVector(parameters3Location, NzVector2f(std::cos(NzDegreeToRadian(m_innerAngle)), std::cos(NzDegreeToRadian(m_outerAngle)))); + program->SendVector(parameters1Location, NzVector4f(m_derivedPosition, m_attenuation)); + program->SendVector(parameters2Location, NzVector4f(m_derivedRotation * NzVector3f::Forward(), 1.f/m_radius)); + program->SendVector(parameters3Location, NzVector2f(std::cos(NzDegreeToRadian(m_innerAngle)), std::cos(NzDegreeToRadian(m_outerAngle)))); break; } } @@ -218,10 +218,10 @@ NzLight& NzLight::operator=(const NzLight& light) return *this; } -void NzLight::Disable(const NzShader* shader, unsigned int lightUnit) +void NzLight::Disable(const NzShaderProgram* program, unsigned int lightUnit) { ///TODO: Optimiser - shader->SendInteger(shader->GetUniformLocation("Lights[" + NzString::Number(lightUnit) + "].type"), -1); + program->SendInteger(program->GetUniformLocation("Lights[" + NzString::Number(lightUnit) + "].type"), -1); } void NzLight::Invalidate() diff --git a/src/Nazara/Graphics/SkyboxBackground.cpp b/src/Nazara/Graphics/SkyboxBackground.cpp index fa0ba81fb..5a57dff06 100644 --- a/src/Nazara/Graphics/SkyboxBackground.cpp +++ b/src/Nazara/Graphics/SkyboxBackground.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -44,7 +43,7 @@ namespace return indexBuffer.release(); } - NzShader* BuildShader() + NzShaderProgram* BuildProgram() { const char* fragmentSource110 = "#version 110\n" @@ -88,30 +87,30 @@ namespace "}\n"; ///TODO: Remplacer ça par des ShaderNode - std::unique_ptr shader(new NzShader(nzShaderLanguage_GLSL)); - shader->SetPersistent(false); + std::unique_ptr program(new NzShaderProgram(nzShaderLanguage_GLSL)); + program->SetPersistent(false); bool useGLSL140 = (NzOpenGL::GetVersion() >= 310); - if (!shader->Load(nzShaderType_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110)) + if (!program->LoadShader(nzShaderType_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110)) { NazaraError("Failed to load fragment shader"); return nullptr; } - if (!shader->Load(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110)) + if (!program->LoadShader(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110)) { NazaraError("Failed to load vertex shader"); return nullptr; } - if (!shader->Compile()) + if (!program->Compile()) { - NazaraError("Failed to compile shader"); + NazaraError("Failed to compile program"); return nullptr; } - return shader.release(); + return program.release(); } NzRenderStates BuildRenderStates() @@ -150,7 +149,7 @@ namespace } static NzIndexBuffer* s_indexBuffer = nullptr; - static NzShader* s_shader = nullptr; + static NzShaderProgram* s_program = nullptr; static NzVertexBuffer* s_vertexBuffer = nullptr; static unsigned int s_skyboxLocation; } @@ -160,17 +159,17 @@ NzSkyboxBackground::NzSkyboxBackground() if (!s_indexBuffer) s_indexBuffer = BuildIndexBuffer(); - if (!s_shader) + if (!s_program) { - s_shader = BuildShader(); - s_skyboxLocation = s_shader->GetUniformLocation("Skybox"); + s_program = BuildProgram(); + s_skyboxLocation = s_program->GetUniformLocation("Skybox"); } if (!s_vertexBuffer) s_vertexBuffer = BuildVertexBuffer(); m_indexBuffer = s_indexBuffer; - m_shader = s_shader; + m_program = s_program; m_sampler.SetWrapMode(nzSamplerWrap_Clamp); // Nécessaire pour ne pas voir les côtés m_vertexBuffer = s_vertexBuffer; } @@ -186,8 +185,8 @@ NzSkyboxBackground::~NzSkyboxBackground() if (m_indexBuffer.Reset()) s_indexBuffer = nullptr; - if (m_shader.Reset()) - s_shader = nullptr; + if (m_program.Reset()) + s_program = nullptr; if (m_vertexBuffer.Reset()) s_vertexBuffer = nullptr; @@ -197,7 +196,7 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const { static NzRenderStates states(BuildRenderStates()); - m_shader->SendInteger(s_skyboxLocation, 0); + s_program->SendInteger(s_skyboxLocation, 0); const NzMatrix4f& viewMatrix = NzRenderer::GetMatrix(nzMatrixType_View); NzMatrix4f skyboxMatrix(viewMatrix); @@ -207,7 +206,7 @@ void NzSkyboxBackground::Draw(const NzScene* scene) const NzRenderer::SetMatrix(nzMatrixType_View, skyboxMatrix); NzRenderer::SetMatrix(nzMatrixType_World, NzMatrix4f::Scale(NzVector3f(scene->GetActiveCamera()->GetZNear()))); NzRenderer::SetRenderStates(states); - NzRenderer::SetShader(m_shader); + NzRenderer::SetShaderProgram(s_program); NzRenderer::SetTexture(0, m_texture); NzRenderer::SetTextureSampler(0, m_sampler); NzRenderer::SetVertexBuffer(m_vertexBuffer); diff --git a/src/Nazara/Graphics/TextureBackground.cpp b/src/Nazara/Graphics/TextureBackground.cpp index f6caecee5..1bda23b5d 100644 --- a/src/Nazara/Graphics/TextureBackground.cpp +++ b/src/Nazara/Graphics/TextureBackground.cpp @@ -4,20 +4,20 @@ #include #include -#include +#include #include #include NzTextureBackground::NzTextureBackground() { - NzShaderManagerParams params; + NzShaderProgramManagerParams params; params.target = nzShaderTarget_FullscreenQuad; params.flags = 0; params.fullscreenQuad.alphaMapping = false; params.fullscreenQuad.alphaTest = false; params.fullscreenQuad.diffuseMapping = true; - m_shader = NzShaderManager::Get(params); + m_program = NzShaderProgramManager::Get(params); } NzTextureBackground::NzTextureBackground(NzTexture* texture) : @@ -32,11 +32,11 @@ void NzTextureBackground::Draw(const NzScene* scene) const static NzRenderStates states; - m_shader->SendColor(m_shader->GetUniformLocation(nzShaderUniform_MaterialDiffuse), NzColor::White); - m_shader->SendInteger(m_shader->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap), 0); + m_program->SendColor(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuse), NzColor::White); + m_program->SendInteger(m_program->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap), 0); NzRenderer::SetRenderStates(states); - NzRenderer::SetShader(m_shader); + NzRenderer::SetShaderProgram(m_program); NzRenderer::SetTexture(0, m_texture); NzRenderer::DrawFullscreenQuad(); diff --git a/src/Nazara/Renderer/AbstractShader.cpp b/src/Nazara/Renderer/AbstractShaderProgram.cpp similarity index 65% rename from src/Nazara/Renderer/AbstractShader.cpp rename to src/Nazara/Renderer/AbstractShaderProgram.cpp index fdcb10986..1adac9323 100644 --- a/src/Nazara/Renderer/AbstractShader.cpp +++ b/src/Nazara/Renderer/AbstractShaderProgram.cpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include -NzAbstractShader::~NzAbstractShader() = default; +NzAbstractShaderProgram::~NzAbstractShaderProgram() = default; diff --git a/src/Nazara/Renderer/AbstractShader.hpp b/src/Nazara/Renderer/AbstractShaderProgram.hpp similarity index 83% rename from src/Nazara/Renderer/AbstractShader.hpp rename to src/Nazara/Renderer/AbstractShaderProgram.hpp index 6867e476c..af9008381 100644 --- a/src/Nazara/Renderer/AbstractShader.hpp +++ b/src/Nazara/Renderer/AbstractShaderProgram.hpp @@ -4,18 +4,18 @@ #pragma once -#ifndef NAZARA_ABSTRACTSHADER_HPP -#define NAZARA_ABSTRACTSHADER_HPP +#ifndef NAZARA_ABSTRACTSHADERPROGRAM_HPP +#define NAZARA_ABSTRACTSHADERPROGRAM_HPP -#include +#include -class NzAbstractShader +class NzAbstractShaderProgram { friend class NzRenderer; public: - NzAbstractShader() = default; - virtual ~NzAbstractShader(); + NzAbstractShaderProgram() = default; + virtual ~NzAbstractShaderProgram(); virtual bool Bind() = 0; virtual bool BindTextures() = 0; @@ -35,7 +35,7 @@ class NzAbstractShader virtual bool IsBinaryRetrievable() const = 0; virtual bool IsLoaded(nzShaderType type) const = 0; - virtual bool Load(nzShaderType type, const NzString& source) = 0; + virtual bool LoadShader(nzShaderType type, const NzString& source) = 0; virtual bool SendBoolean(int location, bool value) = 0; virtual bool SendColor(int location, const NzColor& color) = 0; @@ -53,4 +53,4 @@ class NzAbstractShader virtual bool SendVector(int location, const NzVector4f& vector) = 0; }; -#endif // NAZARA_ABSTRACTSHADER_HPP +#endif // NAZARA_ABSTRACTSHADERPROGRAM_HPP diff --git a/src/Nazara/Renderer/Context.cpp b/src/Nazara/Renderer/Context.cpp index adbb5e2cc..deb73b829 100644 --- a/src/Nazara/Renderer/Context.cpp +++ b/src/Nazara/Renderer/Context.cpp @@ -50,7 +50,7 @@ namespace break; case GL_DEBUG_SOURCE_THIRD_PARTY: - ss << "Shader compiler"; + ss << "Third party"; break; case GL_DEBUG_SOURCE_APPLICATION: diff --git a/src/Nazara/Renderer/DebugDrawer.cpp b/src/Nazara/Renderer/DebugDrawer.cpp index 7ea5d5c82..aab67c845 100644 --- a/src/Nazara/Renderer/DebugDrawer.cpp +++ b/src/Nazara/Renderer/DebugDrawer.cpp @@ -6,8 +6,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -23,7 +22,7 @@ namespace static NzColor primaryColor; static NzColor secondaryColor; static NzRenderStates renderStates; - static const NzShader* shader = nullptr; + static const NzShaderProgram* program = nullptr; static NzVertexBuffer* vertexBuffer = nullptr; static NzVertexDeclaration* vertexDeclaration = nullptr; static bool depthBufferEnabled = true; @@ -129,10 +128,10 @@ void NzDebugDrawer::Draw(const NzBoxf& box) mapper.Unmap(); NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); } @@ -216,10 +215,10 @@ void NzDebugDrawer::Draw(const NzFrustumf& frustum) mapper.Unmap(); NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); } @@ -298,10 +297,10 @@ void NzDebugDrawer::Draw(const NzOrientedBoxf& orientedBox) mapper.Unmap(); NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 24); } @@ -346,13 +345,13 @@ void NzDebugDrawer::Draw(const NzSkeleton* skeleton) if (vertexCount > 0) { NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount); - shader->SendColor(colorLocation, secondaryColor); + program->SendColor(colorLocation, secondaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_PointList, 0, vertexCount); } } @@ -396,10 +395,10 @@ void NzDebugDrawer::DrawBinormals(const NzStaticMesh* subMesh) if (vertexCount > 0) { NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount); } } @@ -443,10 +442,10 @@ void NzDebugDrawer::DrawNormals(const NzStaticMesh* subMesh) if (vertexCount > 0) { NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount); } } @@ -490,10 +489,10 @@ void NzDebugDrawer::DrawTangents(const NzStaticMesh* subMesh) if (vertexCount > 0) { NzRenderer::SetRenderStates(renderStates); - NzRenderer::SetShader(shader); + NzRenderer::SetShaderProgram(program); NzRenderer::SetVertexBuffer(vertexBuffer); - shader->SendColor(colorLocation, primaryColor); + program->SendColor(colorLocation, primaryColor); NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, vertexCount); } } @@ -527,9 +526,9 @@ bool NzDebugDrawer::Initialize() { if (!initialized) { - // Shader + // Program { - NzShaderManagerParams params; + NzShaderProgramManagerParams params; params.target = nzShaderTarget_Model; params.flags = 0; params.model.alphaMapping = false; @@ -541,14 +540,14 @@ bool NzDebugDrawer::Initialize() params.model.parallaxMapping = false; params.model.specularMapping = false; - shader = NzShaderManager::Get(params); - if (!shader) + program = NzShaderProgramManager::Get(params); + if (!program) { - NazaraError("Failed to build debug shader"); + NazaraError("Failed to build debug program"); return false; } - colorLocation = shader->GetUniformLocation(nzShaderUniform_MaterialDiffuse); + colorLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuse); } // VertexBuffer (Nécessite la déclaration) diff --git a/src/Nazara/Renderer/GLSLShader.cpp b/src/Nazara/Renderer/GLSLProgram.cpp similarity index 86% rename from src/Nazara/Renderer/GLSLShader.cpp rename to src/Nazara/Renderer/GLSLProgram.cpp index 37c1a58e6..7990f8956 100644 --- a/src/Nazara/Renderer/GLSLShader.cpp +++ b/src/Nazara/Renderer/GLSLProgram.cpp @@ -2,7 +2,7 @@ // This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include #include #include @@ -12,12 +12,12 @@ #include #include -NzGLSLShader::NzGLSLShader(NzShader* parent) : +NzGLSLProgram::NzGLSLProgram(NzShaderProgram* parent) : m_parent(parent) { } -bool NzGLSLShader::Bind() +bool NzGLSLProgram::Bind() { #ifdef NAZARA_DEBUG if (NzContext::GetCurrent() == nullptr) @@ -32,7 +32,7 @@ bool NzGLSLShader::Bind() return true; } -bool NzGLSLShader::BindTextures() +bool NzGLSLProgram::BindTextures() { for (const std::pair& pair : m_textures) { @@ -44,7 +44,7 @@ bool NzGLSLShader::BindTextures() return true; } -bool NzGLSLShader::Compile() +bool NzGLSLProgram::Compile() { NzContext::EnsureContext(); @@ -116,7 +116,7 @@ bool NzGLSLShader::Compile() } } -bool NzGLSLShader::Create() +bool NzGLSLProgram::Create() { NzContext::EnsureContext(); @@ -163,7 +163,7 @@ bool NzGLSLShader::Create() return true; } -void NzGLSLShader::Destroy() +void NzGLSLProgram::Destroy() { NzContext::EnsureContext(); @@ -173,7 +173,7 @@ void NzGLSLShader::Destroy() NzOpenGL::DeleteProgram(m_program); } -NzByteArray NzGLSLShader::GetBinary() const +NzByteArray NzGLSLProgram::GetBinary() const { NzByteArray byteArray; @@ -199,17 +199,17 @@ NzByteArray NzGLSLShader::GetBinary() const return byteArray; } -NzString NzGLSLShader::GetLog() const +NzString NzGLSLProgram::GetLog() const { return m_log; } -nzShaderLanguage NzGLSLShader::GetLanguage() const +nzShaderLanguage NzGLSLProgram::GetLanguage() const { return nzShaderLanguage_GLSL; } -NzString NzGLSLShader::GetSourceCode(nzShaderType type) const +NzString NzGLSLProgram::GetSourceCode(nzShaderType type) const { NzString source; @@ -226,7 +226,7 @@ NzString NzGLSLShader::GetSourceCode(nzShaderType type) const return source; } -int NzGLSLShader::GetUniformLocation(const NzString& name) const +int NzGLSLProgram::GetUniformLocation(const NzString& name) const { auto it = m_idCache.find(name); GLint id; @@ -243,22 +243,22 @@ int NzGLSLShader::GetUniformLocation(const NzString& name) const return id; } -int NzGLSLShader::GetUniformLocation(nzShaderUniform uniform) const +int NzGLSLProgram::GetUniformLocation(nzShaderUniform uniform) const { return m_uniformLocations[uniform]; } -bool NzGLSLShader::IsBinaryRetrievable() const +bool NzGLSLProgram::IsBinaryRetrievable() const { return NzOpenGL::IsSupported(nzOpenGLExtension_GetProgramBinary); } -bool NzGLSLShader::IsLoaded(nzShaderType type) const +bool NzGLSLProgram::IsLoaded(nzShaderType type) const { return m_shaders[type] != 0; } -bool NzGLSLShader::Load(nzShaderType type, const NzString& source) +bool NzGLSLProgram::LoadShader(nzShaderType type, const NzString& source) { NzContext::EnsureContext(); @@ -317,7 +317,7 @@ bool NzGLSLShader::Load(nzShaderType type, const NzString& source) } } -bool NzGLSLShader::SendBoolean(int location, bool value) +bool NzGLSLProgram::SendBoolean(int location, bool value) { if (glProgramUniform1i) glProgramUniform1i(m_program, location, value); @@ -330,7 +330,7 @@ bool NzGLSLShader::SendBoolean(int location, bool value) return true; } -bool NzGLSLShader::SendColor(int location, const NzColor& color) +bool NzGLSLProgram::SendColor(int location, const NzColor& color) { NzVector4f vecColor(color.r/255.f, color.g/255.f, color.b/255.f, color.a/255.f); @@ -345,7 +345,7 @@ bool NzGLSLShader::SendColor(int location, const NzColor& color) return true; } -bool NzGLSLShader::SendDouble(int location, double value) +bool NzGLSLProgram::SendDouble(int location, double value) { if (glProgramUniform1d) glProgramUniform1d(m_program, location, value); @@ -358,7 +358,7 @@ bool NzGLSLShader::SendDouble(int location, double value) return true; } -bool NzGLSLShader::SendFloat(int location, float value) +bool NzGLSLProgram::SendFloat(int location, float value) { if (glProgramUniform1f) glProgramUniform1f(m_program, location, value); @@ -371,7 +371,7 @@ bool NzGLSLShader::SendFloat(int location, float value) return true; } -bool NzGLSLShader::SendInteger(int location, int value) +bool NzGLSLProgram::SendInteger(int location, int value) { if (glProgramUniform1i) glProgramUniform1i(m_program, location, value); @@ -384,7 +384,7 @@ bool NzGLSLShader::SendInteger(int location, int value) return true; } -bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) +bool NzGLSLProgram::SendMatrix(int location, const NzMatrix4d& matrix) { if (glProgramUniformMatrix4dv) glProgramUniformMatrix4dv(m_program, location, 1, GL_FALSE, matrix); @@ -397,7 +397,7 @@ bool NzGLSLShader::SendMatrix(int location, const NzMatrix4d& matrix) return true; } -bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) +bool NzGLSLProgram::SendMatrix(int location, const NzMatrix4f& matrix) { if (glProgramUniformMatrix4fv) glProgramUniformMatrix4fv(m_program, location, 1, GL_FALSE, matrix); @@ -410,7 +410,7 @@ bool NzGLSLShader::SendMatrix(int location, const NzMatrix4f& matrix) return true; } -bool NzGLSLShader::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) +bool NzGLSLProgram::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) { auto it = m_textures.find(location); if (it != m_textures.end()) @@ -475,7 +475,7 @@ bool NzGLSLShader::SendTexture(int location, const NzTexture* texture, nzUInt8* return true; } -bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) +bool NzGLSLProgram::SendVector(int location, const NzVector2d& vector) { if (glProgramUniform2dv) glProgramUniform2dv(m_program, location, 1, vector); @@ -488,7 +488,7 @@ bool NzGLSLShader::SendVector(int location, const NzVector2d& vector) return true; } -bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) +bool NzGLSLProgram::SendVector(int location, const NzVector2f& vector) { if (glProgramUniform2fv) glProgramUniform2fv(m_program, location, 1, vector); @@ -501,7 +501,7 @@ bool NzGLSLShader::SendVector(int location, const NzVector2f& vector) return true; } -bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) +bool NzGLSLProgram::SendVector(int location, const NzVector3d& vector) { if (glProgramUniform3dv) glProgramUniform3dv(m_program, location, 1, vector); @@ -514,7 +514,7 @@ bool NzGLSLShader::SendVector(int location, const NzVector3d& vector) return true; } -bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) +bool NzGLSLProgram::SendVector(int location, const NzVector3f& vector) { if (glProgramUniform3fv) glProgramUniform3fv(m_program, location, 1, vector); @@ -527,7 +527,7 @@ bool NzGLSLShader::SendVector(int location, const NzVector3f& vector) return true; } -bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) +bool NzGLSLProgram::SendVector(int location, const NzVector4d& vector) { if (glProgramUniform4dv) glProgramUniform4dv(m_program, location, 1, vector); @@ -540,7 +540,7 @@ bool NzGLSLShader::SendVector(int location, const NzVector4d& vector) return true; } -bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) +bool NzGLSLProgram::SendVector(int location, const NzVector4f& vector) { if (glProgramUniform4fv) glProgramUniform4fv(m_program, location, 1, vector); @@ -553,7 +553,7 @@ bool NzGLSLShader::SendVector(int location, const NzVector4f& vector) return true; } -void NzGLSLShader::OnResourceCreated(const NzResource* resource, int index) +void NzGLSLProgram::OnResourceCreated(const NzResource* resource, int index) { NazaraUnused(resource); @@ -581,7 +581,7 @@ void NzGLSLShader::OnResourceCreated(const NzResource* resource, int index) slot.updated = false; } -void NzGLSLShader::OnResourceDestroy(const NzResource* resource, int index) +void NzGLSLProgram::OnResourceDestroy(const NzResource* resource, int index) { NazaraUnused(resource); @@ -608,7 +608,7 @@ void NzGLSLShader::OnResourceDestroy(const NzResource* resource, int index) slot.enabled = false; } -void NzGLSLShader::OnResourceReleased(const NzResource* resource, int index) +void NzGLSLProgram::OnResourceReleased(const NzResource* resource, int index) { if (m_textures.erase(index) == 0) NazaraInternalError("Texture " + NzString::Pointer(resource) + " not found"); diff --git a/src/Nazara/Renderer/GLSLShader.hpp b/src/Nazara/Renderer/GLSLProgram.hpp similarity index 83% rename from src/Nazara/Renderer/GLSLShader.hpp rename to src/Nazara/Renderer/GLSLProgram.hpp index e8a1fee9d..5de7dcf31 100644 --- a/src/Nazara/Renderer/GLSLShader.hpp +++ b/src/Nazara/Renderer/GLSLProgram.hpp @@ -4,24 +4,24 @@ #pragma once -#ifndef NAZARA_GLSLSHADER_HPP -#define NAZARA_GLSLSHADER_HPP +#ifndef NAZARA_GLSLPROGRAM_HPP +#define NAZARA_GLSLPROGRAM_HPP #include #include -#include +#include #include -#include +#include #include #include class NzResource; -class NzGLSLShader : public NzAbstractShader, NzResourceListener +class NzGLSLProgram : public NzAbstractShaderProgram, NzResourceListener { public: - NzGLSLShader(NzShader* parent); - ~NzGLSLShader() = default; + NzGLSLProgram(NzShaderProgram* parent); + ~NzGLSLProgram() = default; bool Bind(); bool BindTextures(); @@ -41,7 +41,7 @@ class NzGLSLShader : public NzAbstractShader, NzResourceListener bool IsBinaryRetrievable() const; bool IsLoaded(nzShaderType type) const; - bool Load(nzShaderType type, const NzString& source); + bool LoadShader(nzShaderType type, const NzString& source); bool SendBoolean(int location, bool value); bool SendColor(int location, const NzColor& color); @@ -75,9 +75,9 @@ class NzGLSLShader : public NzAbstractShader, NzResourceListener std::map m_textures; GLuint m_program; GLuint m_shaders[nzShaderType_Max+1]; - NzShader* m_parent; + NzShaderProgram* m_parent; NzString m_log; int m_uniformLocations[nzShaderUniform_Max+1]; }; -#endif // NAZARA_GLSLSHADER_HPPs +#endif // NAZARA_GLSLPROGRAM_HPP diff --git a/src/Nazara/Renderer/Material.cpp b/src/Nazara/Renderer/Material.cpp index a873115f2..eda92286e 100644 --- a/src/Nazara/Renderer/Material.cpp +++ b/src/Nazara/Renderer/Material.cpp @@ -4,8 +4,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -39,25 +39,25 @@ NzMaterial::NzMaterial(NzMaterial&& material) material.m_specularMap.Reset(); for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i) - for (ShaderUnit& unit : material.m_shaders[i]) - unit.shader.Reset(); + for (ProgramUnit& unit : material.m_programs[i]) + unit.program.Reset(); } -void NzMaterial::Apply(const NzShader* shader) const +void NzMaterial::Apply(const NzShaderProgram* program) const { - int alphaThresholdLocation = shader->GetUniformLocation(nzShaderUniform_MaterialAlphaThreshold); - int ambientColorLocation = shader->GetUniformLocation(nzShaderUniform_MaterialAmbient); - int diffuseColorLocation = shader->GetUniformLocation(nzShaderUniform_MaterialDiffuse); - int shininessLocation = shader->GetUniformLocation(nzShaderUniform_MaterialShininess); - int specularColorLocation = shader->GetUniformLocation(nzShaderUniform_MaterialSpecular); + int alphaThresholdLocation = program->GetUniformLocation(nzShaderUniform_MaterialAlphaThreshold); + int ambientColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialAmbient); + int diffuseColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuse); + int shininessLocation = program->GetUniformLocation(nzShaderUniform_MaterialShininess); + int specularColorLocation = program->GetUniformLocation(nzShaderUniform_MaterialSpecular); if (m_alphaMap) { - int alphaMapLocation = shader->GetUniformLocation(nzShaderUniform_MaterialAlphaMap); + int alphaMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialAlphaMap); if (alphaMapLocation != -1) { nzUInt8 textureUnit; - if (shader->SendTexture(alphaMapLocation, m_alphaMap, &textureUnit)) + if (program->SendTexture(alphaMapLocation, m_alphaMap, &textureUnit)) NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler); else NazaraWarning("Failed to send diffuse map"); @@ -65,21 +65,21 @@ void NzMaterial::Apply(const NzShader* shader) const } if (alphaThresholdLocation != -1) - shader->SendFloat(alphaThresholdLocation, m_alphaThreshold); + program->SendFloat(alphaThresholdLocation, m_alphaThreshold); if (ambientColorLocation != -1) - shader->SendColor(ambientColorLocation, m_ambientColor); + program->SendColor(ambientColorLocation, m_ambientColor); if (diffuseColorLocation != -1) - shader->SendColor(diffuseColorLocation, m_diffuseColor); + program->SendColor(diffuseColorLocation, m_diffuseColor); if (m_diffuseMap) { - int diffuseMapLocation = shader->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap); + int diffuseMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialDiffuseMap); if (diffuseMapLocation != -1) { nzUInt8 textureUnit; - if (shader->SendTexture(diffuseMapLocation, m_diffuseMap, &textureUnit)) + if (program->SendTexture(diffuseMapLocation, m_diffuseMap, &textureUnit)) NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler); else NazaraWarning("Failed to send diffuse map"); @@ -88,11 +88,11 @@ void NzMaterial::Apply(const NzShader* shader) const if (m_emissiveMap) { - int emissiveMapLocation = shader->GetUniformLocation(nzShaderUniform_MaterialEmissiveMap); + int emissiveMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialEmissiveMap); if (emissiveMapLocation != -1) { nzUInt8 textureUnit; - if (shader->SendTexture(emissiveMapLocation, m_emissiveMap, &textureUnit)) + if (program->SendTexture(emissiveMapLocation, m_emissiveMap, &textureUnit)) NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler); else NazaraWarning("Failed to send emissive map"); @@ -101,11 +101,11 @@ void NzMaterial::Apply(const NzShader* shader) const if (m_heightMap) { - int heightMapLocation = shader->GetUniformLocation(nzShaderUniform_MaterialHeightMap); + int heightMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialHeightMap); if (heightMapLocation != -1) { nzUInt8 textureUnit; - if (shader->SendTexture(heightMapLocation, m_heightMap, &textureUnit)) + if (program->SendTexture(heightMapLocation, m_heightMap, &textureUnit)) NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler); else NazaraWarning("Failed to send height map"); @@ -114,11 +114,11 @@ void NzMaterial::Apply(const NzShader* shader) const if (m_normalMap) { - int normalMapLocation = shader->GetUniformLocation(nzShaderUniform_MaterialNormalMap); + int normalMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialNormalMap); if (normalMapLocation != -1) { nzUInt8 textureUnit; - if (shader->SendTexture(normalMapLocation, m_normalMap, &textureUnit)) + if (program->SendTexture(normalMapLocation, m_normalMap, &textureUnit)) NzRenderer::SetTextureSampler(textureUnit, m_diffuseSampler); else NazaraWarning("Failed to send normal map"); @@ -126,18 +126,18 @@ void NzMaterial::Apply(const NzShader* shader) const } if (shininessLocation != -1) - shader->SendFloat(shininessLocation, m_shininess); + program->SendFloat(shininessLocation, m_shininess); if (specularColorLocation != -1) - shader->SendColor(specularColorLocation, m_specularColor); + program->SendColor(specularColorLocation, m_specularColor); if (m_specularMap) { - int specularMapLocation = shader->GetUniformLocation(nzShaderUniform_MaterialSpecularMap); + int specularMapLocation = program->GetUniformLocation(nzShaderUniform_MaterialSpecularMap); if (specularMapLocation != -1) { nzUInt8 textureUnit; - if (shader->SendTexture(specularMapLocation, m_specularMap, &textureUnit)) + if (program->SendTexture(specularMapLocation, m_specularMap, &textureUnit)) NzRenderer::SetTextureSampler(textureUnit, m_specularSampler); else NazaraWarning("Failed to send specular map"); @@ -245,13 +245,13 @@ const NzRenderStates& NzMaterial::GetRenderStates() const return m_states; } -const NzShader* NzMaterial::GetShader(nzShaderTarget target, nzUInt32 flags) const +const NzShaderProgram* NzMaterial::GetShaderProgram(nzShaderTarget target, nzUInt32 flags) const { - const ShaderUnit& unit = m_shaders[target][flags]; - if (!unit.shader.IsValid()) - GenerateShader(target, flags); + const ProgramUnit& unit = m_programs[target][flags]; + if (!unit.program.IsValid()) + GenerateProgram(target, flags); - return unit.shader; + return unit.program; } float NzMaterial::GetShininess() const @@ -363,10 +363,10 @@ void NzMaterial::Reset() for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i) { - for (ShaderUnit& unit : m_shaders[i]) + for (ProgramUnit& unit : m_programs[i]) { unit.custom = false; - unit.shader.Reset(); + unit.program.Reset(); } } @@ -405,7 +405,7 @@ void NzMaterial::SetAlphaMap(NzTexture* map) { m_alphaMap = map; - InvalidateShaders(nzShaderTarget_Model); + InvalidatePrograms(nzShaderTarget_Model); } void NzMaterial::SetAlphaThreshold(float alphaThreshold) @@ -449,7 +449,7 @@ void NzMaterial::SetDiffuseMap(NzTexture* map) { m_diffuseMap = map; - InvalidateShaders(nzShaderTarget_Model); + InvalidatePrograms(nzShaderTarget_Model); } void NzMaterial::SetDiffuseSampler(const NzTextureSampler& sampler) @@ -483,7 +483,7 @@ void NzMaterial::SetEmissiveMap(NzTexture* map) { m_emissiveMap = map; - InvalidateShaders(nzShaderTarget_Model); + InvalidatePrograms(nzShaderTarget_Model); } void NzMaterial::SetFaceCulling(nzFaceCulling culling) @@ -517,7 +517,7 @@ void NzMaterial::SetHeightMap(NzTexture* map) { m_heightMap = map; - InvalidateShaders(nzShaderTarget_Model); + InvalidatePrograms(nzShaderTarget_Model); } bool NzMaterial::SetNormalMap(const NzString& texturePath) @@ -541,7 +541,7 @@ void NzMaterial::SetNormalMap(NzTexture* map) { m_normalMap = map; - InvalidateShaders(nzShaderTarget_Model); + InvalidatePrograms(nzShaderTarget_Model); } void NzMaterial::SetRenderStates(const NzRenderStates& states) @@ -549,12 +549,12 @@ void NzMaterial::SetRenderStates(const NzRenderStates& states) m_states = states; } -void NzMaterial::SetShader(nzShaderTarget target, nzUInt32 flags, const NzShader* shader) +void NzMaterial::SetShaderProgram(nzShaderTarget target, nzUInt32 flags, const NzShaderProgram* program) { - ShaderUnit& unit = m_shaders[target][flags]; + ProgramUnit& unit = m_programs[target][flags]; - unit.custom = (shader != nullptr); - unit.shader = shader; + unit.custom = (program != nullptr); + unit.program = program; } void NzMaterial::SetShininess(float shininess) @@ -588,7 +588,7 @@ void NzMaterial::SetSpecularMap(NzTexture* map) { m_specularMap = map; - InvalidateShaders(nzShaderTarget_Model); + InvalidatePrograms(nzShaderTarget_Model); } void NzMaterial::SetSpecularSampler(const NzTextureSampler& sampler) @@ -621,8 +621,8 @@ NzMaterial& NzMaterial::operator=(NzMaterial&& material) material.m_specularMap.Reset(); for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i) - for (ShaderUnit& unit : material.m_shaders[i]) - unit.shader.Reset(); + for (ProgramUnit& unit : material.m_programs[i]) + unit.program.Reset(); return *this; } @@ -642,8 +642,8 @@ void NzMaterial::Copy(const NzMaterial& material) m_specularMap.Reset(); for (unsigned int i = 0; i <= nzShaderTarget_Max; ++i) - for (ShaderUnit& unit : m_shaders[i]) - unit.shader.Reset(); + for (ProgramUnit& unit : m_programs[i]) + unit.program.Reset(); std::memcpy(this, &material, sizeof(NzMaterial)); // Autorisé dans notre cas, et bien plus rapide @@ -666,17 +666,17 @@ void NzMaterial::Copy(const NzMaterial& material) { for (unsigned int j = 0; j <= nzShaderFlags_Max; ++j) { - NzShaderConstRef& shader = m_shaders[i][j].shader; + NzShaderProgramConstRef& program = m_programs[i][j].program; - shader.Release(); - shader = material.m_shaders[i][j].shader; + program.Release(); + program = material.m_programs[i][j].program; } } } -void NzMaterial::GenerateShader(nzShaderTarget target, nzUInt32 flags) const +void NzMaterial::GenerateProgram(nzShaderTarget target, nzUInt32 flags) const { - NzShaderManagerParams params; + NzShaderProgramManagerParams params; params.target = target; params.flags = flags; @@ -703,15 +703,15 @@ void NzMaterial::GenerateShader(nzShaderTarget target, nzUInt32 flags) const break; } - m_shaders[target][flags].shader = NzShaderManager::Get(params); + m_programs[target][flags].program = NzShaderProgramManager::Get(params); } -void NzMaterial::InvalidateShaders(nzShaderTarget target) +void NzMaterial::InvalidatePrograms(nzShaderTarget target) { - for (ShaderUnit& unit : m_shaders[target]) + for (ProgramUnit& unit : m_programs[target]) { if (!unit.custom) - unit.shader.Reset(); + unit.program.Reset(); } } diff --git a/src/Nazara/Renderer/Renderer.cpp b/src/Nazara/Renderer/Renderer.cpp index 0d4dfc012..0595e2972 100644 --- a/src/Nazara/Renderer/Renderer.cpp +++ b/src/Nazara/Renderer/Renderer.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -38,7 +38,7 @@ namespace Update_None = 0, Update_Matrices = 0x1, - Update_Shader = 0x2, + Update_Program = 0x2, Update_Textures = 0x4, Update_VAO = 0x8 }; @@ -78,7 +78,7 @@ namespace nzUInt32 s_updateFlags; const NzIndexBuffer* s_indexBuffer; const NzRenderTarget* s_target; - const NzShader* s_shader; + const NzShaderProgram* s_program; const NzVertexBuffer* s_vertexBuffer; const NzVertexDeclaration* s_instancingDeclaration; bool s_capabilities[nzRendererCap_Max+1]; @@ -445,9 +445,9 @@ NzRectui NzRenderer::GetScissorRect() return NzRectui(params[0], params[1], params[2], params[3]); } -const NzShader* NzRenderer::GetShader() +const NzShaderProgram* NzRenderer::GetShaderProgram() { - return s_shader; + return s_program; } const NzRenderTarget* NzRenderer::GetTarget() @@ -570,14 +570,14 @@ bool NzRenderer::Initialize() s_states = NzRenderStates(); s_indexBuffer = nullptr; - s_shader = nullptr; + s_program = nullptr; s_target = nullptr; s_textureUnits.resize(s_maxTextureUnit); s_uniformTargetSizeUpdated = false; s_useSamplerObjects = NzOpenGL::IsSupported(nzOpenGLExtension_SamplerObjects); s_useVertexArrayObjects = NzOpenGL::IsSupported(nzOpenGLExtension_VertexArrayObjects); s_vertexBuffer = nullptr; - s_updateFlags = (Update_Matrices | Update_Shader | Update_VAO); + s_updateFlags = (Update_Matrices | Update_Program | Update_VAO); s_fullscreenQuadBuffer = new NzVertexBuffer(NzVertexDeclaration::Get(nzVertexLayout_XY), 4, nzBufferStorage_Hardware, nzBufferUsage_Static); float vertices[4*2] = @@ -620,9 +620,9 @@ bool NzRenderer::Initialize() return false; } - if (!NzShaderManager::Initialize()) + if (!NzShaderProgramManager::Initialize()) { - NazaraError("Failed to initialize shader manager"); + NazaraError("Failed to initialize shader program manager"); Uninitialize(); return false; @@ -950,20 +950,20 @@ void NzRenderer::SetScissorRect(const NzRectui& rect) glScissor(rect.x, height-rect.height-rect.y, rect.width, rect.height); } -void NzRenderer::SetShader(const NzShader* shader) +void NzRenderer::SetShaderProgram(const NzShaderProgram* program) { #if NAZARA_RENDERER_SAFE - if (shader && !shader->IsCompiled()) + if (program && !program->IsCompiled()) { - NazaraError("Shader is not compiled"); + NazaraError("Shader program is not compiled"); return; } #endif - if (s_shader != shader) + if (s_program != program) { - s_shader = shader; - s_updateFlags |= Update_Shader; + s_program = program; + s_updateFlags |= Update_Program; } } @@ -1180,7 +1180,7 @@ void NzRenderer::Uninitialize() NzLoaders_Texture_Unregister(); NzTextureSampler::Uninitialize(); - NzShaderManager::Uninitialize(); + NzShaderProgramManager::Uninitialize(); NzMaterial::Uninitialize(); NzDebugDrawer::Uninitialize(); @@ -1230,48 +1230,48 @@ bool NzRenderer::EnsureStateUpdate() #endif #if NAZARA_RENDERER_SAFE - if (!s_shader) + if (!s_program) { - NazaraError("No shader"); + NazaraError("No shader program"); return false; } #endif - NzAbstractShader* shaderImpl = s_shader->m_impl; - shaderImpl->Bind(); // Active le shader si ce n'est pas déjà le cas + NzAbstractShaderProgram* programImpl = s_program->m_impl; + programImpl->Bind(); // Active le programme si ce n'est pas déjà le cas - // Si le shader a été changé depuis la dernière fois - if (s_updateFlags & Update_Shader) + // Si le programme a été changé depuis la dernière fois + if (s_updateFlags & Update_Program) { // Récupération des indices des variables uniformes (-1 si la variable n'existe pas) - s_matrices[nzMatrixType_Projection].location = shaderImpl->GetUniformLocation(nzShaderUniform_ProjMatrix); - s_matrices[nzMatrixType_View].location = shaderImpl->GetUniformLocation(nzShaderUniform_ViewMatrix); - s_matrices[nzMatrixType_World].location = shaderImpl->GetUniformLocation(nzShaderUniform_WorldMatrix); + s_matrices[nzMatrixType_Projection].location = programImpl->GetUniformLocation(nzShaderUniform_ProjMatrix); + s_matrices[nzMatrixType_View].location = programImpl->GetUniformLocation(nzShaderUniform_ViewMatrix); + s_matrices[nzMatrixType_World].location = programImpl->GetUniformLocation(nzShaderUniform_WorldMatrix); - s_matrices[nzMatrixType_ViewProj].location = shaderImpl->GetUniformLocation(nzShaderUniform_ViewProjMatrix); - s_matrices[nzMatrixType_WorldView].location = shaderImpl->GetUniformLocation(nzShaderUniform_WorldViewMatrix); - s_matrices[nzMatrixType_WorldViewProj].location = shaderImpl->GetUniformLocation(nzShaderUniform_WorldViewProjMatrix); + s_matrices[nzMatrixType_ViewProj].location = programImpl->GetUniformLocation(nzShaderUniform_ViewProjMatrix); + s_matrices[nzMatrixType_WorldView].location = programImpl->GetUniformLocation(nzShaderUniform_WorldViewMatrix); + s_matrices[nzMatrixType_WorldViewProj].location = programImpl->GetUniformLocation(nzShaderUniform_WorldViewProjMatrix); s_uniformTargetSizeUpdated = false; - s_updateFlags |= Update_Matrices; // Changement de shader, on renvoie toutes les matrices demandées + s_updateFlags |= Update_Matrices; // Changement de programme, on renvoie toutes les matrices demandées - s_updateFlags &= ~Update_Shader; + s_updateFlags &= ~Update_Program; } - shaderImpl->BindTextures(); + programImpl->BindTextures(); // Envoi des uniformes liées au Renderer if (!s_uniformTargetSizeUpdated) { int location; - location = shaderImpl->GetUniformLocation(nzShaderUniform_InvTargetSize); + location = programImpl->GetUniformLocation(nzShaderUniform_InvTargetSize); if (location != -1) - shaderImpl->SendVector(location, 1.f/NzVector2f(s_targetSize)); + programImpl->SendVector(location, 1.f/NzVector2f(s_targetSize)); - location = shaderImpl->GetUniformLocation(nzShaderUniform_TargetSize); + location = programImpl->GetUniformLocation(nzShaderUniform_TargetSize); if (location != -1) - shaderImpl->SendVector(location, NzVector2f(s_targetSize)); + programImpl->SendVector(location, NzVector2f(s_targetSize)); s_uniformTargetSizeUpdated = true; } @@ -1326,12 +1326,12 @@ bool NzRenderer::EnsureStateUpdate() for (unsigned int i = 0; i <= nzMatrixType_Max; ++i) { MatrixUnit& unit = s_matrices[i]; - if (unit.location != -1) // On ne traite que les matrices existant dans le shader + if (unit.location != -1) // On ne traite que les matrices existant dans le programme { if (!unit.updated) UpdateMatrix(static_cast(i)); - shaderImpl->SendMatrix(unit.location, unit.matrix); + programImpl->SendMatrix(unit.location, unit.matrix); } } diff --git a/src/Nazara/Renderer/Shader.cpp b/src/Nazara/Renderer/ShaderProgram.cpp similarity index 58% rename from src/Nazara/Renderer/Shader.cpp rename to src/Nazara/Renderer/ShaderProgram.cpp index 45533af9d..38e87c5f2 100644 --- a/src/Nazara/Renderer/Shader.cpp +++ b/src/Nazara/Renderer/ShaderProgram.cpp @@ -2,26 +2,26 @@ // This file is part of the "Nazara Engine - Renderer module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include #include #include #include -#include +#include #include -#include +#include #include #include #include #include -NzShader::NzShader() : +NzShaderProgram::NzShaderProgram() : m_flags(nzShaderFlags_None), m_impl(nullptr), m_compiled(false) { } -NzShader::NzShader(nzShaderLanguage language) : +NzShaderProgram::NzShaderProgram(nzShaderLanguage language) : m_flags(nzShaderFlags_None), m_impl(nullptr), m_compiled(false) @@ -29,20 +29,20 @@ m_compiled(false) Create(language); } -NzShader::NzShader(NzShader&& shader) : -m_flags(shader.m_flags), -m_impl(shader.m_impl), -m_compiled(shader.m_compiled) +NzShaderProgram::NzShaderProgram(NzShaderProgram&& program) : +m_flags(program.m_flags), +m_impl(program.m_impl), +m_compiled(program.m_compiled) { - shader.m_impl = nullptr; + program.m_impl = nullptr; } -NzShader::~NzShader() +NzShaderProgram::~NzShaderProgram() { Destroy(); } -bool NzShader::Create(nzShaderLanguage language) +bool NzShaderProgram::Create(nzShaderLanguage language) { Destroy(); @@ -53,17 +53,17 @@ bool NzShader::Create(nzShaderLanguage language) return false; case nzShaderLanguage_GLSL: - m_impl = new NzGLSLShader(this); + m_impl = new NzGLSLProgram(this); break; default: - NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); + NazaraError("Program language not handled (0x" + NzString::Number(language, 16) + ')'); return false; } if (!m_impl->Create()) { - NazaraError("Failed to create shader"); + NazaraError("Failed to create program"); delete m_impl; m_impl = nullptr; @@ -74,12 +74,12 @@ bool NzShader::Create(nzShaderLanguage language) return true; } -bool NzShader::Compile() +bool NzShaderProgram::Compile() { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -94,7 +94,7 @@ bool NzShader::Compile() return false; } -void NzShader::Destroy() +void NzShaderProgram::Destroy() { if (m_impl) { @@ -106,24 +106,24 @@ void NzShader::Destroy() } } -NzByteArray NzShader::GetBinary() const +NzByteArray NzShaderProgram::GetBinary() const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return NzByteArray(); } if (!m_compiled) { - NazaraError("Shader is not compiled"); + NazaraError("Program is not compiled"); return NzByteArray(); } if (!m_impl->IsBinaryRetrievable()) { - NazaraError("Shader binary is not retrievable"); + NazaraError("Program binary is not retrievable"); return NzByteArray(); } #endif @@ -131,17 +131,17 @@ NzByteArray NzShader::GetBinary() const return m_impl->GetBinary(); } -nzUInt32 NzShader::GetFlags() const +nzUInt32 NzShaderProgram::GetFlags() const { return m_flags; } -NzString NzShader::GetLog() const +NzString NzShaderProgram::GetLog() const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NzString error = "Shader not created"; + NzString error = "Program not created"; NazaraError(error); return error; @@ -151,12 +151,12 @@ NzString NzShader::GetLog() const return m_impl->GetLog(); } -nzShaderLanguage NzShader::GetLanguage() const +nzShaderLanguage NzShaderProgram::GetLanguage() const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NzString error = "Shader not created"; + NzString error = "Program not created"; NazaraError(error); return nzShaderLanguage_Unknown; @@ -166,20 +166,20 @@ nzShaderLanguage NzShader::GetLanguage() const return m_impl->GetLanguage(); } -NzString NzShader::GetSourceCode(nzShaderType type) const +NzString NzShaderProgram::GetSourceCode(nzShaderType type) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NzString error = "Shader not created"; + NzString error = "Program not created"; NazaraError(error); return error; } - if (!IsTypeSupported(type)) + if (!IsShaderTypeSupported(type)) { - NzString error = "Shader type not supported"; + NzString error = "Program type not supported"; NazaraError(error); return error; @@ -187,7 +187,7 @@ NzString NzShader::GetSourceCode(nzShaderType type) const if (!m_impl->IsLoaded(type)) { - NzString error = "Shader not loaded"; + NzString error = "Program not loaded"; NazaraError(error); return error; @@ -197,12 +197,12 @@ NzString NzShader::GetSourceCode(nzShaderType type) const return m_impl->GetSourceCode(type); } -int NzShader::GetUniformLocation(const NzString& name) const +int NzShaderProgram::GetUniformLocation(const NzString& name) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -210,12 +210,12 @@ int NzShader::GetUniformLocation(const NzString& name) const return m_impl->GetUniformLocation(name); } -int NzShader::GetUniformLocation(nzShaderUniform uniform) const +int NzShaderProgram::GetUniformLocation(nzShaderUniform uniform) const { #ifdef NAZARA_DEBUG if (uniform > nzShaderUniform_Max) { - NazaraError("Shader uniform out of enum"); + NazaraError("Program uniform out of enum"); return -1; } #endif @@ -223,12 +223,12 @@ int NzShader::GetUniformLocation(nzShaderUniform uniform) const return m_impl->GetUniformLocation(uniform); } -bool NzShader::HasUniform(const NzString& name) const +bool NzShaderProgram::HasUniform(const NzString& name) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -236,12 +236,12 @@ bool NzShader::HasUniform(const NzString& name) const return m_impl->GetUniformLocation(name) != -1; } -bool NzShader::IsBinaryRetrievable() const +bool NzShaderProgram::IsBinaryRetrievable() const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -249,12 +249,12 @@ bool NzShader::IsBinaryRetrievable() const return m_impl->IsBinaryRetrievable(); } -bool NzShader::IsCompiled() const +bool NzShaderProgram::IsCompiled() const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -262,18 +262,18 @@ bool NzShader::IsCompiled() const return m_compiled; } -bool NzShader::IsLoaded(nzShaderType type) const +bool NzShaderProgram::IsLoaded(nzShaderType type) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } - if (!IsTypeSupported(type)) + if (!IsShaderTypeSupported(type)) { - NazaraError("Shader type not supported"); + NazaraError("Program type not supported"); return false; } #endif @@ -281,23 +281,23 @@ bool NzShader::IsLoaded(nzShaderType type) const return m_impl->IsLoaded(type); } -bool NzShader::IsValid() const +bool NzShaderProgram::IsValid() const { return m_impl != nullptr; } -bool NzShader::Load(nzShaderType type, const NzString& source) +bool NzShaderProgram::LoadShader(nzShaderType type, const NzString& source) { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } - if (!IsTypeSupported(type)) + if (!IsShaderTypeSupported(type)) { - NazaraError("Shader type not supported"); + NazaraError("Program type not supported"); return false; } @@ -309,32 +309,32 @@ bool NzShader::Load(nzShaderType type, const NzString& source) if (m_impl->IsLoaded(type)) { - NazaraError("Shader already loaded"); + NazaraError("Program already loaded"); return false; } #endif - return m_impl->Load(type, source); + return m_impl->LoadShader(type, source); } -bool NzShader::LoadFromFile(nzShaderType type, const NzString& filePath) +bool NzShaderProgram::LoadShaderFromFile(nzShaderType type, const NzString& filePath) { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } - if (!IsTypeSupported(type)) + if (!IsShaderTypeSupported(type)) { - NazaraError("Shader type not supported"); + NazaraError("Program type not supported"); return false; } if (m_impl->IsLoaded(type)) { - NazaraError("Shader already loaded"); + NazaraError("Program already loaded"); return false; } #endif @@ -353,21 +353,21 @@ bool NzShader::LoadFromFile(nzShaderType type, const NzString& filePath) if (file.Read(&source[0], length) != length) { - NazaraError("Failed to read shader file"); + NazaraError("Failed to read program file"); return false; } file.Close(); - return m_impl->Load(type, source); + return m_impl->LoadShader(type, source); } -bool NzShader::SendBoolean(int location, bool value) const +bool NzShaderProgram::SendBoolean(int location, bool value) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -378,12 +378,12 @@ bool NzShader::SendBoolean(int location, bool value) const return m_impl->SendBoolean(location, value); } -bool NzShader::SendColor(int location, const NzColor& color) const +bool NzShaderProgram::SendColor(int location, const NzColor& color) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -394,7 +394,7 @@ bool NzShader::SendColor(int location, const NzColor& color) const return m_impl->SendColor(location, color); } -bool NzShader::SendDouble(int location, double value) const +bool NzShaderProgram::SendDouble(int location, double value) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -405,7 +405,7 @@ bool NzShader::SendDouble(int location, double value) const if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -416,12 +416,12 @@ bool NzShader::SendDouble(int location, double value) const return m_impl->SendDouble(location, value); } -bool NzShader::SendFloat(int location, float value) const +bool NzShaderProgram::SendFloat(int location, float value) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -432,12 +432,12 @@ bool NzShader::SendFloat(int location, float value) const return m_impl->SendFloat(location, value); } -bool NzShader::SendInteger(int location, int value) const +bool NzShaderProgram::SendInteger(int location, int value) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -448,7 +448,7 @@ bool NzShader::SendInteger(int location, int value) const return m_impl->SendInteger(location, value); } -bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) const +bool NzShaderProgram::SendMatrix(int location, const NzMatrix4d& matrix) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -459,7 +459,7 @@ bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) const if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -470,12 +470,12 @@ bool NzShader::SendMatrix(int location, const NzMatrix4d& matrix) const return m_impl->SendMatrix(location, matrix); } -bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) const +bool NzShaderProgram::SendMatrix(int location, const NzMatrix4f& matrix) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -486,12 +486,12 @@ bool NzShader::SendMatrix(int location, const NzMatrix4f& matrix) const return m_impl->SendMatrix(location, matrix); } -bool NzShader::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) const +bool NzShaderProgram::SendTexture(int location, const NzTexture* texture, nzUInt8* textureUnit) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -502,7 +502,7 @@ bool NzShader::SendTexture(int location, const NzTexture* texture, nzUInt8* text return m_impl->SendTexture(location, texture, textureUnit); } -bool NzShader::SendVector(int location, const NzVector2d& vector) const +bool NzShaderProgram::SendVector(int location, const NzVector2d& vector) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -513,7 +513,7 @@ bool NzShader::SendVector(int location, const NzVector2d& vector) const if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -524,12 +524,12 @@ bool NzShader::SendVector(int location, const NzVector2d& vector) const return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector2f& vector) const +bool NzShaderProgram::SendVector(int location, const NzVector2f& vector) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -540,7 +540,7 @@ bool NzShader::SendVector(int location, const NzVector2f& vector) const return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector3d& vector) const +bool NzShaderProgram::SendVector(int location, const NzVector3d& vector) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -551,7 +551,7 @@ bool NzShader::SendVector(int location, const NzVector3d& vector) const if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -562,12 +562,12 @@ bool NzShader::SendVector(int location, const NzVector3d& vector) const return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector3f& vector) const +bool NzShaderProgram::SendVector(int location, const NzVector3f& vector) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -578,7 +578,7 @@ bool NzShader::SendVector(int location, const NzVector3f& vector) const return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector4d& vector) const +bool NzShaderProgram::SendVector(int location, const NzVector4d& vector) const { #if NAZARA_RENDERER_SAFE if (!NzRenderer::HasCapability(nzRendererCap_FP64)) @@ -589,7 +589,7 @@ bool NzShader::SendVector(int location, const NzVector4d& vector) const if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -600,12 +600,12 @@ bool NzShader::SendVector(int location, const NzVector4d& vector) const return m_impl->SendVector(location, vector); } -bool NzShader::SendVector(int location, const NzVector4f& vector) const +bool NzShaderProgram::SendVector(int location, const NzVector4f& vector) const { #if NAZARA_RENDERER_SAFE if (!m_impl) { - NazaraError("Shader not created"); + NazaraError("Program not created"); return false; } #endif @@ -616,22 +616,22 @@ bool NzShader::SendVector(int location, const NzVector4f& vector) const return m_impl->SendVector(location, vector); } -void NzShader::SetFlags(nzUInt32 flags) +void NzShaderProgram::SetFlags(nzUInt32 flags) { m_flags = flags; } -NzShader& NzShader::operator=(NzShader&& shader) +NzShaderProgram& NzShaderProgram::operator=(NzShaderProgram&& program) { Destroy(); - m_impl = shader.m_impl; - shader.m_impl = nullptr; + m_impl = program.m_impl; + program.m_impl = nullptr; return *this; } -bool NzShader::IsLanguageSupported(nzShaderLanguage language) +bool NzShaderProgram::IsLanguageSupported(nzShaderLanguage language) { switch (language) { @@ -642,12 +642,12 @@ bool NzShader::IsLanguageSupported(nzShaderLanguage language) return true; default: - NazaraError("Shader language not handled (0x" + NzString::Number(language, 16) + ')'); + NazaraError("Program language not handled (0x" + NzString::Number(language, 16) + ')'); return false; } } -bool NzShader::IsTypeSupported(nzShaderType type) +bool NzShaderProgram::IsShaderTypeSupported(nzShaderType type) { switch (type) { @@ -659,7 +659,7 @@ bool NzShader::IsTypeSupported(nzShaderType type) return NzOpenGL::GetVersion() >= 320; default: - NazaraError("Shader type not handled (0x" + NzString::Number(type, 16) + ')'); + NazaraError("Program type not handled (0x" + NzString::Number(type, 16) + ')'); return false; } } diff --git a/src/Nazara/Renderer/ShaderManager.cpp b/src/Nazara/Renderer/ShaderProgramManager.cpp similarity index 91% rename from src/Nazara/Renderer/ShaderManager.cpp rename to src/Nazara/Renderer/ShaderProgramManager.cpp index 705a56836..e7ee06d87 100644 --- a/src/Nazara/Renderer/ShaderManager.cpp +++ b/src/Nazara/Renderer/ShaderProgramManager.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include #include @@ -14,7 +14,7 @@ namespace { struct ParamsHash { - std::size_t operator()(const NzShaderManagerParams& params) const + std::size_t operator()(const NzShaderProgramManagerParams& params) const { static_assert(nzShaderTarget_Max < 0x4, "Maximum shader target takes more than 2 bits"); @@ -50,7 +50,7 @@ namespace struct ParamsEquality { - bool operator()(const NzShaderManagerParams& first, const NzShaderManagerParams& second) const + bool operator()(const NzShaderProgramManagerParams& first, const NzShaderProgramManagerParams& second) const { if (first.target != second.target || first.flags != second.flags) return false; @@ -58,10 +58,10 @@ namespace switch (first.target) { case nzShaderTarget_FullscreenQuad: - return std::memcmp(&first.fullscreenQuad, &second.fullscreenQuad, sizeof(NzShaderManagerParams::FullscreenQuad)) == 0; + return std::memcmp(&first.fullscreenQuad, &second.fullscreenQuad, sizeof(NzShaderProgramManagerParams::FullscreenQuad)) == 0; case nzShaderTarget_Model: - return std::memcmp(&first.model, &second.model, sizeof(NzShaderManagerParams::Model)) == 0; + return std::memcmp(&first.model, &second.model, sizeof(NzShaderProgramManagerParams::Model)) == 0; case nzShaderTarget_None: return true; @@ -71,7 +71,7 @@ namespace } }; - std::unordered_map s_shaders; + std::unordered_map s_programs; NzString s_inKW; NzString s_outKW; NzString s_fragmentColorKW; @@ -81,33 +81,33 @@ namespace unsigned int s_glslVersion; } -const NzShader* NzShaderManager::Get(const NzShaderManagerParams& params) +const NzShaderProgram* NzShaderProgramManager::Get(const NzShaderProgramManagerParams& params) { - auto it = s_shaders.find(params); - if (it == s_shaders.end()) + auto it = s_programs.find(params); + if (it == s_programs.end()) { - // Alors nous gébérons le shader - NzShader* shader = GenerateShader(params); - if (!shader) + // Alors nous gébérons le programme + NzShaderProgram* program = GenerateProgram(params); + if (!program) { - NazaraWarning("Failed to build shader, using default one..."); + NazaraWarning("Failed to build program, using default one..."); - NzShaderManagerParams defaultParams; + NzShaderProgramManagerParams defaultParams; defaultParams.flags = params.flags; defaultParams.target = nzShaderTarget_None; - shader = s_shaders[defaultParams]; // Shader par défaut + program = s_programs[defaultParams]; // Shader par défaut } - s_shaders[params] = shader; + s_programs[params] = program; - return shader; + return program; } else return it->second; } -NzString NzShaderManager::BuildFragmentCode(const NzShaderManagerParams& params) +NzString NzShaderProgramManager::BuildFragmentCode(const NzShaderProgramManagerParams& params) { #ifdef NAZARA_DEBUG if (params.target > nzShaderTarget_Max) @@ -570,7 +570,7 @@ NzString NzShaderManager::BuildFragmentCode(const NzShaderManagerParams& params) return source; } -NzString NzShaderManager::BuildVertexCode(const NzShaderManagerParams& params) +NzString NzShaderProgramManager::BuildVertexCode(const NzShaderProgramManagerParams& params) { #ifdef NAZARA_DEBUG if (params.target > nzShaderTarget_Max) @@ -759,45 +759,45 @@ NzString NzShaderManager::BuildVertexCode(const NzShaderManagerParams& params) return source; } -NzShader* NzShaderManager::GenerateShader(const NzShaderManagerParams& params) +NzShaderProgram* NzShaderProgramManager::GenerateProgram(const NzShaderProgramManagerParams& params) { - std::unique_ptr shader(new NzShader); - shader->SetPersistent(false); + std::unique_ptr program(new NzShaderProgram); + program->SetPersistent(false); - if (!shader->Create(nzShaderLanguage_GLSL)) + if (!program->Create(nzShaderLanguage_GLSL)) { - NazaraError("Failed to create shader"); + NazaraError("Failed to create program"); return nullptr; } NzString fragmentSource = BuildFragmentCode(params); NazaraDebug("Fragment shader source:\n" + fragmentSource); - if (!shader->Load(nzShaderType_Fragment, fragmentSource)) + if (!program->LoadShader(nzShaderType_Fragment, fragmentSource)) { - NazaraError("Failed to load fragment shader: " + shader->GetLog()); + NazaraError("Failed to load fragment shader: " + program->GetLog()); NazaraNotice("Source:\n" + fragmentSource); return nullptr; } NzString vertexSource = BuildVertexCode(params); NazaraDebug("Vertex shader source:\n" + vertexSource); - if (!shader->Load(nzShaderType_Vertex, vertexSource)) + if (!program->LoadShader(nzShaderType_Vertex, vertexSource)) { - NazaraError("Failed to load vertex shader: " + shader->GetLog()); + NazaraError("Failed to load vertex shader: " + program->GetLog()); NazaraNotice("Source:\n" + vertexSource); return nullptr; } - if (!shader->Compile()) + if (!program->Compile()) { - NazaraError("Failed to compile shader: " + shader->GetLog()); + NazaraError("Failed to compile program: " + program->GetLog()); return nullptr; } - return shader.release(); + return program.release(); } -bool NzShaderManager::Initialize() +bool NzShaderProgramManager::Initialize() { s_glslVersion = NzOpenGL::GetGLSLVersion(); s_earlyFragmentTest = (s_glslVersion >= 420 || NzOpenGL::IsSupported(nzOpenGLExtension_Shader_ImageLoadStore)); @@ -808,29 +808,29 @@ bool NzShaderManager::Initialize() s_outKW = (s_glsl140) ? "out" : "varying"; s_textureLookupKW = (s_glsl140) ? "texture" : "texture2D"; - NzShaderManagerParams params; + NzShaderProgramManagerParams params; params.target = nzShaderTarget_None; for (unsigned int i = 0; i <= nzShaderFlags_Max; ++i) { params.flags = i; - NzShader* shader = GenerateShader(params); - if (!shader) + NzShaderProgram* program = GenerateProgram(params); + if (!program) { - NazaraError("Failed to generate default shader (flags: 0x" + NzString::Number(i, 16) + ')'); + NazaraError("Failed to generate default program (flags: 0x" + NzString::Number(i, 16) + ')'); Uninitialize(); return false; } - s_shaders[params] = shader; + s_programs[params] = program; } return true; } -void NzShaderManager::Uninitialize() +void NzShaderProgramManager::Uninitialize() { - s_shaders.clear(); + s_programs.clear(); s_fragmentColorKW.Clear(false); s_inKW.Clear(false); s_outKW.Clear(false);