OpenGL class now uses CallOnExit class

Former-commit-id: c8c5bb7e50e73ba007e095eaf801fa7d5e3aa215
This commit is contained in:
Lynix 2014-03-06 09:54:17 +01:00
parent 67951074b1
commit cd73159d5b
1 changed files with 4 additions and 18 deletions

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp // For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Renderer/OpenGL.hpp> #include <Nazara/Renderer/OpenGL.hpp>
#include <Nazara/Core/CallOnExit.hpp>
#include <Nazara/Core/Error.hpp> #include <Nazara/Core/Error.hpp>
#include <Nazara/Core/Log.hpp> #include <Nazara/Core/Log.hpp>
#include <Nazara/Math/Basic.hpp> #include <Nazara/Math/Basic.hpp>
@ -647,6 +648,8 @@ bool NzOpenGL::Initialize()
s_initialized = true; s_initialized = true;
NzCallOnExit onExit(NzOpenGL::Uninitialize);
// Le chargement des fonctions OpenGL nécessite un contexte OpenGL // Le chargement des fonctions OpenGL nécessite un contexte OpenGL
NzContextParameters parameters; NzContextParameters parameters;
parameters.majorVersion = 2; parameters.majorVersion = 2;
@ -667,8 +670,6 @@ bool NzOpenGL::Initialize()
if (!loadContext.Create(parameters)) if (!loadContext.Create(parameters))
{ {
NazaraError("Failed to create load context"); NazaraError("Failed to create load context");
Uninitialize();
return false; return false;
} }
@ -688,8 +689,6 @@ bool NzOpenGL::Initialize()
if (!glGetString) if (!glGetString)
{ {
NazaraError("Unable to load OpenGL: failed to load glGetString"); NazaraError("Unable to load OpenGL: failed to load glGetString");
Uninitialize();
return false; return false;
} }
@ -701,8 +700,6 @@ bool NzOpenGL::Initialize()
if (!version) if (!version)
{ {
NazaraError("Unable to retrieve OpenGL version"); NazaraError("Unable to retrieve OpenGL version");
Uninitialize();
return false; return false;
} }
@ -728,8 +725,6 @@ bool NzOpenGL::Initialize()
if (s_openglVersion < 200) if (s_openglVersion < 200)
{ {
NazaraError("OpenGL " + NzString::Number(major) + '.' + NzString::Number(minor) + " detected (2.0 required). Please upgrade your drivers or your video card"); NazaraError("OpenGL " + NzString::Number(major) + '.' + NzString::Number(minor) + " detected (2.0 required). Please upgrade your drivers or your video card");
Uninitialize();
return false; return false;
} }
@ -737,8 +732,6 @@ bool NzOpenGL::Initialize()
if (!version) if (!version)
{ {
NazaraError("Unable to retrieve GLSL version"); NazaraError("Unable to retrieve GLSL version");
Uninitialize();
return false; return false;
} }
@ -761,8 +754,6 @@ bool NzOpenGL::Initialize()
if (s_glslVersion < 110) if (s_glslVersion < 110)
{ {
NazaraError("GLSL version is too low, please upgrade your drivers or your video card"); NazaraError("GLSL version is too low, please upgrade your drivers or your video card");
Uninitialize();
return false; return false;
} }
@ -773,8 +764,6 @@ bool NzOpenGL::Initialize()
if (!loadContext.Create(parameters)) // Destruction implicite du premier contexte if (!loadContext.Create(parameters)) // Destruction implicite du premier contexte
{ {
NazaraError("Failed to create load context"); NazaraError("Failed to create load context");
Uninitialize();
return false; return false;
} }
@ -882,8 +871,6 @@ bool NzOpenGL::Initialize()
catch (const std::exception& e) catch (const std::exception& e)
{ {
NazaraError("Unable to load OpenGL: " + NzString(e.what())); NazaraError("Unable to load OpenGL: " + NzString(e.what()));
Uninitialize();
return false; return false;
} }
@ -1241,12 +1228,11 @@ bool NzOpenGL::Initialize()
if (!NzContext::Initialize()) if (!NzContext::Initialize())
{ {
NazaraError("Failed to initialize contexts"); NazaraError("Failed to initialize contexts");
Uninitialize();
return false; return false;
} }
// Le contexte OpenGL n'est plus assuré à partir d'ici // Le contexte OpenGL n'est plus assuré à partir d'ici
onExit.Reset();
return true; return true;
} }