DebugDrawer now use ShaderBuilder
Fixed demo not initializing debug drawer Former-commit-id: a14612a374507501496f895ef6ba94886db98ec9
This commit is contained in:
parent
c65e3d5def
commit
0a11e82432
|
|
@ -33,6 +33,8 @@ int main()
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NzDebugDrawer::Initialize();
|
||||||
|
|
||||||
// Maintenant nous pouvons utiliser le moteur comme bon nous semble, tout d'abord nous allons charger les ressources
|
// 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
|
// Charger une ressource se fait actuellement manuellement, mais un ResourceManager est à venir
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <Nazara/Renderer/DebugDrawer.hpp>
|
#include <Nazara/Renderer/DebugDrawer.hpp>
|
||||||
#include <Nazara/Renderer/Renderer.hpp>
|
#include <Nazara/Renderer/Renderer.hpp>
|
||||||
#include <Nazara/Renderer/Shader.hpp>
|
#include <Nazara/Renderer/Shader.hpp>
|
||||||
|
#include <Nazara/Renderer/ShaderBuilder.hpp>
|
||||||
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
#include <Nazara/Utility/AxisAlignedBox.hpp>
|
||||||
#include <Nazara/Utility/Skeleton.hpp>
|
#include <Nazara/Utility/Skeleton.hpp>
|
||||||
#include <Nazara/Utility/VertexBuffer.hpp>
|
#include <Nazara/Utility/VertexBuffer.hpp>
|
||||||
|
|
@ -19,7 +20,7 @@ namespace
|
||||||
{
|
{
|
||||||
static NzColor primaryColor = NzColor::Red;
|
static NzColor primaryColor = NzColor::Red;
|
||||||
static NzColor secondaryColor = NzColor::Green;
|
static NzColor secondaryColor = NzColor::Green;
|
||||||
static NzShader* shader = nullptr;
|
static const NzShader* shader = nullptr;
|
||||||
static NzVertexBuffer* vertexBuffer = nullptr;
|
static NzVertexBuffer* vertexBuffer = nullptr;
|
||||||
static NzVertexDeclaration* vertexDeclaration = nullptr;
|
static NzVertexDeclaration* vertexDeclaration = nullptr;
|
||||||
static bool depthTest = true;
|
static bool depthTest = true;
|
||||||
|
|
@ -241,69 +242,14 @@ bool NzDebugDrawer::Initialize()
|
||||||
{
|
{
|
||||||
// Shader
|
// Shader
|
||||||
{
|
{
|
||||||
const char* fragmentSource110 =
|
shader = NzShaderBuilder::Get(nzShaderBuilder_None);
|
||||||
"#version 110\n"
|
if (!shader)
|
||||||
"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))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load fragment shader");
|
NazaraError("Failed to build debug shader");
|
||||||
Uninitialize();
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shader->Load(nzShaderType_Vertex, (useGLSL140) ? vertexSource140 : vertexSource110))
|
colorLocation = shader->GetUniformLocation("DiffuseColor");
|
||||||
{
|
|
||||||
NazaraError("Failed to load vertex shader");
|
|
||||||
Uninitialize();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!shader->Compile())
|
|
||||||
{
|
|
||||||
NazaraError("Failed to compile shader");
|
|
||||||
Uninitialize();
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
colorLocation = shader->GetUniformLocation("color");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// VertexDeclaration
|
// VertexDeclaration
|
||||||
|
|
@ -393,12 +339,6 @@ void NzDebugDrawer::SetSecondaryColor(const NzColor& color)
|
||||||
|
|
||||||
void NzDebugDrawer::Uninitialize()
|
void NzDebugDrawer::Uninitialize()
|
||||||
{
|
{
|
||||||
if (shader)
|
|
||||||
{
|
|
||||||
delete shader;
|
|
||||||
shader = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vertexBuffer)
|
if (vertexBuffer)
|
||||||
{
|
{
|
||||||
delete vertexBuffer;
|
delete vertexBuffer;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue