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

@@ -6,7 +6,7 @@
#include <Nazara/Core/Color.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp>
#include <Nazara/Renderer/AbstractShader.hpp>
#include <Nazara/Renderer/AbstractShaderProgram.hpp>
#include <Nazara/Renderer/Config.hpp>
#include <Nazara/Renderer/Context.hpp>
#include <Nazara/Renderer/DebugDrawer.hpp>
@@ -14,8 +14,8 @@
#include <Nazara/Renderer/Material.hpp>
#include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Renderer/RenderTarget.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderManager.hpp>
#include <Nazara/Renderer/ShaderProgram.hpp>
#include <Nazara/Renderer/ShaderProgramManager.hpp>
#include <Nazara/Renderer/Loaders/Texture.hpp>
#include <Nazara/Utility/AbstractBuffer.hpp>
#include <Nazara/Utility/IndexBuffer.hpp>
@@ -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<nzMatrixType>(i));
shaderImpl->SendMatrix(unit.location, unit.matrix);
programImpl->SendMatrix(unit.location, unit.matrix);
}
}