DebugDrawer now use ShaderBuilder

Fixed demo not initializing debug drawer


Former-commit-id: a14612a374507501496f895ef6ba94886db98ec9
This commit is contained in:
Lynix 2012-12-25 12:29:19 +01:00
parent c65e3d5def
commit 0a11e82432
2 changed files with 8 additions and 66 deletions

View File

@ -33,6 +33,8 @@ int main()
return EXIT_FAILURE;
}
NzDebugDrawer::Initialize();
// Maintenant nous pouvons utiliser le moteur comme bon nous semble, tout d'abord nous allons charger les ressources
// Charger une ressource se fait actuellement manuellement, mais un ResourceManager est à venir

View File

@ -6,6 +6,7 @@
#include <Nazara/Renderer/DebugDrawer.hpp>
#include <Nazara/Renderer/Renderer.hpp>
#include <Nazara/Renderer/Shader.hpp>
#include <Nazara/Renderer/ShaderBuilder.hpp>
#include <Nazara/Utility/AxisAlignedBox.hpp>
#include <Nazara/Utility/Skeleton.hpp>
#include <Nazara/Utility/VertexBuffer.hpp>
@ -19,7 +20,7 @@ namespace
{
static NzColor primaryColor = NzColor::Red;
static NzColor secondaryColor = NzColor::Green;
static NzShader* shader = nullptr;
static const NzShader* shader = nullptr;
static NzVertexBuffer* vertexBuffer = nullptr;
static NzVertexDeclaration* vertexDeclaration = nullptr;
static bool depthTest = true;
@ -241,69 +242,14 @@ bool NzDebugDrawer::Initialize()
{
// Shader
{
const char* fragmentSource110 =
"#version 110\n"
"uniform vec3 color;\n"
"void main()\n"
"{\n"
" gl_FragColor = vec4(color, 1.0);\n"
"}\n";
const char* fragmentSource140 =
"#version 140\n"
"uniform vec3 color;\n"
"out vec4 RenderTarget0;\n"
"void main()\n"
"{\n"
" RenderTarget0 = vec4(color, 1.0);\n"
"}\n";
const char* vertexSource110 =
"#version 110\n"
"attribute vec3 Position;\n"
"uniform mat4 WorldViewProjMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjMatrix * vec4(Position, 1.0);\n"
"}\n";
const char* vertexSource140 =
"#version 140\n"
"in vec3 Position;\n"
"uniform mat4 WorldViewProjMatrix;\n"
"void main()\n"
"{\n"
" gl_Position = WorldViewProjMatrix * vec4(Position, 1.0);\n"
"}\n";
bool useGLSL140 = (NzOpenGL::GetVersion() >= 310);
shader = new NzShader(nzShaderLanguage_GLSL);
if (!shader->Load(nzShaderType_Fragment, (useGLSL140) ? fragmentSource140 : fragmentSource110))
shader = NzShaderBuilder::Get(nzShaderBuilder_None);
if (!shader)
{
NazaraError("Failed to load fragment shader");
Uninitialize();
NazaraError("Failed to build debug shader");
return false;
}
if (!shader->Load(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
{
NazaraError("Failed to load vertex shader");
Uninitialize();
return false;
}
if (!shader->Compile())
{
NazaraError("Failed to compile shader");
Uninitialize();
return false;
}
colorLocation = shader->GetUniformLocation("color");
colorLocation = shader->GetUniformLocation("DiffuseColor");
}
// VertexDeclaration
@ -393,12 +339,6 @@ void NzDebugDrawer::SetSecondaryColor(const NzColor& color)
void NzDebugDrawer::Uninitialize()
{
if (shader)
{
delete shader;
shader = nullptr;
}
if (vertexBuffer)
{
delete vertexBuffer;