Renamed Shader to ShaderProgram

Former-commit-id: 492b12d8bb48cff46ea46c83141b6d5a1540ff8f
This commit is contained in:
Lynix
2013-08-02 18:39:20 +02:00
parent ea6e9d7d33
commit 4b783f6f6f
28 changed files with 462 additions and 465 deletions

View File

@@ -4,21 +4,21 @@
#include <Nazara/Graphics/ColorBackGround.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/ShaderManager.hpp>
#include <Nazara/Renderer/ShaderProgramManager.hpp>
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
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();
}

View File

@@ -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();

View File

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

View File

@@ -8,7 +8,7 @@
#include <Nazara/Math/Basic.hpp>
#include <Nazara/Math/Sphere.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <cstring>
#include <Nazara/Graphics/Debug.hpp>
@@ -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()

View File

@@ -11,7 +11,6 @@
#include <Nazara/Graphics/Scene.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
#include <Nazara/Utility/VertexDeclaration.hpp>
@@ -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<NzShader> shader(new NzShader(nzShaderLanguage_GLSL));
shader->SetPersistent(false);
std::unique_ptr<NzShaderProgram> 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);

View File

@@ -4,20 +4,20 @@
#include <Nazara/Graphics/TextureBackground.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/ShaderManager.hpp>
#include <Nazara/Renderer/ShaderProgramManager.hpp>
#include <memory>
#include <Nazara/Graphics/Debug.hpp>
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();